Merge branch 'develop' into column_width_for_odt
This commit is contained in:
commit
4d9e9bc81b
|
|
@ -5,7 +5,7 @@ echo "TRAVIS_REPO_SLUG: $TRAVIS_REPO_SLUG"
|
||||||
echo "TRAVIS_PHP_VERSION: $TRAVIS_PHP_VERSION"
|
echo "TRAVIS_PHP_VERSION: $TRAVIS_PHP_VERSION"
|
||||||
echo "TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"
|
echo "TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"
|
||||||
|
|
||||||
if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPWord" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then
|
if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPWord" ] && [ "$TRAVIS_BRANCH" != "develop" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.6" ]; then
|
||||||
|
|
||||||
echo -e "Publishing PHPDoc...\n"
|
echo -e "Publishing PHPDoc...\n"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ v0.15.0 (?? ??? 2018)
|
||||||
- Added support for Image text wrapping distance @troosan #1310
|
- Added support for Image text wrapping distance @troosan #1310
|
||||||
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
|
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
|
||||||
- Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576
|
- Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576
|
||||||
|
- Add support for table indent (tblInd) @Trainmaster #1343
|
||||||
- Added parsing of internal links in HTML reader @lalop #1336
|
- Added parsing of internal links in HTML reader @lalop #1336
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ Available Table style options:
|
||||||
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
|
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
|
||||||
- ``border(Top|Right|Bottom|Left)Size``. Border size in *twip*.
|
- ``border(Top|Right|Bottom|Left)Size``. Border size in *twip*.
|
||||||
- ``cellMargin(Top|Right|Bottom|Left)``. Cell margin in *twip*.
|
- ``cellMargin(Top|Right|Bottom|Left)``. Cell margin in *twip*.
|
||||||
|
- ``indent``. Table indent from leading margin. Must be an instance of ``\PhpOffice\PhpWord\ComplexType\TblWidth``.
|
||||||
- ``width``. Table width in percent.
|
- ``width``. Table width in percent.
|
||||||
- ``unit``. The unit to use for the width. One of ``\PhpOffice\PhpWord\SimpleType\TblWidth``. Defaults to *auto*.
|
- ``unit``. The unit to use for the width. One of ``\PhpOffice\PhpWord\SimpleType\TblWidth``. Defaults to *auto*.
|
||||||
- ``layout``. Table layout, either *fixed* or *autofit* See ``\PhpOffice\PhpWord\Style\Table`` for constants.
|
- ``layout``. Table layout, either *fixed* or *autofit* See ``\PhpOffice\PhpWord\Style\Table`` for constants.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?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\ComplexType;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\SimpleType\TblWidth as TblWidthSimpleType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see http://www.datypic.com/sc/ooxml/t-w_CT_TblWidth.html
|
||||||
|
*/
|
||||||
|
final class TblWidth
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
private $type;
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
private $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $value If omitted, then its value shall be assumed to be 0
|
||||||
|
* @param string $type If omitted, then its value shall be assumed to be dxa
|
||||||
|
*/
|
||||||
|
public function __construct($value = 0, $type = TblWidthSimpleType::TWIP)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
TblWidthSimpleType::validate($type);
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
namespace PhpOffice\PhpWord\Reader\Word2007;
|
namespace PhpOffice\PhpWord\Reader\Word2007;
|
||||||
|
|
||||||
use PhpOffice\Common\XMLReader;
|
use PhpOffice\Common\XMLReader;
|
||||||
|
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
|
||||||
use PhpOffice\PhpWord\Element\AbstractContainer;
|
use PhpOffice\PhpWord\Element\AbstractContainer;
|
||||||
use PhpOffice\PhpWord\Element\TextRun;
|
use PhpOffice\PhpWord\Element\TextRun;
|
||||||
use PhpOffice\PhpWord\Element\TrackChange;
|
use PhpOffice\PhpWord\Element\TrackChange;
|
||||||
|
|
@ -472,6 +473,11 @@ abstract class AbstractPart
|
||||||
if ($tablePositionNode !== null) {
|
if ($tablePositionNode !== null) {
|
||||||
$style['position'] = $this->readTablePosition($xmlReader, $tablePositionNode);
|
$style['position'] = $this->readTablePosition($xmlReader, $tablePositionNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$indentNode = $xmlReader->getElement('w:tblInd', $styleNode);
|
||||||
|
if ($indentNode !== null) {
|
||||||
|
$style['indent'] = $this->readTableIndent($xmlReader, $indentNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -503,6 +509,24 @@ abstract class AbstractPart
|
||||||
return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
|
return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read w:tblInd
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\Common\XMLReader $xmlReader
|
||||||
|
* @param \DOMElement $domNode
|
||||||
|
* @return TblWidthComplexType
|
||||||
|
*/
|
||||||
|
private function readTableIndent(XMLReader $xmlReader, \DOMElement $domNode)
|
||||||
|
{
|
||||||
|
$styleDefs = array(
|
||||||
|
'value' => array(self::READ_VALUE, '.', 'w:w'),
|
||||||
|
'type' => array(self::READ_VALUE, '.', 'w:type'),
|
||||||
|
);
|
||||||
|
$styleDefs = $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
|
||||||
|
|
||||||
|
return new TblWidthComplexType((int) $styleDefs['value'], $styleDefs['type']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read w:tcPr
|
* Read w:tcPr
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Style;
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
|
||||||
use PhpOffice\PhpWord\SimpleType\Jc;
|
use PhpOffice\PhpWord\SimpleType\Jc;
|
||||||
use PhpOffice\PhpWord\SimpleType\JcTable;
|
use PhpOffice\PhpWord\SimpleType\JcTable;
|
||||||
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
||||||
|
|
@ -159,6 +160,9 @@ class Table extends Border
|
||||||
*/
|
*/
|
||||||
private $position;
|
private $position;
|
||||||
|
|
||||||
|
/** @var TblWidthComplexType|null */
|
||||||
|
private $indent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The width of each column, computed based on the max cell width of each column
|
* The width of each column, computed based on the max cell width of each column
|
||||||
*
|
*
|
||||||
|
|
@ -751,4 +755,24 @@ class Table extends Border
|
||||||
{
|
{
|
||||||
$this->columnWidths = $value;
|
$this->columnWidths = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TblWidthComplexType
|
||||||
|
*/
|
||||||
|
public function getIndent()
|
||||||
|
{
|
||||||
|
return $this->indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TblWidthComplexType $indent
|
||||||
|
* @return self
|
||||||
|
* @see http://www.datypic.com/sc/ooxml/e-w_tblInd-1.html
|
||||||
|
*/
|
||||||
|
public function setIndent(TblWidthComplexType $indent)
|
||||||
|
{
|
||||||
|
$this->indent = $indent;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ class Table extends AbstractStyle
|
||||||
|
|
||||||
$this->writeTblWidth($xmlWriter, 'w:tblW', $style->getUnit(), $style->getWidth());
|
$this->writeTblWidth($xmlWriter, 'w:tblW', $style->getUnit(), $style->getWidth());
|
||||||
$this->writeTblWidth($xmlWriter, 'w:tblCellSpacing', TblWidth::TWIP, $style->getCellSpacing());
|
$this->writeTblWidth($xmlWriter, 'w:tblCellSpacing', TblWidth::TWIP, $style->getCellSpacing());
|
||||||
|
$this->writeIndent($xmlWriter, $style);
|
||||||
$this->writeLayout($xmlWriter, $style->getLayout());
|
$this->writeLayout($xmlWriter, $style->getLayout());
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
|
|
@ -216,4 +217,19 @@ class Table extends AbstractStyle
|
||||||
{
|
{
|
||||||
$this->width = $value;
|
$this->width = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param XMLWriter $xmlWriter
|
||||||
|
* @param TableStyle $style
|
||||||
|
*/
|
||||||
|
private function writeIndent(XMLWriter $xmlWriter, TableStyle $style)
|
||||||
|
{
|
||||||
|
$indent = $style->getIndent();
|
||||||
|
|
||||||
|
if ($indent === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->writeTblWidth($xmlWriter, 'w:tblInd', $indent->getType(), $indent->getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,4 +126,23 @@ class StyleTest extends AbstractTestReader
|
||||||
$fontStyle = $textRun->getElement(0)->getFontStyle();
|
$fontStyle = $textRun->getElement(0)->getFontStyle();
|
||||||
$this->assertEquals(15, $fontStyle->getPosition());
|
$this->assertEquals(15, $fontStyle->getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testReadIndent()
|
||||||
|
{
|
||||||
|
$documentXml = '<w:tbl>
|
||||||
|
<w:tblPr>
|
||||||
|
<w:tblInd w:w="2160" w:type="dxa"/>
|
||||||
|
</w:tblPr>
|
||||||
|
</w:tbl>';
|
||||||
|
|
||||||
|
$phpWord = $this->getDocumentFromString(array('document' => $documentXml));
|
||||||
|
|
||||||
|
$elements = $phpWord->getSection(0)->getElements();
|
||||||
|
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Table', $elements[0]);
|
||||||
|
$this->assertInstanceOf('PhpOffice\PhpWord\Style\Table', $elements[0]->getStyle());
|
||||||
|
/** @var \PhpOffice\PhpWord\Style\Table $tableStyle */
|
||||||
|
$tableStyle = $elements[0]->getStyle();
|
||||||
|
$this->assertSame(TblWidth::TWIP, $tableStyle->getIndent()->getType());
|
||||||
|
$this->assertSame(2160, $tableStyle->getIndent()->getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Style;
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
|
||||||
use PhpOffice\PhpWord\SimpleType\JcTable;
|
use PhpOffice\PhpWord\SimpleType\JcTable;
|
||||||
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
||||||
|
|
||||||
|
|
@ -57,6 +58,7 @@ class TableTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertNull($object->getBgColor());
|
$this->assertNull($object->getBgColor());
|
||||||
$this->assertEquals(Table::LAYOUT_AUTO, $object->getLayout());
|
$this->assertEquals(Table::LAYOUT_AUTO, $object->getLayout());
|
||||||
$this->assertEquals(TblWidth::AUTO, $object->getUnit());
|
$this->assertEquals(TblWidth::AUTO, $object->getUnit());
|
||||||
|
$this->assertNull($object->getIndent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -208,4 +210,13 @@ class TableTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertNotNull($object->getPosition());
|
$this->assertNotNull($object->getPosition());
|
||||||
$this->assertEquals(TablePosition::VANCHOR_PAGE, $object->getPosition()->getVertAnchor());
|
$this->assertEquals(TablePosition::VANCHOR_PAGE, $object->getPosition()->getVertAnchor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIndent()
|
||||||
|
{
|
||||||
|
$indent = new TblWidthComplexType(100, TblWidth::TWIP);
|
||||||
|
|
||||||
|
$table = new Table(array('indent' => $indent));
|
||||||
|
|
||||||
|
$this->assertSame($indent, $table->getIndent());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\ComplexType\TblWidth as TblWidthComplexType;
|
||||||
|
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
||||||
use PhpOffice\PhpWord\Style\Table;
|
use PhpOffice\PhpWord\Style\Table;
|
||||||
use PhpOffice\PhpWord\Style\TablePosition;
|
use PhpOffice\PhpWord\Style\TablePosition;
|
||||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||||
|
|
@ -75,7 +77,7 @@ class TableTest extends \PHPUnit\Framework\TestCase
|
||||||
$path = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellSpacing';
|
$path = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellSpacing';
|
||||||
$this->assertTrue($doc->elementExists($path));
|
$this->assertTrue($doc->elementExists($path));
|
||||||
$this->assertEquals(10.3, $doc->getElementAttribute($path, 'w:w'));
|
$this->assertEquals(10.3, $doc->getElementAttribute($path, 'w:w'));
|
||||||
$this->assertEquals(\PhpOffice\PhpWord\SimpleType\TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
|
$this->assertEquals(TblWidth::TWIP, $doc->getElementAttribute($path, 'w:type'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -118,4 +120,25 @@ class TableTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->assertEquals(TablePosition::YALIGN_TOP, $doc->getElementAttribute($path, 'w:tblpYSpec'));
|
$this->assertEquals(TablePosition::YALIGN_TOP, $doc->getElementAttribute($path, 'w:tblpYSpec'));
|
||||||
$this->assertEquals(60, $doc->getElementAttribute($path, 'w:tblpY'));
|
$this->assertEquals(60, $doc->getElementAttribute($path, 'w:tblpY'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIndent()
|
||||||
|
{
|
||||||
|
$value = 100;
|
||||||
|
$type = TblWidth::TWIP;
|
||||||
|
|
||||||
|
$tableStyle = new Table();
|
||||||
|
$tableStyle->setIndent(new TblWidthComplexType($value, $type));
|
||||||
|
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$table = $section->addTable($tableStyle);
|
||||||
|
$table->addRow();
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
|
|
||||||
|
$path = '/w:document/w:body/w:tbl/w:tblPr/w:tblInd';
|
||||||
|
$this->assertTrue($doc->elementExists($path));
|
||||||
|
$this->assertSame($value, (int) $doc->getElementAttribute($path, 'w:w'));
|
||||||
|
$this->assertSame($type, $doc->getElementAttribute($path, 'w:type'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue