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
This commit is contained in:
troosan 2017-09-17 21:38:00 +02:00 committed by GitHub
parent 2fc685b4da
commit 8ce1a19ec4
35 changed files with 153 additions and 89 deletions

View File

@ -65,7 +65,7 @@ final class FootnoteProperties
/** /**
* Get the Footnote Positioning Location * Get the Footnote Positioning Location
* *
* @return string * @return string
*/ */
public function getPos() public function getPos()
@ -75,7 +75,7 @@ final class FootnoteProperties
/** /**
* Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd) * Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd)
* *
* @param string $pos * @param string $pos
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return self * @return self
@ -99,7 +99,7 @@ final class FootnoteProperties
/** /**
* Get the Footnote Numbering Format * Get the Footnote Numbering Format
* *
* @return string * @return string
*/ */
public function getNumFmt() public function getNumFmt()
@ -109,7 +109,7 @@ final class FootnoteProperties
/** /**
* Set the Footnote Numbering Format * Set the Footnote Numbering Format
* *
* @param string $numFmt One of NumberFormat * @param string $numFmt One of NumberFormat
* @return self * @return self
*/ */
@ -122,7 +122,7 @@ final class FootnoteProperties
/** /**
* Get the Footnote Numbering Format * Get the Footnote Numbering Format
* *
* @return double * @return double
*/ */
public function getNumStart() public function getNumStart()
@ -132,7 +132,7 @@ final class FootnoteProperties
/** /**
* Set the Footnote Numbering Format * Set the Footnote Numbering Format
* *
* @param double $numStart * @param double $numStart
* @return self * @return self
*/ */
@ -144,7 +144,7 @@ final class FootnoteProperties
/** /**
* Get the Footnote and Endnote Numbering Starting Value * Get the Footnote and Endnote Numbering Starting Value
* *
* @return string * @return string
*/ */
public function getNumRestart() public function getNumRestart()
@ -154,7 +154,7 @@ final class FootnoteProperties
/** /**
* Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage) * Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage)
* *
* @param string $numRestart * @param string $numRestart
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return self * @return self

View File

@ -51,7 +51,7 @@ final class ProofState
/** /**
* Set the Spell Checking State (dirty or clean) * Set the Spell Checking State (dirty or clean)
* *
* @param string $spelling * @param string $spelling
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return self * @return self
*/ */
@ -78,7 +78,7 @@ final class ProofState
/** /**
* Set the Grammatical Checking State (dirty or clean) * Set the Grammatical Checking State (dirty or clean)
* *
* @param string $grammar * @param string $grammar
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return self * @return self
*/ */

View File

@ -116,14 +116,14 @@ abstract class AbstractElement
/** /**
* The start position for the linked comment * The start position for the linked comment
* *
* @var Comment * @var Comment
*/ */
protected $commentRangeStart; protected $commentRangeStart;
/** /**
* The end position for the linked comment * The end position for the linked comment
* *
* @var Comment * @var Comment
*/ */
protected $commentRangeEnd; protected $commentRangeEnd;
@ -291,7 +291,7 @@ abstract class AbstractElement
/** /**
* Set comment start * Set comment start
* *
* @param Comment $value * @param Comment $value
*/ */
public function setCommentRangeStart(Comment $value) public function setCommentRangeStart(Comment $value)

View File

@ -31,14 +31,14 @@ class Comment extends TrackChange
/** /**
* The Element where this comment starts * The Element where this comment starts
* *
* @var AbstractElement * @var AbstractElement
*/ */
private $startElement; private $startElement;
/** /**
* The Element where this comment ends * The Element where this comment ends
* *
* @var AbstractElement * @var AbstractElement
*/ */
private $endElement; private $endElement;
@ -76,7 +76,7 @@ class Comment extends TrackChange
/** /**
* Sets the element where this comment starts * Sets the element where this comment starts
* *
* @param \PhpOffice\PhpWord\Element\AbstractElement $value * @param \PhpOffice\PhpWord\Element\AbstractElement $value
*/ */
public function setStartElement(AbstractElement $value) public function setStartElement(AbstractElement $value)
@ -89,7 +89,7 @@ class Comment extends TrackChange
/** /**
* Get the element where this comment starts * Get the element where this comment starts
* *
* @return \PhpOffice\PhpWord\Element\AbstractElement * @return \PhpOffice\PhpWord\Element\AbstractElement
*/ */
public function getStartElement() public function getStartElement()
@ -99,7 +99,7 @@ class Comment extends TrackChange
/** /**
* Sets the element where this comment ends * Sets the element where this comment ends
* *
* @param \PhpOffice\PhpWord\Element\AbstractElement $value * @param \PhpOffice\PhpWord\Element\AbstractElement $value
*/ */
public function setEndElement(AbstractElement $value) public function setEndElement(AbstractElement $value)
@ -112,7 +112,7 @@ class Comment extends TrackChange
/** /**
* Get the element where this comment ends * Get the element where this comment ends
* *
* @return \PhpOffice\PhpWord\Element\AbstractElement * @return \PhpOffice\PhpWord\Element\AbstractElement
*/ */
public function getEndElement() public function getEndElement()

View File

@ -476,9 +476,9 @@ class Image extends AbstractElement
/** /**
* get image size from string * get image size from string
* *
* @param string $source * @param string $source
* *
* @codeCoverageIgnore this method is just a replacement for getimagesizefromstring which exists only as of PHP 5.4 * @codeCoverageIgnore this method is just a replacement for getimagesizefromstring which exists only as of PHP 5.4
*/ */
private function getStringImageSize($source) private function getStringImageSize($source)

View File

@ -50,7 +50,7 @@ class Section extends AbstractContainer
/** /**
* The properties for the footnote of this section * The properties for the footnote of this section
* *
* @var FootnoteProperties * @var FootnoteProperties
*/ */
private $footnoteProperties; private $footnoteProperties;
@ -148,7 +148,7 @@ class Section extends AbstractContainer
/** /**
* Get the footnote properties * Get the footnote properties
* *
* @return \PhpOffice\PhpWord\Element\FooterProperties * @return \PhpOffice\PhpWord\Element\FooterProperties
*/ */
public function getFootnotePropoperties() public function getFootnotePropoperties()
@ -158,7 +158,7 @@ class Section extends AbstractContainer
/** /**
* Set the footnote properties * Set the footnote properties
* *
* @param FootnoteProperties $footnoteProperties * @param FootnoteProperties $footnoteProperties
*/ */
public function setFootnoteProperties(FootnoteProperties $footnoteProperties = null) public function setFootnoteProperties(FootnoteProperties $footnoteProperties = null)
@ -219,7 +219,6 @@ class Section extends AbstractContainer
} else { } else {
throw new \Exception('Invalid header/footer type.'); throw new \Exception('Invalid header/footer type.');
} }
} }
/** /**

View File

@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper;
/** /**
* @since 0.13.0 * @since 0.13.0
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
abstract class AbstractEscaper implements EscaperInterface abstract class AbstractEscaper implements EscaperInterface

View File

@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper;
/** /**
* @since 0.13.0 * @since 0.13.0
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
interface EscaperInterface interface EscaperInterface

View File

@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper;
/** /**
* @since 0.13.0 * @since 0.13.0
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class RegExp extends AbstractEscaper class RegExp extends AbstractEscaper

View File

@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper;
/** /**
* @since 0.13.0 * @since 0.13.0
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class Rtf extends AbstractEscaper class Rtf extends AbstractEscaper

View File

@ -19,7 +19,7 @@ namespace PhpOffice\PhpWord\Escaper;
/** /**
* @since 0.13.0 * @since 0.13.0
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class Xml extends AbstractEscaper class Xml extends AbstractEscaper

View File

@ -203,7 +203,7 @@ class Settings
/** /**
* Get the Visibility of Annotation Types * Get the Visibility of Annotation Types
* *
* @return \PhpOffice\PhpWord\ComplexType\TrackChangesView * @return \PhpOffice\PhpWord\ComplexType\TrackChangesView
*/ */
public function getRevisionView() public function getRevisionView()
@ -213,7 +213,7 @@ class Settings
/** /**
* Set the Visibility of Annotation Types * Set the Visibility of Annotation Types
* *
* @param TrackChangesView $trackChangesView * @param TrackChangesView $trackChangesView
*/ */
public function setRevisionView(TrackChangesView $trackChangesView = null) public function setRevisionView(TrackChangesView $trackChangesView = null)
@ -293,7 +293,7 @@ class Settings
/** /**
* Returns the Radix Point for Field Code Evaluation * Returns the Radix Point for Field Code Evaluation
* *
* @return string * @return string
*/ */
public function getDecimalSymbol() public function getDecimalSymbol()
@ -303,7 +303,7 @@ class Settings
/** /**
* sets the Radix Point for Field Code Evaluation * sets the Radix Point for Field Code Evaluation
* *
* @param string $decimalSymbol * @param string $decimalSymbol
*/ */
public function setDecimalSymbol($decimalSymbol) public function setDecimalSymbol($decimalSymbol)

View File

@ -1303,7 +1303,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
print_r('$sprm.ispmd : 0x'.dechex($sprm_IsPmd).PHP_EOL); print_r('$sprm.ispmd : 0x'.dechex($sprm_IsPmd).PHP_EOL);
print_r('$sprm.f : 0x'.dechex($sprm_F).PHP_EOL); print_r('$sprm.f : 0x'.dechex($sprm_F).PHP_EOL);
print_r('$sprm.sgc : 0x'.dechex($sprm_Sgc)); print_r('$sprm.sgc : 0x'.dechex($sprm_Sgc));
switch(dechex($sprm_Sgc)) { switch (dechex($sprm_Sgc)) {
case 0x01: case 0x01:
print_r(' (Paragraph property)'); print_r(' (Paragraph property)');
break; break;
@ -1322,12 +1322,12 @@ class MsDoc extends AbstractReader implements ReaderInterface
} }
print_r(PHP_EOL); print_r(PHP_EOL);
print_r('$sprm.spra : 0x'.dechex($sprm_Spra).PHP_EOL); print_r('$sprm.spra : 0x'.dechex($sprm_Spra).PHP_EOL);
switch(dechex($sprm_Spra)) { switch (dechex($sprm_Spra)) {
case 0x0: case 0x0:
$operand = self::getInt1d($this->dataWorkDocument, $offset); $operand = self::getInt1d($this->dataWorkDocument, $offset);
$offset += 1; $offset += 1;
$cb -= 1; $cb -= 1;
switch(dechex($operand)) { switch (dechex($operand)) {
case 0x00: case 0x00:
$operand = 'OFF'; $operand = 'OFF';
break; 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. case 0x01: // Sprm is modifying a paragraph property.
switch($sprm_IsPmd) { switch ($sprm_IsPmd) {
case 0x0A: // sprmPIlvl case 0x0A: // sprmPIlvl
print_r('sprmPIlvl : '.$operand.PHP_EOL.PHP_EOL); print_r('sprmPIlvl : '.$operand.PHP_EOL.PHP_EOL);
break; break;
@ -1391,28 +1391,28 @@ class MsDoc extends AbstractReader implements ReaderInterface
} }
break; break;
case 0x02: // Sprm is modifying a character property. case 0x02: // Sprm is modifying a character property.
switch($sprm_IsPmd) { switch ($sprm_IsPmd) {
default: default:
print_r('$sprm_IsPmd(2) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); print_r('$sprm_IsPmd(2) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL);
break; break;
} }
break; break;
case 0x03: // Sprm is modifying a picture property. case 0x03: // Sprm is modifying a picture property.
switch($sprm_IsPmd) { switch ($sprm_IsPmd) {
default: default:
print_r('$sprm_IsPmd(3) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); print_r('$sprm_IsPmd(3) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL);
break; break;
} }
break; break;
case 0x04: // Sprm is modifying a section property. case 0x04: // Sprm is modifying a section property.
switch($sprm_IsPmd) { switch ($sprm_IsPmd) {
default: default:
print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL);
break; break;
} }
break; break;
case 0x05: // Sprm is modifying a table property. case 0x05: // Sprm is modifying a table property.
switch($sprm_IsPmd) { switch ($sprm_IsPmd) {
default: default:
print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL); print_r('$sprm_IsPmd(4) : '.$sprm_IsPmd.PHP_EOL.PHP_EOL);
break; break;
@ -1514,11 +1514,11 @@ class MsDoc extends AbstractReader implements ReaderInterface
$length = 0; $length = 0;
$operand = null; $operand = null;
switch(dechex($oSprm->spra)) { switch (dechex($oSprm->spra)) {
case 0x0: case 0x0:
$operand = self::getInt1d($data, $pos); $operand = self::getInt1d($data, $pos);
$length = 1; $length = 1;
switch(dechex($operand)) { switch (dechex($operand)) {
case 0x00: case 0x00:
$operand = false; $operand = false;
break; break;
@ -1593,7 +1593,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
$cbNum -= $arrayReturn['length']; $cbNum -= $arrayReturn['length'];
$operand = $arrayReturn['operand']; $operand = $arrayReturn['operand'];
switch(dechex($oSprm->sgc)) { switch (dechex($oSprm->sgc)) {
// Paragraph property // Paragraph property
case 0x01: case 0x01:
break; break;
@ -1602,7 +1602,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
if (!isset($oStylePrl->styleFont)) { if (!isset($oStylePrl->styleFont)) {
$oStylePrl->styleFont = array(); $oStylePrl->styleFont = array();
} }
switch($oSprm->isPmd) { switch ($oSprm->isPmd) {
// sprmCFRMarkIns // sprmCFRMarkIns
case 0x01: case 0x01:
break; break;
@ -1620,7 +1620,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
// sprmCFItalic // sprmCFItalic
case 0x36: case 0x36:
// By default, text is not italicized. // By default, text is not italicized.
switch($operand) { switch ($operand) {
case false: case false:
case true: case true:
$oStylePrl->styleFont['italic'] = $operand; $oStylePrl->styleFont['italic'] = $operand;
@ -1640,7 +1640,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
// sprmCFBold // sprmCFBold
case 0x35: case 0x35:
// By default, text is not bold. // By default, text is not bold.
switch($operand) { switch ($operand) {
case false: case false:
case true: case true:
$oStylePrl->styleFont['bold'] = $operand; $oStylePrl->styleFont['bold'] = $operand;
@ -1656,7 +1656,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
// sprmCFStrike // sprmCFStrike
case 0x37: case 0x37:
// By default, text is not struck through. // By default, text is not struck through.
switch($operand) { switch ($operand) {
case false: case false:
case true: case true:
$oStylePrl->styleFont['strikethrough'] = $operand; $oStylePrl->styleFont['strikethrough'] = $operand;
@ -1671,7 +1671,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
break; break;
// sprmCKul // sprmCKul
case 0x3E: case 0x3E:
switch(dechex($operand)) { switch (dechex($operand)) {
case 0x00: case 0x00:
$oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_NONE; $oStylePrl->styleFont['underline'] = Style\Font::UNDERLINE_NONE;
break; break;
@ -1734,7 +1734,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
// sprmCIco // sprmCIco
//@link http://msdn.microsoft.com/en-us/library/dd773060%28v=office.12%29.aspx //@link http://msdn.microsoft.com/en-us/library/dd773060%28v=office.12%29.aspx
case 0x42: case 0x42:
switch(dechex($operand)) { switch (dechex($operand)) {
case 0x00: case 0x00:
case 0x01: case 0x01:
$oStylePrl->styleFont['color'] = '000000'; $oStylePrl->styleFont['color'] = '000000';
@ -1873,7 +1873,7 @@ class MsDoc extends AbstractReader implements ReaderInterface
if (!isset($oStylePrl->styleSection)) { if (!isset($oStylePrl->styleSection)) {
$oStylePrl->styleSection = array(); $oStylePrl->styleSection = array();
} }
switch($oSprm->isPmd) { switch ($oSprm->isPmd) {
// sprmSNfcPgn // sprmSNfcPgn
case 0x0E: case 0x0E:
// numbering format used for page numbers // numbering format used for page numbers
@ -1925,7 +1925,6 @@ class MsDoc extends AbstractReader implements ReaderInterface
default: default:
// print_r('@todo Section : 0x'.dechex($oSprm->isPmd)); // print_r('@todo Section : 0x'.dechex($oSprm->isPmd));
// print_r(PHP_EOL); // print_r(PHP_EOL);
} }
break; break;
// Table property // Table property
@ -2285,7 +2284,6 @@ class MsDoc extends AbstractReader implements ReaderInterface
} }
} }
} }
} }
} }

View File

@ -44,7 +44,6 @@ class Content extends AbstractPart
foreach ($nodes as $node) { foreach ($nodes as $node) {
// $styleName = $xmlReader->getAttribute('text:style-name', $node); // $styleName = $xmlReader->getAttribute('text:style-name', $node);
switch ($node->nodeName) { switch ($node->nodeName) {
case 'text:h': // Heading case 'text:h': // Heading
$depth = $xmlReader->getAttribute('text:outline-level', $node); $depth = $xmlReader->getAttribute('text:outline-level', $node);
$section->addTitle($node->nodeValue, $depth); $section->addTitle($node->nodeValue, $depth);

View File

@ -94,7 +94,6 @@ class Word2007 extends AbstractReader implements ReaderInterface
$part->setRels($relationships); $part->setRels($relationships);
$part->read($phpWord); $part->read($phpWord);
} }
} }
/** /**

View File

@ -263,7 +263,6 @@ abstract class AbstractPart
foreach ($tblNodes as $tblNode) { foreach ($tblNodes as $tblNode) {
if ('w:tblGrid' == $tblNode->nodeName) { // Column if ('w:tblGrid' == $tblNode->nodeName) { // Column
// @todo Do something with table columns // @todo Do something with table columns
} elseif ('w:tr' == $tblNode->nodeName) { // Row } elseif ('w:tr' == $tblNode->nodeName) { // Row
$rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight'); $rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight');
$rowHRule = $xmlReader->getAttribute('w:hRule', $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) { foreach ($rowNodes as $rowNode) {
if ('w:trPr' == $rowNode->nodeName) { // Row style if ('w:trPr' == $rowNode->nodeName) { // Row style
// @todo Do something with row style // @todo Do something with row style
} elseif ('w:tc' == $rowNode->nodeName) { // Cell } elseif ('w:tc' == $rowNode->nodeName) { // Cell
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW'); $cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
$cellStyle = null; $cellStyle = null;

View File

@ -68,7 +68,7 @@ class Settings extends AbstractPart
/** /**
* Sets the document protection * Sets the document protection
* *
* @param XMLReader $xmlReader * @param XMLReader $xmlReader
* @param PhpWord $phpWord * @param PhpWord $phpWord
* @param \DOMNode $node * @param \DOMNode $node
@ -83,7 +83,7 @@ class Settings extends AbstractPart
/** /**
* Sets the proof state * Sets the proof state
* *
* @param XMLReader $xmlReader * @param XMLReader $xmlReader
* @param PhpWord $phpWord * @param PhpWord $phpWord
* @param \DOMNode $node * @param \DOMNode $node
@ -105,7 +105,7 @@ class Settings extends AbstractPart
/** /**
* Sets the proof state * Sets the proof state
* *
* @param XMLReader $xmlReader * @param XMLReader $xmlReader
* @param PhpWord $phpWord * @param PhpWord $phpWord
* @param \DOMNode $node * @param \DOMNode $node
@ -122,7 +122,7 @@ class Settings extends AbstractPart
/** /**
* Set the Revision view * Set the Revision view
* *
* @param XMLReader $xmlReader * @param XMLReader $xmlReader
* @param PhpWord $phpWord * @param PhpWord $phpWord
* @param \DOMNode $node * @param \DOMNode $node

View File

@ -49,7 +49,6 @@ class Styles extends AbstractPart
preg_match('/Heading(\d)/', $name, $headingMatches); preg_match('/Heading(\d)/', $name, $headingMatches);
// $default = ($xmlReader->getAttribute('w:default', $node) == 1); // $default = ($xmlReader->getAttribute('w:default', $node) == 1);
switch ($type) { switch ($type) {
case 'paragraph': case 'paragraph':
$paragraphStyle = $this->readParagraphStyle($xmlReader, $node); $paragraphStyle = $this->readParagraphStyle($xmlReader, $node);
$fontStyle = $this->readFontStyle($xmlReader, $node); $fontStyle = $this->readFontStyle($xmlReader, $node);

View File

@ -318,7 +318,7 @@ class Settings
/** /**
* @since 0.13.0 * @since 0.13.0
* *
* @return boolean * @return boolean
* *
* @codeCoverageIgnore * @codeCoverageIgnore
@ -330,7 +330,7 @@ class Settings
/** /**
* @since 0.13.0 * @since 0.13.0
* *
* @param boolean $outputEscapingEnabled * @param boolean $outputEscapingEnabled
* *
* @codeCoverageIgnore * @codeCoverageIgnore

View File

@ -21,7 +21,7 @@ abstract class AbstractEnum
/** /**
* Returns all values for this enum * Returns all values for this enum
* *
* @return array * @return array
*/ */
public static function values() public static function values()
@ -31,7 +31,7 @@ abstract class AbstractEnum
/** /**
* Returns true the value is valid for this enum * Returns true the value is valid for this enum
* *
* @param strign $value * @param strign $value
* @return boolean true if value is valid * @return boolean true if value is valid
*/ */
@ -43,7 +43,7 @@ abstract class AbstractEnum
/** /**
* Validates that the value passed is a valid value * Validates that the value passed is a valid value
* *
* @param string $value * @param string $value
* @throws \InvalidArgumentException if the value passed is not valid for this enum * @throws \InvalidArgumentException if the value passed is not valid for this enum
*/ */

View File

@ -294,7 +294,6 @@ class OLERead
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE; $offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
} }
} }
/** /**

View File

@ -223,7 +223,7 @@ class Font extends AbstractStyle
private $shading; private $shading;
/** /**
* Right to left languages * Right to left languages
* @var boolean * @var boolean
*/ */
private $rtl = false; private $rtl = false;
@ -725,7 +725,7 @@ class Font extends AbstractStyle
} }
/** /**
* Set shading * Set Paragraph
* *
* @param mixed $value * @param mixed $value
* @return self * @return self

View File

@ -85,7 +85,7 @@ class NumberingLevel extends AbstractStyle
/** /**
* Justification, w:lvlJc * Justification, w:lvlJc
* *
* @var string, one of PhpOffice\PhpWord\SimpleType\Jc * @var string, one of PhpOffice\PhpWord\SimpleType\Jc
*/ */
private $alignment = ''; private $alignment = '';

View File

@ -742,7 +742,7 @@ class Paragraph extends Border
/** /**
* Get contextualSpacing * Get contextualSpacing
* *
* @return bool * @return bool
*/ */
public function hasContextualSpacing() public function hasContextualSpacing()
@ -752,7 +752,7 @@ class Paragraph extends Border
/** /**
* Set contextualSpacing * Set contextualSpacing
* *
* @param bool $contextualSpacing * @param bool $contextualSpacing
* @return self * @return self
*/ */

View File

@ -147,7 +147,7 @@ class TemplateProcessor
/** /**
* Applies XSL style sheet to template's parts. * 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, * 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. * make sure that output is correctly escaped. Otherwise you may get broken document.
* *

View File

@ -48,7 +48,7 @@ abstract class AbstractPart
/** /**
* @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer
* *
* @return void * @return void
*/ */
public function setParentWriter(AbstractWriter $writer = null) public function setParentWriter(AbstractWriter $writer = null)

View File

@ -48,7 +48,7 @@ abstract class AbstractPart
/** /**
* @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer
* *
* @return void * @return void
*/ */
public function setParentWriter(AbstractWriter $writer = null) public function setParentWriter(AbstractWriter $writer = null)

View File

@ -134,7 +134,6 @@ abstract class AbstractElement
} }
$this->xmlWriter->writeElementBlock('w:commentRangeStart', array('w:id' => $comment->getElementId())); $this->xmlWriter->writeElementBlock('w:commentRangeStart', array('w:id' => $comment->getElementId()));
} }
} }

View File

@ -213,7 +213,6 @@ class Chart extends AbstractPart
$xmlWriter->endElement(); // c:ser $xmlWriter->endElement(); // c:ser
$index++; $index++;
} }
} }
/** /**

View File

@ -161,7 +161,7 @@ class Settings extends AbstractPart
/** /**
* Adds a boolean attribute to the settings array * Adds a boolean attribute to the settings array
* *
* @param string $settingName * @param string $settingName
* @param boolean $booleanValue * @param boolean $booleanValue
*/ */
@ -219,7 +219,6 @@ class Settings extends AbstractPart
private function setRevisionView(TrackChangesView $trackChangesView = null) private function setRevisionView(TrackChangesView $trackChangesView = null)
{ {
if ($trackChangesView != null) { if ($trackChangesView != null) {
$revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true': 'false'; $revisionView['w:markup'] = $trackChangesView->hasMarkup() ? 'true': 'false';
$revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true': 'false'; $revisionView['w:comments'] = $trackChangesView->hasComments() ? 'true': 'false';
$revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true': 'false'; $revisionView['w:insDel'] = $trackChangesView->hasInsDel() ? 'true': 'false';
@ -232,7 +231,7 @@ class Settings extends AbstractPart
/** /**
* Set the magnification * Set the magnification
* *
* @param mixed $zoom * @param mixed $zoom
*/ */
private function setZoom($zoom = null) private function setZoom($zoom = null)

View File

@ -170,6 +170,9 @@ class Styles extends AbstractPart
$xmlWriter->startElement('w:link'); $xmlWriter->startElement('w:link');
$xmlWriter->writeAttribute('w:val', $styleLink); $xmlWriter->writeAttribute('w:val', $styleLink);
$xmlWriter->endElement(); $xmlWriter->endElement();
} else if (!is_null($paragraphStyle)) {
// if type is 'paragraph' it should have a styleId
$xmlWriter->writeAttribute('w:styleId', $styleName);
} }
// Style name // Style name
@ -178,7 +181,13 @@ class Styles extends AbstractPart
$xmlWriter->endElement(); $xmlWriter->endElement();
// Parent style // 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 // w:pPr
if (!is_null($paragraphStyle)) { if (!is_null($paragraphStyle)) {

View File

@ -47,7 +47,7 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
/** /**
* Test throws exception if wrong position given * Test throws exception if wrong position given
* *
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testWrongPos() public function testWrongPos()
@ -58,7 +58,7 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
/** /**
* Test throws exception if wrong number format given * Test throws exception if wrong number format given
* *
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testWrongNumFmt() public function testWrongNumFmt()
@ -69,7 +69,7 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
/** /**
* Test throws exception if wrong number restart given * Test throws exception if wrong number restart given
* *
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testWrongNumRestart() public function testWrongNumRestart()

View File

@ -99,7 +99,6 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
$phpWord->$method($styleId, array()); $phpWord->$method($styleId, array());
$this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$value}", Style::getStyle($styleId)); $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$value}", Style::getStyle($styleId));
} }
} }
/** /**

View File

@ -18,7 +18,10 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TestHelperDOCX; use PhpOffice\PhpWord\TestHelperDOCX;
use PhpOffice\PhpWord\Writer\Word2007;
/** /**
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Styles * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Styles
@ -74,4 +77,70 @@ class StylesTest extends \PHPUnit_Framework_TestCase
$element = $doc->getElement($path, $file); $element = $doc->getElement($path, $file);
$this->assertEquals('Normal', $element->getAttribute('w:val')); $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'));
}
} }

View File

@ -96,7 +96,6 @@ class XmlDocument
if (null === $this->xpath) { if (null === $this->xpath) {
$this->xpath = new \DOMXpath($this->dom); $this->xpath = new \DOMXpath($this->dom);
} }
return $this->xpath->query($path); return $this->xpath->query($path);