Skip to content

Commit 626ea08

Browse files
committed
Merge pull request #86 from ivanlanin/develop
New features: (1) multicolumn section; (2) table width; (3) table row repeat as header & break across pages; (4) superscript & subscript font
2 parents 1f4a18d + 350e7a6 commit 626ea08

File tree

15 files changed

+535
-51
lines changed

15 files changed

+535
-51
lines changed

Classes/PHPWord.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
class PHPWord
4040
{
4141

42+
const DEFAULT_FONT_NAME = 'Arial';
43+
const DEFAULT_FONT_SIZE = 20;
44+
4245
/**
4346
* Document properties
4447
*
@@ -74,8 +77,8 @@ class PHPWord
7477
public function __construct()
7578
{
7679
$this->_properties = new PHPWord_DocumentProperties();
77-
$this->_defaultFontName = 'Arial';
78-
$this->_defaultFontSize = 20;
80+
$this->_defaultFontName = PHPWord::DEFAULT_FONT_NAME;
81+
$this->_defaultFontSize = PHPWord::DEFAULT_FONT_SIZE;
7982
}
8083

8184
/**

Classes/PHPWord/Section/Settings.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,34 @@ class PHPWord_Section_Settings
168168
*/
169169
private $footerHeight;
170170

171+
/**
172+
* Section columns count
173+
*
174+
* @var int
175+
*/
176+
private $_colsNum;
177+
178+
/**
179+
* Section spacing between columns
180+
*
181+
* @var int
182+
*/
183+
private $_colsSpace;
184+
185+
/**
186+
* Section break type
187+
*
188+
* Options:
189+
* - nextPage: Next page section break
190+
* - nextColumn: Column section break
191+
* - continuous: Continuous section break
192+
* - evenPage: Even page section break
193+
* - oddPage: Odd page section break
194+
*
195+
* @var string
196+
*/
197+
private $_breakType;
198+
171199
/**
172200
* Create new Section Settings
173201
*/
@@ -190,6 +218,9 @@ public function __construct()
190218
$this->_borderBottomColor = null;
191219
$this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches)
192220
$this->footerHeight = 720;
221+
$this->_colsNum = 1;
222+
$this->_colsSpace = 720;
223+
$this->_breakType = null;
193224
}
194225

195226
/**
@@ -618,4 +649,62 @@ public function setFooterHeight($pValue = '') {
618649
$this->footerHeight = $pValue;
619650
return $this;
620651
}
652+
653+
/**
654+
* Set Section Columns Count
655+
*
656+
* @param in $pValue
657+
*/
658+
public function setColsNum($pValue = '') {
659+
$this->_colsNum = $pValue;
660+
return $this;
661+
}
662+
663+
/**
664+
* Get Section Columns Count
665+
*
666+
* @return int
667+
*/
668+
public function getColsNum() {
669+
return $this->_colsNum;
670+
}
671+
672+
/**
673+
* Set Section Space Between Columns
674+
*
675+
* @param int $pValue
676+
*/
677+
public function setColsSpace($pValue = '') {
678+
$this->_colsSpace = $pValue;
679+
return $this;
680+
}
681+
682+
/**
683+
* Get Section Space Between Columns
684+
*
685+
* @return int
686+
*/
687+
public function getColsSpace() {
688+
return $this->_colsSpace;
689+
}
690+
691+
/**
692+
* Set Break Type
693+
*
694+
* @param string $pValue
695+
*/
696+
public function setBreakType($pValue = null) {
697+
$this->_breakType = $pValue;
698+
return $this;
699+
}
700+
701+
/**
702+
* Get Break Type
703+
*
704+
* @return string
705+
*/
706+
public function getBreakType() {
707+
return $this->_breakType;
708+
}
709+
621710
}

Classes/PHPWord/Section/Table.php

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ class PHPWord_Section_Table
4545
*/
4646
private $_rows = array();
4747

48-
/**
49-
* Row heights
50-
*
51-
* @var array
52-
*/
53-
private $_rowHeights = array();
54-
5548
/**
5649
* Table holder
5750
*
@@ -66,6 +59,13 @@ class PHPWord_Section_Table
6659
*/
6760
private $_pCount;
6861

62+
/**
63+
* Table width
64+
*
65+
* @var int
66+
*/
67+
private $_width = null;
68+
6969

7070
/**
7171
* Create a new table
@@ -100,10 +100,11 @@ public function __construct($insideOf, $pCount, $style = null)
100100
*
101101
* @param int $height
102102
*/
103-
public function addRow($height = null)
103+
public function addRow($height = null, $style = null)
104104
{
105-
$this->_rows[] = array();
106-
$this->_rowHeights[] = $height;
105+
$row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style);
106+
$this->_rows[] = $row;
107+
return $row;
107108
}
108109

109110
/**
@@ -113,11 +114,10 @@ public function addRow($height = null)
113114
* @param mixed $style
114115
* @return PHPWord_Section_Table_Cell
115116
*/
116-
public function addCell($width, $style = null)
117+
public function addCell($width = null, $style = null)
117118
{
118-
$cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style);
119119
$i = count($this->_rows) - 1;
120-
$this->_rows[$i][] = $cell;
120+
$cell = $this->_rows[$i]->addCell($width, $style);
121121
return $cell;
122122
}
123123

@@ -132,22 +132,33 @@ public function getRows()
132132
}
133133

134134
/**
135-
* Get all row heights
135+
* Get table style
136136
*
137-
* @return array
137+
* @return PHPWord_Style_Table
138138
*/
139-
public function getRowHeights()
139+
public function getStyle()
140140
{
141-
return $this->_rowHeights;
141+
return $this->_style;
142142
}
143143

144144
/**
145-
* Get table style
145+
* Set table width
146146
*
147-
* @return PHPWord_Style_Table
147+
* @var int $width
148148
*/
149-
public function getStyle()
149+
public function setWidth($width)
150150
{
151-
return $this->_style;
151+
$this->_width = $width;
152+
}
153+
154+
/**
155+
* Get table width
156+
*
157+
* @return int
158+
*/
159+
public function getWidth()
160+
{
161+
return $this->_width;
152162
}
163+
153164
}

Classes/PHPWord/Section/Table/Row.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* PHPWord
4+
*
5+
* Copyright (c) 2014 PHPWord
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* @category PHPWord
22+
* @package PHPWord
23+
* @copyright Copyright (c) 2013 PHPWord
24+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25+
* @version 0.7.0
26+
*/
27+
28+
/**
29+
* PHPWord_Section_Table_Row
30+
*/
31+
class PHPWord_Section_Table_Row
32+
{
33+
34+
/**
35+
* Row height
36+
*
37+
* @var int
38+
*/
39+
private $_height = null;
40+
41+
/**
42+
* Row style
43+
*
44+
* @var PHPWord_Style_Row
45+
*/
46+
private $_style;
47+
48+
/**
49+
* Row cells
50+
*
51+
* @var array
52+
*/
53+
private $_cells = array();
54+
55+
/**
56+
* Table holder
57+
*
58+
* @var string
59+
*/
60+
private $_insideOf;
61+
62+
/**
63+
* Section/Header/Footer count
64+
*
65+
* @var int
66+
*/
67+
private $_pCount;
68+
69+
70+
/**
71+
* Create a new table row
72+
*
73+
* @param string $insideOf
74+
* @param int $pCount
75+
* @param int $height
76+
* @param mixed $style
77+
*/
78+
public function __construct($insideOf, $pCount, $height = null, $style = null)
79+
{
80+
$this->_insideOf = $insideOf;
81+
$this->_pCount = $pCount;
82+
$this->_height = $height;
83+
$this->_style = new PHPWord_Style_Row();
84+
85+
if (!is_null($style)) {
86+
if (is_array($style)) {
87+
88+
foreach ($style as $key => $value) {
89+
if (substr($key, 0, 1) != '_') {
90+
$key = '_' . $key;
91+
}
92+
$this->_style->setStyleValue($key, $value);
93+
}
94+
}
95+
}
96+
}
97+
98+
/**
99+
* Add a cell
100+
*
101+
* @param int $width
102+
* @param mixed $style
103+
* @return PHPWord_Section_Table_Cell
104+
*/
105+
public function addCell($width = null, $style = null)
106+
{
107+
$cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style);
108+
$this->_cells[] = $cell;
109+
return $cell;
110+
}
111+
112+
/**
113+
* Get all cells
114+
*
115+
* @return array
116+
*/
117+
public function getCells()
118+
{
119+
return $this->_cells;
120+
}
121+
122+
/**
123+
* Get row style
124+
*
125+
* @return PHPWord_Style_Row
126+
*/
127+
public function getStyle()
128+
{
129+
return $this->_style;
130+
}
131+
132+
/**
133+
* Get row height
134+
*
135+
* @return int
136+
*/
137+
public function getHeight()
138+
{
139+
return $this->_height;
140+
}
141+
}

0 commit comments

Comments
 (0)