Merge branch 'develop' of https://github.com/PHPOffice/PHPWord into patch-1

This commit is contained in:
Antoine de Troostembergh 2021-02-05 21:12:43 +01:00
commit 83ba5a7b57
119 changed files with 4480 additions and 350 deletions

View File

@ -3,6 +3,12 @@ build:
analysis: analysis:
tests: tests:
override: [php-scrutinizer-run] override: [php-scrutinizer-run]
environment:
php:
version: '7.4'
pecl_extensions:
- zip
filter: filter:
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ] excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ]

View File

@ -11,29 +11,26 @@ php:
- 7.1 - 7.1
- 7.2 - 7.2
- 7.3 - 7.3
- 7.4snapshot - 7.4
- 8.0
matrix: matrix:
include: include:
- php: 5.3 - php: 5.3
dist: precise dist: precise
env: COMPOSER_MEMORY_LIMIT=3G
- php: 5.4 - php: 5.4
dist: trusty dist: trusty
- php: 5.5 - php: 5.5
dist: trusty dist: trusty
- php: 7.0 - php: 7.0
env: COVERAGE=1 env: COVERAGE=1
- php: 7.3
env: DEPENDENCIES="--ignore-platform-reqs"
exclude: exclude:
- php: 5.3 - php: 5.3
dist: xenial
- php: 5.4 - php: 5.4
dist: xenial
- php: 5.5 - php: 5.5
- php: 7.0 dist: xenial
- php: 7.3
allow_failures:
- php: 7.4snapshot
cache: cache:
directories: directories:
@ -55,7 +52,31 @@ before_script:
- if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini || echo "xdebug not available" ; fi - if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini || echo "xdebug not available" ; fi
## Composer ## Composer
- composer self-update - composer self-update
## Composer in PHP versions 5.x requires 3 GB memory
- if [ ${TRAVIS_PHP_VERSION:0:2} == "5." ]; then export COMPOSER_MEMORY_LIMIT=3G ; fi
## PHP 8 require PHPUnit 8 (ugly hack for support PHPUnit 7 and 8 together)
- |
if [[ ${TRAVIS_PHP_VERSION:0:2} == "8." ]] || [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
travis_wait composer remove phpunit/phpunit --dev --no-update --no-interaction
travis_wait composer require phpunit/phpunit ^8.0 --dev --no-update
fi
## Install composer packages
- travis_wait composer install --prefer-source $(if [ -n "$DEPENDENCIES" ]; then echo $DEPENDENCIES; fi) - travis_wait composer install --prefer-source $(if [ -n "$DEPENDENCIES" ]; then echo $DEPENDENCIES; fi)
## PHP 8 require PHPUnit 8 (ugly hack for support PHPUnit 7 and 8 together)
- |
if [[ ${TRAVIS_PHP_VERSION:0:2} == "8." ]] || [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUpBeforeClass()$/function setUpBeforeClass(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDownAfterClass()$/function tearDownAfterClass(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUp()$/function setUp(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDown()$/function tearDown(): void/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertContains(/->assertStringContainsString(/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertNotContains(/->assertStringNotContainsString(/' {} \;
find ./tests/ -name "*.php" -type f -exec sed -i -e "s/->assertInternalType('array', /->assertIsArray(/" {} \;
sed -i "s/\$this->addWarning('The @expectedException,/\/\/\$this->addWarning('The @expectedException,/" ./vendor/phpunit/phpunit/src/Framework/TestCase.php
sed -i "s/self::createWarning('The optional \$delta/\/\/self::createWarning('The optional \$delta/" ./vendor/phpunit/phpunit/src/Framework/Assert.php
fi
## PHPDocumentor ## PHPDocumentor
##- mkdir -p build/docs ##- mkdir -p build/docs
- mkdir -p build/coverage - mkdir -p build/coverage

View File

@ -62,8 +62,7 @@ PHPWord requires the following:
- PHP 5.3.3+ - PHP 5.3.3+
- [XML Parser extension](http://www.php.net/manual/en/xml.installation.php) - [XML Parser extension](http://www.php.net/manual/en/xml.installation.php)
- [Zend\Escaper component](http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html) - [Laminas Escaper component](https://docs.laminas.dev/laminas-escaper/intro/)
- [Zend\Stdlib component](http://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html)
- [Zip extension](http://php.net/manual/en/book.zip.php) (optional, used to write OOXML and ODF) - [Zip extension](http://php.net/manual/en/book.zip.php) (optional, used to write OOXML and ODF)
- [GD extension](http://php.net/manual/en/book.image.php) (optional, used to add images) - [GD extension](http://php.net/manual/en/book.image.php) (optional, used to add images)
- [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write OOXML and ODF) - [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write OOXML and ODF)

View File

@ -58,24 +58,26 @@
"fix": "Fixes issues found by PHP-CS" "fix": "Fixes issues found by PHP-CS"
}, },
"require": { "require": {
"php": "^5.3.3 || ^7.0", "php": "^5.3.3 || ^7.0 || ^8.0",
"ext-xml": "*", "ext-xml": "*",
"zendframework/zend-escaper": "^2.2", "laminas/laminas-escaper": "^2.2"
"phpoffice/common": "^0.2.9"
}, },
"require-dev": { "require-dev": {
"ext-zip": "*", "ext-zip": "*",
"ext-gd": "*", "ext-gd": "*",
"phpunit/phpunit": "^4.8.36 || ^7.0", "phpunit/phpunit": "^4.8.36 || ^7.0",
"squizlabs/php_codesniffer": "^2.9", "squizlabs/php_codesniffer": "^2.9 || ^3.5",
"friendsofphp/php-cs-fixer": "^2.2", "friendsofphp/php-cs-fixer": "^2.2",
"phpmd/phpmd": "2.*", "phpmd/phpmd": "2.*",
"phploc/phploc": "2.* || 3.* || 4.*", "phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*",
"dompdf/dompdf":"0.8.*", "dompdf/dompdf":"0.8.* || 1.0.*",
"tecnickcom/tcpdf": "6.*", "tecnickcom/tcpdf": "6.*",
"mpdf/mpdf": "5.7.4 || 6.* || 7.*", "mpdf/mpdf": "5.7.4 || 6.* || 7.* || 8.*",
"php-coveralls/php-coveralls": "1.1.0 || ^2.0" "php-coveralls/php-coveralls": "1.1.0 || ^2.0"
}, },
"replace": {
"laminas/laminas-zendframework-bridge": "*"
},
"suggest": { "suggest": {
"ext-zip": "Allows writing OOXML and ODF", "ext-zip": "Allows writing OOXML and ODF",
"ext-gd2": "Allows adding images", "ext-gd2": "Allows adding images",

View File

@ -130,6 +130,16 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); \PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
Default Paper
~~~~~~~~~~~~~
By default, all sections of the document will print on A4 paper.
You can alter the default paper by using the following function:
.. code-block:: php
\PhpOffice\PhpWord\Settings::setDefaultPaper('Letter');
Default font Default font
~~~~~~~~~~~~ ~~~~~~~~~~~~

View File

@ -10,9 +10,7 @@ Mandatory:
- PHP 5.3.3+ - PHP 5.3.3+
- `XML Parser <http://www.php.net/manual/en/xml.installation.php>`__ extension - `XML Parser <http://www.php.net/manual/en/xml.installation.php>`__ extension
- `Zend\\Escaper <http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html>`__ component - `Laminas Escaper <https://docs.laminas.dev/laminas-escaper/intro/>`__ component
- Zend\\Stdlib component
- `Zend\\Validator <http://framework.zend.com/manual/current/en/modules/zend.validator.html>`__ component
Optional: Optional:

View File

@ -190,7 +190,7 @@ Finds a row in a table row identified by `$search` param and clones it as many t
['userId' => 1, 'userName' => 'Batman', 'userAddress' => 'Gotham City'], ['userId' => 1, 'userName' => 'Batman', 'userAddress' => 'Gotham City'],
['userId' => 2, 'userName' => 'Superman', 'userAddress' => 'Metropolis'], ['userId' => 2, 'userName' => 'Superman', 'userAddress' => 'Metropolis'],
]; ];
$templateProcessor->cloneRowAndSetValues('userId', ); $templateProcessor->cloneRowAndSetValues('userId', $values);
Will result in Will result in

View File

@ -5,6 +5,8 @@
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" 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"> xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/naming.xml"> <rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
<exclude name="ShortClassName" />
<exclude name="LongVariable" /> <exclude name="LongVariable" />
</rule> </rule>
<rule ref="rulesets/naming.xml/LongVariable"> <rule ref="rulesets/naming.xml/LongVariable">

View File

@ -14,3 +14,7 @@ outputEscapingEnabled = false
defaultFontName = Arial defaultFontName = Arial
defaultFontSize = 10 defaultFontSize = 10
[Paper]
defaultPaper = "A4"

View File

@ -109,6 +109,7 @@ abstract class AbstractContainer extends AbstractElement
} else { } else {
// All other elements // All other elements
array_unshift($args, $element); // Prepend element name to the beginning of args array array_unshift($args, $element); // Prepend element name to the beginning of args array
return call_user_func_array(array($this, 'addElement'), $args); return call_user_func_array(array($this, 'addElement'), $args);
} }
} }

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Shared\Text as SharedText;
/** /**
* Bookmark element * Bookmark element
@ -45,7 +45,7 @@ class Bookmark extends AbstractElement
*/ */
public function __construct($name = '') public function __construct($name = '')
{ {
$this->name = CommonText::toUTF8($name); $this->name = SharedText::toUTF8($name);
} }
/** /**

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Shared\Text as SharedText;
/** /**
* Check box element * Check box element
@ -55,7 +55,7 @@ class CheckBox extends Text
*/ */
public function setName($name) public function setName($name)
{ {
$this->name = CommonText::toUTF8($name); $this->name = SharedText::toUTF8($name);
return $this; return $this;
} }

View File

@ -454,7 +454,7 @@ class Image extends AbstractElement
} else { } else {
$this->sourceType = self::SOURCE_GD; $this->sourceType = self::SOURCE_GD;
} }
} elseif (@file_exists($this->source)) { } elseif ((strpos($this->source, chr(0)) === false) && @file_exists($this->source)) {
$this->memoryImage = false; $this->memoryImage = false;
$this->sourceType = self::SOURCE_LOCAL; $this->sourceType = self::SOURCE_LOCAL;
} else { } else {

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
@ -79,8 +79,8 @@ class Link extends AbstractElement
*/ */
public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false) public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
{ {
$this->source = CommonText::toUTF8($source); $this->source = SharedText::toUTF8($source);
$this->text = is_null($text) ? $this->source : CommonText::toUTF8($text); $this->text = is_null($text) ? $this->source : SharedText::toUTF8($text);
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->internal = $internal; $this->internal = $internal;

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/** /**
@ -57,7 +57,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(CommonText::toUTF8($text), $fontStyle, $paragraphStyle); $this->textObject = new Text(SharedText::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

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
@ -59,7 +59,7 @@ class PreserveText extends AbstractElement
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->text = CommonText::toUTF8($text); $this->text = SharedText::toUTF8($text);
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $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

@ -157,6 +157,8 @@ class Section extends AbstractContainer
* @deprecated Use the `getFootnoteProperties` method instead * @deprecated Use the `getFootnoteProperties` method instead
* *
* @return FootnoteProperties * @return FootnoteProperties
*
* @codeCoverageIgnore
*/ */
public function getFootnotePropoperties() public function getFootnotePropoperties()
{ {

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
@ -136,7 +136,7 @@ class Text extends AbstractElement
*/ */
public function setText($text) public function setText($text)
{ {
$this->text = CommonText::toUTF8($text); $this->text = SharedText::toUTF8($text);
return $this; return $this;
} }

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
/** /**
@ -62,7 +62,7 @@ class Title extends AbstractElement
public function __construct($text, $depth = 1) public function __construct($text, $depth = 1)
{ {
if (is_string($text)) { if (is_string($text)) {
$this->text = CommonText::toUTF8($text); $this->text = SharedText::toUTF8($text);
} elseif ($text instanceof TextRun) { } elseif ($text instanceof TextRun) {
$this->text = $text; $this->text = $text;
} else { } else {

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Metadata; namespace PhpOffice\PhpWord\Metadata;
use PhpOffice\Common\Microsoft\PasswordEncoder; use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder;
use PhpOffice\PhpWord\SimpleType\DocProtect; use PhpOffice\PhpWord\SimpleType\DocProtect;
/** /**

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader; namespace PhpOffice\PhpWord\Reader;
use PhpOffice\Common\Drawing;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Drawing;
use PhpOffice\PhpWord\Shared\OLERead; use PhpOffice\PhpWord\Shared\OLERead;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
@ -1581,7 +1581,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
// Variables // Variables
$sprmCPicLocation = null; $sprmCPicLocation = null;
$sprmCFData = null; $sprmCFData = null;
$sprmCFSpec = null; //$sprmCFSpec = null;
do { do {
// Variables // Variables
@ -1830,7 +1830,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
break; break;
// sprmCFSpec // sprmCFSpec
case 0x55: case 0x55:
$sprmCFSpec = $operand; //$sprmCFSpec = $operand;
break; break;
// sprmCFtcBi // sprmCFtcBi
case 0x5E: case 0x5E:
@ -2094,11 +2094,11 @@ class MsDoc extends AbstractReader implements ReaderInterface
$sprmCPicLocation += 1; $sprmCPicLocation += 1;
// stPicName // stPicName
$stPicName = ''; //$stPicName = '';
for ($inc = 0; $inc <= $cchPicName; $inc++) { for ($inc = 0; $inc <= $cchPicName; $inc++) {
$chr = self::getInt1d($this->dataData, $sprmCPicLocation); //$chr = self::getInt1d($this->dataData, $sprmCPicLocation);
$sprmCPicLocation += 1; $sprmCPicLocation += 1;
$stPicName .= chr($chr); //$stPicName .= chr($chr);
} }
} }
@ -2143,11 +2143,11 @@ class MsDoc extends AbstractReader implements ReaderInterface
$sprmCPicLocation += 1; $sprmCPicLocation += 1;
// nameData // nameData
if ($cbName > 0) { if ($cbName > 0) {
$nameData = ''; //$nameData = '';
for ($inc = 0; $inc <= ($cbName / 2); $inc++) { for ($inc = 0; $inc <= ($cbName / 2); $inc++) {
$chr = self::getInt2d($this->dataData, $sprmCPicLocation); //$chr = self::getInt2d($this->dataData, $sprmCPicLocation);
$sprmCPicLocation += 2; $sprmCPicLocation += 2;
$nameData .= chr($chr); //$nameData .= chr($chr);
} }
} }
// embeddedBlip // embeddedBlip

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader; namespace PhpOffice\PhpWord\Reader;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Reader for ODText * Reader for ODText

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Reader\ODText; namespace PhpOffice\PhpWord\Reader\ODText;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Content reader * Content reader

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader\ODText; namespace PhpOffice\PhpWord\Reader\ODText;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Meta reader * Meta reader

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader; namespace PhpOffice\PhpWord\Reader;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Shared\ZipArchive; use PhpOffice\PhpWord\Shared\ZipArchive;
/** /**

View File

@ -17,12 +17,12 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType; use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
use PhpOffice\PhpWord\Element\AbstractContainer; use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Abstract part reader * Abstract part reader
@ -95,7 +95,7 @@ abstract class AbstractPart
/** /**
* Read w:p. * Read w:p.
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent * @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param string $docPart * @param string $docPart
@ -202,7 +202,7 @@ abstract class AbstractPart
/** /**
* Read w:r. * Read w:r.
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent * @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param string $docPart * @param string $docPart
@ -292,6 +292,19 @@ abstract class AbstractPart
$parent->addTextBreak(); $parent->addTextBreak();
} elseif ($node->nodeName == 'w:tab') { } elseif ($node->nodeName == 'w:tab') {
$parent->addText("\t"); $parent->addText("\t");
} elseif ($node->nodeName == 'mc:AlternateContent') {
if ($node->hasChildNodes()) {
// Get fallback instead of mc:Choice to make sure it is compatible
$fallbackElements = $node->getElementsByTagName('Fallback');
if ($fallbackElements->length) {
$fallback = $fallbackElements->item(0);
// TextRun
$textContent = htmlspecialchars($fallback->nodeValue, ENT_QUOTES, 'UTF-8');
$parent->addText($textContent, $fontStyle, $paragraphStyle);
}
}
} elseif ($node->nodeName == 'w:t' || $node->nodeName == 'w:delText') { } elseif ($node->nodeName == 'w:t' || $node->nodeName == 'w:delText') {
// TextRun // TextRun
$textContent = htmlspecialchars($xmlReader->getValue('.', $node), ENT_QUOTES, 'UTF-8'); $textContent = htmlspecialchars($xmlReader->getValue('.', $node), ENT_QUOTES, 'UTF-8');
@ -320,7 +333,7 @@ abstract class AbstractPart
/** /**
* Read w:tbl. * Read w:tbl.
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @param mixed $parent * @param mixed $parent
* @param string $docPart * @param string $docPart
@ -378,7 +391,7 @@ abstract class AbstractPart
/** /**
* Read w:pPr. * Read w:pPr.
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @return array|null * @return array|null
*/ */
@ -413,7 +426,7 @@ abstract class AbstractPart
/** /**
* Read w:rPr * Read w:rPr
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @return array|null * @return array|null
*/ */
@ -459,7 +472,7 @@ abstract class AbstractPart
/** /**
* Read w:tblPr * Read w:tblPr
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @return string|array|null * @return string|array|null
* @todo Capture w:tblStylePr w:type="firstRow" * @todo Capture w:tblStylePr w:type="firstRow"
@ -509,7 +522,7 @@ abstract class AbstractPart
/** /**
* Read w:tblpPr * Read w:tblpPr
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @return array * @return array
*/ */
@ -534,7 +547,7 @@ abstract class AbstractPart
/** /**
* Read w:tblInd * Read w:tblInd
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @return TblWidthComplexType * @return TblWidthComplexType
*/ */
@ -552,7 +565,7 @@ abstract class AbstractPart
/** /**
* Read w:tcPr * Read w:tcPr
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @return array * @return array
*/ */
@ -573,11 +586,11 @@ abstract class AbstractPart
* Returns the first child element found * Returns the first child element found
* *
* @param XMLReader $xmlReader * @param XMLReader $xmlReader
* @param \DOMElement $parentNode * @param \DOMElement|null $parentNode
* @param string|array $elements * @param string|array|null $elements
* @return string|null * @return string|null
*/ */
private function findPossibleElement(XMLReader $xmlReader, \DOMElement $parentNode = null, $elements) private function findPossibleElement(XMLReader $xmlReader, \DOMElement $parentNode = null, $elements = null)
{ {
if (is_array($elements)) { if (is_array($elements)) {
//if element is an array, we take the first element that exists in the XML //if element is an array, we take the first element that exists in the XML
@ -620,7 +633,7 @@ abstract class AbstractPart
/** /**
* Read style definition * Read style definition
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $parentNode * @param \DOMElement $parentNode
* @param array $styleDefs * @param array $styleDefs
* @ignoreScrutinizerPatch * @ignoreScrutinizerPatch

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Core properties reader * Core properties reader

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\Metadata\DocInfo; use PhpOffice\PhpWord\Metadata\DocInfo;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Custom properties reader * Custom properties reader

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Document reader * Document reader
@ -97,7 +97,7 @@ class Document extends AbstractPart
/** /**
* Read w:sectPr * Read w:sectPr
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode * @param \DOMElement $domNode
* @ignoreScrutinizerPatch * @ignoreScrutinizerPatch
* @return array * @return array
@ -141,7 +141,7 @@ class Document extends AbstractPart
/** /**
* Read w:p node. * Read w:p node.
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $node * @param \DOMElement $node
* @param \PhpOffice\PhpWord\Element\Section &$section * @param \PhpOffice\PhpWord\Element\Section &$section
* *
@ -170,7 +170,7 @@ class Document extends AbstractPart
/** /**
* Read w:sectPr node. * Read w:sectPr node.
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $node * @param \DOMElement $node
* @param \PhpOffice\PhpWord\Element\Section &$section * @param \PhpOffice\PhpWord\Element\Section &$section
*/ */

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Footnotes reader * Footnotes reader

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/** /**
* Numbering reader * Numbering reader
@ -89,7 +89,7 @@ class Numbering extends AbstractPart
/** /**
* Read numbering level definition from w:abstractNum and w:num * Read numbering level definition from w:abstractNum and w:num
* *
* @param \PhpOffice\Common\XMLReader $xmlReader * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $subnode * @param \DOMElement $subnode
* @param int $levelId * @param int $levelId
* @return array * @return array

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\ComplexType\TrackChangesView; use PhpOffice\PhpWord\ComplexType\TrackChangesView;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\Style\Language;
/** /**

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader\Word2007; namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\Style\Language;
/** /**

View File

@ -70,6 +70,7 @@ class Settings
const DEFAULT_FONT_SIZE = 10; const DEFAULT_FONT_SIZE = 10;
const DEFAULT_FONT_COLOR = '000000'; const DEFAULT_FONT_COLOR = '000000';
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
const DEFAULT_PAPER = 'A4';
/** /**
* Compatibility option for XMLWriter * Compatibility option for XMLWriter
@ -119,6 +120,12 @@ class Settings
*/ */
private static $defaultFontSize = self::DEFAULT_FONT_SIZE; private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
/**
* Default paper
* @var string
*/
private static $defaultPaper = self::DEFAULT_PAPER;
/** /**
* The user defined temporary directory. * The user defined temporary directory.
* *
@ -432,6 +439,33 @@ class Settings
return $config; return $config;
} }
/**
* Get default paper
*
* @return string
*/
public static function getDefaultPaper()
{
return self::$defaultPaper;
}
/**
* Set default paper
*
* @param string $value
* @return bool
*/
public static function setDefaultPaper($value)
{
if (is_string($value) && trim($value) !== '') {
self::$defaultPaper = $value;
return true;
}
return false;
}
/** /**
* Return the compatibility option used by the XMLWriter * Return the compatibility option used by the XMLWriter
* *

View File

@ -338,9 +338,9 @@ class Converter
return false; return false;
} }
$red = hexdec($red); $red = ctype_xdigit($red) ? hexdec($red) : 0;
$green = hexdec($green); $green = ctype_xdigit($green) ? hexdec($green) : 0;
$blue = hexdec($blue); $blue = ctype_xdigit($blue) ? hexdec($blue) : 0;
return array($red, $green, $blue); return array($red, $green, $blue);
} }

View File

@ -0,0 +1,248 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Drawing
*/
class Drawing
{
const DPI_96 = 96;
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int
*/
public static function pixelsToEmu($pValue = 0)
{
return round($pValue * 9525);
}
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int
*/
public static function emuToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 9525);
}
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return float
*/
public static function pixelsToPoints($pValue = 0)
{
return $pValue * 0.67777777;
}
/**
* Convert points width to centimeters
*
* @param int $pValue Value in points
* @return float
*/
public static function pointsToCentimeters($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return (($pValue * 1.333333333) / self::DPI_96) * 2.54;
}
/**
* Convert points width to pixels
*
* @param int $pValue Value in points
* @return float
*/
public static function pointsToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 1.333333333;
}
/**
* Convert pixels to centimeters
*
* @param int $pValue Value in pixels
* @return float
*/
public static function pixelsToCentimeters($pValue = 0)
{
//return $pValue * 0.028;
return ($pValue / self::DPI_96) * 2.54;
}
/**
* Convert centimeters width to pixels
*
* @param int $pValue Value in centimeters
* @return float
*/
public static function centimetersToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return ($pValue / 2.54) * self::DPI_96;
}
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int
*/
public static function degreesToAngle($pValue = 0)
{
return (int) round($pValue * 60000);
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int
*/
public static function angleToDegrees($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 60000);
}
/**
* Convert centimeters width to twips
*
* @param int $pValue
* @return float
*/
public static function centimetersToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 566.928;
}
/**
* Convert twips width to centimeters
*
* @param int $pValue
* @return float
*/
public static function twipsToCentimeters($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue / 566.928;
}
/**
* Convert inches width to twips
*
* @param int $pValue
* @return float
*/
public static function inchesToTwips($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue * 1440;
}
/**
* Convert twips width to inches
*
* @param int $pValue
* @return float
*/
public static function twipsToInches($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return $pValue / 1440;
}
/**
* Convert twips width to pixels
*
* @param int $pValue
* @return float
*/
public static function twipsToPixels($pValue = 0)
{
if ($pValue == 0) {
return 0;
}
return round($pValue / 15.873984);
}
/**
* Convert HTML hexadecimal to RGB
*
* @param string $pValue HTML Color in hexadecimal
* @return array|false Value in RGB
*/
public static function htmlToRGB($pValue)
{
if ($pValue[0] == '#') {
$pValue = substr($pValue, 1);
}
if (strlen($pValue) == 6) {
list($colorR, $colorG, $colorB) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]);
} elseif (strlen($pValue) == 3) {
list($colorR, $colorG, $colorB) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]);
} else {
return false;
}
$colorR = hexdec($colorR);
$colorG = hexdec($colorG);
$colorB = hexdec($colorB);
return array($colorR, $colorG, $colorB);
}
}

View File

@ -72,7 +72,9 @@ class Html
} }
// Load DOM // Load DOM
if (\PHP_VERSION_ID < 80000) {
$orignalLibEntityLoader = libxml_disable_entity_loader(true); $orignalLibEntityLoader = libxml_disable_entity_loader(true);
}
$dom = new \DOMDocument(); $dom = new \DOMDocument();
$dom->preserveWhiteSpace = $preserveWhiteSpace; $dom->preserveWhiteSpace = $preserveWhiteSpace;
$dom->loadXML($html); $dom->loadXML($html);
@ -80,8 +82,10 @@ class Html
$node = $dom->getElementsByTagName('body'); $node = $dom->getElementsByTagName('body');
self::parseNode($node->item(0), $element); self::parseNode($node->item(0), $element);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($orignalLibEntityLoader); libxml_disable_entity_loader($orignalLibEntityLoader);
} }
}
/** /**
* parse Inline style of a node * parse Inline style of a node
@ -178,7 +182,7 @@ class Html
} }
} }
$method = "parse{$method}"; $method = "parse{$method}";
$newElement = call_user_func_array(array('PhpOffice\PhpWord\Shared\Html', $method), $arguments); $newElement = call_user_func_array(array('PhpOffice\PhpWord\Shared\Html', $method), array_values($arguments));
// Retrieve back variables from arguments // Retrieve back variables from arguments
foreach ($keys as $key) { foreach ($keys as $key) {

View File

@ -0,0 +1,235 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared\Microsoft;
/**
* Password encoder for microsoft office applications
*/
class PasswordEncoder
{
const ALGORITHM_MD2 = 'MD2';
const ALGORITHM_MD4 = 'MD4';
const ALGORITHM_MD5 = 'MD5';
const ALGORITHM_SHA_1 = 'SHA-1';
const ALGORITHM_SHA_256 = 'SHA-256';
const ALGORITHM_SHA_384 = 'SHA-384';
const ALGORITHM_SHA_512 = 'SHA-512';
const ALGORITHM_RIPEMD = 'RIPEMD';
const ALGORITHM_RIPEMD_160 = 'RIPEMD-160';
const ALGORITHM_MAC = 'MAC';
const ALGORITHM_HMAC = 'HMAC';
/**
* Mapping between algorithm name and algorithm ID
*
* @var array
* @see https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.writeprotection.cryptographicalgorithmsid(v=office.14).aspx
*/
private static $algorithmMapping = array(
self::ALGORITHM_MD2 => array(1, 'md2'),
self::ALGORITHM_MD4 => array(2, 'md4'),
self::ALGORITHM_MD5 => array(3, 'md5'),
self::ALGORITHM_SHA_1 => array(4, 'sha1'),
self::ALGORITHM_MAC => array(5, ''), // 'mac' -> not possible with hash()
self::ALGORITHM_RIPEMD => array(6, 'ripemd'),
self::ALGORITHM_RIPEMD_160 => array(7, 'ripemd160'),
self::ALGORITHM_HMAC => array(9, ''), //'hmac' -> not possible with hash()
self::ALGORITHM_SHA_256 => array(12, 'sha256'),
self::ALGORITHM_SHA_384 => array(13, 'sha384'),
self::ALGORITHM_SHA_512 => array(14, 'sha512'),
);
private static $initialCodeArray = array(
0xE1F0,
0x1D0F,
0xCC9C,
0x84C0,
0x110C,
0x0E10,
0xF1CE,
0x313E,
0x1872,
0xE139,
0xD40F,
0x84F9,
0x280C,
0xA96A,
0x4EC3,
);
private static $encryptionMatrix = array(
array(0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09),
array(0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF),
array(0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0),
array(0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40),
array(0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5),
array(0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A),
array(0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9),
array(0x47D3, 0x8FA6, 0x0F6D, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0),
array(0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC),
array(0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10),
array(0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168),
array(0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C),
array(0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD),
array(0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC),
array(0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4),
);
private static $passwordMaxLength = 15;
/**
* Create a hashed password that MS Word will be able to work with
* @see https://blogs.msdn.microsoft.com/vsod/2010/04/05/how-to-set-the-editing-restrictions-in-word-using-open-xml-sdk-2-0/
*
* @param string $password
* @param string $algorithmName
* @param string $salt
* @param int $spinCount
* @return string
*/
public static function hashPassword($password, $algorithmName = self::ALGORITHM_SHA_1, $salt = null, $spinCount = 10000)
{
$origEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');
$password = mb_substr($password, 0, min(self::$passwordMaxLength, mb_strlen($password)));
// Get the single-byte values by iterating through the Unicode characters of the truncated password.
// For each character, if the low byte is not equal to 0, take it. Otherwise, take the high byte.
$passUtf8 = mb_convert_encoding($password, 'UCS-2LE', 'UTF-8');
$byteChars = array();
for ($i = 0; $i < mb_strlen($password); $i++) {
$byteChars[$i] = ord(substr($passUtf8, $i * 2, 1));
if ($byteChars[$i] == 0) {
$byteChars[$i] = ord(substr($passUtf8, $i * 2 + 1, 1));
}
}
// build low-order word and hig-order word and combine them
$combinedKey = self::buildCombinedKey($byteChars);
// build reversed hexadecimal string
$hex = str_pad(strtoupper(dechex($combinedKey & 0xFFFFFFFF)), 8, '0', \STR_PAD_LEFT);
$reversedHex = $hex[6] . $hex[7] . $hex[4] . $hex[5] . $hex[2] . $hex[3] . $hex[0] . $hex[1];
$generatedKey = mb_convert_encoding($reversedHex, 'UCS-2LE', 'UTF-8');
// Implementation Notes List:
// Word requires that the initial hash of the password with the salt not be considered in the count.
// The initial hash of salt + key is not included in the iteration count.
$algorithm = self::getAlgorithm($algorithmName);
$generatedKey = hash($algorithm, $salt . $generatedKey, true);
for ($i = 0; $i < $spinCount; $i++) {
$generatedKey = hash($algorithm, $generatedKey . pack('CCCC', $i, $i >> 8, $i >> 16, $i >> 24), true);
}
$generatedKey = base64_encode($generatedKey);
mb_internal_encoding($origEncoding);
return $generatedKey;
}
/**
* Get algorithm from self::$algorithmMapping
*
* @param string $algorithmName
* @return string
*/
private static function getAlgorithm($algorithmName)
{
$algorithm = self::$algorithmMapping[$algorithmName][1];
if ($algorithm == '') {
$algorithm = 'sha1';
}
return $algorithm;
}
/**
* Returns the algorithm ID
*
* @param string $algorithmName
* @return int
*/
public static function getAlgorithmId($algorithmName)
{
return self::$algorithmMapping[$algorithmName][0];
}
/**
* Build combined key from low-order word and high-order word
*
* @param array $byteChars byte array representation of password
* @return int
*/
private static function buildCombinedKey($byteChars)
{
$byteCharsLength = count($byteChars);
// Compute the high-order word
// Initialize from the initial code array (see above), depending on the passwords length.
$highOrderWord = self::$initialCodeArray[$byteCharsLength - 1];
// For each character in the password:
// For every bit in the character, starting with the least significant and progressing to (but excluding)
// the most significant, if the bit is set, XOR the keys high-order word with the corresponding word from
// the Encryption Matrix
for ($i = 0; $i < $byteCharsLength; $i++) {
$tmp = self::$passwordMaxLength - $byteCharsLength + $i;
$matrixRow = self::$encryptionMatrix[$tmp];
for ($intBit = 0; $intBit < 7; $intBit++) {
if (($byteChars[$i] & (0x0001 << $intBit)) != 0) {
$highOrderWord = ($highOrderWord ^ $matrixRow[$intBit]);
}
}
}
// Compute low-order word
// Initialize with 0
$lowOrderWord = 0;
// For each character in the password, going backwards
for ($i = $byteCharsLength - 1; $i >= 0; $i--) {
// low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR character
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteChars[$i]);
}
// Lastly, low-order word = (((low-order word SHR 14) AND 0x0001) OR (low-order word SHL 1) AND 0x7FFF)) XOR strPassword length XOR 0xCE4B.
$lowOrderWord = (((($lowOrderWord >> 14) & 0x0001) | (($lowOrderWord << 1) & 0x7FFF)) ^ $byteCharsLength ^ 0xCE4B);
// Combine the Low and High Order Word
return self::int32(($highOrderWord << 16) + $lowOrderWord);
}
/**
* Simulate behaviour of (signed) int32
*
* @codeCoverageIgnore
* @param int $value
* @return int
*/
private static function int32($value)
{
$value = ($value & 0xFFFFFFFF);
if ($value & 0x80000000) {
$value = -((~$value & 0xFFFFFFFF) + 1);
}
return $value;
}
}

236
src/PhpWord/Shared/Text.php Normal file
View File

@ -0,0 +1,236 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Text
*/
class Text
{
/**
* Control characters array
*
* @var string[]
*/
private static $controlCharacters = array();
/**
* Build control characters array
*/
private static function buildControlCharacters()
{
for ($i = 0; $i <= 19; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$controlCharacters[$find] = $replace;
}
}
}
/**
* Convert from PHP control character to OpenXML escaped control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to escape
* @return string
*/
public static function controlCharacterPHP2OOXML($value = '')
{
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
}
/**
* Return a number formatted for being integrated in xml files
* @param float $number
* @param int $decimals
* @return string
*/
public static function numberFormat($number, $decimals)
{
return number_format($number, $decimals, '.', '');
}
/**
* @param int $dec
* @see http://stackoverflow.com/a/7153133/2235790
* @author velcrow
* @return string
*/
public static function chr($dec)
{
if ($dec <= 0x7F) {
return chr($dec);
}
if ($dec <= 0x7FF) {
return chr(($dec >> 6) + 192) . chr(($dec & 63) + 128);
}
if ($dec <= 0xFFFF) {
return chr(($dec >> 12) + 224) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
}
if ($dec <= 0x1FFFFF) {
return chr(($dec >> 18) + 240) . chr((($dec >> 12) & 63) + 128) . chr((($dec >> 6) & 63) + 128) . chr(($dec & 63) + 128);
}
return '';
}
/**
* Convert from OpenXML escaped control character to PHP control character
*
* @param string $value Value to unescape
* @return string
*/
public static function controlCharacterOOXML2PHP($value = '')
{
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
}
/**
* Check if a string contains UTF-8 data
*
* @param string $value
* @return bool
*/
public static function isUTF8($value = '')
{
return is_string($value) && ($value === '' || preg_match('/^./su', $value) == 1);
}
/**
* Return UTF8 encoded value
*
* @param string $value
* @return string
*/
public static function toUTF8($value = '')
{
if (!is_null($value) && !self::isUTF8($value)) {
$value = utf8_encode($value);
}
return $value;
}
/**
* Returns unicode from UTF8 text
*
* The function is splitted to reduce cyclomatic complexity
*
* @param string $text UTF8 text
* @return string Unicode text
* @since 0.11.0
*/
public static function toUnicode($text)
{
return self::unicodeToEntities(self::utf8ToUnicode($text));
}
/**
* Returns unicode array from UTF8 text
*
* @param string $text UTF8 text
* @return array
* @since 0.11.0
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
*/
public static function utf8ToUnicode($text)
{
$unicode = array();
$values = array();
$lookingFor = 1;
// Gets unicode for each character
for ($i = 0; $i < strlen($text); $i++) {
$thisValue = ord($text[$i]);
if ($thisValue < 128) {
$unicode[] = $thisValue;
} else {
if (count($values) == 0) {
$lookingFor = $thisValue < 224 ? 2 : 3;
}
$values[] = $thisValue;
if (count($values) == $lookingFor) {
if ($lookingFor == 3) {
$number = (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64);
} else {
$number = (($values[0] % 32) * 64) + ($values[1] % 64);
}
$unicode[] = $number;
$values = array();
$lookingFor = 1;
}
}
}
return $unicode;
}
/**
* Returns entites from unicode array
*
* @param array $unicode
* @return string
* @since 0.11.0
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
*/
private static function unicodeToEntities($unicode)
{
$entities = '';
foreach ($unicode as $value) {
if ($value != 65279) {
$entities .= $value > 127 ? '\uc0{\u' . $value . '}' : chr($value);
}
}
return $entities;
}
/**
* Return name without underscore for < 0.10.0 variable name compatibility
*
* @param string $value
* @return string
*/
public static function removeUnderscorePrefix($value)
{
if (!is_null($value)) {
if (substr($value, 0, 1) == '_') {
$value = substr($value, 1);
}
}
return $value;
}
}

View File

@ -0,0 +1,216 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* XML Reader wrapper
*
* @since 0.2.1
*/
class XMLReader
{
/**
* DOMDocument object
*
* @var \DOMDocument
*/
private $dom = null;
/**
* DOMXpath object
*
* @var \DOMXpath
*/
private $xpath = null;
/**
* Get DOMDocument from ZipArchive
*
* @param string $zipFile
* @param string $xmlFile
* @throws \Exception
* @return \DOMDocument|false
*/
public function getDomFromZip($zipFile, $xmlFile)
{
if (file_exists($zipFile) === false) {
throw new \Exception('Cannot find archive file.');
}
$zip = new \ZipArchive();
$zip->open($zipFile);
$content = $zip->getFromName($xmlFile);
$zip->close();
if ($content === false) {
return false;
}
return $this->getDomFromString($content);
}
/**
* Get DOMDocument from content string
*
* @param string $content
* @return \DOMDocument
*/
public function getDomFromString($content)
{
if (\PHP_VERSION_ID < 80000) {
$originalLibXMLEntityValue = libxml_disable_entity_loader(true);
}
$this->dom = new \DOMDocument();
$this->dom->loadXML($content);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($originalLibXMLEntityValue);
}
return $this->dom;
}
/**
* Get elements
*
* @param string $path
* @param \DOMElement $contextNode
* @return \DOMNodeList
*/
public function getElements($path, \DOMElement $contextNode = null)
{
if ($this->dom === null) {
return array();
}
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
}
if (is_null($contextNode)) {
return $this->xpath->query($path);
}
return $this->xpath->query($path, $contextNode);
}
/**
* Registers the namespace with the DOMXPath object
*
* @param string $prefix The prefix
* @param string $namespaceURI The URI of the namespace
* @throws \InvalidArgumentException If called before having loaded the DOM document
* @return bool true on success or false on failure
*/
public function registerNamespace($prefix, $namespaceURI)
{
if ($this->dom === null) {
throw new \InvalidArgumentException('Dom needs to be loaded before registering a namespace');
}
if ($this->xpath === null) {
$this->xpath = new \DOMXpath($this->dom);
}
return $this->xpath->registerNamespace($prefix, $namespaceURI);
}
/**
* Get element
*
* @param string $path
* @param \DOMElement $contextNode
* @return \DOMElement|null
*/
public function getElement($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
return $elements->item(0);
}
return null;
}
/**
* Get element attribute
*
* @param string $attribute
* @param \DOMElement $contextNode
* @param string $path
* @return string|null
*/
public function getAttribute($attribute, \DOMElement $contextNode = null, $path = null)
{
$return = null;
if ($path !== null) {
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
/** @var \DOMElement $node Type hint */
$node = $elements->item(0);
$return = $node->getAttribute($attribute);
}
} else {
if ($contextNode !== null) {
$return = $contextNode->getAttribute($attribute);
}
}
return ($return == '') ? null : $return;
}
/**
* Get element value
*
* @param string $path
* @param \DOMElement $contextNode
* @return string|null
*/
public function getValue($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
return $elements->item(0)->nodeValue;
}
return null;
}
/**
* Count elements
*
* @param string $path
* @param \DOMElement $contextNode
* @return int
*/
public function countElements($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
return $elements->length;
}
/**
* Element exists
*
* @param string $path
* @param \DOMElement $contextNode
* @return bool
*/
public function elementExists($path, \DOMElement $contextNode = null)
{
return $this->getElements($path, $contextNode)->length > 0;
}
}

View File

@ -0,0 +1,182 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* XMLWriter
*
* @method bool endElement()
* @method mixed flush(bool $empty = null)
* @method bool openMemory()
* @method string outputMemory(bool $flush = null)
* @method bool setIndent(bool $indent)
* @method bool startDocument(string $version = 1.0, string $encoding = null, string $standalone = null)
* @method bool startElement(string $name)
* @method bool text(string $content)
* @method bool writeCData(string $content)
* @method bool writeComment(string $content)
* @method bool writeElement(string $name, string $content = null)
* @method bool writeRaw(string $content)
*/
class XMLWriter extends \XMLWriter
{
/** Temporary storage method */
const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
/**
* Temporary filename
*
* @var string
*/
private $tempFileName = '';
/**
* Create a new \PhpOffice\PhpWord\Shared\XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageDir Temporary storage folder
* @param bool $compatibility
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageDir = null, $compatibility = false)
{
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->openMemory();
} else {
if (!is_dir($pTemporaryStorageDir)) {
$pTemporaryStorageDir = sys_get_temp_dir();
}
// Create temporary filename
$this->tempFileName = @tempnam($pTemporaryStorageDir, 'xml');
// Open storage
$this->openUri($this->tempFileName);
}
if ($compatibility) {
$this->setIndent(false);
$this->setIndentString('');
} else {
$this->setIndent(true);
$this->setIndentString(' ');
}
}
/**
* Destructor
*/
public function __destruct()
{
// Unlink temporary files
if (empty($this->tempFileName)) {
return;
}
if (PHP_OS != 'WINNT' && @unlink($this->tempFileName) === false) {
throw new \Exception('The file ' . $this->tempFileName . ' could not be deleted.');
}
}
/**
* Get written data
*
* @return string
*/
public function getData()
{
if ($this->tempFileName == '') {
return $this->outputMemory(true);
}
$this->flush();
return file_get_contents($this->tempFileName);
}
/**
* Write simple element and attribute(s) block
*
* There are two options:
* 1. If the `$attributes` is an array, then it's an associative array of attributes
* 2. If not, then it's a simple attribute-value pair
*
* @param string $element
* @param string|array $attributes
* @param string $value
*/
public function writeElementBlock($element, $attributes, $value = null)
{
$this->startElement($element);
if (!is_array($attributes)) {
$attributes = array($attributes => $value);
}
foreach ($attributes as $attribute => $value) {
$this->writeAttribute($attribute, $value);
}
$this->endElement();
}
/**
* Write element if ...
*
* @param bool $condition
* @param string $element
* @param string $attribute
* @param mixed $value
*/
public function writeElementIf($condition, $element, $attribute = null, $value = null)
{
if ($condition == true) {
if (is_null($attribute)) {
$this->writeElement($element, $value);
} else {
$this->startElement($element);
$this->writeAttribute($attribute, $value);
$this->endElement();
}
}
}
/**
* Write attribute if ...
*
* @param bool $condition
* @param string $attribute
* @param mixed $value
*/
public function writeAttributeIf($condition, $attribute, $value)
{
if ($condition == true) {
$this->writeAttribute($attribute, $value);
}
}
/**
* @param string $name
* @param mixed $value
* @return bool
*/
public function writeAttribute($name, $value)
{
if (is_float($value)) {
$value = json_encode($value);
}
return parent::writeAttribute($name, $value);
}
}

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Style; namespace PhpOffice\PhpWord\Style;
use PhpOffice\Common\Text; use PhpOffice\PhpWord\Shared\Text;
/** /**
* Abstract style class * Abstract style class

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Style; namespace PhpOffice\PhpWord\Style;
use PhpOffice\Common\Text;
use PhpOffice\PhpWord\Exception\InvalidStyleException; use PhpOffice\PhpWord\Exception\InvalidStyleException;
use PhpOffice\PhpWord\Shared\Text;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\TextAlignment; use PhpOffice\PhpWord\SimpleType\TextAlignment;
@ -85,7 +85,7 @@ class Paragraph extends Border
/** /**
* Indentation * Indentation
* *
* @var \PhpOffice\PhpWord\Style\Indentation * @var \PhpOffice\PhpWord\Style\Indentation|null
*/ */
private $indentation; private $indentation;

View File

@ -17,6 +17,7 @@
namespace PhpOffice\PhpWord\Style; namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\SimpleType\VerticalJc; use PhpOffice\PhpWord\SimpleType\VerticalJc;
/** /**
@ -200,8 +201,11 @@ class Section extends Border
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setPaperSize($value = 'A4') public function setPaperSize($value = '')
{ {
if (!$value) {
$value = Settings::getDefaultPaper();
}
if ($this->paper === null) { if ($this->paper === null) {
$this->paper = new Paper(); $this->paper = new Paper();
} }

View File

@ -17,13 +17,13 @@
namespace PhpOffice\PhpWord; namespace PhpOffice\PhpWord;
use PhpOffice\Common\Text;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Escaper\RegExp; use PhpOffice\PhpWord\Escaper\RegExp;
use PhpOffice\PhpWord\Escaper\Xml; use PhpOffice\PhpWord\Escaper\Xml;
use PhpOffice\PhpWord\Exception\CopyFileException; use PhpOffice\PhpWord\Exception\CopyFileException;
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\Text;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Shared\ZipArchive; use PhpOffice\PhpWord\Shared\ZipArchive;
class TemplateProcessor class TemplateProcessor
@ -170,7 +170,9 @@ class TemplateProcessor
*/ */
protected function transformSingleXml($xml, $xsltProcessor) protected function transformSingleXml($xml, $xsltProcessor)
{ {
if (\PHP_VERSION_ID < 80000) {
$orignalLibEntityLoader = libxml_disable_entity_loader(true); $orignalLibEntityLoader = libxml_disable_entity_loader(true);
}
$domDocument = new \DOMDocument(); $domDocument = new \DOMDocument();
if (false === $domDocument->loadXML($xml)) { if (false === $domDocument->loadXML($xml)) {
throw new Exception('Could not load the given XML document.'); throw new Exception('Could not load the given XML document.');
@ -180,7 +182,9 @@ class TemplateProcessor
if (false === $transformedXml) { if (false === $transformedXml) {
throw new Exception('Could not transform the given XML document.'); throw new Exception('Could not transform the given XML document.');
} }
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($orignalLibEntityLoader); libxml_disable_entity_loader($orignalLibEntityLoader);
}
return $transformedXml; return $transformedXml;
} }
@ -575,7 +579,7 @@ class TemplateProcessor
// define templates // define templates
// result can be verified via "Open XML SDK 2.5 Productivity Tool" (http://www.microsoft.com/en-us/download/details.aspx?id=30425) // result can be verified via "Open XML SDK 2.5 Productivity Tool" (http://www.microsoft.com/en-us/download/details.aspx?id=30425)
$imgTpl = '<w:pict><v:shape type="#_x0000_t75" style="width:{WIDTH};height:{HEIGHT}"><v:imagedata r:id="{RID}" o:title=""/></v:shape></w:pict>'; $imgTpl = '<w:pict><v:shape type="#_x0000_t75" style="width:{WIDTH};height:{HEIGHT}" stroked="f"><v:imagedata r:id="{RID}" o:title=""/></v:shape></w:pict>';
foreach ($searchParts as $partFileName => &$partContent) { foreach ($searchParts as $partFileName => &$partContent) {
$partVariables = $this->getVariablesForPart($partContent); $partVariables = $this->getVariablesForPart($partContent);

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Writer\HTML\Element; namespace PhpOffice\PhpWord\Writer\HTML\Element;
use Laminas\Escaper\Escaper;
use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Element\AbstractElement as Element;
use PhpOffice\PhpWord\Writer\AbstractWriter; use PhpOffice\PhpWord\Writer\AbstractWriter;
use Zend\Escaper\Escaper;
/** /**
* Abstract HTML element writer * Abstract HTML element writer
@ -50,7 +50,7 @@ abstract class AbstractElement
protected $withoutP = false; protected $withoutP = false;
/** /**
* @var \Zend\Escaper\Escaper|\PhpOffice\PhpWord\Escaper\AbstractEscaper * @var \Laminas\Escaper\Escaper|\PhpOffice\PhpWord\Escaper\AbstractEscaper
*/ */
protected $escaper; protected $escaper;

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Writer\HTML\Part; namespace PhpOffice\PhpWord\Writer\HTML\Part;
use Laminas\Escaper\Escaper;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Writer\AbstractWriter; use PhpOffice\PhpWord\Writer\AbstractWriter;
use Zend\Escaper\Escaper;
/** /**
* @since 0.11.0 * @since 0.11.0
@ -32,7 +32,7 @@ abstract class AbstractPart
private $parentWriter; private $parentWriter;
/** /**
* @var \Zend\Escaper\Escaper * @var \Laminas\Escaper\Escaper
*/ */
protected $escaper; protected $escaper;

View File

@ -0,0 +1,81 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
// Not fully implemented
// - supports only PAGE and NUMPAGES
// - supports only default formats and options
// - supports style only if specified by name
// - spaces before and after field may be dropped
namespace PhpOffice\PhpWord\Writer\ODText\Element;
/**
* Field element writer
*
* @since 0.11.0
*/
class Field extends Text
{
/**
* Write field element.
*/
public function write()
{
$element = $this->getElement();
if (!$element instanceof \PhpOffice\PhpWord\Element\Field) {
return;
}
$type = strtolower($element->getType());
switch ($type) {
case 'date':
case 'page':
case 'numpages':
$this->writeDefault($element, $type);
break;
}
}
private function writeDefault(\PhpOffice\PhpWord\Element\Field $element, $type)
{
$xmlWriter = $this->getXmlWriter();
$xmlWriter->startElement('text:span');
if (method_exists($element, 'getFontStyle')) {
$fstyle = $element->getFontStyle();
if (is_string($fstyle)) {
$xmlWriter->writeAttribute('text:style-name', $fstyle);
}
}
switch ($type) {
case 'date':
$xmlWriter->startElement('text:date');
$xmlWriter->writeAttribute('text:fixed', 'false');
$xmlWriter->endElement();
break;
case 'page':
$xmlWriter->startElement('text:page-number');
$xmlWriter->writeAttribute('text:fixed', 'false');
$xmlWriter->endElement();
break;
case 'numpages':
$xmlWriter->startElement('text:page-count');
$xmlWriter->endElement();
break;
}
$xmlWriter->endElement(); // text:span
}
}

View File

@ -44,7 +44,7 @@ class Image extends AbstractElement
$height = Converter::pixelToCm($style->getHeight()); $height = Converter::pixelToCm($style->getHeight());
$xmlWriter->startElement('text:p'); $xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard'); $xmlWriter->writeAttribute('text:style-name', 'IM' . $mediaIndex);
$xmlWriter->startElement('draw:frame'); $xmlWriter->startElement('draw:frame');
$xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex); $xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex);

View File

@ -41,7 +41,7 @@ class Link extends AbstractElement
$xmlWriter->startElement('text:a'); $xmlWriter->startElement('text:a');
$xmlWriter->writeAttribute('xlink:type', 'simple'); $xmlWriter->writeAttribute('xlink:type', 'simple');
$xmlWriter->writeAttribute('xlink:href', $element->getSource()); $xmlWriter->writeAttribute('xlink:href', ($element->isInternal() ? '#' : '') . $element->getSource());
$this->writeText($element->getText()); $this->writeText($element->getText());
$xmlWriter->endElement(); // text:a $xmlWriter->endElement(); // text:a

View File

@ -30,7 +30,7 @@ class PageBreak extends AbstractElement
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
$xmlWriter->startElement('text:p'); $xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'P1'); $xmlWriter->writeAttribute('text:style-name', 'PB');
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
} }

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Writer\ODText\Element; namespace PhpOffice\PhpWord\Writer\ODText\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Row as RowElement; use PhpOffice\PhpWord\Element\Row as RowElement;
use PhpOffice\PhpWord\Element\Table as TableElement; use PhpOffice\PhpWord\Element\Table as TableElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Table element writer * Table element writer
@ -60,7 +60,7 @@ class Table extends AbstractElement
/** /**
* Write column. * Write column.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Table $element * @param \PhpOffice\PhpWord\Element\Table $element
*/ */
private function writeColumns(XMLWriter $xmlWriter, TableElement $element) private function writeColumns(XMLWriter $xmlWriter, TableElement $element)
@ -77,7 +77,7 @@ class Table extends AbstractElement
/** /**
* Write row. * Write row.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Row $row * @param \PhpOffice\PhpWord\Element\Row $row
*/ */
private function writeRow(XMLWriter $xmlWriter, RowElement $row) private function writeRow(XMLWriter $xmlWriter, RowElement $row)

View File

@ -42,12 +42,12 @@ class Text extends AbstractElement
// @todo Commented for TextRun. Should really checkout this value // @todo Commented for TextRun. Should really checkout this value
// $fStyleIsObject = ($fontStyle instanceof Font) ? true : false; // $fStyleIsObject = ($fontStyle instanceof Font) ? true : false;
$fStyleIsObject = false; //$fStyleIsObject = false;
if ($fStyleIsObject) { //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 : $fStyleIsObject wouldn\'t be an object'); // throw new Exception('PhpWord : $fStyleIsObject wouldn\'t be an object');
} //}
if (!$this->withoutP) { if (!$this->withoutP) {
$xmlWriter->startElement('text:p'); // text:p $xmlWriter->startElement('text:p'); // text:p
@ -59,26 +59,34 @@ class Text extends AbstractElement
} else { } else {
if (empty($fontStyle)) { if (empty($fontStyle)) {
if (empty($paragraphStyle)) { if (empty($paragraphStyle)) {
$xmlWriter->writeAttribute('text:style-name', 'P1'); if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', 'Normal');
}
} elseif (is_string($paragraphStyle)) { } elseif (is_string($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle); $xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
} }
}
$this->writeChangeInsertion(true, $element->getTrackChange()); $this->writeChangeInsertion(true, $element->getTrackChange());
$this->writeText($element->getText()); $this->replaceTabs($element->getText(), $xmlWriter);
$this->writeChangeInsertion(false, $element->getTrackChange()); $this->writeChangeInsertion(false, $element->getTrackChange());
} else { } else {
if (empty($paragraphStyle)) { if (empty($paragraphStyle)) {
$xmlWriter->writeAttribute('text:style-name', 'Standard'); if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', 'Normal');
}
} elseif (is_string($paragraphStyle)) { } elseif (is_string($paragraphStyle)) {
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle); $xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
} }
}
// text:span // text:span
$xmlWriter->startElement('text:span'); $xmlWriter->startElement('text:span');
if (is_string($fontStyle)) { if (is_string($fontStyle)) {
$xmlWriter->writeAttribute('text:style-name', $fontStyle); $xmlWriter->writeAttribute('text:style-name', $fontStyle);
} }
$this->writeChangeInsertion(true, $element->getTrackChange()); $this->writeChangeInsertion(true, $element->getTrackChange());
$this->writeText($element->getText()); $this->replaceTabs($element->getText(), $xmlWriter);
$this->writeChangeInsertion(false, $element->getTrackChange()); $this->writeChangeInsertion(false, $element->getTrackChange());
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
@ -88,6 +96,34 @@ class Text extends AbstractElement
} }
} }
private function replacetabs($text, $xmlWriter)
{
if (preg_match('/^ +/', $text, $matches)) {
$num = strlen($matches[0]);
$xmlWriter->startElement('text:s');
$xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num");
$xmlWriter->endElement();
$text = preg_replace('/^ +/', '', $text);
}
preg_match_all('/([\\s\\S]*?)(\\t| +| ?$)/', $text, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$this->writeText($match[1]);
if ($match[2] === '') {
break;
} elseif ($match[2] === "\t") {
$xmlWriter->writeElement('text:tab');
} elseif ($match[2] === ' ') {
$xmlWriter->writeElement('text:s');
break;
} else {
$num = strlen($match[2]);
$xmlWriter->startElement('text:s');
$xmlWriter->writeAttributeIf($num > 1, 'text:c', "$num");
$xmlWriter->endElement();
}
}
}
private function writeChangeInsertion($start = true, TrackChange $trackChange = null) private function writeChangeInsertion($start = true, TrackChange $trackChange = null)
{ {
if ($trackChange == null || $trackChange->getChangeType() != TrackChange::INSERTED) { if ($trackChange == null || $trackChange->getChangeType() != TrackChange::INSERTED) {

View File

@ -22,7 +22,7 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element;
* *
* @since 0.10.0 * @since 0.10.0
*/ */
class TextRun extends AbstractElement class TextRun extends Text
{ {
/** /**
* Write element * Write element
@ -33,6 +33,12 @@ class TextRun extends AbstractElement
$element = $this->getElement(); $element = $this->getElement();
$xmlWriter->startElement('text:p'); $xmlWriter->startElement('text:p');
/** @scrutinizer ignore-call */
$pStyle = $element->getParagraphStyle();
if (!is_string($pStyle)) {
$pStyle = 'Normal';
}
$xmlWriter->writeAttribute('text:style-name', $pStyle);
$containerWriter = new Container($xmlWriter, $element); $containerWriter = new Container($xmlWriter, $element);
$containerWriter->write(); $containerWriter->write();

View File

@ -36,7 +36,22 @@ class Title extends AbstractElement
} }
$xmlWriter->startElement('text:h'); $xmlWriter->startElement('text:h');
$xmlWriter->writeAttribute('text:outline-level', $element->getDepth()); $hdname = 'HD';
$sect = $element->getParent();
if ($sect instanceof \PhpOffice\PhpWord\Element\Section) {
if (self::compareToFirstElement($element, $sect->getElements())) {
$hdname = 'HE';
}
}
$depth = $element->getDepth();
$xmlWriter->writeAttribute('text:style-name', "$hdname$depth");
$xmlWriter->writeAttribute('text:outline-level', $depth);
$xmlWriter->startElement('text:span');
if ($depth > 0) {
$xmlWriter->writeAttribute('text:style-name', 'Heading_' . $depth);
} else {
$xmlWriter->writeAttribute('text:style-name', 'Title');
}
$text = $element->getText(); $text = $element->getText();
if (is_string($text)) { if (is_string($text)) {
$this->writeText($text); $this->writeText($text);
@ -44,6 +59,21 @@ class Title extends AbstractElement
$containerWriter = new Container($xmlWriter, $text); $containerWriter = new Container($xmlWriter, $text);
$containerWriter->write(); $containerWriter->write();
} }
$xmlWriter->endElement(); // text:span
$xmlWriter->endElement(); // text:h $xmlWriter->endElement(); // text:h
} }
/**
* Test if element is same as first element in array
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $elem
*
* @param \PhpOffice\PhpWord\Element\AbstractElement[] $elemarray
*
* @return bool
*/
private static function compareToFirstElement($elem, $elemarray)
{
return $elem === $elemarray[0];
}
} }

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part; namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart; use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart;
@ -36,7 +36,7 @@ abstract class AbstractPart extends Word2007AbstractPart
/** /**
* Write common root attributes. * Write common root attributes.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
protected function writeCommonRootAttributes(XMLWriter $xmlWriter) protected function writeCommonRootAttributes(XMLWriter $xmlWriter)
{ {
@ -72,7 +72,7 @@ abstract class AbstractPart extends Word2007AbstractPart
/** /**
* Write font faces declaration. * Write font faces declaration.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
protected function writeFontFaces(XMLWriter $xmlWriter) protected function writeFontFaces(XMLWriter $xmlWriter)
{ {

View File

@ -17,14 +17,15 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part; namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\AbstractContainer; use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\Field;
use PhpOffice\PhpWord\Element\Image; use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Element\Table; use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Element\Text; use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange; use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
@ -46,6 +47,7 @@ class Content extends AbstractPart
* @var array * @var array
*/ */
private $autoStyles = array('Section' => array(), 'Image' => array(), 'Table' => array()); private $autoStyles = array('Section' => array(), 'Image' => array(), 'Table' => array());
private $imageParagraphStyles = array();
/** /**
* Write part * Write part
@ -128,6 +130,9 @@ class Content extends AbstractPart
$xmlWriter->startElement('text:section'); $xmlWriter->startElement('text:section');
$xmlWriter->writeAttribute('text:name', $name); $xmlWriter->writeAttribute('text:name', $name);
$xmlWriter->writeAttribute('text:style-name', $name); $xmlWriter->writeAttribute('text:style-name', $name);
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'SB' . $section->getSectionId());
$xmlWriter->endElement();
$containerWriter = new Container($xmlWriter, $section); $containerWriter = new Container($xmlWriter, $section);
$containerWriter->write(); $containerWriter->write();
$xmlWriter->endElement(); // text:section $xmlWriter->endElement(); // text:section
@ -146,7 +151,7 @@ class Content extends AbstractPart
* *
* @since 0.11.0 * @since 0.11.0
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writeAutoStyles(XMLWriter $xmlWriter) private function writeAutoStyles(XMLWriter $xmlWriter)
{ {
@ -168,13 +173,48 @@ class Content extends AbstractPart
/** /**
* Write automatic styles. * Write automatic styles.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writeTextStyles(XMLWriter $xmlWriter) private function writeTextStyles(XMLWriter $xmlWriter)
{ {
$styles = Style::getStyles(); $styles = Style::getStyles();
$paragraphStyleCount = 0; $paragraphStyleCount = 0;
if (count($styles) > 0) {
$style = new Paragraph();
$style->setStyleName('PB');
$style->setAuto();
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
$styleWriter->write();
$sects = $this->getParentWriter()->getPhpWord()->getSections();
$countsects = count($sects);
for ($i = 0; $i < $countsects; ++$i) {
$iplus1 = $i + 1;
$style = new Paragraph();
$style->setStyleName("SB$iplus1");
$style->setAuto();
$pnstart = $sects[$i]->getStyle()->getPageNumberingStart();
$style->setNumLevel($pnstart);
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
$styleWriter->write();
}
foreach ($styles as $style) {
$sty = $style->getStyleName();
if (substr($sty, 0, 8) === 'Heading_') {
$style = new Paragraph();
$style->setStyleName('HD' . substr($sty, 8));
$style->setAuto();
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
$styleWriter->write();
$style = new Paragraph();
$style->setStyleName('HE' . substr($sty, 8));
$style->setAuto();
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
$styleWriter->write();
}
}
foreach ($styles as $style) { foreach ($styles as $style) {
if ($style->isAuto() === true) { if ($style->isAuto() === true) {
$styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style)); $styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style));
@ -188,15 +228,11 @@ class Content extends AbstractPart
} }
} }
} }
if ($paragraphStyleCount == 0) { foreach ($this->imageParagraphStyles as $style) {
$style = new Paragraph(); $styleWriter = new \PhpOffice\PhpWord\Writer\ODText\Style\Paragraph($xmlWriter, $style);
$style->setStyleName('P1');
$style->setAuto();
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
$styleWriter->write(); $styleWriter->write();
} }
} }
}
/** /**
* Get automatic styles. * Get automatic styles.
@ -231,20 +267,29 @@ class Content extends AbstractPart
$elements = $container->getElements(); $elements = $container->getElements();
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element instanceof TextRun) { if ($element instanceof TextRun) {
$this->getElementStyleTextRun($element, $paragraphStyleCount);
$this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount); $this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount);
} elseif ($element instanceof Text) { } elseif ($element instanceof Text) {
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount); $this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
} elseif ($element instanceof Field) {
$this->getElementStyleField($element, $fontStyleCount);
} elseif ($element instanceof Image) { } elseif ($element instanceof Image) {
$style = $element->getStyle(); $style = $element->getStyle();
$style->setStyleName('fr' . $element->getMediaIndex()); $style->setStyleName('fr' . $element->getMediaIndex());
$this->autoStyles['Image'][] = $style; $this->autoStyles['Image'][] = $style;
$sty = new \PhpOffice\PhpWord\Style\Paragraph();
$sty->setStyleName('IM' . $element->getMediaIndex());
$sty->setAuto();
$sty->setAlignment($style->getAlignment());
$this->imageParagraphStyles[] = $sty;
} elseif ($element instanceof Table) { } elseif ($element instanceof Table) {
/** @var \PhpOffice\PhpWord\Style\Table $style */ /** @var \PhpOffice\PhpWord\Style\Table $style */
$style = $element->getStyle(); $style = $element->getStyle();
if (is_string($style)) {
$style = Style::getStyle($style);
}
if ($style === null) { if ($style === null) {
$style = new TableStyle(); $style = new TableStyle();
} elseif (is_string($style)) {
$style = Style::getStyle($style);
} }
$style->setStyleName($element->getElementId()); $style->setStyleName($element->getElementId());
$style->setColumnWidths($element->findFirstDefinedCellWidths()); $style->setColumnWidths($element->findFirstDefinedCellWidths());
@ -260,7 +305,7 @@ class Content extends AbstractPart
* @param int $paragraphStyleCount * @param int $paragraphStyleCount
* @param int $fontStyleCount * @param int $fontStyleCount
*/ */
private function getElementStyle(&$element, &$paragraphStyleCount, &$fontStyleCount) private function getElementStyle($element, &$paragraphStyleCount, &$fontStyleCount)
{ {
$fontStyle = $element->getFontStyle(); $fontStyle = $element->getFontStyle();
$paragraphStyle = $element->getParagraphStyle(); $paragraphStyle = $element->getParagraphStyle();
@ -268,16 +313,91 @@ class Content extends AbstractPart
if ($fontStyle instanceof Font) { if ($fontStyle instanceof Font) {
// Font // Font
$name = $fontStyle->getStyleName();
if (!$name) {
$fontStyleCount++; $fontStyleCount++;
$style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle); $style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle, null);
$style->setAuto(); $style->setAuto();
$style->setParagraph(null);
$element->setFontStyle("T{$fontStyleCount}"); $element->setFontStyle("T{$fontStyleCount}");
} elseif ($paragraphStyle instanceof Paragraph) { } else {
$element->setFontStyle($name);
}
}
if ($paragraphStyle instanceof Paragraph) {
// Paragraph // Paragraph
$name = $paragraphStyle->getStyleName();
if (!$name) {
$paragraphStyleCount++; $paragraphStyleCount++;
$style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", array()); $style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", $paragraphStyle);
$style->setAuto(); $style->setAuto();
$element->setParagraphStyle("P{$paragraphStyleCount}"); $element->setParagraphStyle("P{$paragraphStyleCount}");
} else {
$element->setParagraphStyle($name);
}
} elseif ($paragraphStyle) {
$paragraphStyleCount++;
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
$style->setAuto();
$element->setParagraphStyle($parstylename);
}
}
/**
* Get font style of individual field element
*
* @param \PhpOffice\PhpWord\Element\Field $element
* @param int $paragraphStyleCount
* @param int $fontStyleCount
*/
private function getElementStyleField($element, &$fontStyleCount)
{
$fontStyle = $element->getFontStyle();
$phpWord = $this->getParentWriter()->getPhpWord();
if ($fontStyle instanceof Font) {
$name = $fontStyle->getStyleName();
if (!$name) {
$fontStyleCount++;
$style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle, null);
$style->setAuto();
$style->setParagraph(null);
$element->setFontStyle("T{$fontStyleCount}");
} else {
$element->setFontStyle($name);
}
}
}
/**
* Get style of individual element
*
* @param \PhpOffice\PhpWord\Element\TextRun $element
* @param int $paragraphStyleCount
*/
private function getElementStyleTextRun($element, &$paragraphStyleCount)
{
$paragraphStyle = $element->getParagraphStyle();
$phpWord = $this->getParentWriter()->getPhpWord();
if ($paragraphStyle instanceof Paragraph) {
// Paragraph
$name = $paragraphStyle->getStyleName();
if (!$name) {
$paragraphStyleCount++;
$style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", $paragraphStyle);
$style->setAuto();
$element->setParagraphStyle("P{$paragraphStyleCount}");
} else {
$element->setParagraphStyle($name);
}
} elseif ($paragraphStyle) {
$paragraphStyleCount++;
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
$style->setAuto();
$element->setParagraphStyle($parstylename);
} }
} }

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part; namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* ODText meta part writer: meta.xml * ODText meta part writer: meta.xml
@ -86,7 +86,7 @@ class Meta extends AbstractPart
/** /**
* Write individual property * Write individual property
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $property * @param string $property
* @param string $value * @param string $value
* *

View File

@ -17,8 +17,9 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part; namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
/** /**
@ -65,7 +66,7 @@ class Styles extends AbstractPart
/** /**
* Write default styles. * Write default styles.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writeDefault(XMLWriter $xmlWriter) private function writeDefault(XMLWriter $xmlWriter)
{ {
@ -86,6 +87,9 @@ class Styles extends AbstractPart
$latinLang = $language != null && is_string($language->getLatin()) ? explode('-', $language->getLatin()) : array('fr', 'FR'); $latinLang = $language != null && is_string($language->getLatin()) ? explode('-', $language->getLatin()) : array('fr', 'FR');
$asianLang = $language != null && is_string($language->getEastAsia()) ? explode('-', $language->getEastAsia()) : array('zh', 'CN'); $asianLang = $language != null && is_string($language->getEastAsia()) ? explode('-', $language->getEastAsia()) : array('zh', 'CN');
$complexLang = $language != null && is_string($language->getBidirectional()) ? explode('-', $language->getBidirectional()) : array('hi', 'IN'); $complexLang = $language != null && is_string($language->getBidirectional()) ? explode('-', $language->getBidirectional()) : array('hi', 'IN');
if ($this->getParentWriter()->getPhpWord()->getSettings()->hasHideGrammaticalErrors()) {
$latinLang = $asianLang = $complexLang = array('zxx', 'none');
}
// Font // Font
$xmlWriter->startElement('style:text-properties'); $xmlWriter->startElement('style:text-properties');
@ -114,7 +118,7 @@ class Styles extends AbstractPart
/** /**
* Write named styles. * Write named styles.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writeNamed(XMLWriter $xmlWriter) private function writeNamed(XMLWriter $xmlWriter)
{ {
@ -134,24 +138,74 @@ class Styles extends AbstractPart
} }
/** /**
* Write page layout styles. * Convert int in twips to inches/cm then to string and append unit
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param int|float $twips
* @param float $factor
* return string
*/
private static function cvttwiptostr($twips, $factor = 1.0)
{
$ins = (string) ($twips * $factor / Converter::INCH_TO_TWIP) . 'in';
$cms = (string) ($twips * $factor * Converter::INCH_TO_CM / Converter::INCH_TO_TWIP) . 'cm';
return (strlen($ins) < strlen($cms)) ? $ins : $cms;
}
/**
* call writePageLayoutIndiv to write page layout styles for each page
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writePageLayout(XMLWriter $xmlWriter) private function writePageLayout(XMLWriter $xmlWriter)
{ {
$sections = $this->getParentWriter()->getPhpWord()->getSections();
$countsects = count($sections);
for ($i = 0; $i < $countsects; ++$i) {
$this->writePageLayoutIndiv($xmlWriter, $sections[$i], $i + 1);
}
}
/**
* Write page layout styles.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Section $section
* @param int $sectionNbr
*/
private function writePageLayoutIndiv(XMLWriter $xmlWriter, $section, $sectionNbr)
{
$sty = $section->getStyle();
if (count($section->getHeaders()) > 0) {
$topfactor = 0.5;
} else {
$topfactor = 1.0;
}
if (count($section->getFooters()) > 0) {
$botfactor = 0.5;
} else {
$botfactor = 1.0;
}
$orient = $sty->getOrientation();
$pwidth = self::cvttwiptostr($sty->getPageSizeW());
$pheight = self::cvttwiptostr($sty->getPageSizeH());
$mtop = self::cvttwiptostr($sty->getMarginTop(), $topfactor);
$mbottom = self::cvttwiptostr($sty->getMarginBottom(), $botfactor);
$mleft = self::cvttwiptostr($sty->getMarginRight());
$mright = self::cvttwiptostr($sty->getMarginLeft());
$xmlWriter->startElement('style:page-layout'); $xmlWriter->startElement('style:page-layout');
$xmlWriter->writeAttribute('style:name', 'Mpm1'); $xmlWriter->writeAttribute('style:name', "Mpm$sectionNbr");
$xmlWriter->startElement('style:page-layout-properties'); $xmlWriter->startElement('style:page-layout-properties');
$xmlWriter->writeAttribute('fo:page-width', '21.001cm'); $xmlWriter->writeAttribute('fo:page-width', $pwidth);
$xmlWriter->writeAttribute('fo:page-height', '29.7cm'); $xmlWriter->writeAttribute('fo:page-height', $pheight);
$xmlWriter->writeAttribute('style:num-format', '1'); $xmlWriter->writeAttribute('style:num-format', '1');
$xmlWriter->writeAttribute('style:print-orientation', 'portrait'); $xmlWriter->writeAttribute('style:print-orientation', $orient);
$xmlWriter->writeAttribute('fo:margin-top', '2.501cm'); $xmlWriter->writeAttribute('fo:margin-top', $mtop);
$xmlWriter->writeAttribute('fo:margin-bottom', '2cm'); $xmlWriter->writeAttribute('fo:margin-bottom', $mbottom);
$xmlWriter->writeAttribute('fo:margin-left', '2.501cm'); $xmlWriter->writeAttribute('fo:margin-left', $mleft);
$xmlWriter->writeAttribute('fo:margin-right', '2.501cm'); $xmlWriter->writeAttribute('fo:margin-right', $mright);
$xmlWriter->writeAttribute('style:writing-mode', 'lr-tb'); $xmlWriter->writeAttribute('style:writing-mode', 'lr-tb');
$xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0'); $xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
$xmlWriter->writeAttribute('style:layout-grid-lines', '25199'); $xmlWriter->writeAttribute('style:layout-grid-lines', '25199');
@ -176,9 +230,23 @@ class Styles extends AbstractPart
$xmlWriter->endElement(); // style:page-layout-properties $xmlWriter->endElement(); // style:page-layout-properties
$xmlWriter->startElement('style:header-style'); $xmlWriter->startElement('style:header-style');
if ($topfactor < 1.0) {
$xmlWriter->startElement('style:header-footer-properties');
$xmlWriter->writeAttribute('fo:min-height', $mtop);
$xmlWriter->writeAttribute('fo:margin-bottom', $mtop);
$xmlWriter->writeAttribute('style:dynamic-spacing', 'true');
$xmlWriter->endElement(); // style:header-footer-properties
}
$xmlWriter->endElement(); // style:header-style $xmlWriter->endElement(); // style:header-style
$xmlWriter->startElement('style:footer-style'); $xmlWriter->startElement('style:footer-style');
if ($botfactor < 1.0) {
$xmlWriter->startElement('style:header-footer-properties');
$xmlWriter->writeAttribute('fo:min-height', $mbottom);
$xmlWriter->writeAttribute('fo:margin-top', $mbottom);
$xmlWriter->writeAttribute('style:dynamic-spacing', 'true');
$xmlWriter->endElement(); // style:header-footer-properties
}
$xmlWriter->endElement(); // style:footer-style $xmlWriter->endElement(); // style:footer-style
$xmlWriter->endElement(); // style:page-layout $xmlWriter->endElement(); // style:page-layout
@ -187,17 +255,50 @@ class Styles extends AbstractPart
/** /**
* Write master style. * Write master style.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writeMaster(XMLWriter $xmlWriter) private function writeMaster(XMLWriter $xmlWriter)
{ {
$xmlWriter->startElement('office:master-styles'); $xmlWriter->startElement('office:master-styles');
$sections = $this->getParentWriter()->getPhpWord()->getSections();
$countsects = count($sections);
for ($i = 0; $i < $countsects; ++$i) {
$iplus1 = $i + 1;
$xmlWriter->startElement('style:master-page'); $xmlWriter->startElement('style:master-page');
$xmlWriter->writeAttribute('style:name', 'Standard'); $xmlWriter->writeAttribute('style:name', "Standard$iplus1");
$xmlWriter->writeAttribute('style:page-layout-name', 'Mpm1'); $xmlWriter->writeAttribute('style:page-layout-name', "Mpm$iplus1");
// Multiple headers and footers probably not supported,
// and, even if they are, I'm not sure how,
// so quit after generating one.
foreach ($sections[$i]->getHeaders() as $hdr) {
$xmlWriter->startElement('style:header');
foreach ($hdr->getElements() as $elem) {
$cl1 = get_class($elem);
$cl2 = str_replace('\\Element\\', '\\Writer\\ODText\\Element\\', $cl1);
if (class_exists($cl2)) {
$wtr = new $cl2($xmlWriter, $elem);
$wtr->write();
}
}
$xmlWriter->endElement(); // style:header
break;
}
foreach ($sections[$i]->getFooters() as $hdr) {
$xmlWriter->startElement('style:footer');
foreach ($hdr->getElements() as $elem) {
$cl1 = get_class($elem);
$cl2 = str_replace('\\Element\\', '\\Writer\\ODText\\Element\\', $cl1);
if (class_exists($cl2)) {
$wtr = new $cl2($xmlWriter, $elem);
$wtr->write();
}
}
$xmlWriter->endElement(); // style:footer
break;
}
$xmlWriter->endElement(); // style:master-page $xmlWriter->endElement(); // style:master-page
}
$xmlWriter->endElement(); // office:master-styles $xmlWriter->endElement(); // office:master-styles
} }
} }

View File

@ -35,6 +35,14 @@ class Font extends AbstractStyle
} }
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
$stylep = (method_exists($style, 'getParagraph')) ? $style->getParagraph() : null;
if ($stylep instanceof \PhpOffice\PhpWord\Style\Paragraph) {
$temp1 = clone $stylep;
$temp1->setStyleName($style->getStyleName());
$temp2 = new \PhpOffice\PhpWord\Writer\ODText\Style\Paragraph($xmlWriter, $temp1);
$temp2->write();
}
$xmlWriter->startElement('style:style'); $xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $style->getStyleName()); $xmlWriter->writeAttribute('style:name', $style->getStyleName());
$xmlWriter->writeAttribute('style:family', 'text'); $xmlWriter->writeAttribute('style:family', 'text');
@ -53,7 +61,7 @@ class Font extends AbstractStyle
// Color // Color
$color = $style->getColor(); $color = $style->getColor();
$xmlWriter->writeAttributeIf($color != '', 'fo:color', '#' . $color); $xmlWriter->writeAttributeIf($color != '', 'fo:color', '#' . \PhpOffice\PhpWord\Shared\Converter::stringToRgb($color));
// Bold & italic // Bold & italic
$xmlWriter->writeAttributeIf($style->isBold(), 'fo:font-weight', 'bold'); $xmlWriter->writeAttributeIf($style->isBold(), 'fo:font-weight', 'bold');
@ -82,6 +90,15 @@ class Font extends AbstractStyle
$xmlWriter->writeAttributeIf($style->isSuperScript(), 'style:text-position', 'super'); $xmlWriter->writeAttributeIf($style->isSuperScript(), 'style:text-position', 'super');
$xmlWriter->writeAttributeIf($style->isSubScript(), 'style:text-position', 'sub'); $xmlWriter->writeAttributeIf($style->isSubScript(), 'style:text-position', 'sub');
if ($style->isNoProof()) {
$xmlWriter->writeAttribute('fo:language', 'zxx');
$xmlWriter->writeAttribute('style:language-asian', 'zxx');
$xmlWriter->writeAttribute('style:language-complex', 'zxx');
$xmlWriter->writeAttribute('fo:country', 'none');
$xmlWriter->writeAttribute('style:country-asian', 'none');
$xmlWriter->writeAttribute('style:country-complex', 'none');
}
// @todo Foreground-Color // @todo Foreground-Color
// @todo Background color // @todo Background color

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Writer\ODText\Style; namespace PhpOffice\PhpWord\Writer\ODText\Style;
use PhpOffice\PhpWord\Shared\Converter;
/** /**
* Font style writer * Font style writer
* *
@ -35,31 +37,119 @@ class Paragraph extends AbstractStyle
} }
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
$marginTop = (is_null($style->getSpaceBefore()) || $style->getSpaceBefore() == 0) ? '0' : round(17.6 / $style->getSpaceBefore(), 2); $marginTop = $style->getSpaceBefore();
$marginBottom = (is_null($style->getSpaceAfter()) || $style->getSpaceAfter() == 0) ? '0' : round(17.6 / $style->getSpaceAfter(), 2); $marginBottom = $style->getSpaceAfter();
$xmlWriter->startElement('style:style'); $xmlWriter->startElement('style:style');
$styleName = $style->getStyleName();
$styleAuto = false;
$mpm = '';
$psm = '';
$pagestart = -1;
$breakafter = $breakbefore = $breakauto = false;
if ($style->isAuto()) {
if (substr($styleName, 0, 2) === 'PB') {
$styleAuto = true;
$breakafter = true;
} elseif (substr($styleName, 0, 2) === 'SB') {
$styleAuto = true;
$mpm = 'Standard' . substr($styleName, 2);
$psn = $style->getNumLevel();
$pagestart = $psn;
} elseif (substr($styleName, 0, 2) === 'HD') {
$styleAuto = true;
$psm = 'Heading_' . substr($styleName, 2);
$stylep = \PhpOffice\PhpWord\Style::getStyle($psm);
if ($stylep instanceof \PhpOffice\PhpWord\Style\Font) {
if (method_exists($stylep, 'getParagraph')) {
$stylep = $stylep->getParagraph();
}
}
if ($stylep instanceof \PhpOffice\PhpWord\Style\Paragraph) {
if ($stylep->hasPageBreakBefore()) {
$breakbefore = true;
}
}
} elseif (substr($styleName, 0, 2) === 'HE') {
$styleAuto = true;
$psm = 'Heading_' . substr($styleName, 2);
$breakauto = true;
} else {
$styleAuto = true;
$psm = 'Normal';
if (preg_match('/^P\\d+_(\\w+)$/', $styleName, $matches)) {
$psm = $matches[1];
}
}
}
$xmlWriter->writeAttribute('style:name', $style->getStyleName()); $xmlWriter->writeAttribute('style:name', $style->getStyleName());
$xmlWriter->writeAttribute('style:family', 'paragraph'); $xmlWriter->writeAttribute('style:family', 'paragraph');
if ($style->isAuto()) { if ($styleAuto) {
$xmlWriter->writeAttribute('style:parent-style-name', 'Standard'); $xmlWriter->writeAttributeIf($psm !== '', 'style:parent-style-name', $psm);
$xmlWriter->writeAttribute('style:master-page-name', 'Standard'); $xmlWriter->writeAttributeIf($mpm !== '', 'style:master-page-name', $mpm);
} }
$xmlWriter->startElement('style:paragraph-properties'); $xmlWriter->startElement('style:paragraph-properties');
if ($style->isAuto()) { if ($styleAuto) {
$xmlWriter->writeAttribute('style:page-number', 'auto'); if ($breakafter) {
} else { $xmlWriter->writeAttribute('fo:break-after', 'page');
$xmlWriter->writeAttribute('fo:margin-top', $marginTop . 'cm'); $xmlWriter->writeAttribute('fo:margin-top', '0cm');
$xmlWriter->writeAttribute('fo:margin-bottom', $marginBottom . 'cm'); $xmlWriter->writeAttribute('fo:margin-bottom', '0cm');
$xmlWriter->writeAttribute('fo:text-align', $style->getAlignment()); } elseif ($breakbefore) {
$xmlWriter->writeAttribute('fo:break-before', 'page');
} elseif ($breakauto) {
$xmlWriter->writeAttribute('fo:break-before', 'auto');
}
if ($pagestart > 0) {
$xmlWriter->writeAttribute('style:page-number', $pagestart);
}
}
if (!$breakafter && !$breakbefore && !$breakauto) {
$twipToPoint = Converter::INCH_TO_TWIP / Converter::INCH_TO_POINT; // 20
$xmlWriter->writeAttributeIf($marginTop !== null, 'fo:margin-top', ($marginTop / $twipToPoint) . 'pt');
$xmlWriter->writeAttributeIf($marginBottom !== null, 'fo:margin-bottom', ($marginBottom / $twipToPoint) . 'pt');
}
$temp = $style->getAlignment();
$xmlWriter->writeAttributeIf($temp !== '', 'fo:text-align', $temp);
$temp = $style->getLineHeight();
$xmlWriter->writeAttributeIf($temp !== null, 'fo:line-height', ((string) ($temp * 100) . '%'));
$xmlWriter->writeAttributeIf($style->hasPageBreakBefore() === true, 'fo:break-before', 'page');
$tabs = $style->getTabs();
if ($tabs !== null && count($tabs) > 0) {
$xmlWriter->startElement('style:tab-stops');
foreach ($tabs as $tab) {
$xmlWriter->startElement('style:tab-stop');
$xmlWriter->writeAttribute('style:type', $tab->getType());
$xmlWriter->writeAttribute('style:position', (string) ($tab->getPosition() / Converter::INCH_TO_TWIP) . 'in');
$xmlWriter->endElement();
}
$xmlWriter->endElement();
} }
//Right to left //Right to left
$xmlWriter->writeAttributeIf($style->isBidi(), 'style:writing-mode', 'rl-tb'); $xmlWriter->writeAttributeIf($style->isBidi(), 'style:writing-mode', 'rl-tb');
//Indentation
$indent = $style->getIndentation();
//if ($indent instanceof \PhpOffice\PhpWord\Style\Indentation) {
if (!empty($indent)) {
$marg = $indent->getLeft();
$xmlWriter->writeAttributeIf($marg !== null, 'fo:margin-left', (string) ($marg / Converter::INCH_TO_TWIP) . 'in');
$marg = $indent->getRight();
$xmlWriter->writeAttributeIf($marg !== null, 'fo:margin-right', (string) ($marg / Converter::INCH_TO_TWIP) . 'in');
}
$xmlWriter->endElement(); //style:paragraph-properties $xmlWriter->endElement(); //style:paragraph-properties
if ($styleAuto && substr($styleName, 0, 2) === 'SB') {
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('text:display', 'none');
$xmlWriter->endElement();
}
$xmlWriter->endElement(); //style:style $xmlWriter->endElement(); //style:style
} }
} }

View File

@ -35,6 +35,16 @@ class DomPDF extends AbstractRenderer implements WriterInterface
*/ */
protected $includeFile = null; protected $includeFile = null;
/**
* Gets the implementation of external PDF library that should be used.
*
* @return Dompdf implementation
*/
protected function createExternalWriterInstance()
{
return new DompdfLib();
}
/** /**
* Save PhpWord to file. * Save PhpWord to file.
* *
@ -49,7 +59,7 @@ class DomPDF extends AbstractRenderer implements WriterInterface
$orientation = 'portrait'; $orientation = 'portrait';
// Create PDF // Create PDF
$pdf = new DompdfLib(); $pdf = $this->createExternalWriterInstance();
$pdf->setPaper(strtolower($paperSize), $orientation); $pdf->setPaper(strtolower($paperSize), $orientation);
$pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent())); $pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent()));
$pdf->render(); $pdf->render();

View File

@ -44,6 +44,18 @@ class MPDF extends AbstractRenderer implements WriterInterface
parent::__construct($phpWord); parent::__construct($phpWord);
} }
/**
* Gets the implementation of external PDF library that should be used.
*
* @return Mpdf implementation
*/
protected function createExternalWriterInstance()
{
$mPdfClass = $this->getMPdfClassName();
return new $mPdfClass();
}
/** /**
* Save PhpWord to file. * Save PhpWord to file.
* *
@ -58,8 +70,7 @@ class MPDF extends AbstractRenderer implements WriterInterface
$orientation = strtoupper('portrait'); $orientation = strtoupper('portrait');
// Create PDF // Create PDF
$mPdfClass = $this->getMPdfClassName(); $pdf = $this->createExternalWriterInstance();
$pdf = new $mPdfClass();
$pdf->_setPageSize($paperSize, $orientation); $pdf->_setPageSize($paperSize, $orientation);
$pdf->addPage($orientation); $pdf->addPage($orientation);

View File

@ -36,6 +36,20 @@ class TCPDF extends AbstractRenderer implements WriterInterface
*/ */
protected $includeFile = 'tcpdf.php'; protected $includeFile = 'tcpdf.php';
/**
* Gets the implementation of external PDF library that should be used.
*
* @param string $orientation Page orientation
* @param string $unit Unit measure
* @param string $paperSize Paper size
*
* @return \TCPDF implementation
*/
protected function createExternalWriterInstance($orientation, $unit, $paperSize)
{
return new \TCPDF($orientation, $unit, $paperSize);
}
/** /**
* Save PhpWord to file. * Save PhpWord to file.
* *
@ -50,7 +64,7 @@ class TCPDF extends AbstractRenderer implements WriterInterface
$orientation = 'P'; $orientation = 'P';
// Create PDF // Create PDF
$pdf = new \TCPDF($orientation, 'pt', $paperSize); $pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize);
$pdf->setFontSubsetting(false); $pdf->setFontSubsetting(false);
$pdf->setPrintHeader(false); $pdf->setPrintHeader(false);
$pdf->setPrintFooter(false); $pdf->setPrintFooter(false);

View File

@ -17,10 +17,10 @@
namespace PhpOffice\PhpWord\Writer\RTF\Element; namespace PhpOffice\PhpWord\Writer\RTF\Element;
use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Element\AbstractElement as Element;
use PhpOffice\PhpWord\Escaper\Rtf; use PhpOffice\PhpWord\Escaper\Rtf;
use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
@ -126,7 +126,7 @@ abstract class AbstractElement extends HTMLAbstractElement
return $this->escaper->escape($text); return $this->escaper->escape($text);
} }
return CommonText::toUnicode($text); // todo: replace with `return $text;` later. return SharedText::toUnicode($text); // todo: replace with `return $text;` later.
} }
/** /**

View File

@ -17,10 +17,10 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\Text as CommonText;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Element\AbstractElement as Element;
use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Abstract element writer * Abstract element writer
@ -32,7 +32,7 @@ abstract class AbstractElement
/** /**
* XML writer * XML writer
* *
* @var \PhpOffice\Common\XMLWriter * @var \PhpOffice\PhpWord\Shared\XMLWriter
*/ */
private $xmlWriter; private $xmlWriter;
@ -58,7 +58,7 @@ abstract class AbstractElement
/** /**
* Create new instance * Create new instance
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param \PhpOffice\PhpWord\Element\AbstractElement $element
* @param bool $withoutP * @param bool $withoutP
*/ */
@ -72,7 +72,7 @@ abstract class AbstractElement
/** /**
* Get XML Writer * Get XML Writer
* *
* @return \PhpOffice\Common\XMLWriter * @return \PhpOffice\PhpWord\Shared\XMLWriter
*/ */
protected function getXmlWriter() protected function getXmlWriter()
{ {
@ -207,7 +207,7 @@ abstract class AbstractElement
*/ */
protected function getText($text) protected function getText($text)
{ {
return CommonText::controlCharacterPHP2OOXML($text); return SharedText::controlCharacterPHP2OOXML($text);
} }
/** /**

View File

@ -17,10 +17,10 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement; use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Element\AbstractElement as Element;
use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement; use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Container element writer (section, textrun, header, footnote, cell, etc.) * Container element writer (section, textrun, header, footnote, cell, etc.)
@ -71,7 +71,7 @@ class Container extends AbstractElement
/** /**
* Write individual element * Write individual element
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param \PhpOffice\PhpWord\Element\AbstractElement $element
* @param bool $withoutP * @param bool $withoutP
* @return string * @return string

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\FormField as FormFieldElement; use PhpOffice\PhpWord\Element\FormField as FormFieldElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* FormField element writer * FormField element writer
@ -105,7 +105,7 @@ class FormField extends Text
* Write textinput. * Write textinput.
* *
* @see http://www.datypic.com/sc/ooxml/t-w_CT_FFTextInput.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFTextInput.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\FormField $element * @param \PhpOffice\PhpWord\Element\FormField $element
*/ */
private function writeTextInput(XMLWriter $xmlWriter, FormFieldElement $element) private function writeTextInput(XMLWriter $xmlWriter, FormFieldElement $element)
@ -121,7 +121,7 @@ class FormField extends Text
* Write checkbox. * Write checkbox.
* *
* @see http://www.datypic.com/sc/ooxml/t-w_CT_FFCheckBox.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFCheckBox.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\FormField $element * @param \PhpOffice\PhpWord\Element\FormField $element
*/ */
private function writeCheckBox(XMLWriter $xmlWriter, FormFieldElement $element) private function writeCheckBox(XMLWriter $xmlWriter, FormFieldElement $element)
@ -144,7 +144,7 @@ class FormField extends Text
* Write dropdown. * Write dropdown.
* *
* @see http://www.datypic.com/sc/ooxml/t-w_CT_FFDDList.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_FFDDList.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\FormField $element * @param \PhpOffice\PhpWord\Element\FormField $element
*/ */
private function writeDropDown(XMLWriter $xmlWriter, FormFieldElement $element) private function writeDropDown(XMLWriter $xmlWriter, FormFieldElement $element)

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Image as ImageElement; use PhpOffice\PhpWord\Element\Image as ImageElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
use PhpOffice\PhpWord\Style\Frame as FrameStyle; use PhpOffice\PhpWord\Style\Frame as FrameStyle;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\SDT as SDTElement; use PhpOffice\PhpWord\Element\SDT as SDTElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Structured document tag element writer * Structured document tag element writer
@ -77,7 +77,7 @@ class SDT extends Text
* Write text. * Write text.
* *
* @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtText.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtText.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writePlainText(XMLWriter $xmlWriter) private function writePlainText(XMLWriter $xmlWriter)
{ {
@ -89,7 +89,7 @@ class SDT extends Text
* Write combo box. * Write combo box.
* *
* @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtComboBox.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtComboBox.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\SDT $element * @param \PhpOffice\PhpWord\Element\SDT $element
*/ */
private function writeComboBox(XMLWriter $xmlWriter, SDTElement $element) private function writeComboBox(XMLWriter $xmlWriter, SDTElement $element)
@ -108,7 +108,7 @@ class SDT extends Text
* Write drop down list. * Write drop down list.
* *
* @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtDropDownList.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtDropDownList.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\SDT $element * @param \PhpOffice\PhpWord\Element\SDT $element
*/ */
private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element) private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element)
@ -120,7 +120,7 @@ class SDT extends Text
* Write date. * Write date.
* *
* @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtDate.html * @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtDate.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\SDT $element * @param \PhpOffice\PhpWord\Element\SDT $element
*/ */
private function writeDate(XMLWriter $xmlWriter, SDTElement $element) private function writeDate(XMLWriter $xmlWriter, SDTElement $element)

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Shape as ShapeElement; use PhpOffice\PhpWord\Element\Shape as ShapeElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Shape as ShapeStyle; use PhpOffice\PhpWord\Style\Shape as ShapeStyle;
use PhpOffice\PhpWord\Writer\Word2007\Style\Shape as ShapeStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Shape as ShapeStyleWriter;
@ -77,7 +77,7 @@ class Shape extends AbstractElement
/** /**
* Write arc. * Write arc.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Shape $style * @param \PhpOffice\PhpWord\Style\Shape $style
*/ */
private function writeArc(XMLWriter $xmlWriter, ShapeStyle $style) private function writeArc(XMLWriter $xmlWriter, ShapeStyle $style)
@ -91,7 +91,7 @@ class Shape extends AbstractElement
/** /**
* Write curve. * Write curve.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Shape $style * @param \PhpOffice\PhpWord\Style\Shape $style
*/ */
private function writeCurve(XMLWriter $xmlWriter, ShapeStyle $style) private function writeCurve(XMLWriter $xmlWriter, ShapeStyle $style)
@ -106,7 +106,7 @@ class Shape extends AbstractElement
/** /**
* Write line. * Write line.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Shape $style * @param \PhpOffice\PhpWord\Style\Shape $style
*/ */
private function writeLine(XMLWriter $xmlWriter, ShapeStyle $style) private function writeLine(XMLWriter $xmlWriter, ShapeStyle $style)
@ -120,7 +120,7 @@ class Shape extends AbstractElement
/** /**
* Write polyline. * Write polyline.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Shape $style * @param \PhpOffice\PhpWord\Style\Shape $style
*/ */
private function writePolyline(XMLWriter $xmlWriter, ShapeStyle $style) private function writePolyline(XMLWriter $xmlWriter, ShapeStyle $style)
@ -131,7 +131,7 @@ class Shape extends AbstractElement
/** /**
* Write rectangle. * Write rectangle.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Shape $style * @param \PhpOffice\PhpWord\Style\Shape $style
*/ */
private function writeRoundRect(XMLWriter $xmlWriter, ShapeStyle $style) private function writeRoundRect(XMLWriter $xmlWriter, ShapeStyle $style)

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\TOC as TOCElement; use PhpOffice\PhpWord\Element\TOC as TOCElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
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;
@ -64,7 +64,7 @@ class TOC extends AbstractElement
/** /**
* Write title * Write title
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\TOC $element * @param \PhpOffice\PhpWord\Element\TOC $element
* @param \PhpOffice\PhpWord\Element\Title $title * @param \PhpOffice\PhpWord\Element\Title $title
* @param bool $writeFieldMark * @param bool $writeFieldMark
@ -132,7 +132,7 @@ class TOC extends AbstractElement
/** /**
* Write style * Write style
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\TOC $element * @param \PhpOffice\PhpWord\Element\TOC $element
* @param int $indent * @param int $indent
*/ */
@ -178,7 +178,7 @@ class TOC extends AbstractElement
/** /**
* Write TOC Field. * Write TOC Field.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\TOC $element * @param \PhpOffice\PhpWord\Element\TOC $element
*/ */
private function writeFieldMark(XMLWriter $xmlWriter, TOCElement $element) private function writeFieldMark(XMLWriter $xmlWriter, TOCElement $element)

View File

@ -17,10 +17,10 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Cell as CellElement; use PhpOffice\PhpWord\Element\Cell as CellElement;
use PhpOffice\PhpWord\Element\Row as RowElement; use PhpOffice\PhpWord\Element\Row as RowElement;
use PhpOffice\PhpWord\Element\Table as TableElement; use PhpOffice\PhpWord\Element\Table as TableElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Cell as CellStyle; use PhpOffice\PhpWord\Style\Cell as CellStyle;
use PhpOffice\PhpWord\Style\Row as RowStyle; use PhpOffice\PhpWord\Style\Row as RowStyle;
use PhpOffice\PhpWord\Writer\Word2007\Style\Cell as CellStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Cell as CellStyleWriter;
@ -71,7 +71,7 @@ class Table extends AbstractElement
/** /**
* Write column. * Write column.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Table $element * @param \PhpOffice\PhpWord\Element\Table $element
*/ */
private function writeColumns(XMLWriter $xmlWriter, TableElement $element) private function writeColumns(XMLWriter $xmlWriter, TableElement $element)
@ -93,7 +93,7 @@ class Table extends AbstractElement
/** /**
* Write row. * Write row.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Row $row * @param \PhpOffice\PhpWord\Element\Row $row
*/ */
private function writeRow(XMLWriter $xmlWriter, RowElement $row) private function writeRow(XMLWriter $xmlWriter, RowElement $row)
@ -119,7 +119,7 @@ class Table extends AbstractElement
/** /**
* Write cell. * Write cell.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Cell $cell * @param \PhpOffice\PhpWord\Element\Cell $cell
*/ */
private function writeCell(XMLWriter $xmlWriter, CellElement $cell) private function writeCell(XMLWriter $xmlWriter, CellElement $cell)

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\AbstractWriter; use PhpOffice\PhpWord\Writer\AbstractWriter;
/** /**
@ -73,7 +73,7 @@ abstract class AbstractPart
/** /**
* Get XML Writer * Get XML Writer
* *
* @return \PhpOffice\Common\XMLWriter * @return \PhpOffice\PhpWord\Shared\XMLWriter
*/ */
protected function getXmlWriter() protected function getXmlWriter()
{ {

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Chart as ChartElement; use PhpOffice\PhpWord\Element\Chart as ChartElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Word2007 chart part writer: word/charts/chartx.xml * Word2007 chart part writer: word/charts/chartx.xml
@ -99,7 +99,7 @@ class Chart extends AbstractPart
* Write chart * Write chart
* *
* @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_Chart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_Chart.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writeChart(XMLWriter $xmlWriter) private function writeChart(XMLWriter $xmlWriter)
{ {
@ -121,7 +121,7 @@ class Chart extends AbstractPart
* @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_AreaChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_AreaChart.html
* @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_RadarChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_RadarChart.html
* @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_ScatterChart.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_ScatterChart.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/ */
private function writePlotArea(XMLWriter $xmlWriter) private function writePlotArea(XMLWriter $xmlWriter)
{ {
@ -209,7 +209,7 @@ class Chart extends AbstractPart
/** /**
* Write series. * Write series.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param bool $scatter * @param bool $scatter
*/ */
private function writeSeries(XMLWriter $xmlWriter, $scatter = false) private function writeSeries(XMLWriter $xmlWriter, $scatter = false)
@ -294,7 +294,7 @@ class Chart extends AbstractPart
/** /**
* Write series items. * Write series items.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type * @param string $type
* @param array $values * @param array $values
*/ */
@ -335,7 +335,7 @@ class Chart extends AbstractPart
* Write axis * Write axis
* *
* @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_CatAx.html * @see http://www.datypic.com/sc/ooxml/t-draw-chart_CT_CatAx.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type * @param string $type
*/ */
private function writeAxis(XMLWriter $xmlWriter, $type) private function writeAxis(XMLWriter $xmlWriter, $type)
@ -400,7 +400,7 @@ class Chart extends AbstractPart
* Write shape * Write shape
* *
* @see http://www.datypic.com/sc/ooxml/t-a_CT_ShapeProperties.html * @see http://www.datypic.com/sc/ooxml/t-a_CT_ShapeProperties.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param bool $line * @param bool $line
*/ */
private function writeShape(XMLWriter $xmlWriter, $line = false) private function writeShape(XMLWriter $xmlWriter, $line = false)

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Comment; use PhpOffice\PhpWord\Element\Comment;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Element\Container;
/** /**
@ -70,7 +70,7 @@ class Comments extends AbstractPart
/** /**
* Write comment item. * Write comment item.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Comment $comment * @param \PhpOffice\PhpWord\Element\Comment $comment
*/ */
protected function writeComment(XMLWriter $xmlWriter, Comment $comment) protected function writeComment(XMLWriter $xmlWriter, Comment $comment)

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Word2007 contenttypes part writer: [Content_Types].xml * Word2007 contenttypes part writer: [Content_Types].xml
@ -80,7 +80,7 @@ class ContentTypes extends AbstractPart
/** /**
* Write content types element * Write content types element
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter XML Writer * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* @param array $parts * @param array $parts
* @param bool $isDefault * @param bool $isDefault
*/ */

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Element\Container;
use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter;
@ -80,7 +80,7 @@ class Document extends AbstractPart
/** /**
* Write begin section. * Write begin section.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Section $section * @param \PhpOffice\PhpWord\Element\Section $section
*/ */
private function writeSection(XMLWriter $xmlWriter, Section $section) private function writeSection(XMLWriter $xmlWriter, Section $section)
@ -95,7 +95,7 @@ class Document extends AbstractPart
/** /**
* Write end section. * Write end section.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Section $section * @param \PhpOffice\PhpWord\Element\Section $section
*/ */
private function writeSectionSettings(XMLWriter $xmlWriter, Section $section) private function writeSectionSettings(XMLWriter $xmlWriter, Section $section)

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Footnote; use PhpOffice\PhpWord\Element\Footnote;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Element\Container;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
@ -135,7 +135,7 @@ class Footnotes extends AbstractPart
/** /**
* Write note item. * Write note item.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Footnote|\PhpOffice\PhpWord\Element\Endnote $element * @param \PhpOffice\PhpWord\Element\Footnote|\PhpOffice\PhpWord\Element\Endnote $element
*/ */
protected function writeNote(XMLWriter $xmlWriter, $element) protected function writeNote(XMLWriter $xmlWriter, $element)

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Numbering as NumberingStyle; use PhpOffice\PhpWord\Style\Numbering as NumberingStyle;
use PhpOffice\PhpWord\Style\NumberingLevel; use PhpOffice\PhpWord\Style\NumberingLevel;
@ -97,7 +97,7 @@ class Numbering extends AbstractPart
/** /**
* Write level. * Write level.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @param \PhpOffice\PhpWord\Style\NumberingLevel $level
*/ */
private function writeLevel(XMLWriter $xmlWriter, NumberingLevel $level) private function writeLevel(XMLWriter $xmlWriter, NumberingLevel $level)
@ -137,7 +137,7 @@ class Numbering extends AbstractPart
* *
* @since 0.11.0 * @since 0.11.0
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @param \PhpOffice\PhpWord\Style\NumberingLevel $level
* @todo Use paragraph style writer * @todo Use paragraph style writer
*/ */
@ -169,7 +169,7 @@ class Numbering extends AbstractPart
* *
* @since 0.11.0 * @since 0.11.0
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @param \PhpOffice\PhpWord\Style\NumberingLevel $level
* @todo Use font style writer * @todo Use font style writer
*/ */

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Word2007 main relationship writer: _rels/.rels * Word2007 main relationship writer: _rels/.rels
@ -49,7 +49,7 @@ class Rels extends AbstractPart
/** /**
* Write relationships. * Write relationships.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param array $xmlRels * @param array $xmlRels
* @param array $mediaRels * @param array $mediaRels
* @param int $relId * @param int $relId
@ -76,7 +76,7 @@ class Rels extends AbstractPart
/** /**
* Write media relationships. * Write media relationships.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $relId * @param int $relId
* @param array $mediaRel * @param array $mediaRel
*/ */
@ -101,7 +101,7 @@ class Rels extends AbstractPart
* Format: * Format:
* <Relationship Id="rId..." Type="http://..." Target="....xml" TargetMode="..." /> * <Relationship Id="rId..." Type="http://..." Target="....xml" TargetMode="..." />
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $relId Relationship ID * @param int $relId Relationship ID
* @param string $type Relationship type * @param string $type Relationship type
* @param string $target Relationship target * @param string $target Relationship target

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\Microsoft\PasswordEncoder;
use PhpOffice\PhpWord\ComplexType\ProofState; use PhpOffice\PhpWord\ComplexType\ProofState;
use PhpOffice\PhpWord\ComplexType\TrackChangesView; use PhpOffice\PhpWord\ComplexType\TrackChangesView;
use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder;
use PhpOffice\PhpWord\Style\Language; use PhpOffice\PhpWord\Style\Language;
/** /**
@ -69,7 +69,7 @@ class Settings extends AbstractPart
/** /**
* Write indivual setting, recursive to any child settings. * Write indivual setting, recursive to any child settings.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $settingKey * @param string $settingKey
* @param array|string $settingValue * @param array|string $settingValue
*/ */

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
@ -76,7 +76,7 @@ class Styles extends AbstractPart
/** /**
* Write default font and other default styles. * Write default font and other default styles.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\AbstractStyle[] $styles * @param \PhpOffice\PhpWord\Style\AbstractStyle[] $styles
*/ */
private function writeDefaultStyles(XMLWriter $xmlWriter, $styles) private function writeDefaultStyles(XMLWriter $xmlWriter, $styles)
@ -161,7 +161,7 @@ class Styles extends AbstractPart
/** /**
* Write font style. * Write font style.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $styleName * @param string $styleName
* @param \PhpOffice\PhpWord\Style\Font $style * @param \PhpOffice\PhpWord\Style\Font $style
*/ */
@ -229,7 +229,7 @@ class Styles extends AbstractPart
/** /**
* Write paragraph style. * Write paragraph style.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $styleName * @param string $styleName
* @param \PhpOffice\PhpWord\Style\Paragraph $style * @param \PhpOffice\PhpWord\Style\Paragraph $style
*/ */
@ -261,7 +261,7 @@ class Styles extends AbstractPart
/** /**
* Write table style. * Write table style.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $styleName * @param string $styleName
* @param \PhpOffice\PhpWord\Style\Table $style * @param \PhpOffice\PhpWord\Style\Table $style
*/ */

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style; namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Style writer * Style writer
@ -30,7 +30,7 @@ abstract class AbstractStyle
/** /**
* XML writer * XML writer
* *
* @var \PhpOffice\Common\XMLWriter * @var \PhpOffice\PhpWord\Shared\XMLWriter
*/ */
private $xmlWriter; private $xmlWriter;
@ -49,7 +49,7 @@ abstract class AbstractStyle
/** /**
* Create new instance. * Create new instance.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string|\PhpOffice\PhpWord\Style\AbstractStyle $style * @param string|\PhpOffice\PhpWord\Style\AbstractStyle $style
*/ */
public function __construct(XMLWriter $xmlWriter, $style = null) public function __construct(XMLWriter $xmlWriter, $style = null)
@ -61,7 +61,7 @@ abstract class AbstractStyle
/** /**
* Get XML Writer * Get XML Writer
* *
* @return \PhpOffice\Common\XMLWriter * @return \PhpOffice\PhpWord\Shared\XMLWriter
*/ */
protected function getXmlWriter() protected function getXmlWriter()
{ {
@ -96,7 +96,7 @@ abstract class AbstractStyle
); );
$unit = Settings::getMeasurementUnit(); $unit = Settings::getMeasurementUnit();
$factor = 1; $factor = 1;
if (in_array($unit, $factors) && $value != $default) { if (array_key_exists($unit, $factors) && $value != $default) {
$factor = $factors[$unit]; $factor = $factors[$unit];
} }
@ -106,7 +106,7 @@ abstract class AbstractStyle
/** /**
* Write child style. * Write child style.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
*/ */

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style; namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Frame as FrameStyle; use PhpOffice\PhpWord\Style\Frame as FrameStyle;
use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment; use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment;
@ -108,7 +108,7 @@ class Frame extends AbstractStyle
/** /**
* Write wrap. * Write wrap.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Frame $style * @param \PhpOffice\PhpWord\Style\Frame $style
* @param string $wrap * @param string $wrap
*/ */

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style; namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
/** /**
* Margin border style writer * Margin border style writer
@ -78,7 +78,7 @@ class MarginBorder extends AbstractStyle
/** /**
* Write side. * Write side.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $side * @param string $side
* @param int $width * @param int $width
* @param string $color * @param string $color

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style; namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment; use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment;
@ -146,7 +146,7 @@ class Paragraph extends AbstractStyle
/** /**
* Write tabs. * Write tabs.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Tab[] $tabs * @param \PhpOffice\PhpWord\Style\Tab[] $tabs
*/ */
private function writeTabs(XMLWriter $xmlWriter, $tabs) private function writeTabs(XMLWriter $xmlWriter, $tabs)
@ -164,7 +164,7 @@ class Paragraph extends AbstractStyle
/** /**
* Write numbering. * Write numbering.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param array $numbering * @param array $numbering
*/ */
private function writeNumbering(XMLWriter $xmlWriter, $numbering) private function writeNumbering(XMLWriter $xmlWriter, $numbering)

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style; namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\SimpleType\TblWidth; use PhpOffice\PhpWord\SimpleType\TblWidth;
use PhpOffice\PhpWord\Style\Table as TableStyle; use PhpOffice\PhpWord\Style\Table as TableStyle;
use PhpOffice\PhpWord\Writer\Word2007\Element\TableAlignment; use PhpOffice\PhpWord\Writer\Word2007\Element\TableAlignment;
@ -59,7 +59,7 @@ class Table extends AbstractStyle
/** /**
* Write full style. * Write full style.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Table $style * @param \PhpOffice\PhpWord\Style\Table $style
*/ */
private function writeStyle(XMLWriter $xmlWriter, TableStyle $style) private function writeStyle(XMLWriter $xmlWriter, TableStyle $style)
@ -106,7 +106,7 @@ class Table extends AbstractStyle
/** /**
* Enable/Disable automatic resizing of the table * Enable/Disable automatic resizing of the table
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $layout autofit / fixed * @param string $layout autofit / fixed
*/ */
private function writeLayout(XMLWriter $xmlWriter, $layout) private function writeLayout(XMLWriter $xmlWriter, $layout)
@ -119,7 +119,7 @@ class Table extends AbstractStyle
/** /**
* Write margin. * Write margin.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Table $style * @param \PhpOffice\PhpWord\Style\Table $style
*/ */
private function writeMargin(XMLWriter $xmlWriter, TableStyle $style) private function writeMargin(XMLWriter $xmlWriter, TableStyle $style)
@ -138,7 +138,7 @@ class Table extends AbstractStyle
/** /**
* Write border. * Write border.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Table $style * @param \PhpOffice\PhpWord\Style\Table $style
*/ */
private function writeBorder(XMLWriter $xmlWriter, TableStyle $style) private function writeBorder(XMLWriter $xmlWriter, TableStyle $style)
@ -158,7 +158,7 @@ class Table extends AbstractStyle
/** /**
* Writes a table width * Writes a table width
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $elementName * @param string $elementName
* @param string $unit * @param string $unit
* @param int|float $width * @param int|float $width
@ -177,7 +177,7 @@ class Table extends AbstractStyle
/** /**
* Write row style. * Write row style.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Table $style * @param \PhpOffice\PhpWord\Style\Table $style
*/ */
private function writeFirstRow(XMLWriter $xmlWriter, TableStyle $style) private function writeFirstRow(XMLWriter $xmlWriter, TableStyle $style)
@ -196,7 +196,7 @@ class Table extends AbstractStyle
/** /**
* Write shading. * Write shading.
* *
* @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Table $style * @param \PhpOffice\PhpWord\Style\Table $style
*/ */
private function writeShading(XMLWriter $xmlWriter, TableStyle $style) private function writeShading(XMLWriter $xmlWriter, TableStyle $style)

View File

@ -77,10 +77,12 @@ class ImageTest extends AbstractWebServerEmbeddedTest
foreach ($images as $imageData) { foreach ($images as $imageData) {
list($source, $type, $extension, $createFunction, $imageFunction) = $imageData; list($source, $type, $extension, $createFunction, $imageFunction) = $imageData;
$nam = ucfirst(strtok($source, '.'));
$source = __DIR__ . "/../_files/images/{$source}"; $source = __DIR__ . "/../_files/images/{$source}";
$image = new Image($source); $image = new Image($source, null, null, $nam);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image);
$this->assertEquals($source, $image->getSource()); $this->assertEquals($source, $image->getSource());
$this->assertEquals($nam, $image->getName());
$this->assertEquals(md5($source), $image->getMediaId()); $this->assertEquals(md5($source), $image->getMediaId());
$this->assertEquals($type, $image->getImageType()); $this->assertEquals($type, $image->getImageType());
$this->assertEquals($extension, $image->getImageExtension()); $this->assertEquals($extension, $image->getImageExtension());

View File

@ -99,10 +99,10 @@ class TableTest extends \PHPUnit\Framework\TestCase
{ {
$oTable = new Table(); $oTable = new Table();
$oTable->addRow(); $oTable->addRow();
$element = $oTable->addCell(); $oTable->addCell();
$this->assertEquals($oTable->countColumns(), 1); $this->assertEquals($oTable->countColumns(), 1);
$element = $oTable->addCell(); $oTable->addCell();
$element = $oTable->addCell(); $oTable->addCell();
$this->assertEquals($oTable->countColumns(), 3); $this->assertEquals($oTable->countColumns(), 3);
} }
} }

View File

@ -25,6 +25,46 @@ use PhpOffice\PhpWord\Element\TrackChange;
*/ */
class ElementTest extends AbstractTestReader class ElementTest extends AbstractTestReader
{ {
/**
* Test reading of alternate content value
*/
public function testReadAlternateContent()
{
$documentXml = '<w:p>
<w:r>
<mc:AlternateContent>
<mc:Choice Requires="wps"></mc:Choice>
<mc:Fallback>
<w:pict>
<v:rect>
<v:textbox>
<w:txbxContent>
<w:p>
<w:pPr>
<w:jc w:val="center"/>
</w:pPr>
<w:r>
<w:t>Test node value</w:t>
</w:r>
</w:p>
</w:txbxContent>
</v:textbox>
</v:rect>
</w:pict>
</mc:Fallback>
</mc:AlternateContent>
</w:r>
</w:p>';
$phpWord = $this->getDocumentFromString(array('document' => $documentXml));
$elements = $phpWord->getSection(0)->getElements();
$this->assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $elements[0]);
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $elements[0]->getElement(0));
$text = $elements[0];
$this->assertEquals('Test node value', trim($text->getElement(0)->getText()));
}
/** /**
* Test reading of textbreak * Test reading of textbreak
*/ */

View File

@ -25,6 +25,45 @@ namespace PhpOffice\PhpWord;
*/ */
class SettingsTest extends \PHPUnit\Framework\TestCase class SettingsTest extends \PHPUnit\Framework\TestCase
{ {
private $compatibility;
private $defaultFontSize;
private $defaultFontName;
private $defaultPaper;
private $measurementUnit;
private $outputEscapingEnabled;
private $pdfRendererName;
private $pdfRendererPath;
private $tempDir;
private $zipClass;
public function setUp()
{
$this->compatibility = Settings::hasCompatibility();
$this->defaultFontSize = Settings::getDefaultFontSize();
$this->defaultFontName = Settings::getDefaultFontName();
$this->defaultPaper = Settings::getDefaultPaper();
$this->measurementUnit = Settings::getMeasurementUnit();
$this->outputEscapingEnabled = Settings::isOutputEscapingEnabled();
$this->pdfRendererName = Settings::getPdfRendererName();
$this->pdfRendererPath = Settings::getPdfRendererPath();
$this->tempDir = Settings::getTempDir();
$this->zipClass = Settings::getZipClass();
}
public function tearDown()
{
Settings::setCompatibility($this->compatibility);
Settings::setDefaultFontSize($this->defaultFontSize);
Settings::setDefaultFontName($this->defaultFontName);
Settings::setDefaultPaper($this->defaultPaper);
Settings::setMeasurementUnit($this->measurementUnit);
Settings::setOutputEscapingEnabled($this->outputEscapingEnabled);
Settings::setPdfRendererName($this->pdfRendererName);
Settings::setPdfRendererPath($this->pdfRendererPath);
Settings::setTempDir($this->tempDir);
Settings::setZipClass($this->zipClass);
}
/** /**
* Test set/get compatibity option * Test set/get compatibity option
*/ */
@ -35,14 +74,28 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
$this->assertFalse(Settings::hasCompatibility()); $this->assertFalse(Settings::hasCompatibility());
} }
/**
* Test set/get outputEscapingEnabled option
*/
public function testSetGetOutputEscapingEnabled()
{
$this->assertFalse(Settings::isOutputEscapingEnabled());
Settings::setOutputEscapingEnabled(true);
$this->assertTrue(Settings::isOutputEscapingEnabled());
}
/** /**
* Test set/get zip class * Test set/get zip class
*/ */
public function testSetGetZipClass() public function testSetGetZipClass()
{ {
$this->assertEquals(Settings::ZIPARCHIVE, Settings::getZipClass()); $this->assertEquals(Settings::ZIPARCHIVE, Settings::getZipClass());
$this->assertTrue(Settings::setZipClass(Settings::PCLZIP));
$this->assertFalse(Settings::setZipClass('foo')); $this->assertFalse(Settings::setZipClass('foo'));
$this->assertEquals(Settings::ZIPARCHIVE, Settings::getZipClass());
$this->assertTrue(Settings::setZipClass(Settings::PCLZIP));
$this->assertEquals(Settings::getZipClass(), Settings::PCLZIP);
$this->assertFalse(Settings::setZipClass('foo'));
$this->assertEquals(Settings::getZipClass(), Settings::PCLZIP);
} }
/** /**
@ -57,6 +110,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(Settings::PDF_RENDERER_DOMPDF, Settings::getPdfRendererName()); $this->assertEquals(Settings::PDF_RENDERER_DOMPDF, Settings::getPdfRendererName());
$this->assertEquals($domPdfPath, Settings::getPdfRendererPath()); $this->assertEquals($domPdfPath, Settings::getPdfRendererPath());
$this->assertFalse(Settings::setPdfRendererPath('dummy/path')); $this->assertFalse(Settings::setPdfRendererPath('dummy/path'));
$this->assertEquals($domPdfPath, Settings::getPdfRendererPath());
} }
/** /**
@ -65,8 +119,12 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
public function testSetGetMeasurementUnit() public function testSetGetMeasurementUnit()
{ {
$this->assertEquals(Settings::UNIT_TWIP, Settings::getMeasurementUnit()); $this->assertEquals(Settings::UNIT_TWIP, Settings::getMeasurementUnit());
$this->assertTrue(Settings::setMeasurementUnit(Settings::UNIT_INCH));
$this->assertFalse(Settings::setMeasurementUnit('foo')); $this->assertFalse(Settings::setMeasurementUnit('foo'));
$this->assertEquals(Settings::UNIT_TWIP, Settings::getMeasurementUnit());
$this->assertTrue(Settings::setMeasurementUnit(Settings::UNIT_INCH));
$this->assertEquals(Settings::UNIT_INCH, Settings::getMeasurementUnit());
$this->assertFalse(Settings::setMeasurementUnit('foo'));
$this->assertEquals(Settings::UNIT_INCH, Settings::getMeasurementUnit());
} }
/** /**
@ -99,8 +157,12 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
public function testSetGetDefaultFontName() public function testSetGetDefaultFontName()
{ {
$this->assertEquals(Settings::DEFAULT_FONT_NAME, Settings::getDefaultFontName()); $this->assertEquals(Settings::DEFAULT_FONT_NAME, Settings::getDefaultFontName());
$this->assertTrue(Settings::setDefaultFontName('Times New Roman'));
$this->assertFalse(Settings::setDefaultFontName(' ')); $this->assertFalse(Settings::setDefaultFontName(' '));
$this->assertEquals(Settings::DEFAULT_FONT_NAME, Settings::getDefaultFontName());
$this->assertTrue(Settings::setDefaultFontName('Times New Roman'));
$this->assertEquals('Times New Roman', Settings::getDefaultFontName());
$this->assertFalse(Settings::setDefaultFontName(' '));
$this->assertEquals('Times New Roman', Settings::getDefaultFontName());
} }
/** /**
@ -109,8 +171,35 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
public function testSetGetDefaultFontSize() public function testSetGetDefaultFontSize()
{ {
$this->assertEquals(Settings::DEFAULT_FONT_SIZE, Settings::getDefaultFontSize()); $this->assertEquals(Settings::DEFAULT_FONT_SIZE, Settings::getDefaultFontSize());
$this->assertTrue(Settings::setDefaultFontSize(12));
$this->assertFalse(Settings::setDefaultFontSize(null)); $this->assertFalse(Settings::setDefaultFontSize(null));
$this->assertEquals(Settings::DEFAULT_FONT_SIZE, Settings::getDefaultFontSize());
$this->assertTrue(Settings::setDefaultFontSize(12));
$this->assertEquals(12, Settings::getDefaultFontSize());
$this->assertFalse(Settings::setDefaultFontSize(null));
$this->assertEquals(12, Settings::getDefaultFontSize());
}
/**
* Test set/get default paper
*/
public function testSetGetDefaultPaper()
{
$dflt = Settings::DEFAULT_PAPER;
$chng = ($dflt === 'A4') ? 'Letter' : 'A4';
$doc = new PhpWord();
$this->assertEquals($dflt, Settings::getDefaultPaper());
$sec1 = $doc->addSection();
$this->assertEquals($dflt, $sec1->getStyle()->getPaperSize());
$this->assertFalse(Settings::setDefaultPaper(''));
$this->assertEquals($dflt, Settings::getDefaultPaper());
$this->assertTrue(Settings::setDefaultPaper($chng));
$this->assertEquals($chng, Settings::getDefaultPaper());
$sec2 = $doc->addSection();
$this->assertEquals($chng, $sec2->getStyle()->getPaperSize());
$sec3 = $doc->addSection(array('paperSize' => 'Legal'));
$this->assertEquals('Legal', $sec3->getStyle()->getPaperSize());
$this->assertFalse(Settings::setDefaultPaper(''));
$this->assertEquals($chng, Settings::getDefaultPaper());
} }
/** /**
@ -126,6 +215,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
'defaultFontName' => 'Arial', 'defaultFontName' => 'Arial',
'defaultFontSize' => 10, 'defaultFontSize' => 10,
'outputEscapingEnabled' => false, 'outputEscapingEnabled' => false,
'defaultPaper' => 'A4',
); );
// Test default value // Test default value
@ -133,6 +223,16 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
// Test with valid file // Test with valid file
$this->assertEquals($expected, Settings::loadConfig(__DIR__ . '/../../phpword.ini.dist')); $this->assertEquals($expected, Settings::loadConfig(__DIR__ . '/../../phpword.ini.dist'));
foreach ($expected as $key => $value) {
if ($key === 'compatibility') {
$meth = 'hasCompatibility';
} elseif ($key === 'outputEscapingEnabled') {
$meth = 'isOutputEscapingEnabled';
} else {
$meth = 'get' . ucfirst($key);
}
$this->assertEquals(Settings::$meth(), $value);
}
// Test with invalid file // Test with invalid file
$this->assertEmpty(Settings::loadConfig(__DIR__ . '/../../phpunit.xml.dist')); $this->assertEmpty(Settings::loadConfig(__DIR__ . '/../../phpunit.xml.dist'));

View File

@ -131,5 +131,8 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(120, Converter::cssToPoint('10pc')); $this->assertEquals(120, Converter::cssToPoint('10pc'));
$this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001); $this->assertEquals(28.346457, Converter::cssToPoint('10mm'), '', 0.000001);
$this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001); $this->assertEquals(283.464567, Converter::cssToPoint('10cm'), '', 0.000001);
$this->assertEquals(40, Converter::cssToPixel('30pt'));
$this->assertEquals(1.27, Converter::cssToCm('36pt'));
$this->assertEquals(127000, Converter::cssToEmu('10pt'));
} }
} }

View File

@ -0,0 +1,112 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Test class for PhpOffice\PhpWord\Shared\Drawing
*
* @coversDefaultClass \PhpOffice\PhpWord\Shared\Drawing
*/
class DrawingTest extends \PHPUnit\Framework\TestCase
{
public function testDegreesAngle()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::degreesToAngle());
$this->assertEquals((int) round($value * 60000), Drawing::degreesToAngle($value));
$this->assertEquals(0, Drawing::angleToDegrees());
$this->assertEquals(round($value / 60000), Drawing::angleToDegrees($value));
}
public function testPixelsCentimeters()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pixelsToCentimeters());
$this->assertEquals($value / Drawing::DPI_96 * 2.54, Drawing::pixelsToCentimeters($value));
$this->assertEquals(0, Drawing::centimetersToPixels());
$this->assertEquals($value / 2.54 * Drawing::DPI_96, Drawing::centimetersToPixels($value));
}
public function testPixelsEMU()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pixelsToEmu());
$this->assertEquals(round($value * 9525), Drawing::pixelsToEmu($value));
$this->assertEquals(0, Drawing::emuToPixels());
$this->assertEquals(round($value / 9525), Drawing::emuToPixels($value));
}
public function testPixelsPoints()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pixelsToPoints());
$this->assertEquals($value * 0.67777777, Drawing::pixelsToPoints($value));
$this->assertEquals(0, Drawing::pointsToPixels());
$this->assertEquals($value * 1.333333333, Drawing::pointsToPixels($value));
}
public function testPointsCentimeters()
{
$value = rand(1, 100);
$this->assertEquals(0, Drawing::pointsToCentimeters());
$this->assertEquals($value * 1.333333333 / Drawing::DPI_96 * 2.54, Drawing::pointsToCentimeters($value));
}
public function testTwips()
{
$value = rand(1, 100);
// Centimeters
$this->assertEquals(0, Drawing::centimetersToTwips());
$this->assertEquals($value * 566.928, Drawing::centimetersToTwips($value));
$this->assertEquals(0, Drawing::twipsToCentimeters());
$this->assertEquals($value / 566.928, Drawing::twipsToCentimeters($value));
// Inches
$this->assertEquals(0, Drawing::inchesToTwips());
$this->assertEquals($value * 1440, Drawing::inchesToTwips($value));
$this->assertEquals(0, Drawing::twipsToInches());
$this->assertEquals($value / 1440, Drawing::twipsToInches($value));
// Pixels
$this->assertEquals(0, Drawing::twipsToPixels());
$this->assertEquals(round($value / 15.873984), Drawing::twipsToPixels($value));
}
public function testHTML()
{
$this->assertFalse(Drawing::htmlToRGB('0'));
$this->assertFalse(Drawing::htmlToRGB('00'));
$this->assertFalse(Drawing::htmlToRGB('0000'));
$this->assertFalse(Drawing::htmlToRGB('00000'));
$this->assertInternalType('array', Drawing::htmlToRGB('ABCDEF'));
$this->assertCount(3, Drawing::htmlToRGB('ABCDEF'));
$this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('ABCDEF'));
$this->assertEquals(array(0xAB, 0xCD, 0xEF), Drawing::htmlToRGB('#ABCDEF'));
$this->assertEquals(array(0xAA, 0xBB, 0xCC), Drawing::htmlToRGB('ABC'));
$this->assertEquals(array(0xAA, 0xBB, 0xCC), Drawing::htmlToRGB('#ABC'));
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared\Microsoft;
/**
* Test class for \PhpOffice\PhpWord\Shared\Microsoft
* @coversDefaultClass \PhpOffice\PhpWord\Shared\Microsoft
*/
class PasswordEncoderTest extends \PHPUnit\Framework\TestCase
{
/**
* Test that a password can be hashed without specifying any additional parameters
*/
public function testEncodePassword()
{
//given
$password = 'test';
//when
$hashPassword = PasswordEncoder::hashPassword($password);
//then
$this->assertEquals('M795/MAlmGU8RIsY9Q9uDLHC7bk=', $hashPassword);
}
/**
* Test that a password can be hashed with a custom salt
*/
public function testEncodePasswordWithSalt()
{
//given
$password = 'test';
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
//when
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_SHA_1, $salt);
//then
$this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
}
/**
* Test that the encoder falls back on SHA-1 if a non supported algorithm is given
*/
public function testDefaultsToSha1IfUnsupportedAlgorithm()
{
//given
$password = 'test';
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
//when
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt);
//then
$this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
}
/**
* Test that the encoder falls back on SHA-1 if a non supported algorithm is given
*/
public function testEncodePasswordWithNullAsciiCodeInPassword()
{
//given
$password = 'test' . chr(0);
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
//when
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt, 1);
//then
$this->assertEquals('rDV9sgdDsztoCQlvRCb1lF2wxNg=', $hashPassword);
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Test class for Text
*
* @coversDefaultClass \PhpOffice\PhpWord\Shared\Text
*/
class TextTest extends \PHPUnit\Framework\TestCase
{
public function testControlCharacters()
{
$this->assertEquals('', Text::controlCharacterPHP2OOXML());
$this->assertEquals('aeiou', Text::controlCharacterPHP2OOXML('aeiou'));
$this->assertEquals('àéîöù', Text::controlCharacterPHP2OOXML('àéîöù'));
$value = rand(0, 8);
$this->assertEquals('_x' . sprintf('%04s', strtoupper(dechex($value))) . '_', Text::controlCharacterPHP2OOXML(chr($value)));
$this->assertEquals('', Text::controlCharacterOOXML2PHP(''));
$this->assertEquals(chr(0x08), Text::controlCharacterOOXML2PHP('_x0008_'));
}
public function testNumberFormat()
{
$this->assertEquals('2.1', Text::numberFormat('2.06', 1));
$this->assertEquals('2.1', Text::numberFormat('2.12', 1));
$this->assertEquals('1234.0', Text::numberFormat(1234, 1));
}
public function testChr()
{
$this->assertEquals('A', Text::chr(65));
$this->assertEquals('A', Text::chr(0x41));
$this->assertEquals('é', Text::chr(233));
$this->assertEquals('é', Text::chr(0xE9));
$this->assertEquals('⼳', Text::chr(12083));
$this->assertEquals('⼳', Text::chr(0x2F33));
$this->assertEquals('🌃', Text::chr(127747));
$this->assertEquals('🌃', Text::chr(0x1F303));
$this->assertEquals('', Text::chr(2097152));
}
/**
* Is UTF8
*/
public function testIsUTF8()
{
$this->assertTrue(Text::isUTF8(''));
$this->assertTrue(Text::isUTF8('éééé'));
$this->assertFalse(Text::isUTF8(utf8_decode('éééé')));
}
/**
* Test unicode conversion
*/
public function testToUnicode()
{
$this->assertEquals('a', Text::toUnicode('a'));
$this->assertEquals('\uc0{\u8364}', Text::toUnicode('€'));
$this->assertEquals('\uc0{\u233}', Text::toUnicode('é'));
}
/**
* Test remove underscore prefix
*/
public function testRemoveUnderscorePrefix()
{
$this->assertEquals('item', Text::removeUnderscorePrefix('_item'));
}
}

View File

@ -0,0 +1,134 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Test class for XMLReader
*
* @coversDefaultClass \PhpOffice\PhpWord\Shared\XMLReader
*/
class XMLReaderTest extends \PHPUnit\Framework\TestCase
{
/**
* Test reading XML from string
*/
public function testDomFromString()
{
$reader = new XMLReader();
$reader->getDomFromString('<element attr="test"><child attr="subtest">AAA</child></element>');
$this->assertTrue($reader->elementExists('/element/child'));
$this->assertEquals('AAA', $reader->getElement('/element/child')->textContent);
$this->assertEquals('AAA', $reader->getValue('/element/child'));
$this->assertEquals('test', $reader->getAttribute('attr', $reader->getElement('/element')));
$this->assertEquals('subtest', $reader->getAttribute('attr', $reader->getElement('/element'), 'child'));
}
/**
* Test reading XML from zip
*/
public function testDomFromZip()
{
$archiveFile = __DIR__ . '/../_files/xml/reader.zip';
$reader = new XMLReader();
$reader->getDomFromZip($archiveFile, 'test.xml');
$this->assertTrue($reader->elementExists('/element/child'));
$this->assertFalse($reader->getDomFromZip($archiveFile, 'non_existing_xml_file.xml'));
}
/**
* Test that read from non existing archive throws exception
*
* @expectedException \Exception
*/
public function testThrowsExceptionOnNonExistingArchive()
{
$archiveFile = __DIR__ . '/../_files/xml/readers.zip';
$reader = new XMLReader();
$reader->getDomFromZip($archiveFile, 'test.xml');
}
/**
* Test elements count
*/
public function testCountElements()
{
$reader = new XMLReader();
$reader->getDomFromString('<element attr="test"><child>AAA</child><child>BBB</child></element>');
$this->assertEquals(2, $reader->countElements('/element/child'));
}
/**
* Test read non existing elements
*/
public function testReturnNullOnNonExistingNode()
{
$reader = new XMLReader();
$this->assertEmpty($reader->getElements('/element/children'));
$reader->getDomFromString('<element><child>AAA</child></element>');
$this->assertNull($reader->getElement('/element/children'));
$this->assertNull($reader->getValue('/element/children'));
}
/**
* Test that xpath fails if custom namespace is not registered
*/
public function testShouldThrowExceptionIfNamespaceIsNotKnown()
{
try {
$reader = new XMLReader();
$reader->getDomFromString('<element><test:child xmlns:test="http://phpword.com/my/custom/namespace">AAA</test:child></element>');
$this->assertTrue($reader->elementExists('/element/test:child'));
$this->assertEquals('AAA', $reader->getElement('/element/test:child')->textContent);
$this->fail();
} catch (\Exception $e) {
$this->assertTrue(true);
}
}
/**
* Test reading XML with manually registered namespace
*/
public function testShouldParseXmlWithCustomNamespace()
{
$reader = new XMLReader();
$reader->getDomFromString('<element><test:child xmlns:test="http://phpword.com/my/custom/namespace">AAA</test:child></element>');
$reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
$this->assertTrue($reader->elementExists('/element/test:child'));
$this->assertEquals('AAA', $reader->getElement('/element/test:child')->textContent);
}
/**
* Test that xpath fails if custom namespace is not registered
*
* @expectedException \InvalidArgumentException
*/
public function testShouldThowExceptionIfTryingToRegisterNamespaceBeforeReadingDoc()
{
$reader = new XMLReader();
$reader->registerNamespace('test', 'http://phpword.com/my/custom/namespace');
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Shared;
/**
* Test class for XMLWriter
*
* @coversDefaultClass \PhpOffice\PhpWord\Shared\XMLWriter
*/
class XMLWriterTest extends \PHPUnit\Framework\TestCase
{
public function testConstruct()
{
// Memory
$object = new XMLWriter();
$object->startElement('element');
$object->text('AAA');
$object->endElement();
$this->assertEquals('<element>AAA</element>' . chr(10), $object->getData());
// Disk
$object = new XMLWriter(XMLWriter::STORAGE_DISK);
$object->startElement('element');
$object->text('BBB');
$object->endElement();
$this->assertEquals('<element>BBB</element>' . chr(10), $object->getData());
}
public function testWriteAttribute()
{
$xmlWriter = new XMLWriter();
$xmlWriter->startElement('element');
$xmlWriter->writeAttribute('name', 'value');
$xmlWriter->endElement();
$this->assertSame('<element name="value"/>' . chr(10), $xmlWriter->getData());
}
public function testWriteAttributeShouldWriteFloatValueLocaleIndependent()
{
$value = 1.2;
$xmlWriter = new XMLWriter();
$xmlWriter->startElement('element');
$xmlWriter->writeAttribute('name', $value);
$xmlWriter->endElement();
$currentLocale = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'de_DE.UTF-8', 'de');
$this->assertSame('<element name="1.2"/>' . chr(10), $xmlWriter->getData());
setlocale(LC_NUMERIC, $currentLocale);
}
}

View File

@ -140,6 +140,11 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
*/ */
final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue() final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue()
{ {
// Test is not needed for PHP 8.0, because internally validation throws TypeError exception.
if (\PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('not needed for PHP 8.0');
}
$templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/blank.docx'); $templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/blank.docx');
$xslDomDocument = new \DOMDocument(); $xslDomDocument = new \DOMDocument();

View File

@ -0,0 +1,65 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\ODText\Style;
use PhpOffice\PhpWord\Style\Image;
use PhpOffice\PhpWord\TestHelperDOCX;
/**
* Test class for PhpOffice\PhpWord\Writer\ODText\Element\Image
*
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText\Element\Image
*/
class ImageTest extends \PHPUnit\Framework\TestCase
{
/**
* Executed after each method of the class
*/
public function tearDown()
{
TestHelperDOCX::clear();
}
/**
* Test writing image
*/
public function testImage1()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addImage(__DIR__ . '/../../../_files/images/earth.jpg');
$section->addImage(__DIR__ . '/../../../_files/images/mario.gif', array('align' => 'end'));
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
$s2a = '/office:document-content/office:automatic-styles';
$element = "$s2a/style:style[3]";
$this->assertEquals('IM1', $doc->getElementAttribute($element, 'style:name'));
$element .= '/style:paragraph-properties';
$this->assertEquals('', $doc->getElementAttribute($element, 'fo:text-align'));
$element = "$s2a/style:style[4]";
$this->assertEquals('IM2', $doc->getElementAttribute($element, 'style:name'));
$element .= '/style:paragraph-properties';
$this->assertEquals('end', $doc->getElementAttribute($element, 'fo:text-align'));
$path = '/office:document-content/office:body/office:text/text:section/text:p[2]';
$this->assertTrue($doc->elementExists($path));
$this->assertEquals('IM1', $doc->getElementAttribute($path, 'text:style-name'));
$path = '/office:document-content/office:body/office:text/text:section/text:p[3]';
$this->assertTrue($doc->elementExists($path));
$this->assertEquals('IM2', $doc->getElementAttribute($path, 'text:style-name'));
}
}

Some files were not shown because too many files have changed in this diff Show More