From 9e572ecd9b44dd5dc1bcd0f1497fdaa72bdeb00b Mon Sep 17 00:00:00 2001 From: Stephan212 <48237559+Stephan212@users.noreply.github.com> Date: Wed, 21 Aug 2019 10:18:33 +0100 Subject: [PATCH 01/17] chart - Add dynamic Legend positions (#1) * Writer/Part/chart.php - Add dynamic Legend positions The position of the legend of charts was always fixed to the right. Adding in the option to set it dynamically via a new option under styles/chart * Update Styles/Chart.php Add in the public functions to getStyle() to get and set the legend position --- src/PhpWord/Style/Chart.php | 35 ++++++++++++++++++++++ src/PhpWord/Writer/Word2007/Part/Chart.php | 3 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 06b4829c..7b271586 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -66,6 +66,13 @@ class Chart extends AbstractStyle */ private $showLegend = false; + /** + * Chart legend Position. + * + * @var string + */ + private $legendPosition = 'r'; + /** * A list of display options for data labels * @@ -285,6 +292,34 @@ class Chart extends AbstractStyle return $this; } + /** + * Get chart legend position + * + * @return string + */ + public function getLegendPosition() + { + return $this->legendPosition; + } + + /** + * Set chart legend position. choices: + * "r" - right of chart + * "b" - bottom of chart + * "t" - top of chart + * "l" - left of chart + * + * default: right + * + * @param bool $value + */ + public function setLegendPosition($value = 'r') + { + $this->legendPosition = $value; + + return $this; + } + /* * Show labels for axis * diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 812d3bf1..dd738d1e 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'); From 90a8900208c9a4238a85993cac241dcd89d85e5a Mon Sep 17 00:00:00 2001 From: Stephan212 <48237559+Stephan212@users.noreply.github.com> Date: Wed, 21 Aug 2019 10:54:43 +0100 Subject: [PATCH 02/17] Stephan212 chart dynamic legend position (#2) * Writer/Part/Chart.php Add dynamic Legend positions The position of the legend of charts was always fixed to the right. Adding in the option to set it dynamically via a new option under styles/chart * Update Syle/Chart.php Add in the public functions to getStyle() to get and set the legend position --- src/PhpWord/Style/Chart.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 7b271586..f6de7c22 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -308,6 +308,7 @@ class Chart extends AbstractStyle * "b" - bottom of chart * "t" - top of chart * "l" - left of chart + * "tr" - top right of chart * * default: right * From d965a69601847c44acfe2d0648c3e0287cf190e9 Mon Sep 17 00:00:00 2001 From: "oe.sonnh" Date: Tue, 7 Jan 2020 11:44:37 +0700 Subject: [PATCH 03/17] Fix: CloneBlock regexp for different regexp engine with xml line-drop --- src/PhpWord/TemplateProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 7efc0f1a..52470574 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -737,7 +737,7 @@ class TemplateProcessor $xmlBlock = null; $matches = array(); preg_match( - '/(<\?xml.*)(\${' . $blockname . '}<\/w:.*?p>)(.*)()/is', + '/(.*((?s)))(.*)((?s))/is', $this->tempDocumentMainPart, $matches ); From 608730531f8b02567dba17de0c6939f1849f66a7 Mon Sep 17 00:00:00 2001 From: "oe.sonnh" Date: Tue, 21 Jan 2020 16:42:19 +0700 Subject: [PATCH 04/17] Fix: Catastrophic Backtracking RegExp --- src/PhpWord/TemplateProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 52470574..85a405c9 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -737,7 +737,7 @@ class TemplateProcessor $xmlBlock = null; $matches = array(); preg_match( - '/(.*((?s)))(.*)((?s))/is', + '/(.*((?s)))(.*)((?s))/is', $this->tempDocumentMainPart, $matches ); From a0e57459dcbe8645184f636f648739d84da6bcdf Mon Sep 17 00:00:00 2001 From: Ernestas Staugaitis Date: Sun, 16 Feb 2020 22:12:34 +0200 Subject: [PATCH 05/17] Some document have non-standard locale code --- src/PhpWord/Style/Language.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 18ef8897..2ccc44c7 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -228,6 +228,8 @@ final class Language extends AbstractStyle */ private function validateLocale($locale) { + $locale = str_replace('_', '-', $locale); + if (strlen($locale) === 2) { return strtolower($locale) . '-' . strtoupper($locale); } From 37c15e66cda2820162e07ff12db2782c64382b28 Mon Sep 17 00:00:00 2001 From: Ernestas Staugaitis Date: Mon, 17 Feb 2020 11:44:27 +0200 Subject: [PATCH 06/17] Some document have non-standard locale code --- src/PhpWord/Style/Language.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Style/Language.php b/src/PhpWord/Style/Language.php index 2ccc44c7..7b2de51e 100644 --- a/src/PhpWord/Style/Language.php +++ b/src/PhpWord/Style/Language.php @@ -228,7 +228,9 @@ final class Language extends AbstractStyle */ private function validateLocale($locale) { - $locale = str_replace('_', '-', $locale); + if ($locale !== null) { + $locale = str_replace('_', '-', $locale); + } if (strlen($locale) === 2) { return strtolower($locale) . '-' . strtoupper($locale); From 6f1b18937c89df8b27956f788c731050341dbbfb Mon Sep 17 00:00:00 2001 From: csk83 Date: Wed, 26 Aug 2020 12:50:08 +0800 Subject: [PATCH 07/17] code format --- src/PhpWord/Writer/Word2007/Part/Chart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index dd738d1e..b661a102 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -155,7 +155,7 @@ class Chart extends AbstractPart //Chart legend if ($showLegend) { - $xmlWriter->writeRaw(''); + $xmlWriter->writeRaw(''); } $xmlWriter->startElement('c:plotArea'); From d42854ddb6c0083622c7905cb607f453b01aa0c3 Mon Sep 17 00:00:00 2001 From: csk83 Date: Sat, 29 Aug 2020 20:41:25 +0800 Subject: [PATCH 08/17] chart doc/sample/code comments --- docs/styles.rst | 1 + samples/Sample_32_Chart.php | 5 +++++ src/PhpWord/Style/Chart.php | 19 ++++++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) 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/Style/Chart.php b/src/PhpWord/Style/Chart.php index f6de7c22..c02c0af4 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -67,7 +67,8 @@ class Chart extends AbstractStyle private $showLegend = false; /** - * Chart legend Position. + * Chart legend Position. + * Possible values are 'r', 't', 'b', 'l', 'tr' * * @var string */ @@ -240,6 +241,7 @@ class Chart extends AbstractStyle * Set the colors to use in a chart. * * @param array $value a list of colors to use in the chart + * @return self */ public function setColors($value = array()) { @@ -262,6 +264,7 @@ class Chart extends AbstractStyle * Set the chart title * * @param string $value + * @return self */ public function setTitle($value = null) { @@ -284,6 +287,7 @@ class Chart extends AbstractStyle * Set chart legend visibility * * @param bool $value + * @return self */ public function setShowLegend($value = false) { @@ -312,11 +316,13 @@ class Chart extends AbstractStyle * * default: right * - * @param bool $value + * @param string $legendPosition + * @return self */ - public function setLegendPosition($value = 'r') + public function setLegendPosition($legendPosition = 'r') { - $this->legendPosition = $value; + $enum = array('r', 'b', 't', 'l', 'tr'); + $this->legendPosition = $this->setEnumVal($legendPosition, $enum, $this->legendPosition); return $this; } @@ -364,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] + ); } } } From 9a59cf0590e25b1d018712fd4e6f55fcd1ffe97b Mon Sep 17 00:00:00 2001 From: csk83 Date: Mon, 31 Aug 2020 11:56:21 +0800 Subject: [PATCH 09/17] format check --- src/PhpWord/Element/AbstractContainer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 0c773dbe..f9451c8d 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -108,7 +108,8 @@ abstract class AbstractContainer extends AbstractElement } } else { // All other elements - array_unshift($args, $element); // Prepend element name to the beginning of args array + array_unshift($args, $element); + // Prepend element name to the beginning of args array return call_user_func_array(array($this, 'addElement'), $args); } } From b86c60694ca074ef5cb629794f77b0041ba8211f Mon Sep 17 00:00:00 2001 From: Julien Aupart Date: Sun, 8 Nov 2020 20:58:06 +0100 Subject: [PATCH 10/17] feat: Update addHtml to handle style inheritance The aim is to get the output closer to the source html --- src/PhpWord/Element/AbstractContainer.php | 1 + src/PhpWord/Shared/Html.php | 44 ++++++++++++++++++++--- tests/PhpWord/Shared/HtmlTest.php | 14 +++++--- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 0c773dbe..6a1ed930 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -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); } } diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 54e9509e..b29c9a1b 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -364,7 +364,7 @@ class Html $cell = $element->addCell(null, $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; @@ -395,15 +395,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 * diff --git a/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php index 5bc9e241..0dfef405 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 = '
- - - + + + @@ -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')); } /** From cc9dfb86302671f88d4ed8fdad37dcbf67619987 Mon Sep 17 00:00:00 2001 From: emhome Date: Sat, 19 Dec 2020 16:36:55 +0800 Subject: [PATCH 11/17] add/setting page element border style. --- src/PhpWord/Style/Border.php | 35 +++++++++++++++++++ .../Writer/Word2007/Style/Paragraph.php | 1 + 2 files changed, 36 insertions(+) diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index d032d07f..8d2ca37c 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -22,6 +22,41 @@ namespace PhpOffice\PhpWord\Style; */ class Border extends AbstractStyle { + /** + * Border Style Val. + * Wordprocessing Paragraphs Borders + * Specifies the style of the border. Paragraph borders can be only line borders. (Page borders can also be art borders.) Possible values are: + * @see http://officeopenxml.com/WPborders.php + * @const string + */ + const BORDER_STYLE_SINGLE = 'single'; //A single line + const BORDER_STYLE_DASH_DOT_STROKED = 'dashDotStroked'; //A line with a series of alternating thin and thick strokes + const BORDER_STYLE_DASHED = 'dashed'; //A dashed line + const BORDER_STYLE_DASH_SMALL_GAP = 'dashSmallGap'; //A dashed line with small gaps + const BORDER_STYLE_DOT_DASH = 'dotDash'; //A line with alternating dots and dashes + const BORDER_STYLE_DOT_DOT_DASH = 'dotDotDash'; //A line with a repeating dot - dot - dash sequence + const BORDER_STYLE_DOTTED = 'dotted'; //A dotted line + const BORDER_STYLE_DOUBLE = 'double'; //A double line + const BORDER_STYLE_DOUBLE_WAVE = 'doubleWave'; //A double wavy line + const BORDER_STYLE_INSET = 'inset'; //An inset set of lines + const BORDER_STYLE_NIL = 'nil'; //No border + const BORDER_STYLE_NONE = 'none'; //No border + const BORDER_STYLE_OUTSET = 'outset'; //An outset set of lines + const BORDER_STYLE_THICK = 'thick'; //A single line + const BORDER_STYLE_THICK_THIN_LARGE_GAP = 'thickThinLargeGap'; //A thick line contained within a thin line with a large-sized intermediate gap + const BORDER_STYLE_THICK_THIN_MEDIUM_GAP = 'thickThinMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap + const BORDER_STYLE_THICK_THIN_SMALL_GAP = 'thickThinSmallGap'; //A thick line contained within a thin line with a small intermediate gap + const BORDER_STYLE_THIN_THICK_LARGE_GAP = 'thinThickLargeGap'; //A thin line contained within a thick line with a large-sized intermediate gap + const BORDER_STYLE_THIN_THICK_MEDIUM_GAP = 'thinThickMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap + const BORDER_STYLE_THIN_THICK_SMALL_GAP = 'thinThickSmallGap'; //A thick line contained within a thin line with a small intermediate gap + const BORDER_STYLE_THIN_THICK_THINLARGE_GAP = 'thinThickThinLargeGap'; //A thin-thick-thin line with a large gap + const BORDER_STYLE_THIN_THICK_THIN_MEDIUM_GAP = 'thinThickThinMediumGap'; //A thin-thick-thin line with a medium gap + const BORDER_STYLE_THIN_THICK_THIN_SMALL_GAP = 'thinThickThinSmallGap'; //A thin-thick-thin line with a small gap + const BORDER_STYLE_THREE_D_EMBOSS = 'threeDEmboss'; //A three-staged gradient line, getting darker towards the paragraph + const BORDER_STYLE_THREE_D_ENGRAVE = 'threeDEngrave'; //A three-staged gradient like, getting darker away from the paragraph + const BORDER_STYLE_TRIPLE = 'triple'; //A triple line + const BORDER_STYLE_WAVE = 'wave'; //A wavy line + /** * Border Top Size * diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php index 67616086..1e37f844 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(); From 264f1590f0991b8f9ebe7039df52fd6073196023 Mon Sep 17 00:00:00 2001 From: troosan Date: Mon, 8 Feb 2021 22:08:29 +0100 Subject: [PATCH 12/17] make xmlReplaceBlock public --- src/PhpWord/TemplateProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index a3ef6d2d..649fde40 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -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)) { From 1c3fdd27198bdd86d206fd73d234577c12799506 Mon Sep 17 00:00:00 2001 From: troosan Date: Mon, 8 Feb 2021 22:12:24 +0100 Subject: [PATCH 13/17] prepare release 0.18.0 --- CHANGELOG.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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 From b2585dfd288f8f46dfe0b5d903bd6ba488509066 Mon Sep 17 00:00:00 2001 From: troosan Date: Mon, 8 Feb 2021 22:20:00 +0100 Subject: [PATCH 14/17] move constants to simpleType --- src/PhpWord/SimpleType/Border.php | 58 +++++++++++++++++++++++++++++++ src/PhpWord/Style/Border.php | 35 ------------------- 2 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 src/PhpWord/SimpleType/Border.php 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 @@ + Date: Mon, 8 Feb 2021 22:40:46 +0100 Subject: [PATCH 15/17] Make syntax php 5.3 compliant --- tests/PhpWord/Shared/HtmlTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php index 7a806c26..05e2398a 100644 --- a/tests/PhpWord/Shared/HtmlTest.php +++ b/tests/PhpWord/Shared/HtmlTest.php @@ -639,9 +639,9 @@ class HtmlTest extends AbstractWebServerEmbeddedTest 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 = << Date: Mon, 8 Feb 2021 22:58:14 +0100 Subject: [PATCH 16/17] fix code formatting --- src/PhpWord/Shared/Html.php | 48 +++++++++++++++---------------- tests/PhpWord/Shared/HtmlTest.php | 32 ++++++++++----------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 6fa2a64d..ac90b5f0 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.
header aheader b

header a

header b header c
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': @@ -693,7 +693,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], '#'); @@ -871,9 +871,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) @@ -901,10 +901,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) { @@ -959,12 +959,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); @@ -972,19 +972,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/tests/PhpWord/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php index 05e2398a..9f355b67 100644 --- a/tests/PhpWord/Shared/HtmlTest.php +++ b/tests/PhpWord/Shared/HtmlTest.php @@ -634,8 +634,8 @@ 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 + */ public function testParseTableAndCellWidth() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); @@ -703,14 +703,14 @@ HTML; } /** - * Test parsing background color for table rows and table cellspacing - */ + * Test parsing background color for table rows and table cellspacing + */ public function testParseCellspacingRowBgColor() { $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 = <<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'; @@ -785,8 +785,8 @@ HTML; } /** - * Parse ordered list start & numbering style - */ + * Parse ordered list start & numbering style + */ public function testParseOrderedList() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); @@ -846,8 +846,8 @@ HTML; } /** - * Parse ordered list start & numbering style - */ + * Parse ordered list start & numbering style + */ public function testParseVerticalAlign() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); @@ -886,8 +886,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(); @@ -900,6 +900,6 @@ HTML; Html::addHtml($section, $html); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); - $this->assertTrue(is_object($doc)); + $this->assertInternalType('object', $doc); } } From 81d613bc4dcc2233bc041ab96f00438b41d7fd43 Mon Sep 17 00:00:00 2001 From: troosan Date: Wed, 10 Feb 2021 08:25:09 +0100 Subject: [PATCH 17/17] php 5.3 compatible code --- src/PhpWord/Shared/Html.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 3ad8fca9..659298ff 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -717,7 +717,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 = '';