Skip to content

Commit

Permalink
add new style elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Nezbritskiy committed Sep 5, 2017
1 parent cd450a4 commit 31a0fca
Showing 1 changed file with 99 additions and 15 deletions.
114 changes: 99 additions & 15 deletions src/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ abstract class AbstractElement
const CENTER = 4;
const MIDDLE = 5;

const CONTENT_TYPE_TEXT = 'text';
const CONTENT_TYPE_IMAGE = 'image';

/**
* @var Zend_Pdf_Color_Rgb
*/
Expand Down Expand Up @@ -67,6 +70,21 @@ abstract class AbstractElement
*/
protected $textAlign;

/**
* @var string
*/
protected $contentType;

/**
* @var int
*/
protected $contentWidth;

/**
* @var int
*/
protected $contentHeight;

/**
* Options array example
* ```php
Expand Down Expand Up @@ -166,6 +184,15 @@ public function setStyles(array $options)
if (isset($options['text_align'])) {
$this->setTextAlign($options['text_align']);
}
if (isset($options['content_type'])) {
$this->setContentType($options['content_type']);
}
if (isset($options['content_width'])) {
$this->setContentWidth($options['content_width']);
}
if (isset($options['content_height'])) {
$this->setContentHeight($options['content_height']);
}
}

/**
Expand All @@ -189,6 +216,15 @@ public function getStyles()
if ($this->getTextAlign() !== null) {
$result['text_align'] = $this->getTextAlign();
}
if ($this->getContentType() !== null) {
$result['content_type'] = $this->getContentType();
}
if ($this->getContentWidth() !== null) {
$result['content_width'] = $this->getContentWidth();
}
if ($this->getContentHeight() !== null) {
$result['content_height'] = $this->getContentHeight();
}
$result['borders'] = $this->getBorderStyles();
$result['paddings'] = $this->getPaddings();
$result['margins'] = $this->getMargins();
Expand Down Expand Up @@ -402,23 +438,51 @@ public function setMargin($position, $margin)
}

/**
* @param $style
* @return \Zend_Pdf_Style
* @return string
*/
private function ensureLineStyle($style)
public function getContentType()
{
if ($style instanceof Zend_Pdf_Style) {
return $style;
} else {
$result = new \Zend_Pdf_Style();
if (isset($style['line_color'])) {
$result->setLineColor($this->rgbArrayToColor($style['line_color']));
}
if (isset($style['line_width'])) {
$result->setLineWidth($style['line_width']);
}
return $result;
}
return $this->contentType;
}

/**
* @param string $contentType
*/
public function setContentType($contentType)
{
$this->contentType = $contentType;
}

/**
* @return int
*/
public function getContentWidth()
{
return $this->contentWidth;
}

/**
* @param int $contentWidth
*/
public function setContentWidth($contentWidth)
{
$this->contentWidth = $contentWidth;
}

/**
* @return int
*/
public function getContentHeight()
{
return $this->contentHeight;
}

/**
* @param int $contentHeight
*/
public function setContentHeight($contentHeight)
{
$this->contentHeight = $contentHeight;
}

/**
Expand Down Expand Up @@ -452,4 +516,24 @@ protected function rgbArrayToColor(array $color)
);
}

/**
* @param $style
* @return \Zend_Pdf_Style
*/
private function ensureLineStyle($style)
{
if ($style instanceof Zend_Pdf_Style) {
return $style;
} else {
$result = new \Zend_Pdf_Style();
if (isset($style['line_color'])) {
$result->setLineColor($this->rgbArrayToColor($style['line_color']));
}
if (isset($style['line_width'])) {
$result->setLineWidth($style['line_width']);
}
return $result;
}
}

}

0 comments on commit 31a0fca

Please sign in to comment.