Skip to content

Commit d4f08a3

Browse files
committed
Merge branch 'develop' of https://github.com/PHPOffice/PHPWord into tmp
Conflicts: tests/PhpWord/Shared/HtmlTest.php
2 parents cba1edc + 9736d37 commit d4f08a3

File tree

11 files changed

+260
-53
lines changed

11 files changed

+260
-53
lines changed

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,50 @@ 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.18.0 (08 feb 2021)
7+
----------------------
8+
### Added
9+
- allow to use customized pdf library [\#1983](https://github.com/PHPOffice/PHPWord/pull/1983) ([SailorMax](https://github.com/SailorMax))
10+
- Add parsing of Shape node values [\#1924](https://github.com/PHPOffice/PHPWord/pull/1924) ([sven-ahrens](https://github.com/sven-ahrens))
11+
- Allow to redefine TCPDF object [\#1907](https://github.com/PHPOffice/PHPWord/pull/1907) ([SailorMax](https://github.com/SailorMax))
12+
- Make Default Paper Configurable [\#1851](https://github.com/PHPOffice/PHPWord/pull/1851) ([oleibman](https://github.com/oleibman))
13+
- Implement various missing features for the ODT writer [\#1796](https://github.com/PHPOffice/PHPWord/pull/1796) ([oleibman](https://github.com/oleibman))
14+
- Add support for several features for the RTF writer [\#1775](https://github.com/PHPOffice/PHPWord/pull/1775) ([oleibman](https://github.com/oleibman))
15+
- Improvements in RTF writer [\#1755](https://github.com/PHPOffice/PHPWord/pull/1755) ([oleibman](https://github.com/oleibman))
16+
- Add font style for Field elements [\#1774](https://github.com/PHPOffice/PHPWord/pull/1774) ([oleibman](https://github.com/oleibman))
17+
- Added support for "cloudConvert" images [\#1794](https://github.com/PHPOffice/PHPWord/pull/1794) ([ErnestStaug](https://github.com/ErnestStaug))
18+
- Add support for ListItemRun in HTML writer [\#1766](https://github.com/PHPOffice/PHPWord/pull/1766) ([stefan-91](https://github.com/stefan-91))
19+
- Allow a closure to be passed with image replacement tags [\#1716](https://github.com/PHPOffice/PHPWord/pull/1716) ([mbardelmeijer](https://github.com/mbardelmeijer))
20+
- Add support for charts in template processor [\#2012](https://github.com/PHPOffice/PHPWord/pull/2012) ([dbarzin](https://github.com/dbarzin))
21+
- Update addHtml to handle style inheritance [\#1965](https://github.com/PHPOffice/PHPWord/pull/1965) ([Julien1138](https://github.com/Julien1138))
22+
- Add parsing of HTML checkbox input field [\#1832](https://github.com/PHPOffice/PHPWord/pull/1832) ([Matze2010](https://github.com/Matze2010))
23+
- Add Option for Dynamic Chart Legend Position [\#1922](https://github.com/PHPOffice/PHPWord/pull/1922) ([csk83](https://github.com/csk83))
24+
25+
### Fixed
26+
- Add null check when setComplexValue is not found [\#1936](https://github.com/PHPOffice/PHPWord/pull/1936) ([YannikFirre](https://github.com/YannikFirre))
27+
- Fix image stroke in libreoffice 7.x [\#1992](https://github.com/PHPOffice/PHPWord/pull/1992) ([Adizbek](https://github.com/Adizbek))
28+
- Fix deprecated warning for non-hexadecimal number [\#1988](https://github.com/PHPOffice/PHPWord/pull/1988) ([Ciki](https://github.com/Ciki))
29+
- Fix typo in docs. Update templates-processing.rst [\#1952](https://github.com/PHPOffice/PHPWord/pull/1952) ([mnvx](https://github.com/mnvx))
30+
- Fixes PHPDoc @param and @return types for several Converter methods [\#1818](https://github.com/PHPOffice/PHPWord/pull/1818) ([caugner](https://github.com/caugner))
31+
- Fix documentation and method name for FootnoteProperties [\#1776](https://github.com/PHPOffice/PHPWord/pull/1776) ([mdupont](https://github.com/mdupont))
32+
- Fix PHPUnit tests on develop branch [\#1771](https://github.com/PHPOffice/PHPWord/pull/1771) ([mdupont](https://github.com/mdupont))
33+
- fix: documentation about paragraph indentation [\#1764](https://github.com/PHPOffice/PHPWord/pull/1764) ([mdupont](https://github.com/mdupont))
34+
- Update templates-processing.rst [\#1745](https://github.com/PHPOffice/PHPWord/pull/1745) ([igronus](https://github.com/igronus))
35+
- Update templates processing docs [\#1729](https://github.com/PHPOffice/PHPWord/pull/1729) ([hcdias](https://github.com/hcdias))
36+
- Fix limit not taken into account when adding image in template [\#1967](https://github.com/PHPOffice/PHPWord/pull/1967) ([jsochor](https://github.com/jsochor))
37+
- Fix cloneBlock issue [\#2006](https://github.com/PHPOffice/PHPWord/pull/2006) ([lexdewilligen](https://github.com/lexdewilligen))
38+
- TemplateProcessor cloneBlock wrongly clones images [\#1763](https://github.com/PHPOffice/PHPWord/pull/1763) ([alarai](https://github.com/alarai))
39+
- Some document have non-standard locale code [\#1824](https://github.com/PHPOffice/PHPWord/pull/1824) ([ErnestStaug](https://github.com/ErnestStaug))
40+
- Update the regexp to avoid catastrophic backtracking [\#1809](https://github.com/PHPOffice/PHPWord/pull/1809) ([juzser](https://github.com/juzser))
41+
42+
### Miscellaneous
43+
- 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))
44+
- Remove legacy PHPOffice/Common package, fix PHP 8.0 compatibility [\#1996](https://github.com/PHPOffice/PHPWord/pull/1996) ([liborm85](https://github.com/liborm85))
45+
- Improve Word2007 Test Coverage [\#1858](https://github.com/PHPOffice/PHPWord/pull/1858) ([oleibman](https://github.com/oleibman))
46+
- Add unit test for NumberingStyle [\#1744](https://github.com/PHPOffice/PHPWord/pull/1744) ([Manunchik](https://github.com/Manunchik))
47+
- Add unit test for PhpWord Settings [\#1743](https://github.com/PHPOffice/PHPWord/pull/1743) ([Manunchik](https://github.com/Manunchik))
48+
- Add unit test for Media elements [\#1742](https://github.com/PHPOffice/PHPWord/pull/1742) ([Manunchik](https://github.com/Manunchik))
49+
650
v0.17.0 (01 oct 2019)
751
----------------------
852
### Added

docs/styles.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Available Chart style options:
201201
- ``colors``. A list of colors to use in the chart.
202202
- ``title``. The title for the chart.
203203
- ``showLegend``. Show legend, *true* or *false*.
204+
- ``LegendPosition``. Legend position, *r* (default), *b*, *t*, *l* or *tr*.
204205
- ``categoryLabelPosition``. Label position for categories, *nextTo* (default), *low* or *high*.
205206
- ``valueLabelPosition``. Label position for values, *nextTo* (default), *low* or *high*.
206207
- ``categoryAxisTitle``. The title for the category axis.

samples/Sample_32_Chart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
$series3 = array(8, 3, 2, 5, 4);
2626
$showGridLines = false;
2727
$showAxisLabels = false;
28+
$showLegend = true;
29+
$legendPosition = 't';
30+
// r = right, l = left, t = top, b = bottom, tr = top right
2831

2932
foreach ($chartTypes as $chartType) {
3033
$section->addTitle(ucfirst($chartType), 2);
@@ -33,6 +36,8 @@
3336
$chart->getStyle()->setShowGridX($showGridLines);
3437
$chart->getStyle()->setShowGridY($showGridLines);
3538
$chart->getStyle()->setShowAxisLabels($showAxisLabels);
39+
$chart->getStyle()->setShowLegend($showLegend);
40+
$chart->getStyle()->setLegendPosition($legendPosition);
3641
if (in_array($chartType, $twoSeries)) {
3742
$chart->addSeries($categories, $series2);
3843
}

src/PhpWord/Shared/Html.php

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected static function parseInlineStyle($node, $styles = array())
115115
// tables, cells
116116
if (false !== strpos($val, '%')) {
117117
// e.g. <table width="100%"> or <td width="50%">
118-
$styles['width'] = intval($val) * 50;
118+
$styles['width'] = (int) $val * 50;
119119
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
120120
} else {
121121
// e.g. <table width="250> where "250" = 250px (always pixels)
@@ -125,7 +125,7 @@ protected static function parseInlineStyle($node, $styles = array())
125125
break;
126126
case 'cellspacing':
127127
// tables e.g. <table cellspacing="2">, where "2" = 2px (always pixels)
128-
$val = intval($val).'px';
128+
$val = (int) $val . 'px';
129129
$styles['cellSpacing'] = Converter::cssToTwip($val);
130130
break;
131131
case 'bgcolor':
@@ -426,7 +426,7 @@ protected static function parseCell($node, $element, &$styles)
426426
$cell = $element->addCell($width, $cellStyles);
427427

428428
if (self::shouldAddTextRun($node)) {
429-
return $cell->addTextRun(self::parseInlineStyle($node, $styles['paragraph']));
429+
return $cell->addTextRun(self::filterOutNonInheritedStyles(self::parseInlineStyle($node, $styles['paragraph'])));
430430
}
431431

432432
return $cell;
@@ -457,15 +457,51 @@ protected static function shouldAddTextRun(\DOMNode $node)
457457
*/
458458
protected static function recursiveParseStylesInHierarchy(\DOMNode $node, array $style)
459459
{
460-
$parentStyle = self::parseInlineStyle($node, array());
461-
$style = array_merge($parentStyle, $style);
460+
$parentStyle = array();
462461
if ($node->parentNode != null && XML_ELEMENT_NODE == $node->parentNode->nodeType) {
463-
$style = self::recursiveParseStylesInHierarchy($node->parentNode, $style);
462+
$parentStyle = self::recursiveParseStylesInHierarchy($node->parentNode, array());
464463
}
464+
if ($node->nodeName === '#text') {
465+
$parentStyle = array_merge($parentStyle, $style);
466+
} else {
467+
$parentStyle = self::filterOutNonInheritedStyles($parentStyle);
468+
}
469+
$style = self::parseInlineStyle($node, $parentStyle);
465470

466471
return $style;
467472
}
468473

474+
/**
475+
* Removes non-inherited styles from array
476+
*
477+
* @param array &$styles
478+
*/
479+
protected static function filterOutNonInheritedStyles(array $styles)
480+
{
481+
$nonInheritedStyles = array(
482+
'borderSize',
483+
'borderTopSize',
484+
'borderRightSize',
485+
'borderBottomSize',
486+
'borderLeftSize',
487+
'borderColor',
488+
'borderTopColor',
489+
'borderRightColor',
490+
'borderBottomColor',
491+
'borderLeftColor',
492+
'borderStyle',
493+
'spaceAfter',
494+
'spaceBefore',
495+
'underline',
496+
'strikethrough',
497+
'hidden',
498+
);
499+
500+
$styles = array_diff_key($styles, array_flip($nonInheritedStyles));
501+
502+
return $styles;
503+
}
504+
469505
/**
470506
* Parse list node
471507
*
@@ -706,7 +742,8 @@ protected static function parseStyle($attribute, $styles)
706742
// Word does not accept shortened hex colors e.g. #CCC, only full e.g. #CCCCCC
707743
if (preg_match('/([0-9]+[^0-9]*)\s+(\#[a-fA-F0-9]+|[a-zA-Z]+)\s+([a-z]+)/', $cValue, $matches)) {
708744
if (false !== strpos($cKey, '-')) {
709-
$which = explode('-', $cKey)[1];
745+
$tmp = explode('-', $cKey);
746+
$which = $tmp[1];
710747
$which = ucfirst($which); // e.g. bottom -> Bottom
711748
} else {
712749
$which = '';
@@ -718,7 +755,7 @@ protected static function parseStyle($attribute, $styles)
718755
// This may be adjusted, if better ratio or formula found.
719756
// BC change: up to ver. 0.17.0 was $size converted to points - Converter::cssToPoint($size)
720757
$size = Converter::cssToTwip($matches[1]);
721-
$size = intval($size / 2);
758+
$size = (int) ($size / 2);
722759
// valid variants may be e.g. borderSize, borderTopSize, borderLeftColor, etc ..
723760
$styles["border{$which}Size"] = $size; // twips
724761
$styles["border{$which}Color"] = trim($matches[2], '#');
@@ -896,9 +933,9 @@ protected static function mapAlign($cssAlignment)
896933
}
897934

898935
/**
899-
* Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc
936+
* Transforms a HTML/CSS vertical alignment
900937
*
901-
* @param string $cssAlignment
938+
* @param string $alignment
902939
* @return string|null
903940
*/
904941
protected static function mapAlignVertical($alignment)
@@ -926,10 +963,10 @@ protected static function mapAlignVertical($alignment)
926963
}
927964

928965
/**
929-
* Map list style for ordered list
930-
*
931-
* @param string $cssListType
932-
*/
966+
* Map list style for ordered list
967+
*
968+
* @param string $cssListType
969+
*/
933970
protected static function mapListType($cssListType)
934971
{
935972
switch ($cssListType) {
@@ -984,32 +1021,32 @@ protected static function parseLink($node, $element, &$styles)
9841021
}
9851022

9861023
/**
987-
* Render horizontal rule
988-
* Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment
989-
*
990-
* @param \DOMNode $node
991-
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
992-
*/
1024+
* Render horizontal rule
1025+
* Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment
1026+
*
1027+
* @param \DOMNode $node
1028+
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
1029+
*/
9931030
protected static function parseHorizRule($node, $element)
9941031
{
9951032
$styles = self::parseInlineStyle($node);
9961033

9971034
// <hr> is implemented as an empty paragraph - extending 100% inside the section
9981035
// Some properties may be controlled, e.g. <hr style="border-bottom: 3px #DDDDDD solid; margin-bottom: 0;">
9991036

1000-
$fontStyle = $styles + ['size' => 3];
1037+
$fontStyle = $styles + array('size' => 3);
10011038

1002-
$paragraphStyle = $styles + [
1003-
'lineHeight' => 0.25, // multiply default line height - e.g. 1, 1.5 etc
1004-
'spacing' => 0, // twip
1005-
'spaceBefore' => 120, // twip, 240/2 (default line height)
1006-
'spaceAfter' => 120, // twip
1007-
'borderBottomSize' => empty($styles['line-height']) ? 1 : $styles['line-height'],
1039+
$paragraphStyle = $styles + array(
1040+
'lineHeight' => 0.25, // multiply default line height - e.g. 1, 1.5 etc
1041+
'spacing' => 0, // twip
1042+
'spaceBefore' => 120, // twip, 240/2 (default line height)
1043+
'spaceAfter' => 120, // twip
1044+
'borderBottomSize' => empty($styles['line-height']) ? 1 : $styles['line-height'],
10081045
'borderBottomColor' => empty($styles['color']) ? '000000' : $styles['color'],
10091046
'borderBottomStyle' => 'single', // same as "solid"
1010-
];
1047+
);
10111048

1012-
$element->addText("", $fontStyle, $paragraphStyle);
1049+
$element->addText('', $fontStyle, $paragraphStyle);
10131050

10141051
// Notes: <hr/> cannot be:
10151052
// - table - throws error "cannot be inside textruns", e.g. lists

src/PhpWord/SimpleType/Border.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 2010-2018 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\SimpleType;
19+
20+
use PhpOffice\PhpWord\Shared\AbstractEnum;
21+
22+
/**
23+
* Border Styles.
24+
*
25+
* @since 0.18.0
26+
*
27+
* @see http://www.datypic.com/sc/ooxml/t-w_ST_Border.html
28+
*/
29+
final class Border extends AbstractEnum
30+
{
31+
const SINGLE = 'single'; //A single line
32+
const DASH_DOT_STROKED = 'dashDotStroked'; //A line with a series of alternating thin and thick strokes
33+
const DASHED = 'dashed'; //A dashed line
34+
const DASH_SMALL_GAP = 'dashSmallGap'; //A dashed line with small gaps
35+
const DOT_DASH = 'dotDash'; //A line with alternating dots and dashes
36+
const DOT_DOT_DASH = 'dotDotDash'; //A line with a repeating dot - dot - dash sequence
37+
const DOTTED = 'dotted'; //A dotted line
38+
const DOUBLE = 'double'; //A double line
39+
const DOUBLE_WAVE = 'doubleWave'; //A double wavy line
40+
const INSET = 'inset'; //An inset set of lines
41+
const NIL = 'nil'; //No border
42+
const NONE = 'none'; //No border
43+
const OUTSET = 'outset'; //An outset set of lines
44+
const THICK = 'thick'; //A single line
45+
const THICK_THIN_LARGE_GAP = 'thickThinLargeGap'; //A thick line contained within a thin line with a large-sized intermediate gap
46+
const THICK_THIN_MEDIUM_GAP = 'thickThinMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap
47+
const THICK_THIN_SMALL_GAP = 'thickThinSmallGap'; //A thick line contained within a thin line with a small intermediate gap
48+
const THIN_THICK_LARGE_GAP = 'thinThickLargeGap'; //A thin line contained within a thick line with a large-sized intermediate gap
49+
const THIN_THICK_MEDIUM_GAP = 'thinThickMediumGap'; //A thick line contained within a thin line with a medium-sized intermediate gap
50+
const THIN_THICK_SMALL_GAP = 'thinThickSmallGap'; //A thick line contained within a thin line with a small intermediate gap
51+
const THIN_THICK_THINLARGE_GAP = 'thinThickThinLargeGap'; //A thin-thick-thin line with a large gap
52+
const THIN_THICK_THIN_MEDIUM_GAP = 'thinThickThinMediumGap'; //A thin-thick-thin line with a medium gap
53+
const THIN_THICK_THIN_SMALL_GAP = 'thinThickThinSmallGap'; //A thin-thick-thin line with a small gap
54+
const THREE_D_EMBOSS = 'threeDEmboss'; //A three-staged gradient line, getting darker towards the paragraph
55+
const THREE_D_ENGRAVE = 'threeDEngrave'; //A three-staged gradient like, getting darker away from the paragraph
56+
const TRIPLE = 'triple'; //A triple line
57+
const WAVE = 'wave'; //A wavy line
58+
}

0 commit comments

Comments
 (0)