Skip to content

Commit

Permalink
Text direction for Alignment. Writer support only for table cells.
Browse files Browse the repository at this point in the history
  • Loading branch information
SeregPie committed Jan 25, 2016
1 parent 6f9a066 commit dcb837d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/PhpPresentation/Style/Alignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class Alignment implements ComparableInterface
const VERTICAL_TOP = 't';
const VERTICAL_CENTER = 'ctr';

/* Text directions */
const TEXT_DIRECTION_HORIZONTAL = 'horz';
const TEXT_DIRECTION_VERTICAL_90 = 'vert';
const TEXT_DIRECTION_VERTICAL_270 = 'vert270';
const TEXT_DIRECTION_STACKED = 'wordArtVert';

/**
* Horizontal
*
Expand All @@ -53,6 +59,13 @@ class Alignment implements ComparableInterface
*/
private $vertical;

/**
* Text direction - only possible on table cells
*
* @var string
*/
private $textDirection;

/**
* Level
*
Expand Down Expand Up @@ -96,6 +109,7 @@ public function __construct()
// Initialise values
$this->horizontal = self::HORIZONTAL_LEFT;
$this->vertical = self::VERTICAL_BASE;
$this->textDirection = self::TEXT_DIRECTION_HORIZONTAL;
$this->level = 0;
$this->indent = 0;
$this->marginLeft = 0;
Expand Down Expand Up @@ -154,6 +168,32 @@ public function setVertical($pValue = self::VERTICAL_BASE)
return $this;
}

/**
* Get text direction
*
* @return string
*/
public function getTextDirection()
{
return $this->textDirection;
}

/**
* Set text direction
*
* @param string $pValue
* @return \PhpOffice\PhpPresentation\Style\Alignment
*/
public function setTextDirection($pValue = self::TEXT_DIRECTION_HORIZONTAL)
{
if ($pValue == '') {
$pValue = self::TEXT_DIRECTION_HORIZONTAL;
}
$this->textDirection = $pValue;

return $this;
}

/**
* Get Level
*
Expand Down
7 changes: 6 additions & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/Slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,13 @@ private function writeShapeTable(XMLWriter $objWriter, Table $shape, $shapeId)

// a:tcPr
$objWriter->startElement('a:tcPr');
// Alignment (horizontal)
$firstParagraph = $currentCell->getParagraph(0);
// Text direction
$textDirection = $firstParagraph->getAlignment()->getTextDirection();
if ($textDirection != Alignment::TEXT_DIRECTION_HORIZONTAL) {
$objWriter->writeAttribute('vert', $textDirection);
}
// Alignment (horizontal)
$verticalAlign = $firstParagraph->getAlignment()->getVertical();
if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) {
$objWriter->writeAttribute('anchor', $verticalAlign);
Expand Down

0 comments on commit dcb837d

Please sign in to comment.