diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5d55fa2b..49418710 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,50 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
+v0.18.0 (08 feb 2021)
+----------------------
+### Added
+- allow to use customized pdf library [\#1983](https://github.com/PHPOffice/PHPWord/pull/1983) ([SailorMax](https://github.com/SailorMax))
+- Add parsing of Shape node values [\#1924](https://github.com/PHPOffice/PHPWord/pull/1924) ([sven-ahrens](https://github.com/sven-ahrens))
+- Allow to redefine TCPDF object [\#1907](https://github.com/PHPOffice/PHPWord/pull/1907) ([SailorMax](https://github.com/SailorMax))
+- Make Default Paper Configurable [\#1851](https://github.com/PHPOffice/PHPWord/pull/1851) ([oleibman](https://github.com/oleibman))
+- Implement various missing features for the ODT writer [\#1796](https://github.com/PHPOffice/PHPWord/pull/1796) ([oleibman](https://github.com/oleibman))
+- Add support for several features for the RTF writer [\#1775](https://github.com/PHPOffice/PHPWord/pull/1775) ([oleibman](https://github.com/oleibman))
+- Improvements in RTF writer [\#1755](https://github.com/PHPOffice/PHPWord/pull/1755) ([oleibman](https://github.com/oleibman))
+- Add font style for Field elements [\#1774](https://github.com/PHPOffice/PHPWord/pull/1774) ([oleibman](https://github.com/oleibman))
+- Added support for "cloudConvert" images [\#1794](https://github.com/PHPOffice/PHPWord/pull/1794) ([ErnestStaug](https://github.com/ErnestStaug))
+- Add support for ListItemRun in HTML writer [\#1766](https://github.com/PHPOffice/PHPWord/pull/1766) ([stefan-91](https://github.com/stefan-91))
+- Allow a closure to be passed with image replacement tags [\#1716](https://github.com/PHPOffice/PHPWord/pull/1716) ([mbardelmeijer](https://github.com/mbardelmeijer))
+- Add support for charts in template processor [\#2012](https://github.com/PHPOffice/PHPWord/pull/2012) ([dbarzin](https://github.com/dbarzin))
+- Update addHtml to handle style inheritance [\#1965](https://github.com/PHPOffice/PHPWord/pull/1965) ([Julien1138](https://github.com/Julien1138))
+- Add parsing of HTML checkbox input field [\#1832](https://github.com/PHPOffice/PHPWord/pull/1832) ([Matze2010](https://github.com/Matze2010))
+- Add Option for Dynamic Chart Legend Position [\#1922](https://github.com/PHPOffice/PHPWord/pull/1922) ([csk83](https://github.com/csk83))
+
+### Fixed
+- Add null check when setComplexValue is not found [\#1936](https://github.com/PHPOffice/PHPWord/pull/1936) ([YannikFirre](https://github.com/YannikFirre))
+- Fix image stroke in libreoffice 7.x [\#1992](https://github.com/PHPOffice/PHPWord/pull/1992) ([Adizbek](https://github.com/Adizbek))
+- Fix deprecated warning for non-hexadecimal number [\#1988](https://github.com/PHPOffice/PHPWord/pull/1988) ([Ciki](https://github.com/Ciki))
+- Fix typo in docs. Update templates-processing.rst [\#1952](https://github.com/PHPOffice/PHPWord/pull/1952) ([mnvx](https://github.com/mnvx))
+- Fixes PHPDoc @param and @return types for several Converter methods [\#1818](https://github.com/PHPOffice/PHPWord/pull/1818) ([caugner](https://github.com/caugner))
+- Fix documentation and method name for FootnoteProperties [\#1776](https://github.com/PHPOffice/PHPWord/pull/1776) ([mdupont](https://github.com/mdupont))
+- Fix PHPUnit tests on develop branch [\#1771](https://github.com/PHPOffice/PHPWord/pull/1771) ([mdupont](https://github.com/mdupont))
+- fix: documentation about paragraph indentation [\#1764](https://github.com/PHPOffice/PHPWord/pull/1764) ([mdupont](https://github.com/mdupont))
+- Update templates-processing.rst [\#1745](https://github.com/PHPOffice/PHPWord/pull/1745) ([igronus](https://github.com/igronus))
+- Update templates processing docs [\#1729](https://github.com/PHPOffice/PHPWord/pull/1729) ([hcdias](https://github.com/hcdias))
+- Fix limit not taken into account when adding image in template [\#1967](https://github.com/PHPOffice/PHPWord/pull/1967) ([jsochor](https://github.com/jsochor))
+- Fix cloneBlock issue [\#2006](https://github.com/PHPOffice/PHPWord/pull/2006) ([lexdewilligen](https://github.com/lexdewilligen))
+- TemplateProcessor cloneBlock wrongly clones images [\#1763](https://github.com/PHPOffice/PHPWord/pull/1763) ([alarai](https://github.com/alarai))
+- Some document have non-standard locale code [\#1824](https://github.com/PHPOffice/PHPWord/pull/1824) ([ErnestStaug](https://github.com/ErnestStaug))
+- Update the regexp to avoid catastrophic backtracking [\#1809](https://github.com/PHPOffice/PHPWord/pull/1809) ([juzser](https://github.com/juzser))
+
+### Miscellaneous
+- Compatibility with PHP 7.4, PHP 8.0 and migrate to Laminas Escaper [\#1946](https://github.com/PHPOffice/PHPWord/pull/1946) ([liborm85](https://github.com/liborm85))
+- Remove legacy PHPOffice/Common package, fix PHP 8.0 compatibility [\#1996](https://github.com/PHPOffice/PHPWord/pull/1996) ([liborm85](https://github.com/liborm85))
+- Improve Word2007 Test Coverage [\#1858](https://github.com/PHPOffice/PHPWord/pull/1858) ([oleibman](https://github.com/oleibman))
+- Add unit test for NumberingStyle [\#1744](https://github.com/PHPOffice/PHPWord/pull/1744) ([Manunchik](https://github.com/Manunchik))
+- Add unit test for PhpWord Settings [\#1743](https://github.com/PHPOffice/PHPWord/pull/1743) ([Manunchik](https://github.com/Manunchik))
+- Add unit test for Media elements [\#1742](https://github.com/PHPOffice/PHPWord/pull/1742) ([Manunchik](https://github.com/Manunchik))
+
v0.17.0 (01 oct 2019)
----------------------
### Added
diff --git a/docs/styles.rst b/docs/styles.rst
index 18a9c2ec..06d983e5 100644
--- a/docs/styles.rst
+++ b/docs/styles.rst
@@ -201,6 +201,7 @@ Available Chart style options:
- ``colors``. A list of colors to use in the chart.
- ``title``. The title for the chart.
- ``showLegend``. Show legend, *true* or *false*.
+- ``LegendPosition``. Legend position, *r* (default), *b*, *t*, *l* or *tr*.
- ``categoryLabelPosition``. Label position for categories, *nextTo* (default), *low* or *high*.
- ``valueLabelPosition``. Label position for values, *nextTo* (default), *low* or *high*.
- ``categoryAxisTitle``. The title for the category axis.
diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php
index c24a6f8e..bfb9ffe8 100644
--- a/samples/Sample_32_Chart.php
+++ b/samples/Sample_32_Chart.php
@@ -25,6 +25,9 @@ $series2 = array(3, 1, 7, 2, 6);
$series3 = array(8, 3, 2, 5, 4);
$showGridLines = false;
$showAxisLabels = false;
+$showLegend = true;
+$legendPosition = 't';
+// r = right, l = left, t = top, b = bottom, tr = top right
foreach ($chartTypes as $chartType) {
$section->addTitle(ucfirst($chartType), 2);
@@ -33,6 +36,8 @@ foreach ($chartTypes as $chartType) {
$chart->getStyle()->setShowGridX($showGridLines);
$chart->getStyle()->setShowGridY($showGridLines);
$chart->getStyle()->setShowAxisLabels($showAxisLabels);
+ $chart->getStyle()->setShowLegend($showLegend);
+ $chart->getStyle()->setLegendPosition($legendPosition);
if (in_array($chartType, $twoSeries)) {
$chart->addSeries($categories, $series2);
}
diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php
index 1bd29833..982f9462 100644
--- a/src/PhpWord/Shared/Html.php
+++ b/src/PhpWord/Shared/Html.php
@@ -115,7 +115,7 @@ class Html
// tables, cells
if (false !== strpos($val, '%')) {
// e.g.
or
- $styles['width'] = intval($val) * 50;
+ $styles['width'] = (int) $val * 50;
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
} else {
// e.g. , where "2" = 2px (always pixels)
- $val = intval($val).'px';
+ $val = (int) $val . 'px';
$styles['cellSpacing'] = Converter::cssToTwip($val);
break;
case 'bgcolor':
@@ -426,7 +426,7 @@ class Html
$cell = $element->addCell($width, $cellStyles);
if (self::shouldAddTextRun($node)) {
- return $cell->addTextRun(self::parseInlineStyle($node, $styles['paragraph']));
+ return $cell->addTextRun(self::filterOutNonInheritedStyles(self::parseInlineStyle($node, $styles['paragraph'])));
}
return $cell;
@@ -457,15 +457,51 @@ class Html
*/
protected static function recursiveParseStylesInHierarchy(\DOMNode $node, array $style)
{
- $parentStyle = self::parseInlineStyle($node, array());
- $style = array_merge($parentStyle, $style);
+ $parentStyle = array();
if ($node->parentNode != null && XML_ELEMENT_NODE == $node->parentNode->nodeType) {
- $style = self::recursiveParseStylesInHierarchy($node->parentNode, $style);
+ $parentStyle = self::recursiveParseStylesInHierarchy($node->parentNode, array());
}
+ if ($node->nodeName === '#text') {
+ $parentStyle = array_merge($parentStyle, $style);
+ } else {
+ $parentStyle = self::filterOutNonInheritedStyles($parentStyle);
+ }
+ $style = self::parseInlineStyle($node, $parentStyle);
return $style;
}
+ /**
+ * Removes non-inherited styles from array
+ *
+ * @param array &$styles
+ */
+ protected static function filterOutNonInheritedStyles(array $styles)
+ {
+ $nonInheritedStyles = array(
+ 'borderSize',
+ 'borderTopSize',
+ 'borderRightSize',
+ 'borderBottomSize',
+ 'borderLeftSize',
+ 'borderColor',
+ 'borderTopColor',
+ 'borderRightColor',
+ 'borderBottomColor',
+ 'borderLeftColor',
+ 'borderStyle',
+ 'spaceAfter',
+ 'spaceBefore',
+ 'underline',
+ 'strikethrough',
+ 'hidden',
+ );
+
+ $styles = array_diff_key($styles, array_flip($nonInheritedStyles));
+
+ return $styles;
+ }
+
/**
* Parse list node
*
@@ -706,7 +742,8 @@ class Html
// 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];
+ $tmp = explode('-', $cKey);
+ $which = $tmp[1];
$which = ucfirst($which); // e.g. bottom -> Bottom
} else {
$which = '';
@@ -718,7 +755,7 @@ class Html
// 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);
+ $size = (int) ($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], '#');
@@ -896,9 +933,9 @@ class Html
}
/**
- * Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc
+ * Transforms a HTML/CSS vertical alignment
*
- * @param string $cssAlignment
+ * @param string $alignment
* @return string|null
*/
protected static function mapAlignVertical($alignment)
@@ -926,10 +963,10 @@ class Html
}
/**
- * Map list style for ordered list
- *
- * @param string $cssListType
- */
+ * Map list style for ordered list
+ *
+ * @param string $cssListType
+ */
protected static function mapListType($cssListType)
{
switch ($cssListType) {
@@ -984,12 +1021,12 @@ class Html
}
/**
- * Render horizontal rule
- * Note: Word rule is not the same as HTML's since it does not support width and thus neither alignment
- *
- * @param \DOMNode $node
- * @param \PhpOffice\PhpWord\Element\AbstractContainer $element
- */
+ * Render horizontal rule
+ * Note: Word rule is not the same as HTML's 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);
@@ -997,19 +1034,19 @@ class Html
// is implemented as an empty paragraph - extending 100% inside the section
// Some properties may be controlled, e.g.
- $fontStyle = $styles + ['size' => 3];
+ $fontStyle = $styles + array('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'],
+ $paragraphStyle = $styles + array(
+ '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);
+ $element->addText('', $fontStyle, $paragraphStyle);
// Notes: cannot be:
// - table - throws error "cannot be inside textruns", e.g. lists
diff --git a/src/PhpWord/SimpleType/Border.php b/src/PhpWord/SimpleType/Border.php
new file mode 100644
index 00000000..a73c7b4a
--- /dev/null
+++ b/src/PhpWord/SimpleType/Border.php
@@ -0,0 +1,58 @@
+legendPosition;
+ }
+
+ /**
+ * Set chart legend position. choices:
+ * "r" - right of chart
+ * "b" - bottom of chart
+ * "t" - top of chart
+ * "l" - left of chart
+ * "tr" - top right of chart
+ *
+ * default: right
+ *
+ * @param string $legendPosition
+ * @return self
+ */
+ public function setLegendPosition($legendPosition = 'r')
+ {
+ $enum = array('r', 'b', 't', 'l', 'tr');
+ $this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition);
+
+ return $this;
+ }
+
/*
* Show labels for axis
*
@@ -328,7 +370,10 @@ class Chart extends AbstractStyle
{
foreach (array_keys($this->dataLabelOptions) as $option) {
if (isset($values[$option])) {
- $this->dataLabelOptions[$option] = $this->setBoolVal($values[$option], $this->dataLabelOptions[$option]);
+ $this->dataLabelOptions[$option] = $this->setBoolVal(
+ $values[$option],
+ $this->dataLabelOptions[$option]
+ );
}
}
}
diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php
index 18ef8897..7b2de51e 100644
--- a/src/PhpWord/Style/Language.php
+++ b/src/PhpWord/Style/Language.php
@@ -228,6 +228,10 @@ final class Language extends AbstractStyle
*/
private function validateLocale($locale)
{
+ if ($locale !== null) {
+ $locale = str_replace('_', '-', $locale);
+ }
+
if (strlen($locale) === 2) {
return strtolower($locale) . '-' . strtoupper($locale);
}
diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php
index e9d2cf93..649fde40 100644
--- a/src/PhpWord/TemplateProcessor.php
+++ b/src/PhpWord/TemplateProcessor.php
@@ -798,7 +798,7 @@ class TemplateProcessor
$xmlBlock = null;
$matches = array();
preg_match(
- '/(<\?xml.*)(\${' . $blockname . '}<\/w:.*?p>)(.*)()/is',
+ '/(.*((?s)))(.*)((?s))/is',
$this->tempDocumentMainPart,
$matches
);
@@ -1182,7 +1182,7 @@ class TemplateProcessor
* @param string $blockType XML tag type of block
* @return \PhpOffice\PhpWord\TemplateProcessor Fluent interface
*/
- protected function replaceXmlBlock($macro, $block, $blockType = 'w:p')
+ public function replaceXmlBlock($macro, $block, $blockType = 'w:p')
{
$where = $this->findContainingXmlBlockForMacro($macro, $blockType);
if (is_array($where)) {
diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php
index e0d1752b..e3b56eaa 100644
--- a/src/PhpWord/Writer/Word2007/Part/Chart.php
+++ b/src/PhpWord/Writer/Word2007/Part/Chart.php
@@ -131,6 +131,7 @@ class Chart extends AbstractPart
$title = $style->getTitle();
$showLegend = $style->isShowLegend();
+ $legendPosition = $style->getLegendPosition();
//Chart title
if ($title) {
@@ -154,7 +155,7 @@ class Chart extends AbstractPart
//Chart legend
if ($showLegend) {
- $xmlWriter->writeRaw('');
+ $xmlWriter->writeRaw('');
}
$xmlWriter->startElement('c:plotArea');
diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php
index 08987a6a..8d113216 100644
--- a/src/PhpWord/Writer/Word2007/Style/Paragraph.php
+++ b/src/PhpWord/Writer/Word2007/Style/Paragraph.php
@@ -132,6 +132,7 @@ class Paragraph extends AbstractStyle
$styleWriter = new MarginBorder($xmlWriter);
$styleWriter->setSizes($style->getBorderSize());
+ $styleWriter->setStyles($style->getBorderStyle());
$styleWriter->setColors($style->getBorderColor());
$styleWriter->write();
diff --git a/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php
index c12f33ac..fd5d5664 100644
--- a/tests/PhpWord/Shared/HtmlTest.php
+++ b/tests/PhpWord/Shared/HtmlTest.php
@@ -293,11 +293,11 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
- $html = '
+ $html = '
-
- | header a |
- header b |
+
+ header a |
+ header b |
header c |
@@ -324,6 +324,12 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
$this->assertEquals('00BB00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:right', 'w:color'));
$this->assertEquals('00CC00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:bottom', 'w:color'));
$this->assertEquals('00DD00', $doc->getElementAttribute('/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/w:left', 'w:color'));
+
+ //check borders are not propagated inside cells
+ $this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p'));
+ $this->assertFalse($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p/w:pPr/w:pBdr'));
+ $this->assertTrue($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:p'));
+ $this->assertFalse($doc->elementExists('/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:p/w:pPr/w:pBdr'));
}
/**
@@ -634,6 +640,7 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
}
/**
+<<<<<<< HEAD
* Tests checkbox input field
*/
public function testInputCheckbox()
@@ -655,12 +662,16 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
/**
* Parse widths in tables and cells, which also allows for controlling column width
*/
+=======
+ * Parse widths in tables and cells, which also allows for controlling column width
+ */
+>>>>>>> branch 'develop' of https://github.com/PHPOffice/PHPWord
public function testParseTableAndCellWidth()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
- $section = $phpWord->addSection([
+ $section = $phpWord->addSection(array(
'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
- ]);
+ ));
// borders & backgrounds are here just for better visual comparison
$html = <<addSection([
+ $section = $phpWord->addSection(array(
'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
- ]);
+ ));
// borders & backgrounds are here just for better visual comparison
$html = <<assertTrue($doc->elementExists($xpath));
$this->assertEquals('single', $doc->getElement($xpath)->getAttribute('w:val'));
- $this->assertEquals(intval(5 * 15 / 2), $doc->getElement($xpath)->getAttribute('w:sz'));
+ $this->assertEquals((int) (5 * 15 / 2), $doc->getElement($xpath)->getAttribute('w:sz'));
$this->assertEquals('lightblue', $doc->getElement($xpath)->getAttribute('w:color'));
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:spacing';
@@ -804,8 +815,8 @@ HTML;
}
/**
- * Parse ordered list start & numbering style
- */
+ * Parse ordered list start & numbering style
+ */
public function testParseOrderedList()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
@@ -865,8 +876,8 @@ HTML;
}
/**
- * Parse ordered list start & numbering style
- */
+ * Parse ordered list start & numbering style
+ */
public function testParseVerticalAlign()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
@@ -905,8 +916,8 @@ HTML;
}
/**
- * Fix bug - don't decode double quotes inside double quoted string
- */
+ * Fix bug - don't decode double quotes inside double quoted string
+ */
public function testDontDecodeAlreadyEncodedDoubleQuotes()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
@@ -919,6 +930,6 @@ HTML;
Html::addHtml($section, $html);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
- $this->assertTrue(is_object($doc));
+ $this->assertInternalType('object', $doc);
}
}
|