Skip to content

Commit 9b1f2f2

Browse files
committed
Add style class checker and rename $fStyle/$pStyle variables
1 parent 4e5bbb9 commit 9b1f2f2

30 files changed

+223
-213
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ This release marked heavy refactorings on internal code structure with the creat
7676
- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
7777
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
7878
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
79-
- Refactor: Remove Style\Tabs
80-
- Refactor: Apply composite pattern for writers
81-
- Refactor: Split `AbstractContainer` from `AbstractElement`
82-
- Refactor: Apply composite pattern for Word2007 reader
79+
- Refactor: Remove Style\Tabs - @ivanlanin
80+
- Refactor: Apply composite pattern for writers - @ivanlanin
81+
- Refactor: Split `AbstractContainer` from `AbstractElement` - @ivanlanin
82+
- Refactor: Apply composite pattern for Word2007 reader - @ivanlanin
8383

8484
## 0.9.1 - 27 Mar 2014
8585

src/PhpWord/DocumentProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function getLastModifiedBy()
165165
*/
166166
public function setLastModifiedBy($value = '')
167167
{
168-
$this->lastModifiedBy = $this->setValue($value, '');
168+
$this->lastModifiedBy = $this->setValue($value, $this->creator);
169169

170170
return $this;
171171
}

src/PhpWord/Element/PreserveText.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ class PreserveText extends AbstractElement
4343
* Create a new Preserve Text Element
4444
*
4545
* @param string $text
46-
* @param mixed $styleFont
47-
* @param mixed $styleParagraph
46+
* @param mixed $fontStyle
47+
* @param mixed $paragraphStyle
4848
* @return $this
4949
*/
50-
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
50+
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
5151
{
52-
$this->fontStyle = $this->setStyle(new Font('text'), $styleFont);
53-
$this->paragraphStyle = $this->setStyle(new Paragraph(), $styleParagraph);
52+
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
53+
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
5454

5555
$matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5656
if (isset($matches[0])) {

src/PhpWord/Element/Section.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public function addPageBreak()
9393
/**
9494
* Add a Table-of-Contents Element
9595
*
96-
* @param mixed $styleFont
97-
* @param mixed $styleTOC
96+
* @param mixed $fontStyle
97+
* @param mixed $tocStyle
9898
* @param integer $minDepth
9999
* @param integer $maxDepth
100100
* @return \PhpOffice\PhpWord\Element\TOC
101101
*/
102-
public function addTOC($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
102+
public function addTOC($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
103103
{
104-
$toc = new TOC($styleFont, $styleTOC, $minDepth, $maxDepth);
104+
$toc = new TOC($fontStyle, $tocStyle, $minDepth, $maxDepth);
105105
$this->elements[] = $toc;
106106
return $toc;
107107
}

src/PhpWord/Element/TOC.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,29 @@ class TOC extends AbstractElement
5050
/**
5151
* Create a new Table-of-Contents Element
5252
*
53-
* @param mixed $styleFont
54-
* @param array $styleTOC
53+
* @param mixed $fontStyle
54+
* @param array $tocStyle
5555
* @param integer $minDepth
5656
* @param integer $maxDepth
5757
*/
58-
public function __construct($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
58+
public function __construct($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
5959
{
6060
$this->TOCStyle = new TOCStyle();
6161

62-
if (!is_null($styleTOC) && is_array($styleTOC)) {
63-
foreach ($styleTOC as $key => $value) {
62+
if (!is_null($tocStyle) && is_array($tocStyle)) {
63+
foreach ($tocStyle as $key => $value) {
6464
$this->TOCStyle->setStyleValue($key, $value);
6565
}
6666
}
6767

68-
if (!is_null($styleFont)) {
69-
if (is_array($styleFont)) {
68+
if (!is_null($fontStyle)) {
69+
if (is_array($fontStyle)) {
7070
$this->fontStyle = new Font();
71-
foreach ($styleFont as $key => $value) {
71+
foreach ($fontStyle as $key => $value) {
7272
$this->fontStyle->setStyleValue($key, $value);
7373
}
7474
} else {
75-
$this->fontStyle = $styleFont;
75+
$this->fontStyle = $fontStyle;
7676
}
7777
}
7878

src/PhpWord/PhpWord.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ public function addParagraphStyle($styleName, $styles)
171171
* Adds a font style definition to styles.xml
172172
*
173173
* @param string $styleName
174-
* @param mixed $styleFont
175-
* @param mixed $styleParagraph
174+
* @param mixed $fontStyle
175+
* @param mixed $paragraphStyle
176176
*/
177-
public function addFontStyle($styleName, $styleFont, $styleParagraph = null)
177+
public function addFontStyle($styleName, $fontStyle, $paragraphStyle = null)
178178
{
179-
Style::addFontStyle($styleName, $styleFont, $styleParagraph);
179+
Style::addFontStyle($styleName, $fontStyle, $paragraphStyle);
180180
}
181181

182182
/**
@@ -195,12 +195,12 @@ public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
195195
* Adds a heading style definition to styles.xml
196196
*
197197
* @param int $titleCount
198-
* @param mixed $styleFont
199-
* @param mixed $styleParagraph
198+
* @param mixed $fontStyle
199+
* @param mixed $paragraphStyle
200200
*/
201-
public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
201+
public function addTitleStyle($titleCount, $fontStyle, $paragraphStyle = null)
202202
{
203-
Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
203+
Style::addTitleStyle($titleCount, $fontStyle, $paragraphStyle);
204204
}
205205

206206
/**

src/PhpWord/Reader/ODText/AbstractPart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractP
2121
*
2222
* @param mixed $parent
2323
* @param string $docPart
24-
* @param mixed $pStyle
24+
* @param mixed $paragraphStyle
2525
*/
26-
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart, $pStyle = null)
26+
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart, $paragraphStyle = null)
2727
{
2828
}
2929

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,24 @@ public function setRels($value)
7272
* @param \DOMElement $domNode
7373
* @param mixed $parent
7474
* @param string $docPart
75-
* @param mixed $pStyle
75+
* @param mixed $paragraphStyle
7676
*
7777
* @todo Footnote paragraph style
7878
*/
79-
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart, $pStyle = null)
79+
protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart, $paragraphStyle = null)
8080
{
8181
if (!in_array($domNode->nodeName, array('w:r', 'w:hyperlink'))) {
8282
return;
8383
}
84-
$fStyle = $this->readFontStyle($xmlReader, $domNode);
84+
$fontStyle = $this->readFontStyle($xmlReader, $domNode);
8585

8686
// Link
8787
if ($domNode->nodeName == 'w:hyperlink') {
8888
$rId = $xmlReader->getAttribute('r:id', $domNode);
8989
$textContent = $xmlReader->getValue('w:r/w:t', $domNode);
9090
$target = $this->getMediaTarget($docPart, $rId);
9191
if (!is_null($target)) {
92-
$parent->addLink($target, $textContent, $fStyle, $pStyle);
92+
$parent->addLink($target, $textContent, $fontStyle, $paragraphStyle);
9393
}
9494
} else {
9595
// Footnote
@@ -116,13 +116,13 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, &$parent,
116116
$target = $this->getMediaTarget($docPart, $rId);
117117
if (!is_null($target)) {
118118
$textContent = "<Object: {$target}>";
119-
$parent->addText($textContent, $fStyle, $pStyle);
119+
$parent->addText($textContent, $fontStyle, $paragraphStyle);
120120
}
121121

122122
// TextRun
123123
} else {
124124
$textContent = $xmlReader->getValue('w:t', $domNode);
125-
$parent->addText($textContent, $fStyle, $pStyle);
125+
$parent->addText($textContent, $fontStyle, $paragraphStyle);
126126
}
127127
}
128128
}

src/PhpWord/Reader/Word2007/Document.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,20 @@ private function readHeaderFooter($settings, &$section)
121121
private function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$parent, $docPart)
122122
{
123123
// Paragraph style
124-
$pStyle = null;
124+
$paragraphStyle = null;
125125
$headingMatches = array();
126126
if ($xmlReader->elementExists('w:pPr', $domNode)) {
127-
$pStyle = $this->readParagraphStyle($xmlReader, $domNode);
128-
if (is_string($pStyle)) {
129-
preg_match('/Heading(\d)/', $pStyle, $headingMatches);
127+
$paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode);
128+
if (is_string($paragraphStyle)) {
129+
preg_match('/Heading(\d)/', $paragraphStyle, $headingMatches);
130130
}
131131
}
132132

133133
// PreserveText
134134
if ($xmlReader->elementExists('w:r/w:instrText', $domNode)) {
135135
$ignoreText = false;
136136
$textContent = '';
137-
$fStyle = $this->readFontStyle($xmlReader, $domNode);
137+
$fontStyle = $this->readFontStyle($xmlReader, $domNode);
138138
$nodes = $xmlReader->getElements('w:r', $domNode);
139139
foreach ($nodes as $node) {
140140
$instrText = $xmlReader->getValue('w:instrText', $node);
@@ -154,7 +154,7 @@ private function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$par
154154
}
155155
}
156156
}
157-
$parent->addPreserveText($textContent, $fStyle, $pStyle);
157+
$parent->addPreserveText($textContent, $fontStyle, $paragraphStyle);
158158

159159
// List item
160160
} elseif ($xmlReader->elementExists('w:pPr/w:numPr', $domNode)) {
@@ -165,7 +165,7 @@ private function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$par
165165
foreach ($nodes as $node) {
166166
$textContent .= $xmlReader->getValue('w:t', $node);
167167
}
168-
$parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $pStyle);
168+
$parent->addListItem($textContent, $levelId, null, "PHPWordList{$numId}", $paragraphStyle);
169169

170170
// Heading
171171
} elseif (!empty($headingMatches)) {
@@ -182,17 +182,17 @@ private function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, &$par
182182
$linkCount = $xmlReader->countElements('w:hyperlink', $domNode);
183183
$runLinkCount = $runCount + $linkCount;
184184
if ($runLinkCount == 0) {
185-
$parent->addTextBreak(null, $pStyle);
185+
$parent->addTextBreak(null, $paragraphStyle);
186186
} else {
187187
if ($runLinkCount > 1) {
188-
$textrun = $parent->addTextRun($pStyle);
188+
$textrun = $parent->addTextRun($paragraphStyle);
189189
$textParent = &$textrun;
190190
} else {
191191
$textParent = &$parent;
192192
}
193193
$nodes = $xmlReader->getElements('*', $domNode);
194194
foreach ($nodes as $node) {
195-
$this->readRun($xmlReader, $node, $textParent, $docPart, $pStyle);
195+
$this->readRun($xmlReader, $node, $textParent, $docPart, $paragraphStyle);
196196
}
197197
}
198198
}

src/PhpWord/Reader/Word2007/Styles.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,25 @@ public function read(PhpWord &$phpWord)
4040
switch ($type) {
4141

4242
case 'paragraph':
43-
$pStyle = $this->readParagraphStyle($xmlReader, $node);
44-
$fStyle = $this->readFontStyle($xmlReader, $node);
43+
$paragraphStyle = $this->readParagraphStyle($xmlReader, $node);
44+
$fontStyle = $this->readFontStyle($xmlReader, $node);
4545
if (!empty($headingMatches)) {
46-
$phpWord->addTitleStyle($headingMatches[1], $fStyle, $pStyle);
46+
$phpWord->addTitleStyle($headingMatches[1], $fontStyle, $paragraphStyle);
4747
} else {
48-
if (empty($fStyle)) {
49-
if (is_array($pStyle)) {
50-
$phpWord->addParagraphStyle($name, $pStyle);
48+
if (empty($fontStyle)) {
49+
if (is_array($paragraphStyle)) {
50+
$phpWord->addParagraphStyle($name, $paragraphStyle);
5151
}
5252
} else {
53-
$phpWord->addFontStyle($name, $fStyle, $pStyle);
53+
$phpWord->addFontStyle($name, $fontStyle, $paragraphStyle);
5454
}
5555
}
5656
break;
5757

5858
case 'character':
59-
$fStyle = $this->readFontStyle($xmlReader, $node);
60-
if (!empty($fStyle)) {
61-
$phpWord->addFontStyle($name, $fStyle);
59+
$fontStyle = $this->readFontStyle($xmlReader, $node);
60+
if (!empty($fontStyle)) {
61+
$phpWord->addFontStyle($name, $fontStyle);
6262
}
6363
break;
6464

src/PhpWord/Style.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public static function addParagraphStyle($styleName, $styles)
4141
* Add font style
4242
*
4343
* @param string $styleName
44-
* @param array $styleFont
45-
* @param array $styleParagraph
44+
* @param array $fontStyle
45+
* @param array $paragraphStyle
4646
*/
47-
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
47+
public static function addFontStyle($styleName, $fontStyle, $paragraphStyle = null)
4848
{
49-
self::setStyleValues($styleName, new Font('text', $styleParagraph), $styleFont);
49+
self::setStyleValues($styleName, new Font('text', $paragraphStyle), $fontStyle);
5050
}
5151

5252
/**
@@ -76,12 +76,12 @@ public static function addTableStyle($styleName, $styleTable, $styleFirstRow = n
7676
* Add title style
7777
*
7878
* @param int $titleCount
79-
* @param array $styleFont
80-
* @param array $styleParagraph
79+
* @param array $fontStyle
80+
* @param array $paragraphStyle
8181
*/
82-
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
82+
public static function addTitleStyle($titleCount, $fontStyle, $paragraphStyle = null)
8383
{
84-
self::setStyleValues("Heading_{$titleCount}", new Font('title', $styleParagraph), $styleFont);
84+
self::setStyleValues("Heading_{$titleCount}", new Font('title', $paragraphStyle), $fontStyle);
8585
}
8686

8787
/**

src/PhpWord/Writer/HTML/Element/Text.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,33 @@ public function write()
3030
{
3131
$html = '';
3232
// Paragraph style
33-
$pStyle = $this->element->getParagraphStyle();
34-
$pStyleIsObject = ($pStyle instanceof Paragraph);
35-
if ($pStyleIsObject) {
36-
$styleWriter = new ParagraphStyleWriter($pStyle);
37-
$pStyle = $styleWriter->write();
33+
$paragraphStyle = $this->element->getParagraphStyle();
34+
$paragraphStyleIsObject = ($paragraphStyle instanceof Paragraph);
35+
if ($paragraphStyleIsObject) {
36+
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
37+
$paragraphStyle = $styleWriter->write();
3838
}
3939
// Font style
40-
$fStyle = $this->element->getFontStyle();
41-
$fStyleIsObject = ($fStyle instanceof Font);
42-
if ($fStyleIsObject) {
43-
$styleWriter = new FontStyleWriter($fStyle);
44-
$fStyle = $styleWriter->write();
40+
$fontStyle = $this->element->getFontStyle();
41+
$fontStyleIsObject = ($fontStyle instanceof Font);
42+
if ($fontStyleIsObject) {
43+
$styleWriter = new FontStyleWriter($fontStyle);
44+
$fontStyle = $styleWriter->write();
4545
}
4646

47-
if ($pStyle && !$this->withoutP) {
48-
$attribute = $pStyleIsObject ? 'style' : 'class';
49-
$html .= "<p {$attribute}=\"{$pStyle}\">";
47+
if ($paragraphStyle && !$this->withoutP) {
48+
$attribute = $paragraphStyleIsObject ? 'style' : 'class';
49+
$html .= "<p {$attribute}=\"{$paragraphStyle}\">";
5050
}
51-
if ($fStyle) {
52-
$attribute = $fStyleIsObject ? 'style' : 'class';
53-
$html .= "<span {$attribute}=\"{$fStyle}\">";
51+
if ($fontStyle) {
52+
$attribute = $fontStyleIsObject ? 'style' : 'class';
53+
$html .= "<span {$attribute}=\"{$fontStyle}\">";
5454
}
5555
$html .= htmlspecialchars($this->element->getText());
56-
if ($fStyle) {
56+
if ($fontStyle) {
5757
$html .= '</span>';
5858
}
59-
if ($pStyle && !$this->withoutP) {
59+
if ($paragraphStyle && !$this->withoutP) {
6060
$html .= '</p>' . PHP_EOL;
6161
}
6262

0 commit comments

Comments
 (0)