From 31a0fca0f1a51160f070521ec10d374f6bd5a721 Mon Sep 17 00:00:00 2001 From: Sergey Nezbritskiy Date: Tue, 5 Sep 2017 14:43:15 +0300 Subject: [PATCH] add new style elements --- src/AbstractElement.php | 114 ++++++++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 15 deletions(-) diff --git a/src/AbstractElement.php b/src/AbstractElement.php index 56c063f..e490aa7 100644 --- a/src/AbstractElement.php +++ b/src/AbstractElement.php @@ -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 */ @@ -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 @@ -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']); + } } /** @@ -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(); @@ -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; } /** @@ -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; + } + } + } \ No newline at end of file