Merge branch 'develop' into udz-checkbox-feature

This commit is contained in:
troosan 2021-02-07 23:30:28 +01:00 committed by GitHub
commit 6baf287a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
148 changed files with 5935 additions and 440 deletions

View File

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

View File

@ -11,29 +11,26 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- 7.4
- 8.0
matrix:
include:
- php: 5.3
dist: precise
env: COMPOSER_MEMORY_LIMIT=3G
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 7.0
env: COVERAGE=1
- php: 7.3
env: DEPENDENCIES="--ignore-platform-reqs"
exclude:
- php: 5.3
dist: xenial
- php: 5.4
dist: xenial
- php: 5.5
- php: 7.0
- php: 7.3
allow_failures:
- php: 7.4snapshot
dist: xenial
cache:
directories:
@ -55,7 +52,31 @@ before_script:
- if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini || echo "xdebug not available" ; fi
## Composer
- 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)
## 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
##- mkdir -p build/docs
- mkdir -p build/coverage

View File

@ -62,8 +62,7 @@ PHPWord requires the following:
- PHP 5.3.3+
- [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)
- [Zend\Stdlib component](http://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html)
- [Laminas Escaper component](https://docs.laminas.dev/laminas-escaper/intro/)
- [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)
- [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"
},
"require": {
"php": "^5.3.3 || ^7.0",
"php": "^5.3.3 || ^7.0 || ^8.0",
"ext-xml": "*",
"zendframework/zend-escaper": "^2.2",
"phpoffice/common": "^0.2.9"
"laminas/laminas-escaper": "^2.2"
},
"require-dev": {
"ext-zip": "*",
"ext-gd": "*",
"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",
"phpmd/phpmd": "2.*",
"phploc/phploc": "2.* || 3.* || 4.*",
"dompdf/dompdf":"0.8.*",
"phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*",
"dompdf/dompdf":"0.8.* || 1.0.*",
"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"
},
"replace": {
"laminas/laminas-zendframework-bridge": "*"
},
"suggest": {
"ext-zip": "Allows writing OOXML and ODF",
"ext-gd2": "Allows adding images",

View File

@ -359,17 +359,17 @@ The footnote numbering can be controlled by setting the FootnoteProperties on th
.. code-block:: php
$fp = new PhpWord\SimpleType\FootnoteProperties();
$fp = new \PhpOffice\PhpWord\ComplexType\FootnoteProperties();
//sets the position of the footnote (pageBottom (default), beneathText, sectEnd, docEnd)
$fp->setPos(FootnoteProperties::POSITION_DOC_END);
$fp->setPos(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::POSITION_BENEATH_TEXT);
//set the number format to use (decimal (default), upperRoman, upperLetter, ...)
$fp->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN);
$fp->setNumFmt(\PhpOffice\PhpWord\SimpleType\NumberFormat::LOWER_ROMAN);
//force starting at other than 1
$fp->setNumStart(2);
//when to restart counting (continuous (default), eachSect, eachPage)
$fp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
$fp->setNumRestart(\PhpOffice\PhpWord\ComplexType\FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
//And finaly, set it on the Section
$section->setFootnoteProperties($properties);
$section->setFootnoteProperties($fp);
Checkboxes
----------
@ -403,7 +403,9 @@ Currently the following fields are supported:
.. code-block:: php
$section->addField($fieldType, [$properties], [$options], [$fieldText])
$section->addField($fieldType, [$properties], [$options], [$fieldText], [$fontStyle])
- ``$fontStyle``. See :ref:`font-style`.
See ``\PhpOffice\PhpWord\Element\Field`` for list of properties and options available for each field type.
Options which are not specifically defined can be added. Those must start with a ``\``.

View File

@ -130,6 +130,16 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c
\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
~~~~~~~~~~~~

View File

@ -10,9 +10,7 @@ Mandatory:
- PHP 5.3.3+
- `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
- Zend\\Stdlib component
- `Zend\\Validator <http://framework.zend.com/manual/current/en/modules/zend.validator.html>`__ component
- `Laminas Escaper <https://docs.laminas.dev/laminas-escaper/intro/>`__ component
Optional:

View File

@ -75,8 +75,10 @@ Available Paragraph style options:
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
- ``basedOn``. Parent style.
- ``hanging``. Hanging in *twip*.
- ``indent``. Indent in *twip*.
- ``hanging``. Hanging indentation in *half inches*.
- ``indent``. Indent (left indentation) in *half inches*.
- ``indentation``. An array of indentation key => value pairs in *twip*. Supports *left*, *right*, *firstLine* and *hanging* indentation.
See ``\PhpOffice\PhpWord\Style\Indentation`` for possible identation types.
- ``keepLines``. Keep all lines on one page, *true* or *false*.
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc.

View File

@ -63,6 +63,11 @@ Example:
$templateProcessor->setImageValue('CompanyLogo', 'path/to/company/logo.png');
$templateProcessor->setImageValue('UserLogo', array('path' => 'path/to/logo.png', 'width' => 100, 'height' => 100, 'ratio' => false));
$templateProcessor->setImageValue('FeatureImage', function () {
// Closure will only be executed if the replacement tag is found in the template
return array('path' => SlowFeatureImageGenerator::make(), 'width' => 100, 'height' => 100, 'ratio' => false);
});
cloneBlock
""""""""""
@ -127,7 +132,7 @@ Given a template containing
This block content will be replaced
${/block_name}
The following will replace everything between``${block_name}`` and ``${/block_name}`` with the value passed.
The following will replace everything between ``${block_name}`` and ``${/block_name}`` with the value passed.
.. code-block:: php
@ -190,7 +195,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' => 2, 'userName' => 'Superman', 'userAddress' => 'Metropolis'],
];
$templateProcessor->cloneRowAndSetValues('userId', );
$templateProcessor->cloneRowAndSetValues('userId', $values);
Will result in
@ -244,3 +249,31 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples.
$table->addCell(150)->addText('Cell B2');
$table->addCell(150)->addText('Cell B3');
$templateProcessor->setComplexBlock('table', $table);
setChartValue
"""""""""""""
Replace a variable by a chart.
.. code-block:: php
$categories = array('A', 'B', 'C', 'D', 'E');
$series1 = array(1, 3, 2, 5, 4);
$chart = new Chart('doughnut', $categories, $series1);
$templateProcessor->setChartValue('myChart', $chart);
save
""""
Saves the loaded template within the current directory. Returns the file path.
.. code-block:: php
$filepath = $templateProcessor->save();
saveAs
""""""
Saves a copy of the loaded template in the indicated path.
.. code-block:: php
$pathToSave = 'path/to/save/file.ext';
$templateProcessor->saveAs($pathToSave);

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:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/naming.xml">
<exclude name="ShortVariable" />
<exclude name="ShortClassName" />
<exclude name="LongVariable" />
</rule>
<rule ref="rulesets/naming.xml/LongVariable">

View File

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

View File

@ -17,9 +17,9 @@ $cols = 5;
$section->addText('Basic table', $header);
$table = $section->addTable();
for ($r = 1; $r <= 8; $r++) {
for ($r = 1; $r <= $rows; $r++) {
$table->addRow();
for ($c = 1; $c <= 5; $c++) {
for ($c = 1; $c <= $cols; $c++) {
$table->addCell(1750)->addText("Row {$r}, Cell {$c}");
}
}

View File

@ -0,0 +1,45 @@
<?php
use PhpOffice\PhpWord\Element\Chart;
use PhpOffice\PhpWord\Shared\Converter;
include_once 'Sample_Header.php';
// Template processor instance creation
echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_41_TemplateSetChart.docx');
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$threeSeries = array('bar', 'line');
$categories = array('A', 'B', 'C', 'D', 'E');
$series1 = array(1, 3, 2, 5, 4);
$series2 = array(3, 1, 7, 2, 6);
$series3 = array(8, 3, 2, 5, 4);
$i = 0;
foreach ($chartTypes as $chartType) {
$chart = new Chart($chartType, $categories, $series1);
if (in_array($chartType, $twoSeries)) {
$chart->addSeries($categories, $series2);
}
if (in_array($chartType, $threeSeries)) {
$chart->addSeries($categories, $series3);
}
$chart->getStyle()
->setWidth(Converter::inchToEmu(3))
->setHeight(Converter::inchToEmu(3));
$templateProcessor->setChart("chart{$i}", $chart);
$i++;
}
echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_41_TemplateSetChart.docx');
echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_41_TemplateSetChart.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}

Binary file not shown.

View File

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

View File

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

View File

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

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
/**
* Field element
*
@ -115,10 +117,42 @@ class Field extends AbstractElement
/**
* Font style
*
* @var \PhpOffice\PhpWord\Style\Font
* @var string|\PhpOffice\PhpWord\Style\Font
*/
protected $fontStyle;
/**
* Set Font style
*
* @param string|array|\PhpOffice\PhpWord\Style\Font $style
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null)
{
if ($style instanceof Font) {
$this->fontStyle = $style;
} elseif (is_array($style)) {
$this->fontStyle = new Font('text');
$this->fontStyle->setStyleByArray($style);
} elseif (null === $style) {
$this->fontStyle = null;
} else {
$this->fontStyle = $style;
}
return $this->fontStyle;
}
/**
* Get Font style
*
* @return string|\PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Create a new Field Element
*
@ -126,13 +160,15 @@ class Field extends AbstractElement
* @param array $properties
* @param array $options
* @param TextRun|string|null $text
* @param string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
*/
public function __construct($type = null, $properties = array(), $options = array(), $text = null)
public function __construct($type = null, $properties = array(), $options = array(), $text = null, $fontStyle = null)
{
$this->setType($type);
$this->setProperties($properties);
$this->setOptions($options);
$this->setText($text);
$this->setFontStyle($fontStyle);
}
/**

View File

@ -454,7 +454,7 @@ class Image extends AbstractElement
} else {
$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->sourceType = self::SOURCE_LOCAL;
} else {

View File

@ -17,7 +17,7 @@
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\Paragraph;
@ -79,8 +79,8 @@ class Link extends AbstractElement
*/
public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
{
$this->source = CommonText::toUTF8($source);
$this->text = is_null($text) ? $this->source : CommonText::toUTF8($text);
$this->source = SharedText::toUTF8($source);
$this->text = is_null($text) ? $this->source : SharedText::toUTF8($text);
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->internal = $internal;

View File

@ -17,7 +17,7 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;
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)
{
$this->textObject = new Text(CommonText::toUTF8($text), $fontStyle, $paragraphStyle);
$this->textObject = new Text(SharedText::toUTF8($text), $fontStyle, $paragraphStyle);
$this->depth = $depth;
// 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;
use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@ -59,7 +59,7 @@ class PreserveText extends AbstractElement
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$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);
if (isset($matches[0])) {
$this->text = $matches;

View File

@ -146,6 +146,20 @@ class Section extends AbstractContainer
*
* @return FootnoteProperties
*/
public function getFootnoteProperties()
{
return $this->footnoteProperties;
}
/**
* Get the footnote properties
*
* @deprecated Use the `getFootnoteProperties` method instead
*
* @return FootnoteProperties
*
* @codeCoverageIgnore
*/
public function getFootnotePropoperties()
{
return $this->footnoteProperties;

View File

@ -17,7 +17,7 @@
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\Paragraph;
@ -136,7 +136,7 @@ class Text extends AbstractElement
*/
public function setText($text)
{
$this->text = CommonText::toUTF8($text);
$this->text = SharedText::toUTF8($text);
return $this;
}

View File

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

View File

@ -26,8 +26,14 @@ class Rtf extends AbstractEscaper
{
protected function escapeAsciiCharacter($code)
{
if (20 > $code || $code >= 80) {
return '{\u' . $code . '}';
if ($code == 9) {
return '{\\tab}';
}
if (0x20 > $code || $code >= 0x80) {
return '{\\u' . $code . '}';
}
if ($code == 123 || $code == 125 || $code == 92) { // open or close brace or backslash
return '\\' . chr($code);
}
return chr($code);
@ -35,7 +41,7 @@ class Rtf extends AbstractEscaper
protected function escapeMultibyteCharacter($code)
{
return '\uc0{\u' . $code . '}';
return '\\uc0{\\u' . $code . '}';
}
/**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,12 +17,12 @@
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Abstract part reader
@ -95,7 +95,7 @@ abstract class AbstractPart
/**
* Read w:p.
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param string $docPart
@ -202,7 +202,7 @@ abstract class AbstractPart
/**
* Read w:r.
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param \PhpOffice\PhpWord\Element\AbstractContainer $parent
* @param string $docPart
@ -270,6 +270,10 @@ abstract class AbstractPart
$name = $xmlReader->getAttribute('name', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
$embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip');
if ($name === null && $embedId === null) { // some Converters puts images on a different path
$name = $xmlReader->getAttribute('name', $node, 'wp:anchor/a:graphic/a:graphicData/pic:pic/pic:nvPicPr/pic:cNvPr');
$embedId = $xmlReader->getAttribute('r:embed', $node, 'wp:anchor/a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip');
}
$target = $this->getMediaTarget($docPart, $embedId);
if (!is_null($target)) {
$imageSource = "zip://{$this->docFile}#{$target}";
@ -288,6 +292,19 @@ abstract class AbstractPart
$parent->addTextBreak();
} elseif ($node->nodeName == 'w:tab') {
$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') {
// TextRun
$textContent = htmlspecialchars($xmlReader->getValue('.', $node), ENT_QUOTES, 'UTF-8');
@ -316,7 +333,7 @@ abstract class AbstractPart
/**
* Read w:tbl.
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param mixed $parent
* @param string $docPart
@ -374,7 +391,7 @@ abstract class AbstractPart
/**
* Read w:pPr.
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null
*/
@ -409,7 +426,7 @@ abstract class AbstractPart
/**
* Read w:rPr
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null
*/
@ -455,7 +472,7 @@ abstract class AbstractPart
/**
* Read w:tblPr
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return string|array|null
* @todo Capture w:tblStylePr w:type="firstRow"
@ -505,7 +522,7 @@ abstract class AbstractPart
/**
* Read w:tblpPr
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array
*/
@ -530,7 +547,7 @@ abstract class AbstractPart
/**
* Read w:tblInd
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return TblWidthComplexType
*/
@ -548,7 +565,7 @@ abstract class AbstractPart
/**
* Read w:tcPr
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array
*/
@ -569,11 +586,11 @@ abstract class AbstractPart
* Returns the first child element found
*
* @param XMLReader $xmlReader
* @param \DOMElement $parentNode
* @param string|array $elements
* @param \DOMElement|null $parentNode
* @param string|array|null $elements
* @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 element is an array, we take the first element that exists in the XML
@ -616,7 +633,7 @@ abstract class AbstractPart
/**
* Read style definition
*
* @param \PhpOffice\Common\XMLReader $xmlReader
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $parentNode
* @param array $styleDefs
* @ignoreScrutinizerPatch

View File

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

View File

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

View File

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

View File

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

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Reader\Word2007;
use PhpOffice\Common\XMLReader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLReader;
/**
* Numbering reader
@ -89,7 +89,7 @@ class Numbering extends AbstractPart
/**
* 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 int $levelId
* @return array

View File

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

View File

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

View File

@ -70,6 +70,7 @@ class Settings
const DEFAULT_FONT_SIZE = 10;
const DEFAULT_FONT_COLOR = '000000';
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
const DEFAULT_PAPER = 'A4';
/**
* Compatibility option for XMLWriter
@ -119,6 +120,12 @@ class Settings
*/
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;
/**
* Default paper
* @var string
*/
private static $defaultPaper = self::DEFAULT_PAPER;
/**
* The user defined temporary directory.
*
@ -432,6 +439,33 @@ class Settings
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
*

View File

@ -133,7 +133,7 @@ class Converter
* Convert inch to EMU
*
* @param float $inch
* @return float
* @return int
*/
public static function inchToEmu($inch = 1)
{
@ -143,7 +143,7 @@ class Converter
/**
* Convert pixel to twip
*
* @param int $pixel
* @param float $pixel
* @return float
*/
public static function pixelToTwip($pixel = 1)
@ -154,7 +154,7 @@ class Converter
/**
* Convert pixel to centimeter
*
* @param int $pixel
* @param float $pixel
* @return float
*/
public static function pixelToCm($pixel = 1)
@ -165,7 +165,7 @@ class Converter
/**
* Convert pixel to point
*
* @param int $pixel
* @param float $pixel
* @return float
*/
public static function pixelToPoint($pixel = 1)
@ -176,7 +176,7 @@ class Converter
/**
* Convert pixel to EMU
*
* @param int $pixel
* @param float $pixel
* @return int
*/
public static function pixelToEmu($pixel = 1)
@ -187,7 +187,7 @@ class Converter
/**
* Convert point to twip unit
*
* @param int $point
* @param float $point
* @return float
*/
public static function pointToTwip($point = 1)
@ -209,7 +209,7 @@ class Converter
/**
* Convert point to EMU
*
* @param int $point
* @param float $point
* @return float
*/
public static function pointToEmu($point = 1)
@ -231,7 +231,7 @@ class Converter
/**
* Convert EMU to pixel
*
* @param int $emu
* @param float $emu
* @return float
*/
public static function emuToPixel($emu = 1)
@ -242,7 +242,7 @@ class Converter
/**
* Convert pica to point
*
* @param int $pica
* @param float $pica
* @return float
*/
public static function picaToPoint($pica = 1)
@ -253,7 +253,7 @@ class Converter
/**
* Convert degree to angle
*
* @param int $degree
* @param float $degree
* @return int
*/
public static function degreeToAngle($degree = 1)
@ -264,7 +264,7 @@ class Converter
/**
* Convert angle to degrees
*
* @param int $angle
* @param float $angle
* @return int
*/
public static function angleToDegree($angle = 1)
@ -272,6 +272,50 @@ class Converter
return round($angle / self::DEGREE_TO_ANGLE);
}
/**
* Convert colorname as string to RGB
*
* @param string $value color name
* @return string color as hex RGB string, or original value if unknown
*/
public static function stringToRgb($value)
{
switch ($value) {
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW:
return 'FFFF00';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_LIGHTGREEN:
return '90EE90';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_CYAN:
return '00FFFF';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_MAGENTA:
return 'FF00FF';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_BLUE:
return '0000FF';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_RED:
return 'FF0000';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKBLUE:
return '00008B';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKCYAN:
return '008B8B';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKGREEN:
return '006400';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKMAGENTA:
return '8B008B';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKRED:
return '8B0000';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKYELLOW:
return '8B8B00';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_DARKGRAY:
return 'A9A9A9';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_LIGHTGRAY:
return 'D3D3D3';
case \PhpOffice\PhpWord\Style\Font::FGCOLOR_BLACK:
return '000000';
}
return $value;
}
/**
* Convert HTML hexadecimal to RGB
*
@ -282,6 +326,8 @@ class Converter
{
if ($value[0] == '#') {
$value = substr($value, 1);
} else {
$value = self::stringToRgb($value);
}
if (strlen($value) == 6) {
@ -292,9 +338,9 @@ class Converter
return false;
}
$red = hexdec($red);
$green = hexdec($green);
$blue = hexdec($blue);
$red = ctype_xdigit($red) ? hexdec($red) : 0;
$green = ctype_xdigit($green) ? hexdec($green) : 0;
$blue = ctype_xdigit($blue) ? hexdec($blue) : 0;
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

@ -62,17 +62,19 @@ class Html
// Preprocess: remove all line ends, decode HTML entity,
// fix ampersand and angle brackets and add body tag for HTML fragments
$html = str_replace(array("\n", "\r"), '', $html);
$html = str_replace(array('&lt;', '&gt;', '&amp;'), array('_lt_', '_gt_', '_amp_'), $html);
$html = str_replace(array('&lt;', '&gt;', '&amp;', '&quot;'), array('_lt_', '_gt_', '_amp_', '_quot_'), $html);
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
$html = str_replace('&', '&amp;', $html);
$html = str_replace(array('_lt_', '_gt_', '_amp_'), array('&lt;', '&gt;', '&amp;'), $html);
$html = str_replace(array('_lt_', '_gt_', '_amp_', '_quot_'), array('&lt;', '&gt;', '&amp;', '&quot;'), $html);
if (false === $fullHTML) {
$html = '<body>' . $html . '</body>';
}
// Load DOM
$orignalLibEntityLoader = libxml_disable_entity_loader(true);
if (\PHP_VERSION_ID < 80000) {
$orignalLibEntityLoader = libxml_disable_entity_loader(true);
}
$dom = new \DOMDocument();
$dom->preserveWhiteSpace = $preserveWhiteSpace;
$dom->loadXML($html);
@ -80,7 +82,9 @@ class Html
$node = $dom->getElementsByTagName('body');
self::parseNode($node->item(0), $element);
libxml_disable_entity_loader($orignalLibEntityLoader);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($orignalLibEntityLoader);
}
}
/**
@ -96,15 +100,43 @@ class Html
$attributes = $node->attributes; // get all the attributes(eg: id, class)
foreach ($attributes as $attribute) {
switch ($attribute->name) {
$val = $attribute->value;
switch (strtolower($attribute->name)) {
case 'style':
$styles = self::parseStyle($attribute, $styles);
break;
case 'align':
$styles['alignment'] = self::mapAlign($attribute->value);
$styles['alignment'] = self::mapAlign(trim($val));
break;
case 'lang':
$styles['lang'] = $attribute->value;
$styles['lang'] = $val;
break;
case 'width':
// tables, cells
if (false !== strpos($val, '%')) {
// e.g. <table width="100%"> or <td width="50%">
$styles['width'] = intval($val) * 50;
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
} else {
// e.g. <table width="250> where "250" = 250px (always pixels)
$styles['width'] = Converter::pixelToTwip($val);
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::TWIP;
}
break;
case 'cellspacing':
// tables e.g. <table cellspacing="2">, where "2" = 2px (always pixels)
$val = intval($val).'px';
$styles['cellSpacing'] = Converter::cssToTwip($val);
break;
case 'bgcolor':
// tables, rows, cells e.g. <tr bgColor="#FF0000">
$styles['bgColor'] = trim($val, '# ');
break;
case 'valign':
// cells e.g. <td valign="middle">
if (preg_match('#(?:top|bottom|middle|baseline)#i', $val, $matches)) {
$styles['valign'] = self::mapAlignVertical($matches[0]);
}
break;
}
}
@ -162,6 +194,7 @@ class Html
'br' => array('LineBreak', null, $element, $styles, null, null, null),
'a' => array('Link', $node, $element, $styles, null, null, null),
'input' => array('Input', $node, $element, $styles, null, null, null),
'hr' => array('HorizRule', $node, $element, $styles, null, null, null),
);
$newElement = null;
@ -179,7 +212,7 @@ class Html
}
}
$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
foreach ($keys as $key) {
@ -386,7 +419,11 @@ class Html
if (!empty($colspan)) {
$cellStyles['gridSpan'] = $colspan - 0;
}
$cell = $element->addCell(null, $cellStyles);
// set cell width to control column widths
$width = isset($cellStyles['width']) ? $cellStyles['width'] : null;
unset($cellStyles['width']); // would not apply
$cell = $element->addCell($width, $cellStyles);
if (self::shouldAddTextRun($node)) {
return $cell->addTextRun(self::parseInlineStyle($node, $styles['paragraph']));
@ -445,7 +482,32 @@ class Html
} else {
$data['listdepth'] = 0;
$styles['list'] = 'listStyle_' . self::$listIndex++;
$element->getPhpWord()->addNumberingStyle($styles['list'], self::getListStyle($isOrderedList));
$style = $element->getPhpWord()->addNumberingStyle($styles['list'], self::getListStyle($isOrderedList));
// extract attributes start & type e.g. <ol type="A" start="3">
$start = 0;
$type = '';
foreach ($node->attributes as $attribute) {
switch ($attribute->name) {
case 'start':
$start = (int) $attribute->value;
break;
case 'type':
$type = $attribute->value;
break;
}
}
$levels = $style->getLevels();
/** @var \PhpOffice\PhpWord\Style\NumberingLevel */
$level = $levels[0];
if ($start > 0) {
$level->setStart($start);
}
$type = $type ? self::mapListType($type) : null;
if ($type) {
$level->setFormat($type);
}
}
if ($node->parentNode->nodeName === 'li') {
return $element->getParent();
@ -527,7 +589,8 @@ class Html
foreach ($properties as $property) {
list($cKey, $cValue) = array_pad(explode(':', $property, 2), 2, null);
$cValue = trim($cValue);
switch (trim($cKey)) {
$cKey = strtolower(trim($cKey));
switch ($cKey) {
case 'text-decoration':
switch ($cValue) {
case 'underline':
@ -600,11 +663,18 @@ class Html
}
$styles['italic'] = $tValue;
break;
case 'margin':
$cValue = Converter::cssToTwip($cValue);
$styles['spaceBefore'] = $cValue;
$styles['spaceAfter'] = $cValue;
break;
case 'margin-top':
$styles['spaceBefore'] = Converter::cssToPoint($cValue);
// BC change: up to ver. 0.17.0 incorrectly converted to points - Converter::cssToPoint($cValue)
$styles['spaceBefore'] = Converter::cssToTwip($cValue);
break;
case 'margin-bottom':
$styles['spaceAfter'] = Converter::cssToPoint($cValue);
// BC change: up to ver. 0.17.0 incorrectly converted to points - Converter::cssToPoint($cValue)
$styles['spaceAfter'] = Converter::cssToTwip($cValue);
break;
case 'border-color':
self::mapBorderColor($styles, $cValue);
@ -628,10 +698,37 @@ class Html
}
break;
case 'border':
if (preg_match('/([0-9]+[^0-9]*)\s+(\#[a-fA-F0-9]+)\s+([a-z]+)/', $cValue, $matches)) {
$styles['borderSize'] = Converter::cssToPoint($matches[1]);
$styles['borderColor'] = trim($matches[2], '#');
$styles['borderStyle'] = self::mapBorderStyle($matches[3]);
case 'border-top':
case 'border-bottom':
case 'border-right':
case 'border-left':
// must have exact order [width color style], e.g. "1px #0011CC solid" or "2pt green solid"
// Word does not accept shortened hex colors e.g. #CCC, only full e.g. #CCCCCC
if (preg_match('/([0-9]+[^0-9]*)\s+(\#[a-fA-F0-9]+|[a-zA-Z]+)\s+([a-z]+)/', $cValue, $matches)) {
if (false !== strpos($cKey, '-')) {
$which = explode('-', $cKey)[1];
$which = ucfirst($which); // e.g. bottom -> Bottom
} else {
$which = '';
}
// Note - border width normalization:
// Width of border in Word is calculated differently than HTML borders, usually showing up too bold.
// Smallest 1px (or 1pt) appears in Word like 2-3px/pt in HTML once converted to twips.
// Therefore we need to normalize converted twip value to cca 1/2 of value.
// This may be adjusted, if better ratio or formula found.
// BC change: up to ver. 0.17.0 was $size converted to points - Converter::cssToPoint($size)
$size = Converter::cssToTwip($matches[1]);
$size = intval($size / 2);
// valid variants may be e.g. borderSize, borderTopSize, borderLeftColor, etc ..
$styles["border{$which}Size"] = $size; // twips
$styles["border{$which}Color"] = trim($matches[2], '#');
$styles["border{$which}Style"] = self::mapBorderStyle($matches[3]);
}
break;
case 'vertical-align':
// https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align
if (preg_match('#(?:top|bottom|middle|sub|baseline)#i', $cValue, $matches)) {
$styles['valign'] = self::mapAlignVertical($matches[0]);
}
break;
}
@ -676,14 +773,14 @@ class Html
case 'float':
if (trim($v) == 'right') {
$style['hPos'] = \PhpOffice\PhpWord\Style\Image::POS_RIGHT;
$style['hPosRelTo'] = \PhpOffice\PhpWord\Style\Image::POS_RELTO_PAGE;
$style['hPosRelTo'] = \PhpOffice\PhpWord\Style\Image::POS_RELTO_MARGIN; // inner section area
$style['pos'] = \PhpOffice\PhpWord\Style\Image::POS_RELATIVE;
$style['wrap'] = \PhpOffice\PhpWord\Style\Image::WRAP_TIGHT;
$style['overlap'] = true;
}
if (trim($v) == 'left') {
$style['hPos'] = \PhpOffice\PhpWord\Style\Image::POS_LEFT;
$style['hPosRelTo'] = \PhpOffice\PhpWord\Style\Image::POS_RELTO_PAGE;
$style['hPosRelTo'] = \PhpOffice\PhpWord\Style\Image::POS_RELTO_MARGIN; // inner section area
$style['pos'] = \PhpOffice\PhpWord\Style\Image::POS_RELATIVE;
$style['wrap'] = \PhpOffice\PhpWord\Style\Image::WRAP_TIGHT;
$style['overlap'] = true;
@ -798,6 +895,58 @@ class Html
}
}
/**
* Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc
*
* @param string $cssAlignment
* @return string|null
*/
protected static function mapAlignVertical($alignment)
{
$alignment = strtolower($alignment);
switch ($alignment) {
case 'top':
case 'baseline':
case 'bottom':
return $alignment;
case 'middle':
return 'center';
case 'sub':
return 'bottom';
case 'text-top':
case 'baseline':
return 'top';
default:
// @discuss - which one should apply:
// - Word uses default vert. alignment: top
// - all browsers use default vert. alignment: middle
// Returning empty string means attribute wont be set so use Word default (top).
return '';
}
}
/**
* Map list style for ordered list
*
* @param string $cssListType
*/
protected static function mapListType($cssListType)
{
switch ($cssListType) {
case 'a':
return NumberFormat::LOWER_LETTER; // a, b, c, ..
case 'A':
return NumberFormat::UPPER_LETTER; // A, B, C, ..
case 'i':
return NumberFormat::LOWER_ROMAN; // i, ii, iii, iv, ..
case 'I':
return NumberFormat::UPPER_ROMAN; // I, II, III, IV, ..
case '1':
default:
return NumberFormat::DECIMAL; // 1, 2, 3, ..
}
}
/**
* Parse line break
*
@ -833,4 +982,38 @@ class Html
return $element->addLink($target, $node->textContent, $styles['font'], $styles['paragraph']);
}
/**
* Render horizontal rule
* Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment
*
* @param \DOMNode $node
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
*/
protected static function parseHorizRule($node, $element)
{
$styles = self::parseInlineStyle($node);
// <hr> is implemented as an empty paragraph - extending 100% inside the section
// Some properties may be controlled, e.g. <hr style="border-bottom: 3px #DDDDDD solid; margin-bottom: 0;">
$fontStyle = $styles + ['size' => 3];
$paragraphStyle = $styles + [
'lineHeight' => 0.25, // multiply default line height - e.g. 1, 1.5 etc
'spacing' => 0, // twip
'spaceBefore' => 120, // twip, 240/2 (default line height)
'spaceAfter' => 120, // twip
'borderBottomSize' => empty($styles['line-height']) ? 1 : $styles['line-height'],
'borderBottomColor' => empty($styles['color']) ? '000000' : $styles['color'],
'borderBottomStyle' => 'single', // same as "solid"
];
$element->addText("", $fontStyle, $paragraphStyle);
// Notes: <hr/> cannot be:
// - table - throws error "cannot be inside textruns", e.g. lists
// - line - that is a shape, has different behaviour
// - repeated text, e.g. underline "_", because of unpredictable line wrapping
}
}

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;
use PhpOffice\Common\Text;
use PhpOffice\PhpWord\Shared\Text;
/**
* Abstract style class

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Style;
use PhpOffice\Common\Text;
use PhpOffice\PhpWord\Exception\InvalidStyleException;
use PhpOffice\PhpWord\Shared\Text;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\TextAlignment;
@ -85,7 +85,7 @@ class Paragraph extends Border
/**
* Indentation
*
* @var \PhpOffice\PhpWord\Style\Indentation
* @var \PhpOffice\PhpWord\Style\Indentation|null
*/
private $indentation;
@ -198,7 +198,7 @@ class Paragraph extends Border
{
$key = Text::removeUnderscorePrefix($key);
if ('indent' == $key || 'hanging' == $key) {
$value = $value * 720;
$value = $value * 720; // 720 twips is 0.5 inch
}
return parent::setStyleValue($key, $value);

View File

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

View File

@ -17,13 +17,13 @@
namespace PhpOffice\PhpWord;
use PhpOffice\Common\Text;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Escaper\RegExp;
use PhpOffice\PhpWord\Escaper\Xml;
use PhpOffice\PhpWord\Exception\CopyFileException;
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\Text;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Shared\ZipArchive;
class TemplateProcessor
@ -170,7 +170,9 @@ class TemplateProcessor
*/
protected function transformSingleXml($xml, $xsltProcessor)
{
$orignalLibEntityLoader = libxml_disable_entity_loader(true);
if (\PHP_VERSION_ID < 80000) {
$orignalLibEntityLoader = libxml_disable_entity_loader(true);
}
$domDocument = new \DOMDocument();
if (false === $domDocument->loadXML($xml)) {
throw new Exception('Could not load the given XML document.');
@ -180,7 +182,9 @@ class TemplateProcessor
if (false === $transformedXml) {
throw new Exception('Could not transform the given XML document.');
}
libxml_disable_entity_loader($orignalLibEntityLoader);
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader($orignalLibEntityLoader);
}
return $transformedXml;
}
@ -274,6 +278,11 @@ class TemplateProcessor
$elementWriter->write();
$where = $this->findContainingXmlBlockForMacro($search, 'w:r');
if ($where === false) {
return;
}
$block = $this->getSlice($where['start'], $where['end']);
$textParts = $this->splitTextIntoTexts($block);
$this->replaceXmlBlock($search, $textParts, 'w:r');
@ -346,6 +355,46 @@ class TemplateProcessor
}
}
/**
* @param string $search
* @param \PhpOffice\PhpWord\Element\AbstractElement $complexType
*/
public function setChart($search, \PhpOffice\PhpWord\Element\AbstractElement $chart)
{
$elementName = substr(get_class($chart), strrpos(get_class($chart), '\\') + 1);
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $elementName;
// Get the next relation id
$rId = $this->getNextRelationsIndex($this->getMainPartName());
$chart->setRelationId($rId);
// Define the chart filename
$filename = "charts/chart{$rId}.xml";
// Get the part writer
$writerPart = new \PhpOffice\PhpWord\Writer\Word2007\Part\Chart();
$writerPart->setElement($chart);
// ContentTypes.xml
$this->zipClass->addFromString("word/{$filename}", $writerPart->write());
// add chart to content type
$xmlRelationsType = "<Override PartName=\"/word/{$filename}\" ContentType=\"application/vnd.openxmlformats-officedocument.drawingml.chart+xml\"/>";
$this->tempDocumentContentTypes = str_replace('</Types>', $xmlRelationsType, $this->tempDocumentContentTypes) . '</Types>';
// Add the chart to relations
$xmlChartRelation = "<Relationship Id=\"rId{$rId}\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart\" Target=\"charts/chart{$rId}.xml\"/>";
$this->tempDocumentRelations[$this->getMainPartName()] = str_replace('</Relationships>', $xmlChartRelation, $this->tempDocumentRelations[$this->getMainPartName()]) . '</Relationships>';
// Write the chart
$xmlWriter = new XMLWriter();
$elementWriter = new $objectClass($xmlWriter, $chart, true);
$elementWriter->write();
// Place it in the template
$this->replaceXmlBlock($search, '<w:p>' . $xmlWriter->getData() . '</w:p>', 'w:p');
}
private function getImageArgs($varNameWithArgs)
{
$varElements = explode(':', $varNameWithArgs);
@ -447,6 +496,13 @@ class TemplateProcessor
$width = null;
$height = null;
$ratio = null;
// a closure can be passed as replacement value which after resolving, can contain the replacement info for the image
// use case: only when a image if found, the replacement tags can be generated
if (is_callable($replaceImage)) {
$replaceImage = $replaceImage();
}
if (is_array($replaceImage) && isset($replaceImage['path'])) {
$imgPath = $replaceImage['path'];
if (isset($replaceImage['width'])) {
@ -575,8 +631,9 @@ class TemplateProcessor
// 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)
$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>';
$i = 0;
foreach ($searchParts as $partFileName => &$partContent) {
$partVariables = $this->getVariablesForPart($partContent);
@ -609,6 +666,10 @@ class TemplateProcessor
// replace on each iteration, because in one tag we can have 2+ inline variables => before proceed next variable we need to change $partContent
$partContent = $this->setValueForPart($wholeTag, $replaceXml, $partContent, $limit);
}
if (++$i >= $limit) {
break;
}
}
}
}
@ -1085,7 +1146,7 @@ class TemplateProcessor
{
$results = array();
for ($i = 1; $i <= $count; $i++) {
$results[] = preg_replace('/\$\{(.*?)\}/', '\${\\1#' . $i . '}', $xmlBlock);
$results[] = preg_replace('/\$\{([^:]*?)(:.*?)?\}/', '\${\1#' . $i . '\2}', $xmlBlock);
}
return $results;

View File

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

View File

@ -0,0 +1,43 @@
<?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\HTML\Element;
/**
* ListItem element HTML writer
*
* @since 0.10.0
*/
class ListItemRun extends TextRun
{
/**
* Write list item
*
* @return string
*/
public function write()
{
if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItemRun) {
return '';
}
$writer = new Container($this->parentWriter, $this->element);
$content = $writer->write() . PHP_EOL;
return $content;
}
}

View File

@ -52,6 +52,7 @@ class Table extends AbstractElement
for ($j = 0; $j < $rowCellCount; $j++) {
$cellStyle = $rowCells[$j]->getStyle();
$cellBgColor = $cellStyle->getBgColor();
$cellBgColor === 'auto' && $cellBgColor = null; // auto cannot be parsed to hexadecimal number
$cellFgColor = null;
if ($cellBgColor) {
$red = hexdec(substr($cellBgColor, 0, 2));

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Writer\HTML\Part;
use Laminas\Escaper\Escaper;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Writer\AbstractWriter;
use Zend\Escaper\Escaper;
/**
* @since 0.11.0
@ -32,7 +32,7 @@ abstract class AbstractPart
private $parentWriter;
/**
* @var \Zend\Escaper\Escaper
* @var \Laminas\Escaper\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());
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard');
$xmlWriter->writeAttribute('text:style-name', 'IM' . $mediaIndex);
$xmlWriter->startElement('draw:frame');
$xmlWriter->writeAttribute('draw:style-name', 'fr' . $mediaIndex);

View File

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

View File

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

View File

@ -17,9 +17,9 @@
namespace PhpOffice\PhpWord\Writer\ODText\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Row as RowElement;
use PhpOffice\PhpWord\Element\Table as TableElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Table element writer
@ -60,7 +60,7 @@ class Table extends AbstractElement
/**
* Write column.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Table $element
*/
private function writeColumns(XMLWriter $xmlWriter, TableElement $element)
@ -77,7 +77,7 @@ class Table extends AbstractElement
/**
* Write row.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Row $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
// $fStyleIsObject = ($fontStyle instanceof Font) ? true : false;
$fStyleIsObject = false;
//$fStyleIsObject = false;
if ($fStyleIsObject) {
// 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');
}
//if ($fStyleIsObject) {
// 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');
//}
if (!$this->withoutP) {
$xmlWriter->startElement('text:p'); // text:p
@ -59,18 +59,26 @@ class Text extends AbstractElement
} else {
if (empty($fontStyle)) {
if (empty($paragraphStyle)) {
$xmlWriter->writeAttribute('text:style-name', 'P1');
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', 'Normal');
}
} elseif (is_string($paragraphStyle)) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
}
}
$this->writeChangeInsertion(true, $element->getTrackChange());
$this->writeText($element->getText());
$this->replaceTabs($element->getText(), $xmlWriter);
$this->writeChangeInsertion(false, $element->getTrackChange());
} else {
if (empty($paragraphStyle)) {
$xmlWriter->writeAttribute('text:style-name', 'Standard');
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', 'Normal');
}
} elseif (is_string($paragraphStyle)) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
if (!$this->withoutP) {
$xmlWriter->writeAttribute('text:style-name', $paragraphStyle);
}
}
// text:span
$xmlWriter->startElement('text:span');
@ -78,7 +86,7 @@ class Text extends AbstractElement
$xmlWriter->writeAttribute('text:style-name', $fontStyle);
}
$this->writeChangeInsertion(true, $element->getTrackChange());
$this->writeText($element->getText());
$this->replaceTabs($element->getText(), $xmlWriter);
$this->writeChangeInsertion(false, $element->getTrackChange());
$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)
{
if ($trackChange == null || $trackChange->getChangeType() != TrackChange::INSERTED) {

View File

@ -22,7 +22,7 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element;
*
* @since 0.10.0
*/
class TextRun extends AbstractElement
class TextRun extends Text
{
/**
* Write element
@ -33,6 +33,12 @@ class TextRun extends AbstractElement
$element = $this->getElement();
$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->write();

View File

@ -36,7 +36,22 @@ class Title extends AbstractElement
}
$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();
if (is_string($text)) {
$this->writeText($text);
@ -44,6 +59,21 @@ class Title extends AbstractElement
$containerWriter = new Container($xmlWriter, $text);
$containerWriter->write();
}
$xmlWriter->endElement(); // text:span
$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;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart;
@ -36,7 +36,7 @@ abstract class AbstractPart extends Word2007AbstractPart
/**
* Write common root attributes.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/
protected function writeCommonRootAttributes(XMLWriter $xmlWriter)
{
@ -72,7 +72,7 @@ abstract class AbstractPart extends Word2007AbstractPart
/**
* Write font faces declaration.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/
protected function writeFontFaces(XMLWriter $xmlWriter)
{

View File

@ -17,14 +17,15 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\AbstractContainer;
use PhpOffice\PhpWord\Element\Field;
use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\TrackChange;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@ -46,6 +47,7 @@ class Content extends AbstractPart
* @var array
*/
private $autoStyles = array('Section' => array(), 'Image' => array(), 'Table' => array());
private $imageParagraphStyles = array();
/**
* Write part
@ -128,6 +130,9 @@ class Content extends AbstractPart
$xmlWriter->startElement('text:section');
$xmlWriter->writeAttribute('text: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->write();
$xmlWriter->endElement(); // text:section
@ -146,7 +151,7 @@ class Content extends AbstractPart
*
* @since 0.11.0
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/
private function writeAutoStyles(XMLWriter $xmlWriter)
{
@ -168,34 +173,65 @@ class Content extends AbstractPart
/**
* Write automatic styles.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/
private function writeTextStyles(XMLWriter $xmlWriter)
{
$styles = Style::getStyles();
$paragraphStyleCount = 0;
if (count($styles) > 0) {
foreach ($styles as $style) {
if ($style->isAuto() === true) {
$styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style));
if (class_exists($styleClass)) {
/** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */
$styleWriter = new $styleClass($xmlWriter, $style);
$styleWriter->write();
}
if ($style instanceof Paragraph) {
$paragraphStyleCount++;
}
}
}
if ($paragraphStyleCount == 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('P1');
$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) {
if ($style->isAuto() === true) {
$styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style));
if (class_exists($styleClass)) {
/** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */
$styleWriter = new $styleClass($xmlWriter, $style);
$styleWriter->write();
}
if ($style instanceof Paragraph) {
$paragraphStyleCount++;
}
}
}
foreach ($this->imageParagraphStyles as $style) {
$styleWriter = new \PhpOffice\PhpWord\Writer\ODText\Style\Paragraph($xmlWriter, $style);
$styleWriter->write();
}
}
/**
@ -231,20 +267,29 @@ class Content extends AbstractPart
$elements = $container->getElements();
foreach ($elements as $element) {
if ($element instanceof TextRun) {
$this->getElementStyleTextRun($element, $paragraphStyleCount);
$this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount);
} elseif ($element instanceof Text) {
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
} elseif ($element instanceof Field) {
$this->getElementStyleField($element, $fontStyleCount);
} elseif ($element instanceof Image) {
$style = $element->getStyle();
$style->setStyleName('fr' . $element->getMediaIndex());
$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) {
/** @var \PhpOffice\PhpWord\Style\Table $style */
$style = $element->getStyle();
if (is_string($style)) {
$style = Style::getStyle($style);
}
if ($style === null) {
$style = new TableStyle();
} elseif (is_string($style)) {
$style = Style::getStyle($style);
}
$style->setStyleName($element->getElementId());
$style->setColumnWidths($element->findFirstDefinedCellWidths());
@ -260,7 +305,7 @@ class Content extends AbstractPart
* @param int $paragraphStyleCount
* @param int $fontStyleCount
*/
private function getElementStyle(&$element, &$paragraphStyleCount, &$fontStyleCount)
private function getElementStyle($element, &$paragraphStyleCount, &$fontStyleCount)
{
$fontStyle = $element->getFontStyle();
$paragraphStyle = $element->getParagraphStyle();
@ -268,16 +313,91 @@ class Content extends AbstractPart
if ($fontStyle instanceof Font) {
// Font
$fontStyleCount++;
$style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle);
$style->setAuto();
$element->setFontStyle("T{$fontStyleCount}");
} elseif ($paragraphStyle instanceof Paragraph) {
$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);
}
}
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++;
$style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", array());
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
$style->setAuto();
$element->setParagraphStyle("P{$paragraphStyleCount}");
$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;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* ODText meta part writer: meta.xml
@ -86,7 +86,7 @@ class Meta extends AbstractPart
/**
* Write individual property
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $property
* @param string $value
*

View File

@ -17,8 +17,9 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
/**
@ -65,7 +66,7 @@ class Styles extends AbstractPart
/**
* Write default styles.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\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');
$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');
if ($this->getParentWriter()->getPhpWord()->getSettings()->hasHideGrammaticalErrors()) {
$latinLang = $asianLang = $complexLang = array('zxx', 'none');
}
// Font
$xmlWriter->startElement('style:text-properties');
@ -114,7 +118,7 @@ class Styles extends AbstractPart
/**
* Write named styles.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\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)
{
$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->writeAttribute('style:name', 'Mpm1');
$xmlWriter->writeAttribute('style:name', "Mpm$sectionNbr");
$xmlWriter->startElement('style:page-layout-properties');
$xmlWriter->writeAttribute('fo:page-width', '21.001cm');
$xmlWriter->writeAttribute('fo:page-height', '29.7cm');
$xmlWriter->writeAttribute('fo:page-width', $pwidth);
$xmlWriter->writeAttribute('fo:page-height', $pheight);
$xmlWriter->writeAttribute('style:num-format', '1');
$xmlWriter->writeAttribute('style:print-orientation', 'portrait');
$xmlWriter->writeAttribute('fo:margin-top', '2.501cm');
$xmlWriter->writeAttribute('fo:margin-bottom', '2cm');
$xmlWriter->writeAttribute('fo:margin-left', '2.501cm');
$xmlWriter->writeAttribute('fo:margin-right', '2.501cm');
$xmlWriter->writeAttribute('style:print-orientation', $orient);
$xmlWriter->writeAttribute('fo:margin-top', $mtop);
$xmlWriter->writeAttribute('fo:margin-bottom', $mbottom);
$xmlWriter->writeAttribute('fo:margin-left', $mleft);
$xmlWriter->writeAttribute('fo:margin-right', $mright);
$xmlWriter->writeAttribute('style:writing-mode', 'lr-tb');
$xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
$xmlWriter->writeAttribute('style:layout-grid-lines', '25199');
@ -176,9 +230,23 @@ class Styles extends AbstractPart
$xmlWriter->endElement(); // style:page-layout-properties
$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->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:page-layout
@ -187,17 +255,50 @@ class Styles extends AbstractPart
/**
* Write master style.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
*/
private function writeMaster(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('office:master-styles');
$xmlWriter->startElement('style:master-page');
$xmlWriter->writeAttribute('style:name', 'Standard');
$xmlWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$xmlWriter->endElement(); // style:master-page
$sections = $this->getParentWriter()->getPhpWord()->getSections();
$countsects = count($sections);
for ($i = 0; $i < $countsects; ++$i) {
$iplus1 = $i + 1;
$xmlWriter->startElement('style:master-page');
$xmlWriter->writeAttribute('style:name', "Standard$iplus1");
$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(); // office:master-styles
}
}

View File

@ -35,6 +35,14 @@ class Font extends AbstractStyle
}
$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->writeAttribute('style:name', $style->getStyleName());
$xmlWriter->writeAttribute('style:family', 'text');
@ -53,7 +61,7 @@ class Font extends AbstractStyle
// Color
$color = $style->getColor();
$xmlWriter->writeAttributeIf($color != '', 'fo:color', '#' . $color);
$xmlWriter->writeAttributeIf($color != '', 'fo:color', '#' . \PhpOffice\PhpWord\Shared\Converter::stringToRgb($color));
// Bold & italic
$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->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 Background color

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Writer\ODText\Style;
use PhpOffice\PhpWord\Shared\Converter;
/**
* Font style writer
*
@ -35,31 +37,119 @@ class Paragraph extends AbstractStyle
}
$xmlWriter = $this->getXmlWriter();
$marginTop = (is_null($style->getSpaceBefore()) || $style->getSpaceBefore() == 0) ? '0' : round(17.6 / $style->getSpaceBefore(), 2);
$marginBottom = (is_null($style->getSpaceAfter()) || $style->getSpaceAfter() == 0) ? '0' : round(17.6 / $style->getSpaceAfter(), 2);
$marginTop = $style->getSpaceBefore();
$marginBottom = $style->getSpaceAfter();
$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:family', 'paragraph');
if ($style->isAuto()) {
$xmlWriter->writeAttribute('style:parent-style-name', 'Standard');
$xmlWriter->writeAttribute('style:master-page-name', 'Standard');
if ($styleAuto) {
$xmlWriter->writeAttributeIf($psm !== '', 'style:parent-style-name', $psm);
$xmlWriter->writeAttributeIf($mpm !== '', 'style:master-page-name', $mpm);
}
$xmlWriter->startElement('style:paragraph-properties');
if ($style->isAuto()) {
$xmlWriter->writeAttribute('style:page-number', 'auto');
} else {
$xmlWriter->writeAttribute('fo:margin-top', $marginTop . 'cm');
$xmlWriter->writeAttribute('fo:margin-bottom', $marginBottom . 'cm');
$xmlWriter->writeAttribute('fo:text-align', $style->getAlignment());
if ($styleAuto) {
if ($breakafter) {
$xmlWriter->writeAttribute('fo:break-after', 'page');
$xmlWriter->writeAttribute('fo:margin-top', '0cm');
$xmlWriter->writeAttribute('fo:margin-bottom', '0cm');
} 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
$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
if ($styleAuto && substr($styleName, 0, 2) === 'SB') {
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('text:display', 'none');
$xmlWriter->endElement();
}
$xmlWriter->endElement(); //style:style
}
}

View File

@ -35,6 +35,16 @@ class DomPDF extends AbstractRenderer implements WriterInterface
*/
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.
*
@ -49,7 +59,7 @@ class DomPDF extends AbstractRenderer implements WriterInterface
$orientation = 'portrait';
// Create PDF
$pdf = new DompdfLib();
$pdf = $this->createExternalWriterInstance();
$pdf->setPaper(strtolower($paperSize), $orientation);
$pdf->loadHtml(str_replace(PHP_EOL, '', $this->getContent()));
$pdf->render();

View File

@ -44,6 +44,18 @@ class MPDF extends AbstractRenderer implements WriterInterface
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.
*
@ -58,8 +70,7 @@ class MPDF extends AbstractRenderer implements WriterInterface
$orientation = strtoupper('portrait');
// Create PDF
$mPdfClass = $this->getMPdfClassName();
$pdf = new $mPdfClass();
$pdf = $this->createExternalWriterInstance();
$pdf->_setPageSize($paperSize, $orientation);
$pdf->addPage($orientation);

View File

@ -36,6 +36,20 @@ class TCPDF extends AbstractRenderer implements WriterInterface
*/
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.
*
@ -50,7 +64,7 @@ class TCPDF extends AbstractRenderer implements WriterInterface
$orientation = 'P';
// Create PDF
$pdf = new \TCPDF($orientation, 'pt', $paperSize);
$pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize);
$pdf->setFontSubsetting(false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

View File

@ -17,10 +17,10 @@
namespace PhpOffice\PhpWord\Writer\RTF\Element;
use PhpOffice\Common\Text as CommonText;
use PhpOffice\PhpWord\Element\AbstractElement as Element;
use PhpOffice\PhpWord\Escaper\Rtf;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\Text as SharedText;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font as FontStyle;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
@ -41,14 +41,14 @@ abstract class AbstractElement extends HTMLAbstractElement
*
* @var \PhpOffice\PhpWord\Style\Font
*/
private $fontStyle;
protected $fontStyle;
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $paragraphStyle;
protected $paragraphStyle;
public function __construct(AbstractWriter $parentWriter, Element $element, $withoutP = false)
{
@ -126,7 +126,7 @@ abstract class AbstractElement extends HTMLAbstractElement
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

@ -58,6 +58,7 @@ class Table extends AbstractElement
$content .= $this->writeRow($rows[$i]);
$content .= '\row' . PHP_EOL;
}
$content .= '\pard' . PHP_EOL;
}
return $content;

View File

@ -32,6 +32,7 @@ class TextRun extends AbstractElement
public function write()
{
$writer = new Container($this->parentWriter, $this->element);
$this->getStyles();
$content = '';
$content .= $this->writeOpening();

View File

@ -24,4 +24,69 @@ namespace PhpOffice\PhpWord\Writer\RTF\Element;
*/
class Title extends Text
{
protected function getStyles()
{
/** @var \PhpOffice\PhpWord\Element\Title $element Type hint */
$element = $this->element;
$style = $element->getStyle();
$style = str_replace('Heading', 'Heading_', $style);
$style = \PhpOffice\PhpWord\Style::getStyle($style);
if ($style instanceof \PhpOffice\PhpWord\Style\Font) {
$this->fontStyle = $style;
$pstyle = $style->getParagraph();
if ($pstyle instanceof \PhpOffice\PhpWord\Style\Paragraph && $pstyle->hasPageBreakBefore()) {
$sect = $element->getParent();
if ($sect instanceof \PhpOffice\PhpWord\Element\Section) {
$elems = $sect->getElements();
if ($elems[0] === $element) {
$pstyle = clone $pstyle;
$pstyle->setPageBreakBefore(false);
}
}
}
$this->paragraphStyle = $pstyle;
}
}
/**
* Write element
*
* @return string
*/
public function write()
{
/** @var \PhpOffice\PhpWord\Element\Title $element Type hint */
$element = $this->element;
$elementClass = str_replace('\\Writer\\RTF', '', get_class($this));
if (!$element instanceof $elementClass || !is_string($element->getText())) {
return '';
}
$this->getStyles();
$content = '';
$content .= $this->writeOpening();
$endout = '';
$style = $element->getStyle();
if (is_string($style)) {
$style = str_replace('Heading', '', $style);
if (is_numeric($style)) {
$style = (int) $style - 1;
if ($style >= 0 && $style <= 8) {
$content .= '{\\outlinelevel' . $style;
$endout = '}';
}
}
}
$content .= '{';
$content .= $this->writeFontStyle();
$content .= $this->writeText($element->getText());
$content .= '}';
$content .= $this->writeClosing();
$content .= $endout;
return $content;
}
}

View File

@ -17,6 +17,7 @@
namespace PhpOffice\PhpWord\Writer\RTF\Part;
use PhpOffice\PhpWord\Element\Footer;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\RTF\Element\Container;
use PhpOffice\PhpWord\Writer\RTF\Style\Section as SectionStyleWriter;
@ -105,11 +106,36 @@ class Document extends AbstractPart
$content .= '\lang' . $langId;
$content .= '\kerning1'; // Point size (in half-points) above which to kern character pairs
$content .= '\fs' . (Settings::getDefaultFontSize() * 2); // Set the font size in half-points
if ($docSettings->hasEvenAndOddHeaders()) {
$content .= '\\facingp';
}
$content .= PHP_EOL;
return $content;
}
/**
* Write titlepg directive if any "f" headers or footers
*
* @param \PhpOffice\PhpWord\Element\Section $section
* @return string
*/
private static function writeTitlepg($section)
{
foreach ($section->getHeaders() as $header) {
if ($header->getType() === Footer::FIRST) {
return '\\titlepg' . PHP_EOL;
}
}
foreach ($section->getFooters() as $header) {
if ($header->getType() === Footer::FIRST) {
return '\\titlepg' . PHP_EOL;
}
}
return '';
}
/**
* Write sections
*
@ -120,10 +146,53 @@ class Document extends AbstractPart
$content = '';
$sections = $this->getParentWriter()->getPhpWord()->getSections();
$evenOdd = $this->getParentWriter()->getPhpWord()->getSettings()->hasEvenAndOddHeaders();
foreach ($sections as $section) {
$styleWriter = new SectionStyleWriter($section->getStyle());
$styleWriter->setParentWriter($this->getParentWriter());
$content .= $styleWriter->write();
$content .= self::writeTitlepg($section);
foreach ($section->getHeaders() as $header) {
$type = $header->getType();
if ($evenOdd || $type !== FOOTER::EVEN) {
$content .= '{\\header';
if ($type === Footer::FIRST) {
$content .= 'f';
} elseif ($evenOdd) {
$content .= ($type === FOOTER::EVEN) ? 'l' : 'r';
}
foreach ($header->getElements() as $element) {
$cl = get_class($element);
$cl2 = str_replace('Element', 'Writer\\RTF\\Element', $cl);
if (class_exists($cl2)) {
$elementWriter = new $cl2($this->getParentWriter(), $element);
$content .= $elementWriter->write();
}
}
$content .= '}' . PHP_EOL;
}
}
foreach ($section->getFooters() as $footer) {
$type = $footer->getType();
if ($evenOdd || $type !== FOOTER::EVEN) {
$content .= '{\\footer';
if ($type === Footer::FIRST) {
$content .= 'f';
} elseif ($evenOdd) {
$content .= ($type === FOOTER::EVEN) ? 'l' : 'r';
}
foreach ($footer->getElements() as $element) {
$cl = get_class($element);
$cl2 = str_replace('Element', 'Writer\\RTF\\Element', $cl);
if (class_exists($cl2)) {
$elementWriter = new $cl2($this->getParentWriter(), $element);
$content .= $elementWriter->write();
}
}
$content .= '}' . PHP_EOL;
}
}
$elementWriter = new Container($this->getParentWriter(), $section);
$content .= $elementWriter->write();

View File

@ -49,6 +49,7 @@ class Font extends AbstractStyle
}
$content = '';
$content .= $this->getValueIf($style->isRTL(), '\rtlch');
$content .= '\cf' . $this->colorIndex;
$content .= '\f' . $this->nameIndex;

View File

@ -67,6 +67,14 @@ class Paragraph extends AbstractStyle
$content .= $this->writeIndentation($style->getIndentation());
$content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore));
$content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter));
$lineHeight = $style->getLineHeight();
if ($lineHeight) {
$lineHeightAdjusted = (int) ($lineHeight * 240);
$content .= "\\sl$lineHeightAdjusted\\slmult1";
}
if ($style->hasPageBreakBefore()) {
$content .= '\\page';
}
$styles = $style->getStyleValues();
$content .= $this->writeTabs($styles['tabs']);

View File

@ -53,6 +53,7 @@ class Section extends AbstractStyle
$content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . round($style->getHeaderHeight()));
$content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight()));
$content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter()));
$content .= $this->getValueIf($style->getPageNumberingStart() !== null, '\pgnstarts' . $style->getPageNumberingStart() . '\pgnrestart');
$content .= ' ';
// Borders

View File

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

View File

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

View File

@ -65,6 +65,7 @@ class Field extends Text
$instruction .= $this->buildPropertiesAndOptions($element);
}
$xmlWriter->startElement('w:r');
$this->writeFontStyle();
$xmlWriter->startElement('w:instrText');
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->text($instruction);

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\FormField as FormFieldElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* FormField element writer
@ -105,7 +105,7 @@ class FormField extends Text
* Write textinput.
*
* @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
*/
private function writeTextInput(XMLWriter $xmlWriter, FormFieldElement $element)
@ -121,7 +121,7 @@ class FormField extends Text
* Write checkbox.
*
* @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
*/
private function writeCheckBox(XMLWriter $xmlWriter, FormFieldElement $element)
@ -144,7 +144,7 @@ class FormField extends Text
* Write dropdown.
*
* @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
*/
private function writeDropDown(XMLWriter $xmlWriter, FormFieldElement $element)

View File

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

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\SDT as SDTElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Structured document tag element writer
@ -77,7 +77,7 @@ class SDT extends Text
* Write text.
*
* @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)
{
@ -89,7 +89,7 @@ class SDT extends Text
* Write combo box.
*
* @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
*/
private function writeComboBox(XMLWriter $xmlWriter, SDTElement $element)
@ -108,7 +108,7 @@ class SDT extends Text
* Write drop down list.
*
* @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
*/
private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element)
@ -120,7 +120,7 @@ class SDT extends Text
* Write date.
*
* @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
*/
private function writeDate(XMLWriter $xmlWriter, SDTElement $element)

View File

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

View File

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

View File

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

View File

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

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Chart as ChartElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 chart part writer: word/charts/chartx.xml
@ -99,7 +99,7 @@ class Chart extends AbstractPart
* Write chart
*
* @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)
{
@ -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_RadarChart.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)
{
@ -209,7 +209,7 @@ class Chart extends AbstractPart
/**
* Write series.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param bool $scatter
*/
private function writeSeries(XMLWriter $xmlWriter, $scatter = false)
@ -219,6 +219,7 @@ class Chart extends AbstractPart
$colors = $style->getColors();
$index = 0;
$colorIndex = 0;
foreach ($series as $seriesItem) {
$categories = $seriesItem['categories'];
$values = $seriesItem['values'];
@ -265,23 +266,21 @@ class Chart extends AbstractPart
$this->writeSeriesItem($xmlWriter, 'cat', $categories);
$this->writeSeriesItem($xmlWriter, 'val', $values);
// setting the chart colors was taken from https://github.com/PHPOffice/PHPWord/issues/494
if (is_array($colors) && count($colors)) {
// This is a workaround to make each series in a stack chart use a different color
if ($this->options['type'] == 'bar' && stristr($this->options['grouping'], 'stacked')) {
array_shift($colors);
}
$colorIndex = 0;
foreach ($colors as $color) {
// check that there are colors
if (is_array($colors) && count($colors) > 0) {
// assign a color to each value
$valueIndex = 0;
for ($i = 0; $i < count($values); $i++) {
// check that there are still enought colors
$xmlWriter->startElement('c:dPt');
$xmlWriter->writeElementBlock('c:idx', 'val', $colorIndex);
$xmlWriter->writeElementBlock('c:idx', 'val', $valueIndex);
$xmlWriter->startElement('c:spPr');
$xmlWriter->startElement('a:solidFill');
$xmlWriter->writeElementBlock('a:srgbClr', 'val', $color);
$xmlWriter->writeElementBlock('a:srgbClr', 'val', $colors[$colorIndex++ % count($colors)]);
$xmlWriter->endElement(); // a:solidFill
$xmlWriter->endElement(); // c:spPr
$xmlWriter->endElement(); // c:dPt
$colorIndex++;
$valueIndex++;
}
}
}
@ -294,7 +293,7 @@ class Chart extends AbstractPart
/**
* Write series items.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type
* @param array $values
*/
@ -335,7 +334,7 @@ class Chart extends AbstractPart
* Write axis
*
* @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
*/
private function writeAxis(XMLWriter $xmlWriter, $type)
@ -400,7 +399,7 @@ class Chart extends AbstractPart
* Write shape
*
* @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
*/
private function writeShape(XMLWriter $xmlWriter, $line = false)

View File

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

View File

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

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Element\Container;
use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter;
@ -80,7 +80,7 @@ class Document extends AbstractPart
/**
* Write begin section.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Section $section
*/
private function writeSection(XMLWriter $xmlWriter, Section $section)
@ -95,7 +95,7 @@ class Document extends AbstractPart
/**
* Write end section.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Section $section
*/
private function writeSectionSettings(XMLWriter $xmlWriter, Section $section)
@ -126,27 +126,27 @@ class Document extends AbstractPart
$xmlWriter->endElement();
}
//footnote properties
if ($section->getFootnotePropoperties() !== null) {
// Footnote properties
if ($section->getFootnoteProperties() !== null) {
$xmlWriter->startElement('w:footnotePr');
if ($section->getFootnotePropoperties()->getPos() != null) {
if ($section->getFootnoteProperties()->getPos() != null) {
$xmlWriter->startElement('w:pos');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getPos());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getPos());
$xmlWriter->endElement();
}
if ($section->getFootnotePropoperties()->getNumFmt() != null) {
if ($section->getFootnoteProperties()->getNumFmt() != null) {
$xmlWriter->startElement('w:numFmt');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumFmt());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumFmt());
$xmlWriter->endElement();
}
if ($section->getFootnotePropoperties()->getNumStart() != null) {
if ($section->getFootnoteProperties()->getNumStart() != null) {
$xmlWriter->startElement('w:numStart');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumStart());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumStart());
$xmlWriter->endElement();
}
if ($section->getFootnotePropoperties()->getNumRestart() != null) {
if ($section->getFootnoteProperties()->getNumRestart() != null) {
$xmlWriter->startElement('w:numRestart');
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumRestart());
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumRestart());
$xmlWriter->endElement();
}
$xmlWriter->endElement();

View File

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

View File

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

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Word2007 main relationship writer: _rels/.rels
@ -49,7 +49,7 @@ class Rels extends AbstractPart
/**
* Write relationships.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param array $xmlRels
* @param array $mediaRels
* @param int $relId
@ -76,7 +76,7 @@ class Rels extends AbstractPart
/**
* Write media relationships.
*
* @param \PhpOffice\Common\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $relId
* @param array $mediaRel
*/
@ -101,7 +101,7 @@ class Rels extends AbstractPart
* Format:
* <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 string $type Relationship type
* @param string $target Relationship target

View File

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

View File

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

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