Skip to content

Commit dcb837d

Browse files
committed
Text direction for Alignment. Writer support only for table cells.
1 parent 6f9a066 commit dcb837d

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/PhpPresentation/Style/Alignment.php

+40
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class Alignment implements ComparableInterface
3939
const VERTICAL_TOP = 't';
4040
const VERTICAL_CENTER = 'ctr';
4141

42+
/* Text directions */
43+
const TEXT_DIRECTION_HORIZONTAL = 'horz';
44+
const TEXT_DIRECTION_VERTICAL_90 = 'vert';
45+
const TEXT_DIRECTION_VERTICAL_270 = 'vert270';
46+
const TEXT_DIRECTION_STACKED = 'wordArtVert';
47+
4248
/**
4349
* Horizontal
4450
*
@@ -53,6 +59,13 @@ class Alignment implements ComparableInterface
5359
*/
5460
private $vertical;
5561

62+
/**
63+
* Text direction - only possible on table cells
64+
*
65+
* @var string
66+
*/
67+
private $textDirection;
68+
5669
/**
5770
* Level
5871
*
@@ -96,6 +109,7 @@ public function __construct()
96109
// Initialise values
97110
$this->horizontal = self::HORIZONTAL_LEFT;
98111
$this->vertical = self::VERTICAL_BASE;
112+
$this->textDirection = self::TEXT_DIRECTION_HORIZONTAL;
99113
$this->level = 0;
100114
$this->indent = 0;
101115
$this->marginLeft = 0;
@@ -154,6 +168,32 @@ public function setVertical($pValue = self::VERTICAL_BASE)
154168
return $this;
155169
}
156170

171+
/**
172+
* Get text direction
173+
*
174+
* @return string
175+
*/
176+
public function getTextDirection()
177+
{
178+
return $this->textDirection;
179+
}
180+
181+
/**
182+
* Set text direction
183+
*
184+
* @param string $pValue
185+
* @return \PhpOffice\PhpPresentation\Style\Alignment
186+
*/
187+
public function setTextDirection($pValue = self::TEXT_DIRECTION_HORIZONTAL)
188+
{
189+
if ($pValue == '') {
190+
$pValue = self::TEXT_DIRECTION_HORIZONTAL;
191+
}
192+
$this->textDirection = $pValue;
193+
194+
return $this;
195+
}
196+
157197
/**
158198
* Get Level
159199
*

src/PhpPresentation/Writer/PowerPoint2007/Slide.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,13 @@ private function writeShapeTable(XMLWriter $objWriter, Table $shape, $shapeId)
739739

740740
// a:tcPr
741741
$objWriter->startElement('a:tcPr');
742-
// Alignment (horizontal)
743742
$firstParagraph = $currentCell->getParagraph(0);
743+
// Text direction
744+
$textDirection = $firstParagraph->getAlignment()->getTextDirection();
745+
if ($textDirection != Alignment::TEXT_DIRECTION_HORIZONTAL) {
746+
$objWriter->writeAttribute('vert', $textDirection);
747+
}
748+
// Alignment (horizontal)
744749
$verticalAlign = $firstParagraph->getAlignment()->getVertical();
745750
if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) {
746751
$objWriter->writeAttribute('anchor', $verticalAlign);

0 commit comments

Comments
 (0)