Skip to content

Commit e9c548e

Browse files
committed
Merge branch '#228-basjan-textbox' into develop
2 parents e0638f5 + 6a0bfe3 commit e9c548e

File tree

12 files changed

+968
-18
lines changed

12 files changed

+968
-18
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ script:
5252
## PHP Copy/Paste Detector
5353
- php phpcpd.phar src/ tests/ --verbose
5454
## PHP Mess Detector
55-
- phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
55+
#- phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
5656
## PHPLOC
5757
#- php phploc.phar src/
5858
## PHPUnit

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This release changed PHPWord license from LGPL 2.1 to LGPL 3.
1010

1111
- Image: Ability to define relative and absolute positioning - @basjan GH-217
1212
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin GH-219
13+
- TextBox: Ability to add textbox in section, header, and footer - @basjan @ivanlanin GH-228
1314

1415
### Bugfixes
1516

samples/Sample_25_TextBox.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
// New Word Document
5+
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
6+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
7+
8+
$section = $phpWord->addSection();
9+
$textbox = $section->addTextBox(array('align' => 'left', 'width' => 300, 'borderSize' => 1, 'borderColor' => '#FF0000'));
10+
$textbox->addText('Text box content ');
11+
$textbox->addText('with bold text', array('bold' => true));
12+
$textbox->addText(', ');
13+
$textbox->addLink('http://www.google.com', 'link');
14+
$textbox->addText(', and image ');
15+
$textbox->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
16+
$textbox->addText('.');
17+
18+
// Save file
19+
echo write($phpWord, basename(__FILE__, '.php'), $writers);
20+
if (!CLI) {
21+
include_once 'Sample_Footer.php';
22+
}

src/PhpWord/Element/AbstractContainer.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,23 @@ public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = n
295295
return $element;
296296
}
297297

298+
/**
299+
* Add textbox element
300+
*
301+
* @param mixed $style
302+
* @return \PhpOffice\PhpWord\Element\TextBox
303+
*/
304+
public function addTextBox($style = null)
305+
{
306+
$this->checkValidity('TextBox');
307+
308+
$textbox = new TextBox($style);
309+
$textbox->setDocPart($this->getDocPart(), $this->getDocPartId());
310+
$this->addElement($textbox);
311+
312+
return $textbox;
313+
}
314+
298315
/**
299316
* Check if a method is allowed for the current container
300317
*
@@ -304,7 +321,7 @@ public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = n
304321
private function checkValidity($method)
305322
{
306323
// Valid containers for each element
307-
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote');
324+
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote', 'endnote', 'textbox');
308325
$validContainers = array(
309326
'Text' => $allContainers,
310327
'Link' => $allContainers,
@@ -314,6 +331,7 @@ private function checkValidity($method)
314331
'TextRun' => array('section', 'header', 'footer', 'cell'),
315332
'ListItem' => array('section', 'header', 'footer', 'cell'),
316333
'CheckBox' => array('section', 'header', 'footer', 'cell'),
334+
'TextBox' => array('section', 'header', 'footer'),
317335
'Footnote' => array('section', 'textrun', 'cell'),
318336
'Endnote' => array('section', 'textrun', 'cell'),
319337
'PreserveText' => array('header', 'footer', 'cell'),
@@ -352,7 +370,7 @@ private function checkValidity($method)
352370
*/
353371
private function checkElementDocPart()
354372
{
355-
$isCellTextrun = in_array($this->container, array('cell', 'textrun'));
373+
$isCellTextrun = in_array($this->container, array('cell', 'textrun', 'textbox'));
356374
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
357375
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
358376
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');

src/PhpWord/Element/AbstractElement.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,14 @@
2828
abstract class AbstractElement
2929
{
3030
/**
31-
* This file is part of PHPWord - A pure PHP library for reading and writing
32-
* word processing documents.
33-
*
34-
* PHPWord is free software distributed under the terms of the GNU Lesser
35-
* General Public License version 3 as published by the Free Software Foundation.
36-
*
37-
* For the full copyright and license information, please read the LICENSE
38-
* file that was distributed with this source code. For the full list of
39-
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. object
31+
* PhpWord object
32+
*
33+
* @var \PhpOffice\PhpWord\PhpWord
4034
*/
4135
protected $phpWord;
4236

4337
/**
44-
* Container type section|header|footer|cell|textrun|footnote|endnote
38+
* Container type section|header|footer|cell|textrun|footnote|endnote|textbox
4539
*
4640
* @var string
4741
*/

src/PhpWord/Element/TextBox.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2014 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Element;
19+
20+
use PhpOffice\PhpWord\Style\TextBox as TextBoxStyle;
21+
22+
/**
23+
* Table element
24+
*/
25+
class TextBox extends AbstractContainer
26+
{
27+
/**
28+
* TextBox style
29+
*
30+
* @var \PhpOffice\PhpWord\Style\TextBox
31+
*/
32+
private $style;
33+
34+
/**
35+
* Create a new textbox
36+
*
37+
* @param string $docPart
38+
* @param integer $docPartId
39+
* @param mixed $style
40+
*/
41+
public function __construct($style = null)
42+
{
43+
$this->container = 'textbox';
44+
$this->style = $this->setStyle(new TextBoxStyle(), $style);
45+
}
46+
47+
/**
48+
* Get textbox style
49+
*
50+
* @return \PhpOffice\PhpWord\Style\TextBox
51+
*/
52+
public function getStyle()
53+
{
54+
return $this->style;
55+
}
56+
}

src/PhpWord/Style/TextBox.php

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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+
* @link https://github.com/PHPOffice/PHPWord
14+
* @copyright 2010-2014 PHPWord contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpWord\Style;
19+
20+
/**
21+
* TextBox style
22+
*/
23+
class TextBox extends Image
24+
{
25+
/**
26+
* margin top
27+
*
28+
* @var int
29+
*/
30+
private $innerMarginTop = null;
31+
32+
/**
33+
* margin left
34+
*
35+
* @var int
36+
*/
37+
private $innerMarginLeft = null;
38+
39+
/**
40+
* margin right
41+
*
42+
* @var int
43+
*/
44+
private $innerMarginRight = null;
45+
46+
/**
47+
* Cell margin bottom
48+
*
49+
* @var int
50+
*/
51+
private $innerMarginBottom = null;
52+
53+
/**
54+
* border size
55+
*
56+
* @var int
57+
*/
58+
private $borderSize = null;
59+
60+
/**
61+
* border color
62+
*
63+
* @var string
64+
*/
65+
private $borderColor;
66+
67+
/**
68+
* Set margin top
69+
*
70+
* @param int $value
71+
*/
72+
public function setInnerMarginTop($value = null)
73+
{
74+
$this->innerMarginTop = $value;
75+
}
76+
77+
/**
78+
* Get margin top
79+
*
80+
* @return int
81+
*/
82+
public function getInnerMarginTop()
83+
{
84+
return $this->innerMarginTop;
85+
}
86+
87+
/**
88+
* Set margin left
89+
*
90+
* @param int $value
91+
*/
92+
public function setInnerMarginLeft($value = null)
93+
{
94+
$this->innerMarginLeft = $value;
95+
}
96+
97+
/**
98+
* Get margin left
99+
*
100+
* @return int
101+
*/
102+
public function getInnerMarginLeft()
103+
{
104+
return $this->innerMarginLeft;
105+
}
106+
107+
/**
108+
* Set margin right
109+
*
110+
* @param int $value
111+
*/
112+
public function setInnerMarginRight($value = null)
113+
{
114+
$this->innerMarginRight = $value;
115+
}
116+
117+
/**
118+
* Get margin right
119+
*
120+
* @return int
121+
*/
122+
public function getInnerMarginRight()
123+
{
124+
return $this->innerMarginRight;
125+
}
126+
127+
/**
128+
* Set margin bottom
129+
*
130+
* @param int $value
131+
*/
132+
public function setInnerMarginBottom($value = null)
133+
{
134+
$this->innerMarginBottom = $value;
135+
}
136+
137+
/**
138+
* Get margin bottom
139+
*
140+
* @return int
141+
*/
142+
public function getInnerMarginBottom()
143+
{
144+
return $this->innerMarginBottom;
145+
}
146+
147+
/**
148+
* Set TLRB cell margin
149+
*
150+
* @param int $value Margin in twips
151+
*/
152+
public function setInnerMargin($value = null)
153+
{
154+
$this->setInnerMarginTop($value);
155+
$this->setInnerMarginLeft($value);
156+
$this->setInnerMarginRight($value);
157+
$this->setInnerMarginBottom($value);
158+
}
159+
160+
/**
161+
* Get cell margin
162+
*
163+
* @return int[]
164+
*/
165+
public function getInnerMargin()
166+
{
167+
return array($this->innerMarginLeft, $this->innerMarginTop, $this->innerMarginRight, $this->innerMarginBottom);
168+
}
169+
170+
/**
171+
* Set border size
172+
*
173+
* @param int $value Size in points
174+
*/
175+
public function setBorderSize($value = null)
176+
{
177+
$this->borderSize = $value;
178+
}
179+
180+
/**
181+
* Get border size
182+
*
183+
* @return int
184+
*/
185+
public function getBorderSize()
186+
{
187+
return $this->borderSize;
188+
}
189+
190+
/**
191+
* Set border color
192+
*
193+
* @param string $value
194+
*/
195+
public function setBorderColor($value = null)
196+
{
197+
$this->borderColor = $value;
198+
}
199+
200+
/**
201+
* Get border color
202+
*
203+
* @return string
204+
*/
205+
public function getBorderColor()
206+
{
207+
return $this->borderColor;
208+
}
209+
}

0 commit comments

Comments
 (0)