Skip to content

Commit 28f801b

Browse files
author
Roman Syroeshko
committed
1 parent 16495a0 commit 28f801b

File tree

7 files changed

+32
-93
lines changed

7 files changed

+32
-93
lines changed

docs/styles.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Paragraph
6363

6464
Available Paragraph style options:
6565

66-
- ``alignment``. Supports all alignment modes provided by third edition of ISO/IEC 29500 standard. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
66+
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
67+
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
6768
- ``basedOn``. Parent style.
6869
- ``hanging``. Hanging by how much.
6970
- ``indent``. Indent by how much.
@@ -84,7 +85,8 @@ Table
8485

8586
Available Table style options:
8687

87-
- ``alignment``. Supports all alignment modes provided by third edition of ISO/IEC 29500 standard. See ``\PhpOffice\PhpWord\SimpleType\JcTable`` class for the details.
88+
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
89+
See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` classes for the details.
8890
- ``bgColor``. Background color, e.g. '9966CC'.
8991
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
9092
- ``border(Top|Right|Bottom|Left)Size``. Border size in twips.
@@ -129,7 +131,8 @@ Numbering level
129131

130132
Available NumberingLevel style options:
131133

132-
- ``alignment``. Supports all alignment modes provided by third edition of ISO/IEC 29500 standard. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
134+
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
135+
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
133136
- ``font``. Font name.
134137
- ``format``. Numbering format bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter.
135138
- ``hanging``. See paragraph style.

src/PhpWord/SimpleType/Jc.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
/**
2323
* Horizontal Alignment Type.
2424
*
25+
* Introduced in 1st Edition of ECMA-376. Initially it was intended to align paragraphs and tables.
26+
* Since ISO/IEC-29500:2008 the type must not be used for table alignment.
27+
*
2528
* @since 0.13.0
2629
*
30+
* @see \PhpOffice\PhpWord\SimpleType\JcTable For table alignment modes available since ISO/IEC-29500:2008.
31+
*
2732
* @codeCoverageIgnore
2833
*/
2934
final class Jc
@@ -40,15 +45,24 @@ final class Jc
4045
const THAI_DISTRIBUTE = 'thaiDistribute';
4146

4247
/**
43-
* @deprecated 0.13.0 Use `START` instead.
48+
* Kept for compatibility with 1st edition of ECMA-376 standard.
49+
* Microsoft Word 2007 and WPS Writer 2016 still rely on it.
50+
*
51+
* @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `START` instead.
4452
*/
4553
const LEFT = 'left';
4654
/**
47-
* @deprecated 0.13.0 Use `END` instead.
55+
* Kept for compatibility with 1st edition of ECMA-376 standard.
56+
* Microsoft Word 2007 and WPS Writer 2016 still rely on it.
57+
*
58+
* @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `END` instead.
4859
*/
4960
const RIGHT = 'right';
5061
/**
51-
* @deprecated 0.13.0 Use `BOTH` instead.
62+
* Kept for compatibility with 1st edition of ECMA-376 standard.
63+
* Microsoft Word 2007 and WPS Writer 2016 still rely on it.
64+
*
65+
* @deprecated 0.13.0 For documents based on ISO/IEC 29500:2008 and later use `BOTH` instead.
5266
*/
5367
const JUSTIFY = 'justify';
5468

src/PhpWord/SimpleType/JcTable.php

+3-14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
/**
2323
* Table Alignment Type.
2424
*
25+
* Introduced in ISO/IEC-29500:2008.
26+
*
2527
* @since 0.13.0
2628
*
2729
* @codeCoverageIgnore
@@ -32,19 +34,6 @@ final class JcTable
3234
const CENTER = 'center';
3335
const END = 'end';
3436

35-
/**
36-
* @deprecated 0.13.0 Use `START` instead.
37-
*/
38-
const LEFT = 'left';
39-
/**
40-
* @deprecated 0.13.0 Use `END` instead.
41-
*/
42-
const RIGHT = 'right';
43-
/**
44-
* @deprecated 0.13.0 Use `CENTER` instead.
45-
*/
46-
const JUSTIFY = 'justify';
47-
4837
/**
4938
* @since 0.13.0
5039
*
@@ -55,7 +44,7 @@ final public static function getValidator()
5544
// todo: consider caching validator instances.
5645
return new InArray(
5746
array (
58-
'haystack' => array(self::START, self::CENTER, self::END, self::LEFT, self::RIGHT, self::JUSTIFY),
47+
'haystack' => array(self::START, self::CENTER, self::END),
5948
'strict' => InArray::COMPARE_STRICT,
6049
)
6150
);

src/PhpWord/Style/Frame.php

+1-18
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,7 @@ public function getAlignment()
201201
public function setAlignment($value)
202202
{
203203
if (Jc::getValidator()->isValid($value)) {
204-
$alignment = '';
205-
206-
switch ($value) {
207-
case Jc::LEFT:
208-
$alignment = Jc::START;
209-
break;
210-
case Jc::RIGHT:
211-
$alignment = Jc::END;
212-
break;
213-
case Jc::JUSTIFY:
214-
$alignment = Jc::BOTH;
215-
break;
216-
default:
217-
$alignment = $value;
218-
break;
219-
}
220-
221-
$this->alignment = $alignment;
204+
$this->alignment = $value;
222205
}
223206

224207
return $this;

src/PhpWord/Style/NumberingLevel.php

+1-18
Original file line numberDiff line numberDiff line change
@@ -299,24 +299,7 @@ public function getAlignment()
299299
public function setAlignment($value)
300300
{
301301
if (Jc::getValidator()->isValid($value)) {
302-
$alignment = '';
303-
304-
switch ($value) {
305-
case Jc::LEFT:
306-
$alignment = Jc::START;
307-
break;
308-
case Jc::RIGHT:
309-
$alignment = Jc::END;
310-
break;
311-
case Jc::JUSTIFY:
312-
$alignment = Jc::BOTH;
313-
break;
314-
default:
315-
$alignment = $value;
316-
break;
317-
}
318-
319-
$this->alignment = $alignment;
302+
$this->alignment = $value;
320303
}
321304

322305
return $this;

src/PhpWord/Style/Paragraph.php

+1-18
Original file line numberDiff line numberDiff line change
@@ -233,24 +233,7 @@ public function getAlignment()
233233
public function setAlignment($value)
234234
{
235235
if (Jc::getValidator()->isValid($value)) {
236-
$alignment = '';
237-
238-
switch ($value) {
239-
case Jc::LEFT:
240-
$alignment = Jc::START;
241-
break;
242-
case Jc::RIGHT:
243-
$alignment = Jc::END;
244-
break;
245-
case Jc::JUSTIFY:
246-
$alignment = Jc::BOTH;
247-
break;
248-
default:
249-
$alignment = $value;
250-
break;
251-
}
252-
253-
$this->alignment = $alignment;
236+
$this->alignment = $value;
254237
}
255238

256239
return $this;

src/PhpWord/Style/Table.php

+3-19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord\Style;
1919

20+
use PhpOffice\PhpWord\SimpleType\Jc;
2021
use PhpOffice\PhpWord\SimpleType\JcTable;
2122

2223
class Table extends Border
@@ -509,25 +510,8 @@ public function getAlignment()
509510
*/
510511
public function setAlignment($value)
511512
{
512-
if (JcTable::getValidator()->isValid($value)) {
513-
$alignment = '';
514-
515-
switch ($value) {
516-
case JcTable::LEFT:
517-
$alignment = JcTable::START;
518-
break;
519-
case JcTable::RIGHT:
520-
$alignment = JcTable::END;
521-
break;
522-
case JcTable::JUSTIFY:
523-
$alignment = JcTable::CENTER;
524-
break;
525-
default:
526-
$alignment = $value;
527-
break;
528-
}
529-
530-
$this->alignment = $alignment;
513+
if (JcTable::getValidator()->isValid($value) || Jc::getValidator()->isValid($value)) {
514+
$this->alignment = $value;
531515
}
532516

533517
return $this;

0 commit comments

Comments
 (0)