Skip to content

Commit e613e13

Browse files
committed
New Indentation and Spacing style; Ability to define first line and right indentation
1 parent 999a9c5 commit e613e13

File tree

14 files changed

+680
-294
lines changed

14 files changed

+680
-294
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
44

55
## 0.10.0 - Not yet released
66

7-
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML and PDF writing support is enabled.
7+
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML and PDF writing support is enabled. Basic ODText reader is introduced.
88

99
### Features
1010

@@ -43,6 +43,8 @@ This release marked heavy refactorings on internal code structure with the creat
4343
- Font: Small caps, all caps, and double strikethrough - @ivanlanin GH-151
4444
- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin GH-199
4545
- Style: Remove `bgColor` from `Font`, `Table`, and `Cell` and put it into the new `Shading` style - @ivanlanin
46+
- Style: New `Indentation` and `Spacing` style - @ivanlanin
47+
- Paragraph: Ability to define first line and right indentation - @ivanlanin
4648

4749
### Bugfixes
4850

@@ -63,6 +65,7 @@ This release marked heavy refactorings on internal code structure with the creat
6365
- All current methods on `Media`
6466
- `Element\Link::getLinkSrc` replaced by `Element\Link::getTarget`
6567
- `Element\Link::getLinkName` replaced by `Element\Link::getText`
68+
- `Style\Cell::getDefaultBorderColor`
6669

6770
### Miscellaneous
6871

samples/Sample_08_ParagraphPagination.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@
1616
$section->addText('Below are the samples on how to control your paragraph ' .
1717
'pagination. See "Line and Page Break" tab on paragraph properties ' .
1818
'window to see the attribute set by these controls.',
19-
array('bold' => true), null);
19+
array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
2020

2121
$section->addText('Paragraph with widowControl = false (default: true). ' .
2222
'A "widow" is the last line of a paragraph printed by itself at the top ' .
2323
'of a page. An "orphan" is the first line of a paragraph printed by ' .
2424
'itself at the bottom of a page. Set this option to "false" if you want ' .
2525
'to disable this automatic control.',
26-
null, array('widowControl' => false));
26+
null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
2727

2828
$section->addText('Paragraph with keepNext = true (default: false). ' .
2929
'"Keep with next" is used to prevent Word from inserting automatic page ' .
3030
'breaks between paragraphs. Set this option to "true" if you do not want ' .
3131
'your paragraph to be separated with the next paragraph.',
32-
null, array('keepNext' => true));
32+
null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
3333

3434
$section->addText('Paragraph with keepLines = true (default: false). ' .
3535
'"Keep lines together" will prevent Word from inserting an automatic page ' .
3636
'break within a paragraph. Set this option to "true" if you do not want ' .
3737
'all lines of your paragraph to be in the same page.',
38-
null, array('keepLines' => true));
38+
null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
3939

4040
$section->addText('Keep scrolling. More below.');
4141

src/PhpWord/Settings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Settings
3737
* Applied to:
3838
* - Section: margins, header/footer height, gutter, column spacing
3939
* - Tab: position
40+
* - Indentation: left, right, firstLine, hanging
41+
* - Spacing: before, after
4042
*
4143
* @const int|float
4244
*/

src/PhpWord/Style/Cell.php

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,34 @@
1616
*/
1717
class Cell extends Border
1818
{
19+
/**
20+
* Text direction constants
21+
*
22+
* @const string
23+
*/
1924
const TEXT_DIR_BTLR = 'btLr';
2025
const TEXT_DIR_TBRL = 'tbRl';
2126

2227
/**
23-
* Vertical align (top, center, both, bottom)
28+
* Default border color
2429
*
25-
* @var string
30+
* @const string
2631
*/
27-
private $valign;
32+
const DEFAULT_BORDER_COLOR = '000000';
2833

2934
/**
30-
* Text Direction
35+
* Vertical align (top, center, both, bottom)
3136
*
3237
* @var string
3338
*/
34-
private $textDirection;
39+
private $valign;
3540

3641
/**
37-
* Border Default Color
42+
* Text Direction
3843
*
3944
* @var string
4045
*/
41-
private $defaultBorderColor;
46+
private $textDirection;
4247

4348
/**
4449
* colspan
@@ -64,24 +69,6 @@ class Cell extends Border
6469
*/
6570
private $shading;
6671

67-
/**
68-
* Create a new Cell Style
69-
*/
70-
public function __construct()
71-
{
72-
$this->valign = null;
73-
$this->textDirection = null;
74-
$this->borderTopSize = null;
75-
$this->borderTopColor = null;
76-
$this->borderLeftSize = null;
77-
$this->borderLeftColor = null;
78-
$this->borderRightSize = null;
79-
$this->borderRightColor = null;
80-
$this->borderBottomSize = null;
81-
$this->borderBottomColor = null;
82-
$this->defaultBorderColor = '000000';
83-
}
84-
8572
/**
8673
* Get vertical align
8774
*/
@@ -93,11 +80,11 @@ public function getVAlign()
9380
/**
9481
* Set vertical align
9582
*
96-
* @param string $pValue
83+
* @param string $value
9784
*/
98-
public function setVAlign($pValue = null)
85+
public function setVAlign($value = null)
9986
{
100-
$this->valign = $pValue;
87+
$this->valign = $value;
10188
}
10289

10390
/**
@@ -111,11 +98,11 @@ public function getTextDirection()
11198
/**
11299
* Set text direction
113100
*
114-
* @param string $pValue
101+
* @param string $value
115102
*/
116-
public function setTextDirection($pValue = null)
103+
public function setTextDirection($value = null)
117104
{
118-
$this->textDirection = $pValue;
105+
$this->textDirection = $value;
119106
}
120107

121108
/**
@@ -134,29 +121,21 @@ public function getBgColor()
134121
* Set background
135122
*
136123
* @param string $value
137-
* @return \PhpOffice\PhpWord\Style\Table
124+
* @return self
138125
*/
139126
public function setBgColor($value = null)
140127
{
141-
$this->setShading(array('fill' => $value));
142-
}
143-
144-
/**
145-
* Get default border color
146-
*/
147-
public function getDefaultBorderColor()
148-
{
149-
return $this->defaultBorderColor;
128+
return $this->setShading(array('fill' => $value));
150129
}
151130

152131
/**
153132
* Set grid span (colspan)
154133
*
155-
* @param int $pValue
134+
* @param int $value
156135
*/
157-
public function setGridSpan($pValue = null)
136+
public function setGridSpan($value = null)
158137
{
159-
$this->gridSpan = $pValue;
138+
$this->gridSpan = $value;
160139
}
161140

162141
/**
@@ -170,11 +149,11 @@ public function getGridSpan()
170149
/**
171150
* Set vertical merge (rowspan)
172151
*
173-
* @param string $pValue
152+
* @param string $value
174153
*/
175-
public function setVMerge($pValue = null)
154+
public function setVMerge($value = null)
176155
{
177-
$this->vMerge = $pValue;
156+
$this->vMerge = $value;
178157
}
179158

180159
/**
@@ -214,4 +193,15 @@ public function setShading($value = null)
214193

215194
return $this;
216195
}
196+
197+
/**
198+
* Get default border color
199+
*
200+
* @deprecated 0.10.0
201+
* @codeCoverageIgnore
202+
*/
203+
public function getDefaultBorderColor()
204+
{
205+
return self::DEFAULT_BORDER_COLOR;
206+
}
217207
}

src/PhpWord/Style/Indentation.php

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
/**
3+
* PHPWord
4+
*
5+
* @link https://github.com/PHPOffice/PHPWord
6+
* @copyright 2014 PHPWord
7+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
8+
*/
9+
10+
namespace PhpOffice\PhpWord\Style;
11+
12+
/**
13+
* Paragraph indentation style
14+
*
15+
* @link http://www.schemacentral.com/sc/ooxml/t-w_CT_Ind.html
16+
* @since 0.10.0
17+
*/
18+
class Indentation extends AbstractStyle
19+
{
20+
/**
21+
* Left indentation (twip)
22+
*
23+
* @var int|float
24+
*/
25+
private $left = 0;
26+
27+
/**
28+
* Right indentation (twip)
29+
*
30+
* @var int|float
31+
*/
32+
private $right = 0;
33+
34+
/**
35+
* Additional first line indentation (twip)
36+
*
37+
* @var int|float
38+
*/
39+
private $firstLine;
40+
41+
/**
42+
* Indentation removed from first line (twip)
43+
*
44+
* @var int|float
45+
*/
46+
private $hanging;
47+
48+
/**
49+
* Create a new instance
50+
*
51+
* @param array $style
52+
*/
53+
public function __construct($style = array())
54+
{
55+
$this->setStyleByArray($style);
56+
}
57+
58+
/**
59+
* Get left
60+
*
61+
* @return int|float
62+
*/
63+
public function getLeft()
64+
{
65+
return $this->left;
66+
}
67+
68+
/**
69+
* Set left
70+
*
71+
* @param int|float $value
72+
* @return self
73+
*/
74+
public function setLeft($value = null)
75+
{
76+
$this->left = $this->setNumericVal($value, $this->left);
77+
78+
return $this;
79+
}
80+
81+
/**
82+
* Get right
83+
*
84+
* @return int|float
85+
*/
86+
public function getRight()
87+
{
88+
return $this->right;
89+
}
90+
91+
/**
92+
* Set right
93+
*
94+
* @param int|float $value
95+
* @return self
96+
*/
97+
public function setRight($value = null)
98+
{
99+
$this->right = $this->setNumericVal($value, $this->right);
100+
101+
return $this;
102+
}
103+
104+
/**
105+
* Get first line
106+
*
107+
* @return int|float
108+
*/
109+
public function getFirstLine()
110+
{
111+
return $this->firstLine;
112+
}
113+
114+
/**
115+
* Set first line
116+
*
117+
* @param int|float $value
118+
* @return self
119+
*/
120+
public function setFirstLine($value = null)
121+
{
122+
$this->firstLine = $this->setNumericVal($value, $this->firstLine);
123+
124+
return $this;
125+
}
126+
127+
/**
128+
* Get hanging
129+
*
130+
* @return int|float
131+
*/
132+
public function getHanging()
133+
{
134+
return $this->hanging;
135+
}
136+
137+
/**
138+
* Set hanging
139+
*
140+
* @param int|float $value
141+
* @return self
142+
*/
143+
public function setHanging($value = null)
144+
{
145+
$this->hanging = $this->setNumericVal($value, $this->hanging);
146+
147+
return $this;
148+
}
149+
}

0 commit comments

Comments
 (0)