Merge branch 'develop' into fieldstyle
This commit is contained in:
commit
8b2e21b634
|
|
@ -359,17 +359,17 @@ The footnote numbering can be controlled by setting the FootnoteProperties on th
|
||||||
|
|
||||||
.. code-block:: php
|
.. 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)
|
//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, ...)
|
//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
|
//force starting at other than 1
|
||||||
$fp->setNumStart(2);
|
$fp->setNumStart(2);
|
||||||
//when to restart counting (continuous (default), eachSect, eachPage)
|
//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
|
//And finaly, set it on the Section
|
||||||
$section->setFootnoteProperties($properties);
|
$section->setFootnoteProperties($fp);
|
||||||
|
|
||||||
Checkboxes
|
Checkboxes
|
||||||
----------
|
----------
|
||||||
|
|
|
||||||
|
|
@ -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.
|
- ``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.
|
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
|
||||||
- ``basedOn``. Parent style.
|
- ``basedOn``. Parent style.
|
||||||
- ``hanging``. Hanging in *twip*.
|
- ``hanging``. Hanging indentation in *half inches*.
|
||||||
- ``indent``. Indent in *twip*.
|
- ``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*.
|
- ``keepLines``. Keep all lines on one page, *true* or *false*.
|
||||||
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
|
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
|
||||||
- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc.
|
- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc.
|
||||||
|
|
|
||||||
|
|
@ -244,3 +244,20 @@ See ``Sample_40_TemplateSetComplexValue.php`` for examples.
|
||||||
$table->addCell(150)->addText('Cell B2');
|
$table->addCell(150)->addText('Cell B2');
|
||||||
$table->addCell(150)->addText('Cell B3');
|
$table->addCell(150)->addText('Cell B3');
|
||||||
$templateProcessor->setComplexBlock('table', $table);
|
$templateProcessor->setComplexBlock('table', $table);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,18 @@ class Section extends AbstractContainer
|
||||||
*
|
*
|
||||||
* @return FootnoteProperties
|
* @return FootnoteProperties
|
||||||
*/
|
*/
|
||||||
|
public function getFootnoteProperties()
|
||||||
|
{
|
||||||
|
return $this->footnoteProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the footnote properties
|
||||||
|
*
|
||||||
|
* @deprecated Use the `getFootnoteProperties` method instead
|
||||||
|
*
|
||||||
|
* @return FootnoteProperties
|
||||||
|
*/
|
||||||
public function getFootnotePropoperties()
|
public function getFootnotePropoperties()
|
||||||
{
|
{
|
||||||
return $this->footnoteProperties;
|
return $this->footnoteProperties;
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ class Paragraph extends Border
|
||||||
{
|
{
|
||||||
$key = Text::removeUnderscorePrefix($key);
|
$key = Text::removeUnderscorePrefix($key);
|
||||||
if ('indent' == $key || 'hanging' == $key) {
|
if ('indent' == $key || 'hanging' == $key) {
|
||||||
$value = $value * 720;
|
$value = $value * 720; // 720 twips is 0.5 inch
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::setStyleValue($key, $value);
|
return parent::setStyleValue($key, $value);
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -126,27 +126,27 @@ class Document extends AbstractPart
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
//footnote properties
|
// Footnote properties
|
||||||
if ($section->getFootnotePropoperties() !== null) {
|
if ($section->getFootnoteProperties() !== null) {
|
||||||
$xmlWriter->startElement('w:footnotePr');
|
$xmlWriter->startElement('w:footnotePr');
|
||||||
if ($section->getFootnotePropoperties()->getPos() != null) {
|
if ($section->getFootnoteProperties()->getPos() != null) {
|
||||||
$xmlWriter->startElement('w:pos');
|
$xmlWriter->startElement('w:pos');
|
||||||
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getPos());
|
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getPos());
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
if ($section->getFootnotePropoperties()->getNumFmt() != null) {
|
if ($section->getFootnoteProperties()->getNumFmt() != null) {
|
||||||
$xmlWriter->startElement('w:numFmt');
|
$xmlWriter->startElement('w:numFmt');
|
||||||
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumFmt());
|
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumFmt());
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
if ($section->getFootnotePropoperties()->getNumStart() != null) {
|
if ($section->getFootnoteProperties()->getNumStart() != null) {
|
||||||
$xmlWriter->startElement('w:numStart');
|
$xmlWriter->startElement('w:numStart');
|
||||||
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumStart());
|
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumStart());
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
if ($section->getFootnotePropoperties()->getNumRestart() != null) {
|
if ($section->getFootnoteProperties()->getNumRestart() != null) {
|
||||||
$xmlWriter->startElement('w:numRestart');
|
$xmlWriter->startElement('w:numRestart');
|
||||||
$xmlWriter->writeAttribute('w:val', $section->getFootnotePropoperties()->getNumRestart());
|
$xmlWriter->writeAttribute('w:val', $section->getFootnoteProperties()->getNumRestart());
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
}
|
}
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,22 @@ class MediaTest extends AbstractWebServerEmbeddedTest
|
||||||
$this->assertEquals(array(), Media::getElements('section'));
|
$this->assertEquals(array(), Media::getElements('section'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get header media elements
|
||||||
|
*/
|
||||||
|
public function testGetHeaderMediaElementsWithNull()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array(), Media::getElements('header'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get footer media elements
|
||||||
|
*/
|
||||||
|
public function testGetFooterMediaElementsWithNull()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array(), Media::getElements('footer'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count section media elements
|
* Count section media elements
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -225,4 +225,13 @@ class PhpWordTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertEquals(2, $phpWord->getSection(0)->countElements());
|
$this->assertEquals(2, $phpWord->getSection(0)->countElements());
|
||||||
$this->assertEquals(1, $phpWord->getSection(1)->countElements());
|
$this->assertEquals(1, $phpWord->getSection(1)->countElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \PhpOffice\PhpWord\PhpWord::getSettings
|
||||||
|
*/
|
||||||
|
public function testGetSettings()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Metadata\\Settings', $phpWord->getSettings());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class StyleTest extends \PHPUnit\Framework\TestCase
|
||||||
* @covers ::addParagraphStyle
|
* @covers ::addParagraphStyle
|
||||||
* @covers ::addFontStyle
|
* @covers ::addFontStyle
|
||||||
* @covers ::addLinkStyle
|
* @covers ::addLinkStyle
|
||||||
|
* @covers ::addNumberingStyle
|
||||||
* @covers ::addTitleStyle
|
* @covers ::addTitleStyle
|
||||||
* @covers ::addTableStyle
|
* @covers ::addTableStyle
|
||||||
* @covers ::setDefaultParagraphStyle
|
* @covers ::setDefaultParagraphStyle
|
||||||
|
|
@ -47,6 +48,20 @@ class StyleTest extends \PHPUnit\Framework\TestCase
|
||||||
$paragraph = array('alignment' => Jc::CENTER);
|
$paragraph = array('alignment' => Jc::CENTER);
|
||||||
$font = array('italic' => true, '_bold' => true);
|
$font = array('italic' => true, '_bold' => true);
|
||||||
$table = array('bgColor' => 'CCCCCC');
|
$table = array('bgColor' => 'CCCCCC');
|
||||||
|
$numbering = array(
|
||||||
|
'type' => 'multilevel',
|
||||||
|
'levels' => array(
|
||||||
|
array(
|
||||||
|
'start' => 1,
|
||||||
|
'format' => 'decimal',
|
||||||
|
'restart' => 1,
|
||||||
|
'suffix' => 'space',
|
||||||
|
'text' => '%1.',
|
||||||
|
'alignment' => Jc::START,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
$styles = array(
|
$styles = array(
|
||||||
'Paragraph' => 'Paragraph',
|
'Paragraph' => 'Paragraph',
|
||||||
'Font' => 'Font',
|
'Font' => 'Font',
|
||||||
|
|
@ -54,12 +69,13 @@ class StyleTest extends \PHPUnit\Framework\TestCase
|
||||||
'Table' => 'Table',
|
'Table' => 'Table',
|
||||||
'Heading_1' => 'Font',
|
'Heading_1' => 'Font',
|
||||||
'Normal' => 'Paragraph',
|
'Normal' => 'Paragraph',
|
||||||
|
'Numbering' => 'Numbering',
|
||||||
);
|
);
|
||||||
|
|
||||||
Style::addParagraphStyle('Paragraph', $paragraph);
|
Style::addParagraphStyle('Paragraph', $paragraph);
|
||||||
Style::addFontStyle('Font', $font);
|
Style::addFontStyle('Font', $font);
|
||||||
Style::addLinkStyle('Link', $font);
|
Style::addLinkStyle('Link', $font);
|
||||||
// @todo Style::addNumberingStyle
|
Style::addNumberingStyle('Numbering', $numbering);
|
||||||
Style::addTitleStyle(1, $font);
|
Style::addTitleStyle(1, $font);
|
||||||
Style::addTableStyle('Table', $table);
|
Style::addTableStyle('Table', $table);
|
||||||
Style::setDefaultParagraphStyle($paragraph);
|
Style::setDefaultParagraphStyle($paragraph);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
||||||
*/
|
*/
|
||||||
public function testUnmatchedElements()
|
public function testUnmatchedElements()
|
||||||
{
|
{
|
||||||
$elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title', 'Bookmark');
|
$elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'Table', 'Title', 'Bookmark');
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element;
|
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element;
|
||||||
$parentWriter = new HTML();
|
$parentWriter = new HTML();
|
||||||
|
|
@ -163,6 +163,31 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertContains($expected, $content);
|
$this->assertContains($expected, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test write element ListItemRun
|
||||||
|
*/
|
||||||
|
public function testListItemRun()
|
||||||
|
{
|
||||||
|
$expected1 = 'List item run 1';
|
||||||
|
$expected2 = 'List item run 1 in bold';
|
||||||
|
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
$listItemRun = $section->addListItemRun(0, null, 'MyParagraphStyle');
|
||||||
|
$listItemRun->addText($expected1);
|
||||||
|
$listItemRun->addText($expected2, array('bold' => true));
|
||||||
|
|
||||||
|
$htmlWriter = new HTML($phpWord);
|
||||||
|
$content = $htmlWriter->getContent();
|
||||||
|
|
||||||
|
$dom = new \DOMDocument();
|
||||||
|
$dom->loadHTML($content);
|
||||||
|
|
||||||
|
$this->assertEquals($expected1, $dom->getElementsByTagName('p')->item(0)->textContent);
|
||||||
|
$this->assertEquals($expected2, $dom->getElementsByTagName('p')->item(1)->textContent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests writing table with layout
|
* Tests writing table with layout
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
if (self::isBuiltinServerSupported()) {
|
if (self::isBuiltinServerSupported()) {
|
||||||
$commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files';
|
$commandLine = 'php -S localhost:8080 -t tests/PhpWord/_files';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure to invoke \Symfony\Component\Process\Process correctly
|
* Make sure to invoke \Symfony\Component\Process\Process correctly
|
||||||
* regardless of PHP version used.
|
* regardless of PHP version used.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue