Skip to content

Commit a87953a

Browse files
committed
Merge pull request #129 from ivanlanin/develop
Add TextBreak styling
2 parents 3a1a056 + 44d2501 commit a87953a

File tree

18 files changed

+296
-38
lines changed

18 files changed

+296
-38
lines changed

Classes/PHPWord/HashTable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
/**
2929
* PHPWord_HashTable
30+
*
31+
* @codeCoverageIgnore Legacy from PHPExcel
3032
*/
3133
class PHPWord_HashTable
3234
{

Classes/PHPWord/Section.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,14 @@ public function addLink($linkSrc, $linkName = null, $styleFont = null, $stylePar
156156
/**
157157
* Add a TextBreak Element
158158
*
159-
* @param int $count
159+
* @param int $count
160+
* @param null|string|array|PHPWord_Style_Font $fontStyle
161+
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle
160162
*/
161-
public function addTextBreak($count = 1)
163+
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
162164
{
163165
for ($i = 1; $i <= $count; $i++) {
164-
$this->_elementCollection[] = new PHPWord_Section_TextBreak();
166+
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
165167
}
166168
}
167169

Classes/PHPWord/Section/Footer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,16 @@ public function addText($text, $styleFont = null, $styleParagraph = null)
7979
}
8080

8181
/**
82-
* Add a TextBreak Element
82+
* Add TextBreak
8383
*
84-
* @param int $count
84+
* @param int $count
85+
* @param null|string|array|PHPWord_Style_Font $fontStyle
86+
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle
8587
*/
86-
public function addTextBreak($count = 1)
88+
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
8789
{
8890
for ($i = 1; $i <= $count; $i++) {
89-
$this->_elementCollection[] = new PHPWord_Section_TextBreak();
91+
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
9092
}
9193
}
9294

Classes/PHPWord/Section/Header.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@ public function addText($text, $styleFont = null, $styleParagraph = null)
108108
}
109109

110110
/**
111-
* Add a TextBreak Element
111+
* Add TextBreak
112112
*
113-
* @param int $count
113+
* @param int $count
114+
* @param null|string|array|PHPWord_Style_Font $fontStyle
115+
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle
114116
*/
115-
public function addTextBreak($count = 1)
117+
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
116118
{
117119
for ($i = 1; $i <= $count; $i++) {
118-
$this->_elementCollection[] = new PHPWord_Section_TextBreak();
120+
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
119121
}
120122
}
121123

Classes/PHPWord/Section/Table/Cell.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@ public function addLink($linkSrc, $linkName = null, $style = null)
146146
}
147147

148148
/**
149-
* Add a TextBreak Element
149+
* Add TextBreak
150150
*
151-
* @param int $count
151+
* @param int $count
152+
* @param null|string|array|PHPWord_Style_Font $fontStyle
153+
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle
152154
*/
153-
public function addTextBreak()
155+
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
154156
{
155-
$this->_elementCollection[] = new PHPWord_Section_TextBreak();
157+
for ($i = 1; $i <= $count; $i++) {
158+
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
159+
}
156160
}
157161

158162
/**

Classes/PHPWord/Section/TextBreak.php

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,91 @@
3030
*/
3131
class PHPWord_Section_TextBreak
3232
{
33+
/**
34+
* Paragraph style
35+
*
36+
* @var PHPWord_Style_Pagaraph
37+
*/
38+
private $paragraphStyle = null;
39+
40+
/**
41+
* Text style
42+
*
43+
* @var PHPWord_Style_Font
44+
*/
45+
private $fontStyle = null;
3346

3447
/**
3548
* Create a new TextBreak Element
3649
*/
37-
public function __construct()
50+
public function __construct($fontStyle = null, $paragraphStyle = null)
51+
{
52+
if (!is_null($paragraphStyle)) {
53+
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
54+
}
55+
if (!is_null($fontStyle)) {
56+
$this->setFontStyle($fontStyle, $paragraphStyle);
57+
}
58+
}
59+
60+
/**
61+
* Set Text style
62+
*
63+
* @param null|array|\PHPWord_Style_Font $style
64+
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle
65+
* @return PHPWord_Style_Font
66+
*/
67+
public function setFontStyle($style = null, $paragraphStyle = null)
68+
{
69+
if ($style instanceof PHPWord_Style_Font) {
70+
$this->fontStyle = $style;
71+
$this->setParagraphStyle($paragraphStyle);
72+
} elseif (is_array($style)) {
73+
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
74+
$this->fontStyle->setArrayStyle($style);
75+
} else {
76+
$this->fontStyle = $style;
77+
$this->setParagraphStyle($paragraphStyle);
78+
}
79+
return $this->fontStyle;
80+
}
81+
82+
/**
83+
* Get Text style
84+
*
85+
* @return PHPWord_Style_Font
86+
*/
87+
public function getFontStyle()
88+
{
89+
return $this->fontStyle;
90+
}
91+
92+
/**
93+
* Set Paragraph style
94+
*
95+
* @param null|array|\PHPWord_Style_Paragraph $style
96+
* @return null|\PHPWord_Style_Paragraph
97+
*/
98+
public function setParagraphStyle($style = null)
99+
{
100+
if (is_array($style)) {
101+
$this->paragraphStyle = new PHPWord_Style_Paragraph;
102+
$this->paragraphStyle->setArrayStyle($style);
103+
} elseif ($style instanceof PHPWord_Style_Paragraph) {
104+
$this->paragraphStyle = $style;
105+
} else {
106+
$this->paragraphStyle = $style;
107+
}
108+
return $this->paragraphStyle;
109+
}
110+
111+
/**
112+
* Get Paragraph style
113+
*
114+
* @return PHPWord_Style_Paragraph
115+
*/
116+
public function getParagraphStyle()
38117
{
118+
return $this->paragraphStyle;
39119
}
40120
}

Classes/PHPWord/Section/TextRun.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ public function addImage($imageSrc, $style = null)
132132
}
133133

134134
/**
135-
* Add a Text Break
135+
* Add TextBreak
136136
*
137-
* @param int $count
137+
* @param int $count
138+
* @param null|string|array|PHPWord_Style_Font $fontStyle
139+
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle
138140
*/
139-
public function addTextBreak($count = 1)
141+
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
140142
{
141-
for ($i=1; $i<=$count; $i++) {
142-
$this->_elementCollection[] = new PHPWord_Section_TextBreak();
143+
for ($i = 1; $i <= $count; $i++) {
144+
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
143145
}
144146
}
145147

Classes/PHPWord/Shared/ZipStreamWrapper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
* @version 0.7.0
2626
*/
2727

28-
/** Register new zip wrapper */
29-
PHPWord_Shared_ZipStreamWrapper::register();
30-
3128
/**
3229
* Class PHPWord_Shared_ZipStreamWrapper
30+
*
31+
* @codeCoverageIgnore Legacy from PHPExcel
3332
*/
3433
class PHPWord_Shared_ZipStreamWrapper
3534
{

Classes/PHPWord/Writer/ODText.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ public function save($pFilename = null)
141141
// Add META-INF/manifest.xml
142142
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_document));
143143

144-
// Add media
144+
// Add media. Has not used yet. Legacy from PHPExcel.
145+
// @codeCoverageIgnoreStart
145146
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
146147
if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
147148
$imageContents = null;

Classes/PHPWord/Writer/ODText/Manifest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public function writeManifest(PHPWord $pPHPWord = null)
7777
$objWriter->writeAttribute('manifest:full-path', 'styles.xml');
7878
$objWriter->endElement();
7979

80+
// Not used yet. Legacy from PHPExcel
81+
// @codeCoverageIgnoreStart
8082
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
8183
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
8284
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());

0 commit comments

Comments
 (0)