Skip to content

Commit 6811868

Browse files
committed
Merge branch 'master' into allowImageClosure
2 parents 6ed3203 + b8346af commit 6811868

File tree

7 files changed

+144
-8
lines changed

7 files changed

+144
-8
lines changed

CHANGELOG.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,33 @@ Change Log
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6-
v0.17.0 (?? ??? 2019)
6+
v0.17.0 (01 oct 2019)
77
----------------------
88
### Added
9-
- Add RightToLeft table presentation. @troosan #1550
9+
- Add methods setValuesFromArray and cloneRowFromArray to the TemplateProcessor @geraldb-nicat #670
1010
- Set complex type in template @troosan #1565
11+
- implement support for section vAlign @troosan #1569
12+
- ParseStyle for border-color @Gllrm0 #1551
13+
- Html writer auto invert text color @SailorMax #1387
14+
- Add RightToLeft table presentation. @troosan #1550
1115
- Add support for page vertical alignment. @troosan #672 #1569
16+
- Adding setNumId method for ListItem style @eweso #1329
17+
- Add support for basic fields in RTF writer. @Samuel-BF #1717
1218

1319
### Fixed
1420
- Fix HTML border-color parsing. @troosan #1551 #1570
21+
- Language::validateLocale should pass with locale 'zxx'. @efpapado #1558
22+
- can't align center vertically with the text @ter987 #672
23+
- fix parsing of border-color and add test @troosan #1570
24+
- TrackChange doesn't handle all return types of \DateTime::createFromFormat(...) @superhaggis #1584
25+
- To support PreserveText inside sub container @bhattnishant #1637
26+
- No nested w:pPr elements in ListItemRun. @waltertamboer #1628
27+
- Ensure that entity_loader disable variable is re-set back to the original setting @seamuslee001 #1585
1528

1629
### Miscellaneous
17-
- Use embedded http server to test loading of remote images @troosan #
30+
- Use embedded http server to test loading of remote images @troosan #1544
31+
- Change private to protected to be able extending class Html @SpinyMan #1646
32+
- Fix apt-get crash in Travis CI for PHP 5.3 @mdupont #1707
1833

1934
v0.16.0 (30 dec 2018)
2035
----------------------

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
},
9191
"extra": {
9292
"branch-alias": {
93-
"dev-develop": "0.17-dev"
93+
"dev-develop": "0.18-dev"
9494
}
9595
}
9696
}

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# built documents.
4949
#
5050
# The short X.Y version.
51-
version = '0.16.0'
51+
version = '0.17.0'
5252
# The full version, including alpha/beta/rc tags.
5353
release = version
5454

docs/installing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Example:
3434
3535
{
3636
"require": {
37-
"phpoffice/phpword": "v0.14.*"
37+
"phpoffice/phpword": "v0.17.*"
3838
}
3939
}
4040

src/PhpWord/Element/AbstractElement.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ abstract class AbstractElement
9696
/**
9797
* A reference to the parent
9898
*
99-
* @var \PhpOffice\PhpWord\Element\AbstractElement
99+
* @var AbstractElement|null
100100
*/
101101
private $parent;
102102

@@ -335,6 +335,11 @@ public function setCommentRangeEnd(Comment $value)
335335
$this->commentRangeEnd->setEndElement($this);
336336
}
337337

338+
/**
339+
* Get parent element
340+
*
341+
* @return AbstractElement|null
342+
*/
338343
public function getParent()
339344
{
340345
return $this->parent;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* This file is part of PHPWord - A pure PHP library for reading and writing
4+
* word processing documents.
5+
*
6+
* PHPWord is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12+
*
13+
* @see https://github.com/PHPOffice/PHPWord
14+
* @copyright 2019 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Writer\RTF\Element;
19+
20+
/**
21+
* Field element writer
22+
*
23+
* Note: for now, only date, page and numpages fields are implemented for RTF.
24+
*/
25+
class Field extends Text
26+
{
27+
/**
28+
* Write field element.
29+
*/
30+
public function write()
31+
{
32+
$element = $this->element;
33+
if (!$element instanceof \PhpOffice\PhpWord\Element\Field) {
34+
return;
35+
}
36+
37+
$this->getStyles();
38+
39+
$content = '';
40+
$content .= $this->writeOpening();
41+
$content .= '{';
42+
$content .= $this->writeFontStyle();
43+
44+
$methodName = 'write' . ucfirst(strtolower($element->getType()));
45+
if (!method_exists($this, $methodName)) {
46+
// Unsupported field
47+
$content .= '';
48+
} else {
49+
$content .= '\\field{\\*\\fldinst ';
50+
$content .= $this->$methodName($element);
51+
$content .= '}{\\fldrslt}';
52+
}
53+
$content .= '}';
54+
$content .= $this->writeClosing();
55+
56+
return $content;
57+
}
58+
59+
protected function writePage()
60+
{
61+
return 'PAGE';
62+
}
63+
64+
protected function writeNumpages()
65+
{
66+
return 'NUMPAGES';
67+
}
68+
69+
protected function writeDate(\PhpOffice\PhpWord\Element\Field $element)
70+
{
71+
$content = '';
72+
$content .= 'DATE';
73+
$properties = $element->getProperties();
74+
if (isset($properties['dateformat'])) {
75+
$content .= ' \\\\@ "' . $properties['dateformat'] . '"';
76+
}
77+
78+
return $content;
79+
}
80+
}

tests/PhpWord/Writer/RTF/ElementTest.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
2929
*/
3030
public function testUnmatchedElements()
3131
{
32-
$elements = array('Container', 'Text', 'Title', 'Link', 'Image', 'Table');
32+
$elements = array('Container', 'Text', 'Title', 'Link', 'Image', 'Table', 'Field');
3333
foreach ($elements as $element) {
3434
$objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element\\' . $element;
3535
$parentWriter = new RTF();
@@ -39,4 +39,40 @@ public function testUnmatchedElements()
3939
$this->assertEquals('', $object->write());
4040
}
4141
}
42+
43+
public function testPageField()
44+
{
45+
$parentWriter = new RTF();
46+
$element = new \PhpOffice\PhpWord\Element\Field('PAGE');
47+
$field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element);
48+
49+
$this->assertEquals("{\\field{\\*\\fldinst PAGE}{\\fldrslt}}\\par\n", $field->write());
50+
}
51+
52+
public function testNumpageField()
53+
{
54+
$parentWriter = new RTF();
55+
$element = new \PhpOffice\PhpWord\Element\Field('NUMPAGES');
56+
$field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element);
57+
58+
$this->assertEquals("{\\field{\\*\\fldinst NUMPAGES}{\\fldrslt}}\\par\n", $field->write());
59+
}
60+
61+
public function testDateField()
62+
{
63+
$parentWriter = new RTF();
64+
$element = new \PhpOffice\PhpWord\Element\Field('DATE', array('dateformat' => 'd MM yyyy H:mm:ss'));
65+
$field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element);
66+
67+
$this->assertEquals("{\\field{\\*\\fldinst DATE \\\\@ \"d MM yyyy H:mm:ss\"}{\\fldrslt}}\\par\n", $field->write());
68+
}
69+
70+
public function testIndexField()
71+
{
72+
$parentWriter = new RTF();
73+
$element = new \PhpOffice\PhpWord\Element\Field('INDEX');
74+
$field = new \PhpOffice\PhpWord\Writer\RTF\Element\Field($parentWriter, $element);
75+
76+
$this->assertEquals("{}\\par\n", $field->write());
77+
}
4278
}

0 commit comments

Comments
 (0)