PHPWord/src/PhpWord/Style/Image.php

451 lines
9.7 KiB
PHP
Raw Normal View History

2012-05-06 18:25:40 +02:00
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
2012-05-06 18:25:40 +02:00
*
2014-03-27 23:55:06 +07:00
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
2012-05-06 18:25:40 +02:00
*/
namespace PhpOffice\PhpWord\Style;
/**
* Image and memory image style
*/
class Image extends AbstractStyle
{
/**
* Wrapping styles
*
* @const string
*/
2013-12-11 14:51:35 -05:00
const WRAPPING_STYLE_INLINE = 'inline';
const WRAPPING_STYLE_SQUARE = 'square';
const WRAPPING_STYLE_TIGHT = 'tight';
const WRAPPING_STYLE_BEHIND = 'behind';
const WRAPPING_STYLE_INFRONT = 'infront';
/**
* Horizontal alignment
*
* @const string
*/
const POSITION_HORIZONTAL_LEFT = 'left';
const POSITION_HORIZONTAL_CENTER = 'center';
const POSITION_HORIZONTAL_RIGHT = 'right';
2014-05-04 10:34:40 +02:00
/**
* Vertical alignment
*
* @const string
*/
const POSITION_VERTICAL_TOP = 'top';
const POSITION_VERTICAL_CENTER = 'center';
const POSITION_VERTICAL_BOTTOM = 'bottom';
const POSITION_VERTICAL_INSIDE = 'inside';
const POSITION_VERTICAL_OUTSIDE = 'outside';
2014-05-04 10:34:40 +02:00
/**
* Position relative to
*
* @const string
*/
const POSITION_RELATIVE_TO_MARGIN = 'margin';
const POSITION_RELATIVE_TO_PAGE = 'page';
const POSITION_RELATIVE_TO_COLUMN = 'column'; // horizontal only
const POSITION_RELATIVE_TO_CHAR = 'char'; // horizontal only
const POSITION_RELATIVE_TO_LINE = 'line'; // vertical only
const POSITION_RELATIVE_TO_LMARGIN = 'left-margin-area'; // horizontal only
const POSITION_RELATIVE_TO_RMARGIN = 'right-margin-area'; // horizontal only
const POSITION_RELATIVE_TO_TMARGIN = 'top-margin-area'; // vertical only
const POSITION_RELATIVE_TO_BMARGIN = 'bottom-margin-area'; // vertical only
const POSITION_RELATIVE_TO_IMARGIN = 'inner-margin-area';
const POSITION_RELATIVE_TO_OMARGIN = 'outer-margin-area';
/**
* Position type, relative/absolute
*
* @const string
*/
const POSITION_ABSOLUTE = 'absolute';
const POSITION_RELATIVE = 'relative';
2014-05-04 10:34:40 +02:00
2014-03-17 07:26:25 +07:00
/**
* Image width
*
* @var int
*/
private $width;
2014-03-17 07:26:25 +07:00
/**
* Image width
*
* @var int
*/
private $height;
2014-03-17 07:26:25 +07:00
/**
* Alignment
*
* @var \PhpOffice\PhpWord\Style\Alignment
2014-03-17 07:26:25 +07:00
*/
private $alignment;
2014-03-17 07:26:25 +07:00
/**
* Margin Top
*
* @var int
*/
private $marginTop;
/**
* Margin Left
*
* @var int
*/
private $marginLeft;
/**
* Wrapping style
*
* @var string
*/
2014-05-08 19:25:29 +07:00
private $wrappingStyle = self::WRAPPING_STYLE_INLINE;
/**
* Positioning type (relative or absolute)
*
* @var string
*/
private $positioning;
/**
* Horizontal alignment
*
* @var string
*/
2014-05-08 19:25:29 +07:00
private $posHorizontal = self::POSITION_HORIZONTAL_LEFT;
2014-05-04 10:34:40 +02:00
/**
* Horizontal Relation
*
* @var string
*/
2014-05-08 19:25:29 +07:00
private $posHorizontalRel = self::POSITION_RELATIVE_TO_CHAR;
2014-05-04 10:34:40 +02:00
/**
* Vertical alignment
*
* @var string
*/
2014-05-08 19:25:29 +07:00
private $posVertical = self::POSITION_VERTICAL_TOP;
2014-05-04 10:34:40 +02:00
/**
* Vertical Relation
*
* @var string
*/
2014-05-08 19:25:29 +07:00
private $posVerticalRel = self::POSITION_RELATIVE_TO_LINE;
/**
* Create new instance
*/
public function __construct()
{
$this->alignment = new Alignment();
}
2014-03-17 07:26:25 +07:00
/**
* Get width
*
* @return int
2014-03-17 07:26:25 +07:00
*/
public function getWidth()
{
return $this->width;
}
2014-03-17 07:26:25 +07:00
/**
* Set width
*
* @param int $value
* @return self
2014-03-17 07:26:25 +07:00
*/
public function setWidth($value = null)
{
$this->width = $value;
return $this;
}
2014-03-17 07:26:25 +07:00
/**
* Get height
*
* @return int
2014-03-17 07:26:25 +07:00
*/
public function getHeight()
{
return $this->height;
}
2014-03-17 07:26:25 +07:00
/**
* Set height
*
* @param int $value
* @return self
2014-03-17 07:26:25 +07:00
*/
public function setHeight($value = null)
{
$this->height = $value;
return $this;
}
2014-03-17 07:26:25 +07:00
/**
* Get alignment
*
* @return string
2014-03-17 07:26:25 +07:00
*/
public function getAlign()
{
return $this->alignment->getValue();
}
2014-03-17 07:26:25 +07:00
/**
* Set alignment
*
* @param string $value
* @return self
2014-03-17 07:26:25 +07:00
*/
public function setAlign($value = null)
{
$this->alignment->setValue($value);
return $this;
}
/**
* Get margin top
*
* @return int
*/
public function getMarginTop()
{
return $this->marginTop;
}
/**
* Set margin top
*
* @param int $value
* @return self
*/
public function setMarginTop($value = null)
{
$this->marginTop = $value;
return $this;
}
/**
* Get margin left
*
* @return int
*/
public function getMarginLeft()
{
return $this->marginLeft;
}
/**
* Set margin left
*
* @param int $value
* @return self
*/
public function setMarginLeft($value = null)
{
$this->marginLeft = $value;
return $this;
}
/**
* Get wrapping style
*
* @return string
*/
public function getWrappingStyle()
{
return $this->wrappingStyle;
}
2013-12-11 14:51:35 -05:00
/**
2014-03-17 07:26:25 +07:00
* Set wrapping style
*
* @param string $wrappingStyle
* @throws \InvalidArgumentException
* @return self
2013-12-11 14:51:35 -05:00
*/
public function setWrappingStyle($wrappingStyle)
{
2014-05-08 19:25:29 +07:00
$enum = array(
self::WRAPPING_STYLE_INLINE,
self::WRAPPING_STYLE_INFRONT, self::WRAPPING_STYLE_BEHIND,
self::WRAPPING_STYLE_SQUARE, self::WRAPPING_STYLE_TIGHT,
);
$this->wrappingStyle = $this->setEnumVal($wrappingStyle, $enum, $this->wrappingStyle);
2013-12-11 14:51:35 -05:00
return $this;
}
/**
* Get positioning type
2014-03-17 07:26:25 +07:00
*
2013-12-11 14:51:35 -05:00
* @return string
*/
public function getPositioning()
2013-12-11 14:51:35 -05:00
{
return $this->positioning;
2013-12-11 14:51:35 -05:00
}
/**
* Set positioning type
*
* @param string $positioning
* @throws \InvalidArgumentException
* @return self
*/
public function setPositioning($positioning)
{
$enum = array(self::POSITION_RELATIVE, self::POSITION_ABSOLUTE);
2014-05-08 19:25:29 +07:00
$this->positioning = $this->setEnumVal($positioning, $enum, $this->positioning);
2014-05-04 10:34:40 +02:00
return $this;
}
2014-05-04 10:34:40 +02:00
/**
* Get horizontal alignment
2014-05-04 10:34:40 +02:00
*
* @return string
*/
public function getPosHorizontal()
{
return $this->posHorizontal;
}
/**
* Set horizontal alignment
*
* @param string $alignment
* @throws \InvalidArgumentException
* @return self
*/
public function setPosHorizontal($alignment)
{
2014-05-08 19:25:29 +07:00
$enum = array(
self::POSITION_HORIZONTAL_LEFT, self::POSITION_HORIZONTAL_CENTER,
self::POSITION_HORIZONTAL_RIGHT,
);
$this->posHorizontal = $this->setEnumVal($alignment, $enum, $this->posHorizontal);
2014-05-04 10:34:40 +02:00
return $this;
}
2014-05-04 10:34:40 +02:00
/**
* Get vertical alignment
2014-05-04 10:34:40 +02:00
*
* @return string
*/
public function getPosVertical()
{
return $this->posVertical;
}
/**
* Set vertical alignment
*
* @param string $alignment
* @throws \InvalidArgumentException
* @return self
*/
public function setPosVertical($alignment)
{
2014-05-08 19:25:29 +07:00
$enum = array(
self::POSITION_VERTICAL_TOP, self::POSITION_VERTICAL_CENTER,
self::POSITION_VERTICAL_BOTTOM, self::POSITION_VERTICAL_INSIDE,
self::POSITION_VERTICAL_OUTSIDE,
);
$this->posVertical = $this->setEnumVal($alignment, $enum, $this->posVertical);
2014-05-04 10:34:40 +02:00
return $this;
}
2014-05-04 10:34:40 +02:00
/**
* Get horizontal relation
2014-05-04 10:34:40 +02:00
*
* @return string
*/
public function getPosHorizontalRel()
{
return $this->posHorizontalRel;
}
2014-05-04 10:34:40 +02:00
/**
* Set horizontal relation
*
* @param string $relto
* @throws \InvalidArgumentException
* @return self
*/
public function setPosHorizontalRel($relto)
{
2014-05-08 19:25:29 +07:00
$enum = array(
self::POSITION_RELATIVE_TO_MARGIN, self::POSITION_RELATIVE_TO_PAGE,
self::POSITION_RELATIVE_TO_COLUMN, self::POSITION_RELATIVE_TO_CHAR,
self::POSITION_RELATIVE_TO_LMARGIN, self::POSITION_RELATIVE_TO_RMARGIN,
2014-05-08 19:25:29 +07:00
self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN,
);
$this->posHorizontalRel = $this->setEnumVal($relto, $enum, $this->posHorizontalRel);
2014-05-04 10:34:40 +02:00
return $this;
}
2014-05-04 10:34:40 +02:00
/**
* Get vertical relation
2014-05-04 10:34:40 +02:00
*
* @return string
*/
public function getPosVerticalRel()
{
return $this->posVerticalRel;
}
2014-05-04 10:34:40 +02:00
/**
* Set vertical relation
*
* @param string $relto
* @throws \InvalidArgumentException
* @return self
*/
public function setPosVerticalRel($relto)
{
2014-05-08 19:25:29 +07:00
$enum = array(
self::POSITION_RELATIVE_TO_MARGIN, self::POSITION_RELATIVE_TO_PAGE,
self::POSITION_RELATIVE_TO_LINE,
self::POSITION_RELATIVE_TO_TMARGIN, self::POSITION_RELATIVE_TO_BMARGIN,
2014-05-08 19:25:29 +07:00
self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN,
);
$this->posVerticalRel = $this->setEnumVal($relto, $enum, $this->posVerticalRel);
2014-05-04 10:34:40 +02:00
return $this;
2013-12-11 14:51:35 -05:00
}
}