From 8ce1a19ec4201ec1d2fc26e5dc685e54e10f1b13 Mon Sep 17 00:00:00 2001 From: troosan Date: Sun, 17 Sep 2017 21:38:00 +0200 Subject: [PATCH] make FontStyle basedOn paragraph if the paragraph is set on the font (#926) * make FontStyle based on paragraph if it set * replace tab with spaces * basedOn not correctly set if FontStyle is based on other FontStyle * Fix warnings --- .../ComplexType/FootnoteProperties.php | 16 ++--- src/PhpWord/ComplexType/ProofState.php | 4 +- src/PhpWord/Element/AbstractElement.php | 6 +- src/PhpWord/Element/Comment.php | 12 ++-- src/PhpWord/Element/Image.php | 4 +- src/PhpWord/Element/Section.php | 7 +- src/PhpWord/Escaper/AbstractEscaper.php | 2 +- src/PhpWord/Escaper/EscaperInterface.php | 2 +- src/PhpWord/Escaper/RegExp.php | 2 +- src/PhpWord/Escaper/Rtf.php | 2 +- src/PhpWord/Escaper/Xml.php | 2 +- src/PhpWord/Metadata/Settings.php | 8 +-- src/PhpWord/Reader/MsDoc.php | 40 +++++------ src/PhpWord/Reader/ODText/Content.php | 1 - src/PhpWord/Reader/Word2007.php | 1 - src/PhpWord/Reader/Word2007/AbstractPart.php | 2 - src/PhpWord/Reader/Word2007/Settings.php | 8 +-- src/PhpWord/Reader/Word2007/Styles.php | 1 - src/PhpWord/Settings.php | 4 +- src/PhpWord/Shared/AbstractEnum.php | 6 +- src/PhpWord/Shared/OLERead.php | 1 - src/PhpWord/Style/Font.php | 4 +- src/PhpWord/Style/NumberingLevel.php | 2 +- src/PhpWord/Style/Paragraph.php | 4 +- src/PhpWord/TemplateProcessor.php | 2 +- src/PhpWord/Writer/HTML/Part/AbstractPart.php | 2 +- src/PhpWord/Writer/RTF/Part/AbstractPart.php | 2 +- .../Word2007/Element/AbstractElement.php | 1 - src/PhpWord/Writer/Word2007/Part/Chart.php | 1 - src/PhpWord/Writer/Word2007/Part/Settings.php | 5 +- src/PhpWord/Writer/Word2007/Part/Styles.php | 11 ++- .../ComplexType/FootnotePropertiesTest.php | 6 +- tests/PhpWord/PhpWordTest.php | 1 - .../Writer/Word2007/Part/StylesTest.php | 69 +++++++++++++++++++ tests/PhpWord/_includes/XmlDocument.php | 1 - 35 files changed, 153 insertions(+), 89 deletions(-) diff --git a/src/PhpWord/ComplexType/FootnoteProperties.php b/src/PhpWord/ComplexType/FootnoteProperties.php index 882834d5..0c1fb40e 100644 --- a/src/PhpWord/ComplexType/FootnoteProperties.php +++ b/src/PhpWord/ComplexType/FootnoteProperties.php @@ -65,7 +65,7 @@ final class FootnoteProperties /** * Get the Footnote Positioning Location - * + * * @return string */ public function getPos() @@ -75,7 +75,7 @@ final class FootnoteProperties /** * Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd) - * + * * @param string $pos * @throws \InvalidArgumentException * @return self @@ -99,7 +99,7 @@ final class FootnoteProperties /** * Get the Footnote Numbering Format - * + * * @return string */ public function getNumFmt() @@ -109,7 +109,7 @@ final class FootnoteProperties /** * Set the Footnote Numbering Format - * + * * @param string $numFmt One of NumberFormat * @return self */ @@ -122,7 +122,7 @@ final class FootnoteProperties /** * Get the Footnote Numbering Format - * + * * @return double */ public function getNumStart() @@ -132,7 +132,7 @@ final class FootnoteProperties /** * Set the Footnote Numbering Format - * + * * @param double $numStart * @return self */ @@ -144,7 +144,7 @@ final class FootnoteProperties /** * Get the Footnote and Endnote Numbering Starting Value - * + * * @return string */ public function getNumRestart() @@ -154,7 +154,7 @@ final class FootnoteProperties /** * Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage) - * + * * @param string $numRestart * @throws \InvalidArgumentException * @return self diff --git a/src/PhpWord/ComplexType/ProofState.php b/src/PhpWord/ComplexType/ProofState.php index e5ac9c20..daa705dd 100644 --- a/src/PhpWord/ComplexType/ProofState.php +++ b/src/PhpWord/ComplexType/ProofState.php @@ -51,7 +51,7 @@ final class ProofState /** * Set the Spell Checking State (dirty or clean) * - * @param string $spelling + * @param string $spelling * @throws \InvalidArgumentException * @return self */ @@ -78,7 +78,7 @@ final class ProofState /** * Set the Grammatical Checking State (dirty or clean) * - * @param string $grammar + * @param string $grammar * @throws \InvalidArgumentException * @return self */ diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php index 8ff64194..f657dd1b 100644 --- a/src/PhpWord/Element/AbstractElement.php +++ b/src/PhpWord/Element/AbstractElement.php @@ -116,14 +116,14 @@ abstract class AbstractElement /** * The start position for the linked comment - * + * * @var Comment */ protected $commentRangeStart; /** * The end position for the linked comment - * + * * @var Comment */ protected $commentRangeEnd; @@ -291,7 +291,7 @@ abstract class AbstractElement /** * Set comment start - * + * * @param Comment $value */ public function setCommentRangeStart(Comment $value) diff --git a/src/PhpWord/Element/Comment.php b/src/PhpWord/Element/Comment.php index def9d5a8..685ed296 100644 --- a/src/PhpWord/Element/Comment.php +++ b/src/PhpWord/Element/Comment.php @@ -31,14 +31,14 @@ class Comment extends TrackChange /** * The Element where this comment starts - * + * * @var AbstractElement */ private $startElement; /** * The Element where this comment ends - * + * * @var AbstractElement */ private $endElement; @@ -76,7 +76,7 @@ class Comment extends TrackChange /** * Sets the element where this comment starts - * + * * @param \PhpOffice\PhpWord\Element\AbstractElement $value */ public function setStartElement(AbstractElement $value) @@ -89,7 +89,7 @@ class Comment extends TrackChange /** * Get the element where this comment starts - * + * * @return \PhpOffice\PhpWord\Element\AbstractElement */ public function getStartElement() @@ -99,7 +99,7 @@ class Comment extends TrackChange /** * Sets the element where this comment ends - * + * * @param \PhpOffice\PhpWord\Element\AbstractElement $value */ public function setEndElement(AbstractElement $value) @@ -112,7 +112,7 @@ class Comment extends TrackChange /** * Get the element where this comment ends - * + * * @return \PhpOffice\PhpWord\Element\AbstractElement */ public function getEndElement() diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php index b8b5cca1..1c8c520d 100644 --- a/src/PhpWord/Element/Image.php +++ b/src/PhpWord/Element/Image.php @@ -476,9 +476,9 @@ class Image extends AbstractElement /** * get image size from string - * + * * @param string $source - * + * * @codeCoverageIgnore this method is just a replacement for getimagesizefromstring which exists only as of PHP 5.4 */ private function getStringImageSize($source) diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index 3758af99..e9beffcf 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -50,7 +50,7 @@ class Section extends AbstractContainer /** * The properties for the footnote of this section - * + * * @var FootnoteProperties */ private $footnoteProperties; @@ -148,7 +148,7 @@ class Section extends AbstractContainer /** * Get the footnote properties - * + * * @return \PhpOffice\PhpWord\Element\FooterProperties */ public function getFootnotePropoperties() @@ -158,7 +158,7 @@ class Section extends AbstractContainer /** * Set the footnote properties - * + * * @param FootnoteProperties $footnoteProperties */ public function setFootnoteProperties(FootnoteProperties $footnoteProperties = null) @@ -219,7 +219,6 @@ class Section extends AbstractContainer } else { throw new \Exception('Invalid header/footer type.'); } - } /** diff --git a/src/PhpWord/Escaper/AbstractEscaper.php b/src/PhpWord/Escaper/AbstractEscaper.php index 6ddcbb51..8ce4e301 100644 --- a/src/PhpWord/Escaper/AbstractEscaper.php +++ b/src/PhpWord/Escaper/AbstractEscaper.php @@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper; /** * @since 0.13.0 - * + * * @codeCoverageIgnore */ abstract class AbstractEscaper implements EscaperInterface diff --git a/src/PhpWord/Escaper/EscaperInterface.php b/src/PhpWord/Escaper/EscaperInterface.php index c34cf370..71cf36b4 100644 --- a/src/PhpWord/Escaper/EscaperInterface.php +++ b/src/PhpWord/Escaper/EscaperInterface.php @@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper; /** * @since 0.13.0 - * + * * @codeCoverageIgnore */ interface EscaperInterface diff --git a/src/PhpWord/Escaper/RegExp.php b/src/PhpWord/Escaper/RegExp.php index de510bcf..dfcfb1e1 100644 --- a/src/PhpWord/Escaper/RegExp.php +++ b/src/PhpWord/Escaper/RegExp.php @@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper; /** * @since 0.13.0 - * + * * @codeCoverageIgnore */ class RegExp extends AbstractEscaper diff --git a/src/PhpWord/Escaper/Rtf.php b/src/PhpWord/Escaper/Rtf.php index 6f83604d..ec24c0af 100644 --- a/src/PhpWord/Escaper/Rtf.php +++ b/src/PhpWord/Escaper/Rtf.php @@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper; /** * @since 0.13.0 - * + * * @codeCoverageIgnore */ class Rtf extends AbstractEscaper diff --git a/src/PhpWord/Escaper/Xml.php b/src/PhpWord/Escaper/Xml.php index 274cade5..3a0981aa 100644 --- a/src/PhpWord/Escaper/Xml.php +++ b/src/PhpWord/Escaper/Xml.php @@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper; /** * @since 0.13.0 - * + * * @codeCoverageIgnore */ class Xml extends AbstractEscaper diff --git a/src/PhpWord/Metadata/Settings.php b/src/PhpWord/Metadata/Settings.php index 9b2c2285..cd0eaabe 100644 --- a/src/PhpWord/Metadata/Settings.php +++ b/src/PhpWord/Metadata/Settings.php @@ -203,7 +203,7 @@ class Settings /** * Get the Visibility of Annotation Types - * + * * @return \PhpOffice\PhpWord\ComplexType\TrackChangesView */ public function getRevisionView() @@ -213,7 +213,7 @@ class Settings /** * Set the Visibility of Annotation Types - * + * * @param TrackChangesView $trackChangesView */ public function setRevisionView(TrackChangesView $trackChangesView = null) @@ -293,7 +293,7 @@ class Settings /** * Returns the Radix Point for Field Code Evaluation - * + * * @return string */ public function getDecimalSymbol() @@ -303,7 +303,7 @@ class Settings /** * sets the Radix Point for Field Code Evaluation - * + * * @param string $decimalSymbol */ public function setDecimalSymbol($decimalSymbol) diff --git a/src/PhpWord/Reader/MsDoc.php b/src/PhpWord/Reader/MsDoc.php index f21b2bf4..b3fdd9d4 100644 --- a/src/PhpWord/Reader/MsDoc.php +++ b/src/PhpWord/Reader/MsDoc.php @@ -1303,7 +1303,7 @@ class MsDoc extends AbstractReader implements ReaderInterface print_r('$sprm.ispmd : 0x'.dechex($sprm_IsPmd).PHP_EOL); print_r('$sprm.f : 0x'.dechex($sprm_F).PHP_EOL); print_r('$sprm.sgc : 0x'.dechex($sprm_Sgc)); - switch(dechex($sprm_Sgc)) { + switch (dechex($sprm_Sgc)) { case 0x01: print_r(' (Paragraph property)'); break; @@ -1322,12 +1322,12 @@ class MsDoc extends AbstractReader implements ReaderInterface } print_r(PHP_EOL); print_r('$sprm.spra : 0x'.dechex($sprm_Spra).PHP_EOL); - switch(dechex($sprm_Spra)) { + switch (dechex($sprm_Spra)) { case 0x0: $operand = self::getInt1d($this->dataWorkDocument, $offset); $offset += 1; $cb -= 1; - switch(dechex($operand)) { + switch (dechex($operand)) { case 0x00: $operand = 'OFF'; break; @@ -1376,9 +1376,9 @@ class MsDoc extends AbstractReader implements ReaderInterface } // - switch(dechex($sprm_Sgc)) { + switch (dechex($sprm_Sgc)) { case 0x01: // Sprm is modifying a paragraph property. - switch($sprm_IsPmd) { + switch ($sprm_IsPmd) { case 0x0A: // sprmPIlvl print_r('sprmPIlvl : '.$operand.PHP_EOL.PHP_EOL); break; @@ -1391,28 +1391,28 @@ class MsDoc extends AbstractReader implements ReaderInterface } break; case 0x02: // Sprm is modifying a character property. - switch($sprm_IsPmd) { + switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(2) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; case 0x03: // Sprm is modifying a picture property. - switch($sprm_IsPmd) { + switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(3) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; case 0x04: // Sprm is modifying a section property. - switch($sprm_IsPmd) { + switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; } break; case 0x05: // Sprm is modifying a table property. - switch($sprm_IsPmd) { + switch ($sprm_IsPmd) { default: print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); break; @@ -1514,11 +1514,11 @@ class MsDoc extends AbstractReader implements ReaderInterface $length = 0; $operand = null; - switch(dechex($oSprm->spra)) { + switch (dechex($oSprm->spra)) { case 0x0: $operand = self::getInt1d($data, $pos); $length = 1; - switch(dechex($operand)) { + switch (dechex($operand)) { case 0x00: $operand = false; break; @@ -1593,7 +1593,7 @@ class MsDoc extends AbstractReader implements ReaderInterface $cbNum -= $arrayReturn['length']; $operand = $arrayReturn['operand']; - switch(dechex($oSprm->sgc)) { + switch (dechex($oSprm->sgc)) { // Paragraph property case 0x01: break; @@ -1602,7 +1602,7 @@ class MsDoc extends AbstractReader implements ReaderInterface if (!isset($oStylePrl->styleFont)) { $oStylePrl->styleFont = array(); } - switch($oSprm->isPmd) { + switch ($oSprm->isPmd) { // sprmCFRMarkIns case 0x01: break; @@ -1620,7 +1620,7 @@ class MsDoc extends AbstractReader implements ReaderInterface // sprmCFItalic case 0x36: // By default, text is not italicized. - switch($operand) { + switch ($operand) { case false: case true: $oStylePrl->styleFont['italic'] = $operand; @@ -1640,7 +1640,7 @@ class MsDoc extends AbstractReader implements ReaderInterface // sprmCFBold case 0x35: // By default, text is not bold. - switch($operand) { + switch ($operand) { case false: case true: $oStylePrl->styleFont['bold'] = $operand; @@ -1656,7 +1656,7 @@ class MsDoc extends AbstractReader implements ReaderInterface // sprmCFStrike case 0x37: // By default, text is not struck through. - switch($operand) { + switch ($operand) { case false: case true: $oStylePrl->styleFont['strikethrough'] = $operand; @@ -1671,7 +1671,7 @@ class MsDoc extends AbstractReader implements ReaderInterface break; // sprmCKul case 0x3E: - switch(dechex($operand)) { + switch (dechex($operand)) { case 0x00: $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_NONE; break; @@ -1734,7 +1734,7 @@ class MsDoc extends AbstractReader implements ReaderInterface // sprmCIco //@link http://msdn.microsoft.com/en-us/library/dd773060%28v=office.12%29.aspx case 0x42: - switch(dechex($operand)) { + switch (dechex($operand)) { case 0x00: case 0x01: $oStylePrl->styleFont['color'] = '000000'; @@ -1873,7 +1873,7 @@ class MsDoc extends AbstractReader implements ReaderInterface if (!isset($oStylePrl->styleSection)) { $oStylePrl->styleSection = array(); } - switch($oSprm->isPmd) { + switch ($oSprm->isPmd) { // sprmSNfcPgn case 0x0E: // numbering format used for page numbers @@ -1925,7 +1925,6 @@ class MsDoc extends AbstractReader implements ReaderInterface default: // print_r('@todo Section : 0x'.dechex($oSprm->isPmd)); // print_r(PHP_EOL); - } break; // Table property @@ -2285,7 +2284,6 @@ class MsDoc extends AbstractReader implements ReaderInterface } } } - } } diff --git a/src/PhpWord/Reader/ODText/Content.php b/src/PhpWord/Reader/ODText/Content.php index 7362b02c..0e11147b 100644 --- a/src/PhpWord/Reader/ODText/Content.php +++ b/src/PhpWord/Reader/ODText/Content.php @@ -44,7 +44,6 @@ class Content extends AbstractPart foreach ($nodes as $node) { // $styleName = $xmlReader->getAttribute('text:style-name', $node); switch ($node->nodeName) { - case 'text:h': // Heading $depth = $xmlReader->getAttribute('text:outline-level', $node); $section->addTitle($node->nodeValue, $depth); diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index 875415a3..d203dd29 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -94,7 +94,6 @@ class Word2007 extends AbstractReader implements ReaderInterface $part->setRels($relationships); $part->read($phpWord); } - } /** diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 51970a06..5aafcb0d 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -263,7 +263,6 @@ abstract class AbstractPart foreach ($tblNodes as $tblNode) { if ('w:tblGrid' == $tblNode->nodeName) { // Column // @todo Do something with table columns - } elseif ('w:tr' == $tblNode->nodeName) { // Row $rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight'); $rowHRule = $xmlReader->getAttribute('w:hRule', $tblNode, 'w:trPr/w:trHeight'); @@ -279,7 +278,6 @@ abstract class AbstractPart foreach ($rowNodes as $rowNode) { if ('w:trPr' == $rowNode->nodeName) { // Row style // @todo Do something with row style - } elseif ('w:tc' == $rowNode->nodeName) { // Cell $cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW'); $cellStyle = null; diff --git a/src/PhpWord/Reader/Word2007/Settings.php b/src/PhpWord/Reader/Word2007/Settings.php index d2ffc1f3..7ade4dc5 100644 --- a/src/PhpWord/Reader/Word2007/Settings.php +++ b/src/PhpWord/Reader/Word2007/Settings.php @@ -68,7 +68,7 @@ class Settings extends AbstractPart /** * Sets the document protection - * + * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMNode $node @@ -83,7 +83,7 @@ class Settings extends AbstractPart /** * Sets the proof state - * + * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMNode $node @@ -105,7 +105,7 @@ class Settings extends AbstractPart /** * Sets the proof state - * + * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMNode $node @@ -122,7 +122,7 @@ class Settings extends AbstractPart /** * Set the Revision view - * + * * @param XMLReader $xmlReader * @param PhpWord $phpWord * @param \DOMNode $node diff --git a/src/PhpWord/Reader/Word2007/Styles.php b/src/PhpWord/Reader/Word2007/Styles.php index 645c9830..c38ca144 100644 --- a/src/PhpWord/Reader/Word2007/Styles.php +++ b/src/PhpWord/Reader/Word2007/Styles.php @@ -49,7 +49,6 @@ class Styles extends AbstractPart preg_match('/Heading(\d)/', $name, $headingMatches); // $default = ($xmlReader->getAttribute('w:default', $node) == 1); switch ($type) { - case 'paragraph': $paragraphStyle = $this->readParagraphStyle($xmlReader, $node); $fontStyle = $this->readFontStyle($xmlReader, $node); diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 70fad3e8..5309baf7 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -318,7 +318,7 @@ class Settings /** * @since 0.13.0 - * + * * @return boolean * * @codeCoverageIgnore @@ -330,7 +330,7 @@ class Settings /** * @since 0.13.0 - * + * * @param boolean $outputEscapingEnabled * * @codeCoverageIgnore diff --git a/src/PhpWord/Shared/AbstractEnum.php b/src/PhpWord/Shared/AbstractEnum.php index f116e511..35a5749a 100644 --- a/src/PhpWord/Shared/AbstractEnum.php +++ b/src/PhpWord/Shared/AbstractEnum.php @@ -21,7 +21,7 @@ abstract class AbstractEnum /** * Returns all values for this enum - * + * * @return array */ public static function values() @@ -31,7 +31,7 @@ abstract class AbstractEnum /** * Returns true the value is valid for this enum - * + * * @param strign $value * @return boolean true if value is valid */ @@ -43,7 +43,7 @@ abstract class AbstractEnum /** * Validates that the value passed is a valid value - * + * * @param string $value * @throws \InvalidArgumentException if the value passed is not valid for this enum */ diff --git a/src/PhpWord/Shared/OLERead.php b/src/PhpWord/Shared/OLERead.php index cf9b15d3..aa671522 100644 --- a/src/PhpWord/Shared/OLERead.php +++ b/src/PhpWord/Shared/OLERead.php @@ -294,7 +294,6 @@ class OLERead $offset += self::PROPERTY_STORAGE_BLOCK_SIZE; } - } /** diff --git a/src/PhpWord/Style/Font.php b/src/PhpWord/Style/Font.php index b625e3b8..5cc80fb3 100644 --- a/src/PhpWord/Style/Font.php +++ b/src/PhpWord/Style/Font.php @@ -223,7 +223,7 @@ class Font extends AbstractStyle private $shading; /** - * Right to left languages + * Right to left languages * @var boolean */ private $rtl = false; @@ -725,7 +725,7 @@ class Font extends AbstractStyle } /** - * Set shading + * Set Paragraph * * @param mixed $value * @return self diff --git a/src/PhpWord/Style/NumberingLevel.php b/src/PhpWord/Style/NumberingLevel.php index 38b9fbee..9da1a2b1 100644 --- a/src/PhpWord/Style/NumberingLevel.php +++ b/src/PhpWord/Style/NumberingLevel.php @@ -85,7 +85,7 @@ class NumberingLevel extends AbstractStyle /** * Justification, w:lvlJc - * + * * @var string, one of PhpOffice\PhpWord\SimpleType\Jc */ private $alignment = ''; diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index bad9ace9..8d342550 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -742,7 +742,7 @@ class Paragraph extends Border /** * Get contextualSpacing - * + * * @return bool */ public function hasContextualSpacing() @@ -752,7 +752,7 @@ class Paragraph extends Border /** * Set contextualSpacing - * + * * @param bool $contextualSpacing * @return self */ diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index e7a8d039..2f6d6258 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -147,7 +147,7 @@ class TemplateProcessor /** * Applies XSL style sheet to template's parts. - * + * * Note: since the method doesn't make any guess on logic of the provided XSL style sheet, * make sure that output is correctly escaped. Otherwise you may get broken document. * diff --git a/src/PhpWord/Writer/HTML/Part/AbstractPart.php b/src/PhpWord/Writer/HTML/Part/AbstractPart.php index 638f846b..584e4489 100644 --- a/src/PhpWord/Writer/HTML/Part/AbstractPart.php +++ b/src/PhpWord/Writer/HTML/Part/AbstractPart.php @@ -48,7 +48,7 @@ abstract class AbstractPart /** * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer - * + * * @return void */ public function setParentWriter(AbstractWriter $writer = null) diff --git a/src/PhpWord/Writer/RTF/Part/AbstractPart.php b/src/PhpWord/Writer/RTF/Part/AbstractPart.php index 152493db..04fb4cfd 100644 --- a/src/PhpWord/Writer/RTF/Part/AbstractPart.php +++ b/src/PhpWord/Writer/RTF/Part/AbstractPart.php @@ -48,7 +48,7 @@ abstract class AbstractPart /** * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer - * + * * @return void */ public function setParentWriter(AbstractWriter $writer = null) diff --git a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php index 79877b10..305a768e 100644 --- a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php +++ b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php @@ -134,7 +134,6 @@ abstract class AbstractElement } $this->xmlWriter->writeElementBlock('w:commentRangeStart', array('w:id' => $comment->getElementId())); - } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 3dd3968b..86045b9a 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -213,7 +213,6 @@ class Chart extends AbstractPart $xmlWriter->endElement(); // c:ser $index++; } - } /** diff --git a/src/PhpWord/Writer/Word2007/Part/Settings.php b/src/PhpWord/Writer/Word2007/Part/Settings.php index 529d47af..d2cb8117 100644 --- a/src/PhpWord/Writer/Word2007/Part/Settings.php +++ b/src/PhpWord/Writer/Word2007/Part/Settings.php @@ -161,7 +161,7 @@ class Settings extends AbstractPart /** * Adds a boolean attribute to the settings array - * + * * @param string $settingName * @param boolean $booleanValue */ @@ -219,7 +219,6 @@ class Settings extends AbstractPart private function setRevisionView(TrackChangesView $trackChangesView = null) { if ($trackChangesView != null) { - $revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true': 'false'; $revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true': 'false'; $revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true': 'false'; @@ -232,7 +231,7 @@ class Settings extends AbstractPart /** * Set the magnification - * + * * @param mixed $zoom */ private function setZoom($zoom = null) diff --git a/src/PhpWord/Writer/Word2007/Part/Styles.php b/src/PhpWord/Writer/Word2007/Part/Styles.php index 7bcb8d92..01b84c08 100644 --- a/src/PhpWord/Writer/Word2007/Part/Styles.php +++ b/src/PhpWord/Writer/Word2007/Part/Styles.php @@ -170,6 +170,9 @@ class Styles extends AbstractPart $xmlWriter->startElement('w:link'); $xmlWriter->writeAttribute('w:val', $styleLink); $xmlWriter->endElement(); + } else if (!is_null($paragraphStyle)) { + // if type is 'paragraph' it should have a styleId + $xmlWriter->writeAttribute('w:styleId', $styleName); } // Style name @@ -178,7 +181,13 @@ class Styles extends AbstractPart $xmlWriter->endElement(); // Parent style - $xmlWriter->writeElementIf(!is_null($paragraphStyle), 'w:basedOn', 'w:val', 'Normal'); + if (!is_null($paragraphStyle)) { + if ($paragraphStyle->getStyleName() != null) { + $xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getStyleName()); + } elseif ($paragraphStyle->getBasedOn() != null) { + $xmlWriter->writeElementBlock('w:basedOn', 'w:val', $paragraphStyle->getBasedOn()); + } + } // w:pPr if (!is_null($paragraphStyle)) { diff --git a/tests/PhpWord/ComplexType/FootnotePropertiesTest.php b/tests/PhpWord/ComplexType/FootnotePropertiesTest.php index 025e8c91..39392fcd 100644 --- a/tests/PhpWord/ComplexType/FootnotePropertiesTest.php +++ b/tests/PhpWord/ComplexType/FootnotePropertiesTest.php @@ -47,7 +47,7 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase /** * Test throws exception if wrong position given - * + * * @expectedException \InvalidArgumentException */ public function testWrongPos() @@ -58,7 +58,7 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase /** * Test throws exception if wrong number format given - * + * * @expectedException \InvalidArgumentException */ public function testWrongNumFmt() @@ -69,7 +69,7 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase /** * Test throws exception if wrong number restart given - * + * * @expectedException \InvalidArgumentException */ public function testWrongNumRestart() diff --git a/tests/PhpWord/PhpWordTest.php b/tests/PhpWord/PhpWordTest.php index 459c67a0..b49666f5 100644 --- a/tests/PhpWord/PhpWordTest.php +++ b/tests/PhpWord/PhpWordTest.php @@ -99,7 +99,6 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase $phpWord->$method($styleId, array()); $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$value}", Style::getStyle($styleId)); } - } /** diff --git a/tests/PhpWord/Writer/Word2007/Part/StylesTest.php b/tests/PhpWord/Writer/Word2007/Part/StylesTest.php index f40387a1..0c0f7aef 100644 --- a/tests/PhpWord/Writer/Word2007/Part/StylesTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/StylesTest.php @@ -18,7 +18,10 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\Style\Font; +use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\TestHelperDOCX; +use PhpOffice\PhpWord\Writer\Word2007; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Styles @@ -74,4 +77,70 @@ class StylesTest extends \PHPUnit_Framework_TestCase $element = $doc->getElement($path, $file); $this->assertEquals('Normal', $element->getAttribute('w:val')); } + + public function testFontStyleBasedOn() + { + $phpWord = new PhpWord(); + + $baseParagraphStyle = new Paragraph(); + $baseParagraphStyle->setAlignment(Jc::CENTER); + $baseParagraphStyle = $phpWord->addParagraphStyle('BaseStyle', $baseParagraphStyle); + + $childFont = new Font(); + $childFont->setParagraph($baseParagraphStyle); + $childFont->setSize(16); + $childFont = $phpWord->addFontStyle('ChildFontStyle', $childFont); + + $otherFont = new Font(); + $otherFont->setSize(20); + $otherFont = $phpWord->addFontStyle('OtherFontStyle', $otherFont); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/styles.xml'; + + // Normal style generated? + $path = '/w:styles/w:style[@w:styleId="BaseStyle"]/w:name'; + $element = $doc->getElement($path, $file); + $this->assertEquals('BaseStyle', $element->getAttribute('w:val')); + + // Font style with paragraph should have it's base style set to that paragraphs style name + $path = '/w:styles/w:style[w:name/@w:val="ChildFontStyle"]/w:basedOn'; + $element = $doc->getElement($path, $file); + $this->assertEquals('BaseStyle', $element->getAttribute('w:val')); + + // Font style without paragraph should not have a base style set + $path = '/w:styles/w:style[w:name/@w:val="OtherFontStyle"]/w:basedOn'; + $element = $doc->getElement($path, $file); + $this->assertNull($element); + } + + public function testFontStyleBasedOnOtherFontStyle() + { + $phpWord = new PhpWord(); + + $styleGenerationP = new Paragraph(); + $styleGenerationP->setAlignment(Jc::BOTH); + + $styleGeneration = new Font(); + $styleGeneration->setParagraph($styleGenerationP); + $styleGeneration->setSize(9.5); + $phpWord->addFontStyle('Generation', $styleGeneration); + + $styleGenerationEteinteP = new Paragraph(); + $styleGenerationEteinteP->setBasedOn('Generation'); + + $styleGenerationEteinte = new Font(); + $styleGenerationEteinte->setParagraph($styleGenerationEteinteP); + $styleGenerationEteinte->setSize(8.5); + $phpWord->addFontStyle('GeneratEteinte', $styleGenerationEteinte); + + $doc = TestHelperDOCX::getDocument($phpWord); + + $file = 'word/styles.xml'; + + $path = '/w:styles/w:style[@w:styleId="GeneratEteinte"]/w:basedOn'; + $element = $doc->getElement($path, $file); + $this->assertEquals('Generation', $element->getAttribute('w:val')); + } } diff --git a/tests/PhpWord/_includes/XmlDocument.php b/tests/PhpWord/_includes/XmlDocument.php index 72b18c29..c3bab0f6 100644 --- a/tests/PhpWord/_includes/XmlDocument.php +++ b/tests/PhpWord/_includes/XmlDocument.php @@ -96,7 +96,6 @@ class XmlDocument if (null === $this->xpath) { $this->xpath = new \DOMXpath($this->dom); - } return $this->xpath->query($path);