Move `addTextBox` to `AbstractContainer` and add sample for textbox
This commit is contained in:
parent
c7a940cc4c
commit
6a0bfe3314
|
|
@ -52,7 +52,7 @@ script:
|
||||||
## PHP Copy/Paste Detector
|
## PHP Copy/Paste Detector
|
||||||
- php phpcpd.phar src/ tests/ --verbose
|
- php phpcpd.phar src/ tests/ --verbose
|
||||||
## PHP Mess Detector
|
## PHP Mess Detector
|
||||||
- phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
|
#- phpmd src/,tests/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
|
||||||
## PHPLOC
|
## PHPLOC
|
||||||
#- php phploc.phar src/
|
#- php phploc.phar src/
|
||||||
## PHPUnit
|
## PHPUnit
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ This release changed PHPWord license from LGPL 2.1 to LGPL 3.
|
||||||
|
|
||||||
- Image: Ability to define relative and absolute positioning - @basjan GH-217
|
- Image: Ability to define relative and absolute positioning - @basjan GH-217
|
||||||
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin GH-219
|
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin GH-219
|
||||||
|
- TextBox: Ability to add textbox in section, header, and footer - @basjan @ivanlanin GH-228
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// New Word Document
|
||||||
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$textbox = $section->addTextBox(array('align' => 'left', 'width' => 300, 'borderSize' => 1, 'borderColor' => '#FF0000'));
|
||||||
|
$textbox->addText('Text box content ');
|
||||||
|
$textbox->addText('with bold text', array('bold' => true));
|
||||||
|
$textbox->addText(', ');
|
||||||
|
$textbox->addLink('http://www.google.com', 'link');
|
||||||
|
$textbox->addText(', and image ');
|
||||||
|
$textbox->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||||
|
$textbox->addText('.');
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
|
|
@ -295,6 +295,23 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add textbox element
|
||||||
|
*
|
||||||
|
* @param mixed $style
|
||||||
|
* @return \PhpOffice\PhpWord\Element\TextBox
|
||||||
|
*/
|
||||||
|
public function addTextBox($style = null)
|
||||||
|
{
|
||||||
|
$this->checkValidity('TextBox');
|
||||||
|
|
||||||
|
$textbox = new TextBox($style);
|
||||||
|
$textbox->setDocPart($this->getDocPart(), $this->getDocPartId());
|
||||||
|
$this->addElement($textbox);
|
||||||
|
|
||||||
|
return $textbox;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a method is allowed for the current container
|
* Check if a method is allowed for the current container
|
||||||
*
|
*
|
||||||
|
|
@ -314,6 +331,7 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
'TextRun' => array('section', 'header', 'footer', 'cell'),
|
'TextRun' => array('section', 'header', 'footer', 'cell'),
|
||||||
'ListItem' => array('section', 'header', 'footer', 'cell'),
|
'ListItem' => array('section', 'header', 'footer', 'cell'),
|
||||||
'CheckBox' => array('section', 'header', 'footer', 'cell'),
|
'CheckBox' => array('section', 'header', 'footer', 'cell'),
|
||||||
|
'TextBox' => array('section', 'header', 'footer'),
|
||||||
'Footnote' => array('section', 'textrun', 'cell'),
|
'Footnote' => array('section', 'textrun', 'cell'),
|
||||||
'Endnote' => array('section', 'textrun', 'cell'),
|
'Endnote' => array('section', 'textrun', 'cell'),
|
||||||
'PreserveText' => array('header', 'footer', 'cell'),
|
'PreserveText' => array('header', 'footer', 'cell'),
|
||||||
|
|
@ -352,7 +370,7 @@ abstract class AbstractContainer extends AbstractElement
|
||||||
*/
|
*/
|
||||||
private function checkElementDocPart()
|
private function checkElementDocPart()
|
||||||
{
|
{
|
||||||
$isCellTextrun = in_array($this->container, array('cell', 'textrun'));
|
$isCellTextrun = in_array($this->container, array('cell', 'textrun', 'textbox'));
|
||||||
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
|
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
|
||||||
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
|
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
|
||||||
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
|
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,11 @@ use PhpOffice\PhpWord\Style;
|
||||||
*/
|
*/
|
||||||
abstract class AbstractElement
|
abstract class AbstractElement
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* PhpWord object
|
||||||
|
*
|
||||||
|
* @var \PhpOffice\PhpWord\PhpWord
|
||||||
|
*/
|
||||||
protected $phpWord;
|
protected $phpWord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -115,21 +115,6 @@ class Footer extends AbstractContainer
|
||||||
return $this->type = self::EVEN;
|
return $this->type = self::EVEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add textbox element
|
|
||||||
*
|
|
||||||
* @param mixed $style
|
|
||||||
* @return \PhpOffice\PhpWord\Element\TextBox
|
|
||||||
* @todo Merge with the same function on Section
|
|
||||||
*/
|
|
||||||
public function addTextBox($style = null)
|
|
||||||
{
|
|
||||||
$textbox = new TextBox($this->getDocPart(), $this->getDocPartId(), $style);
|
|
||||||
$this->addElement($textbox);
|
|
||||||
|
|
||||||
return $textbox;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add table element
|
* Add table element
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -117,21 +117,6 @@ class Section extends AbstractContainer
|
||||||
$this->addElement(new PageBreak());
|
$this->addElement(new PageBreak());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add textbox element
|
|
||||||
*
|
|
||||||
* @param mixed $style
|
|
||||||
* @return \PhpOffice\PhpWord\Element\TextBox
|
|
||||||
* @todo Merge with the same function on Footer
|
|
||||||
*/
|
|
||||||
public function addTextBox($style = null)
|
|
||||||
{
|
|
||||||
$textbox = new TextBox($this->getDocPart(), $this->getDocPartId(), $style);
|
|
||||||
$this->addElement($textbox);
|
|
||||||
|
|
||||||
return $textbox;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add table element
|
* Add table element
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class TextBox extends AbstractContainer
|
||||||
* @var \PhpOffice\PhpWord\Style\TextBox
|
* @var \PhpOffice\PhpWord\Style\TextBox
|
||||||
*/
|
*/
|
||||||
private $style;
|
private $style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new textbox
|
* Create a new textbox
|
||||||
*
|
*
|
||||||
|
|
@ -38,10 +38,9 @@ class TextBox extends AbstractContainer
|
||||||
* @param integer $docPartId
|
* @param integer $docPartId
|
||||||
* @param mixed $style
|
* @param mixed $style
|
||||||
*/
|
*/
|
||||||
public function __construct($docPart, $docPartId, $style = null)
|
public function __construct($style = null)
|
||||||
{
|
{
|
||||||
$this->container = 'textbox';
|
$this->container = 'textbox';
|
||||||
$this->setDocPart($docPart, $docPartId);
|
|
||||||
$this->style = $this->setStyle(new TextBoxStyle(), $style);
|
$this->style = $this->setStyle(new TextBoxStyle(), $style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,4 +53,4 @@ class TextBox extends AbstractContainer
|
||||||
{
|
{
|
||||||
return $this->style;
|
return $this->style;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,163 +20,29 @@ namespace PhpOffice\PhpWord\Style;
|
||||||
/**
|
/**
|
||||||
* TextBox style
|
* TextBox style
|
||||||
*/
|
*/
|
||||||
class TextBox extends AbstractStyle
|
class TextBox extends Image
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapping styles
|
|
||||||
*
|
|
||||||
* @const string
|
|
||||||
*/
|
|
||||||
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';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Position relative to
|
|
||||||
*
|
|
||||||
* @const string
|
|
||||||
*/
|
|
||||||
const POSITION_RELATIVE_TO_MARGIN = 'margin';
|
|
||||||
const POSITION_RELATIVE_TO_PAGE = 'page';
|
|
||||||
const POSITION_RELATIVE_TO_COLUMN = 'column';
|
|
||||||
const POSITION_RELATIVE_TO_CHAR = 'char';
|
|
||||||
const POSITION_RELATIVE_TO_LMARGIN = 'left-margin-area';
|
|
||||||
const POSITION_RELATIVE_TO_RMARGIN = 'right-margin-area';
|
|
||||||
const POSITION_RELATIVE_TO_IMARGIN = 'inner-margin-area';
|
|
||||||
const POSITION_RELATIVE_TO_OMARGIN = 'outer-margin-area';
|
|
||||||
const POSITION_RELATIVE_TO_LINE = 'line';
|
|
||||||
const POSITION_RELATIVE_TO_TMARGIN = 'top-margin-area';
|
|
||||||
const POSITION_RELATIVE_TO_BMARGIN = 'bottom-margin-area';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Position type, relative/absolute
|
|
||||||
*
|
|
||||||
* @const string
|
|
||||||
*/
|
|
||||||
const POSITION_RELATIVE = 'relative';
|
|
||||||
const POSITION_ABSOLUTE = 'absolute';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TextBox width
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $width;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TextBox height
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $height;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alignment
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $align;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Margin Top
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $marginTop;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Margin Left
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $marginLeft;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapping style
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $wrappingStyle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Positioning type (relative or absolute)
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $positioning;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Horizontal alignment
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $posHorizontal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Horizontal Relation
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $posHorizontalRel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vertical alignment
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $posVertical;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vertical Relation
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $posVerticalRel;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* margin top
|
* margin top
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $innerMarginTop = null;
|
private $innerMarginTop = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* margin left
|
* margin left
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $innerMarginLeft = null;
|
private $innerMarginLeft = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* margin right
|
* margin right
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $innerMarginRight = null;
|
private $innerMarginRight = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cell margin bottom
|
* Cell margin bottom
|
||||||
*
|
*
|
||||||
|
|
@ -186,7 +52,7 @@ class TextBox extends AbstractStyle
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* border size
|
* border size
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $borderSize = null;
|
private $borderSize = null;
|
||||||
|
|
@ -197,305 +63,7 @@ class TextBox extends AbstractStyle
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $borderColor;
|
private $borderColor;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new textbox style
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
|
|
||||||
$this->setPosHorizontal(self::POSITION_HORIZONTAL_LEFT);
|
|
||||||
$this->setPosHorizontalRel(self::POSITION_RELATIVE_TO_CHAR);
|
|
||||||
$this->setPosVertical(self::POSITION_VERTICAL_TOP);
|
|
||||||
$this->setPosVerticalRel(self::POSITION_RELATIVE_TO_LINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get width
|
|
||||||
*/
|
|
||||||
public function getWidth()
|
|
||||||
{
|
|
||||||
return $this->width;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set width
|
|
||||||
*
|
|
||||||
* @param int $value
|
|
||||||
*/
|
|
||||||
public function setWidth($value = null)
|
|
||||||
{
|
|
||||||
$this->width = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get height
|
|
||||||
*/
|
|
||||||
public function getHeight()
|
|
||||||
{
|
|
||||||
return $this->height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set height
|
|
||||||
*
|
|
||||||
* @param int $value
|
|
||||||
*/
|
|
||||||
public function setHeight($value = null)
|
|
||||||
{
|
|
||||||
$this->height = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get alignment
|
|
||||||
*/
|
|
||||||
public function getAlign()
|
|
||||||
{
|
|
||||||
return $this->align;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set alignment
|
|
||||||
*
|
|
||||||
* @param string $value
|
|
||||||
*/
|
|
||||||
public function setAlign($value = null)
|
|
||||||
{
|
|
||||||
$this->align = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set wrapping style
|
|
||||||
*
|
|
||||||
* @param string $wrappingStyle
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function setWrappingStyle($wrappingStyle)
|
|
||||||
{
|
|
||||||
$enum = array(self::WRAPPING_STYLE_INLINE, self::WRAPPING_STYLE_INFRONT, self::WRAPPING_STYLE_BEHIND,
|
|
||||||
self::WRAPPING_STYLE_SQUARE, self::WRAPPING_STYLE_TIGHT);
|
|
||||||
|
|
||||||
if (in_array($wrappingStyle, $enum)) {
|
|
||||||
$this->wrappingStyle = $wrappingStyle;
|
|
||||||
} else {
|
|
||||||
throw new \InvalidArgumentException('Invalid wrapping style.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get positioning type
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPositioning()
|
|
||||||
{
|
|
||||||
return $this->positioning;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set positioning type
|
|
||||||
*
|
|
||||||
* @param string $positioning
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function setPositioning($positioning)
|
|
||||||
{
|
|
||||||
$enum = array(self::POSITION_RELATIVE, self::POSITION_ABSOLUTE);
|
|
||||||
|
|
||||||
if (in_array($positioning, $enum)) {
|
|
||||||
$this->positioning = $positioning;
|
|
||||||
} else {
|
|
||||||
throw new \InvalidArgumentException('Invalid positioning.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get horizontal alignment
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPosHorizontal()
|
|
||||||
{
|
|
||||||
return $this->posHorizontal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set horizontal alignment
|
|
||||||
*
|
|
||||||
* @param string $alignment
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function setPosHorizontal($alignment)
|
|
||||||
{
|
|
||||||
$enum = array(self::POSITION_HORIZONTAL_LEFT, self::POSITION_HORIZONTAL_CENTER,
|
|
||||||
self::POSITION_HORIZONTAL_RIGHT);
|
|
||||||
|
|
||||||
if (in_array($alignment, $enum)) {
|
|
||||||
$this->posHorizontal = $alignment;
|
|
||||||
} else {
|
|
||||||
throw new \InvalidArgumentException('Invalid horizontal alignment.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get vertical alignment
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPosVertical()
|
|
||||||
{
|
|
||||||
return $this->posVertical;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set vertical alignment
|
|
||||||
*
|
|
||||||
* @param string $alignment
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function setPosVertical($alignment)
|
|
||||||
{
|
|
||||||
$enum = array(self::POSITION_VERTICAL_TOP, self::POSITION_VERTICAL_CENTER,
|
|
||||||
self::POSITION_VERTICAL_BOTTOM, self::POSITION_VERTICAL_INSIDE, self::POSITION_VERTICAL_OUTSIDE);
|
|
||||||
|
|
||||||
if (in_array($alignment, $enum)) {
|
|
||||||
$this->posVertical = $alignment;
|
|
||||||
} else {
|
|
||||||
throw new \InvalidArgumentException('Invalid vertical alignment.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get horizontal relation
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPosHorizontalRel()
|
|
||||||
{
|
|
||||||
return $this->posHorizontalRel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set horizontal relation
|
|
||||||
*
|
|
||||||
* @param string $relto
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function setPosHorizontalRel($relto)
|
|
||||||
{
|
|
||||||
$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,
|
|
||||||
self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN);
|
|
||||||
|
|
||||||
if (in_array($relto, $enum)) {
|
|
||||||
$this->posHorizontalRel = $relto;
|
|
||||||
} else {
|
|
||||||
throw new \InvalidArgumentException('Invalid relative horizontal alignment.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get vertical relation
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPosVerticalRel()
|
|
||||||
{
|
|
||||||
return $this->posVerticalRel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set vertical relation
|
|
||||||
*
|
|
||||||
* @param string $relto
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function setPosVerticalRel($relto)
|
|
||||||
{
|
|
||||||
$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,
|
|
||||||
self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN);
|
|
||||||
|
|
||||||
if (in_array($relto, $enum)) {
|
|
||||||
$this->posVerticalRel = $relto;
|
|
||||||
} else {
|
|
||||||
throw new \InvalidArgumentException('Invalid relative vertical alignment.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Set margin top
|
* Set margin top
|
||||||
*
|
*
|
||||||
|
|
@ -505,7 +73,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
$this->innerMarginTop = $value;
|
$this->innerMarginTop = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get margin top
|
* Get margin top
|
||||||
*
|
*
|
||||||
|
|
@ -515,7 +83,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
return $this->innerMarginTop;
|
return $this->innerMarginTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set margin left
|
* Set margin left
|
||||||
*
|
*
|
||||||
|
|
@ -525,7 +93,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
$this->innerMarginLeft = $value;
|
$this->innerMarginLeft = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get margin left
|
* Get margin left
|
||||||
*
|
*
|
||||||
|
|
@ -535,7 +103,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
return $this->innerMarginLeft;
|
return $this->innerMarginLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set margin right
|
* Set margin right
|
||||||
*
|
*
|
||||||
|
|
@ -545,7 +113,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
$this->innerMarginRight = $value;
|
$this->innerMarginRight = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get margin right
|
* Get margin right
|
||||||
*
|
*
|
||||||
|
|
@ -555,7 +123,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
return $this->innerMarginRight;
|
return $this->innerMarginRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set margin bottom
|
* Set margin bottom
|
||||||
*
|
*
|
||||||
|
|
@ -565,7 +133,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
$this->innerMarginBottom = $value;
|
$this->innerMarginBottom = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get margin bottom
|
* Get margin bottom
|
||||||
*
|
*
|
||||||
|
|
@ -575,7 +143,7 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
return $this->innerMarginBottom;
|
return $this->innerMarginBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set TLRB cell margin
|
* Set TLRB cell margin
|
||||||
*
|
*
|
||||||
|
|
@ -588,7 +156,7 @@ class TextBox extends AbstractStyle
|
||||||
$this->setInnerMarginRight($value);
|
$this->setInnerMarginRight($value);
|
||||||
$this->setInnerMarginBottom($value);
|
$this->setInnerMarginBottom($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cell margin
|
* Get cell margin
|
||||||
*
|
*
|
||||||
|
|
@ -598,20 +166,20 @@ class TextBox extends AbstractStyle
|
||||||
{
|
{
|
||||||
return array($this->innerMarginLeft, $this->innerMarginTop, $this->innerMarginRight, $this->innerMarginBottom);
|
return array($this->innerMarginLeft, $this->innerMarginTop, $this->innerMarginRight, $this->innerMarginBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set border size
|
* Set border size
|
||||||
*
|
*
|
||||||
* @param int $value Size in points
|
* @param int $value Size in points
|
||||||
*/
|
*/
|
||||||
public function setBorderSize($value = null)
|
public function setBorderSize($value = null)
|
||||||
{
|
{
|
||||||
$this->borderSize = $value;
|
$this->borderSize = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get border size
|
* Get border size
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getBorderSize()
|
public function getBorderSize()
|
||||||
|
|
@ -621,21 +189,21 @@ class TextBox extends AbstractStyle
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set border color
|
* Set border color
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
public function setBorderColor($value = null)
|
public function setBorderColor($value = null)
|
||||||
{
|
{
|
||||||
$this->borderColor = $value;
|
$this->borderColor = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get border color
|
* Get border color
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBorderColor()
|
public function getBorderColor()
|
||||||
{
|
{
|
||||||
return $this->borderColor;
|
return $this->borderColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,26 +47,28 @@ class TextBox extends Element
|
||||||
$this->xmlWriter->endElement(); // w:pPr
|
$this->xmlWriter->endElement(); // w:pPr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->xmlWriter->startElement('w:r');
|
$this->xmlWriter->startElement('w:r');
|
||||||
$this->xmlWriter->startElement('w:pict');
|
$this->xmlWriter->startElement('w:pict');
|
||||||
$this->xmlWriter->startElement('v:shape');
|
$this->xmlWriter->startElement('v:shape');
|
||||||
$this->xmlWriter->writeAttribute('type', '#_x0000_t0202');
|
$this->xmlWriter->writeAttribute('type', '#_x0000_t0202');
|
||||||
$styleWriter->write();
|
$styleWriter->write();
|
||||||
$this->xmlWriter->startElement('v:textbox');
|
$this->xmlWriter->startElement('v:textbox');
|
||||||
$margins=implode(', ',$tbxStyle->getInnerMargin());
|
$margins = implode(', ', $tbxStyle->getInnerMargin());
|
||||||
$this->xmlWriter->writeAttribute('inset', $margins);
|
$this->xmlWriter->writeAttribute('inset', $margins);
|
||||||
$this->xmlWriter->startElement('w:txbxContent');
|
$this->xmlWriter->startElement('w:txbxContent');
|
||||||
|
$this->xmlWriter->startElement('w:p');
|
||||||
$this->parentWriter->writeContainerElements($this->xmlWriter, $this->element);
|
$this->parentWriter->writeContainerElements($this->xmlWriter, $this->element);
|
||||||
|
$this->xmlWriter->endElement(); // w:p
|
||||||
$this->xmlWriter->endElement(); // w:txbxContent
|
$this->xmlWriter->endElement(); // w:txbxContent
|
||||||
$this->xmlWriter->endElement(); // v: textbox
|
$this->xmlWriter->endElement(); // v: textbox
|
||||||
$styleWriter->writeW10Wrap();
|
$styleWriter->writeW10Wrap();
|
||||||
$this->xmlWriter->endElement(); // v:shape
|
$this->xmlWriter->endElement(); // v:shape
|
||||||
$this->xmlWriter->endElement(); // w:pict
|
$this->xmlWriter->endElement(); // w:pict
|
||||||
$this->xmlWriter->endElement(); // w:r
|
$this->xmlWriter->endElement(); // w:r
|
||||||
|
|
||||||
if (!$this->withoutP) {
|
if (!$this->withoutP) {
|
||||||
$this->xmlWriter->endElement(); // w:p
|
$this->xmlWriter->endElement(); // w:p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ abstract class AbstractPart
|
||||||
'Header' => array_merge($elmMainCell, array('Table', 'PreserveText', 'TextBox')),
|
'Header' => array_merge($elmMainCell, array('Table', 'PreserveText', 'TextBox')),
|
||||||
'Footer' => array_merge($elmMainCell, array('Table', 'PreserveText', 'TextBox')),
|
'Footer' => array_merge($elmMainCell, array('Table', 'PreserveText', 'TextBox')),
|
||||||
'Cell' => array_merge($elmMainCell, array('PreserveText', 'Footnote', 'Endnote')),
|
'Cell' => array_merge($elmMainCell, array('PreserveText', 'Footnote', 'Endnote')),
|
||||||
'TextBox' => array_merge($elmMainCell, array('PreserveText', 'Footnote', 'Endnote')),
|
'TextBox' => array_merge($elmMainCell, array('PreserveText', 'Footnote', 'Endnote')),
|
||||||
'TextRun' => array_merge($elmCommon, array('Footnote', 'Endnote')),
|
'TextRun' => array_merge($elmCommon, array('Footnote', 'Endnote')),
|
||||||
'Footnote' => $elmCommon,
|
'Footnote' => $elmCommon,
|
||||||
'Endnote' => $elmCommon,
|
'Endnote' => $elmCommon,
|
||||||
|
|
@ -110,7 +110,7 @@ abstract class AbstractPart
|
||||||
|
|
||||||
// Loop through elements
|
// Loop through elements
|
||||||
$elements = $container->getElements();
|
$elements = $container->getElements();
|
||||||
$withoutP = in_array($containerName, array('TextRun', 'Footnote', 'Endnote')) ? true : false;
|
$withoutP = in_array($containerName, array('TextRun', 'Footnote', 'Endnote', 'TextBox')) ? true : false;
|
||||||
if (count($elements) > 0) {
|
if (count($elements) > 0) {
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
if ($element instanceof AbstractElement) {
|
if ($element instanceof AbstractElement) {
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class TextBox extends AbstractStyle
|
||||||
if ($borderSize !== null) {
|
if ($borderSize !== null) {
|
||||||
$this->xmlWriter->writeAttribute('strokeweight', $this->style->getBorderSize().'pt');
|
$this->xmlWriter->writeAttribute('strokeweight', $this->style->getBorderSize().'pt');
|
||||||
}
|
}
|
||||||
|
|
||||||
$borderColor = $this->style->getBorderColor();
|
$borderColor = $this->style->getBorderColor();
|
||||||
if (empty($borderColor)) {
|
if (empty($borderColor)) {
|
||||||
$this->xmlWriter->writeAttribute('stroked', 'f');
|
$this->xmlWriter->writeAttribute('stroked', 'f');
|
||||||
|
|
@ -101,7 +101,7 @@ class TextBox extends AbstractStyle
|
||||||
$this->xmlWriter->writeAttribute('strokecolor', $borderColor);
|
$this->xmlWriter->writeAttribute('strokecolor', $borderColor);
|
||||||
}
|
}
|
||||||
//@todo <v:stroke dashstyle="dashDot" linestyle="thickBetweenThin"/>
|
//@todo <v:stroke dashstyle="dashDot" linestyle="thickBetweenThin"/>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -114,7 +114,7 @@ class TextBox extends AbstractStyle
|
||||||
if (!is_null($this->w10wrap)) {
|
if (!is_null($this->w10wrap)) {
|
||||||
$this->xmlWriter->startElement('w10:wrap');
|
$this->xmlWriter->startElement('w10:wrap');
|
||||||
$this->xmlWriter->writeAttribute('type', $this->w10wrap);
|
$this->xmlWriter->writeAttribute('type', $this->w10wrap);
|
||||||
|
|
||||||
switch ($this->style->getPositioning()) {
|
switch ($this->style->getPositioning()) {
|
||||||
case TextBoxStyle::POSITION_ABSOLUTE:
|
case TextBoxStyle::POSITION_ABSOLUTE:
|
||||||
$this->xmlWriter->writeAttribute('anchorx', "page");
|
$this->xmlWriter->writeAttribute('anchorx', "page");
|
||||||
|
|
@ -150,7 +150,7 @@ class TextBox extends AbstractStyle
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->xmlWriter->endElement(); // w10:wrap
|
$this->xmlWriter->endElement(); // w10:wrap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$oTextBox = new TextBox('section', 1);
|
$oTextBox = new TextBox();
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextBox', $oTextBox);
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextBox', $oTextBox);
|
||||||
$this->assertEquals($oTextBox->getStyle(), null);
|
$this->assertEquals($oTextBox->getStyle(), null);
|
||||||
}
|
}
|
||||||
|
|
@ -43,19 +43,17 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testStyleText()
|
public function testStyleText()
|
||||||
{
|
{
|
||||||
$oTextBox = new TextBox('section', 1, 'textBoxStyle');
|
$oTextBox = new TextBox('textBoxStyle');
|
||||||
|
|
||||||
$this->assertEquals($oTextBox->getStyle(), 'textBoxStyle');
|
$this->assertEquals($oTextBox->getStyle(), 'textBoxStyle');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get style array
|
* Get style array
|
||||||
*/
|
*/
|
||||||
public function testStyleArray()
|
public function testStyleArray()
|
||||||
{
|
{
|
||||||
$oTextBox = new TextBox(
|
$oTextBox = new TextBox(
|
||||||
'section',
|
|
||||||
1,
|
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4.5),
|
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4.5),
|
||||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(17.5),
|
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(17.5),
|
||||||
|
|
@ -68,7 +66,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
|
||||||
'borderColor' => ''
|
'borderColor' => ''
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TextBox', $oTextBox->getStyle());
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TextBox', $oTextBox->getStyle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue