Change behaviour of `set...` function of boolean properties; Some bug fixing based on Scrutinizer; New `Row` Word2007 style writer
This commit is contained in:
parent
4b1a16006d
commit
8745c5ee30
|
|
@ -18,7 +18,7 @@ tools:
|
|||
enabled: true
|
||||
timeout: 900
|
||||
php_sim:
|
||||
min_mass: 30
|
||||
min_mass: 16
|
||||
php_pdepend: true
|
||||
php_analyzer: true
|
||||
sensiolabs_security_checker: true
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
|
|||
- QA: Add `.scrutinizer.yml` and include `composer.lock` for preparation to Scrutinizer - @ivanlanin GH-186
|
||||
- Writer: Refactor writer parts using composite pattern - @ivanlanin
|
||||
- Docs: Show code quality and test code coverage badge on README
|
||||
- Style: Change behaviour of `set...` function of boolean properties; when none is defined, assumed true - @ivanlanin
|
||||
|
||||
## 0.10.0 - 4 May 2014
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@
|
|||
<rule ref="rulesets/design.xml/ExitExpression" />
|
||||
<rule ref="rulesets/design.xml/EvalExpression" />
|
||||
<rule ref="rulesets/design.xml/GotoStatement" />
|
||||
<rule ref="rulesets/design.xml/NumberOfChildren" />
|
||||
<rule ref="rulesets/design.xml/DepthOfInheritance" />
|
||||
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
|
||||
<rule ref="rulesets/design.xml/CouplingBetweenObjects" />
|
||||
<rule ref="rulesets/design.xml/NumberOfChildren">
|
||||
<!-- AbstractElement and AbstractStyle still needs a lot of children classes -->
|
||||
<properties>
|
||||
<property name="minimum" value="15" />
|
||||
<property name="minimum" value="20" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/unusedcode.xml" />
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ for($i = 1; $i <= 8; $i++) {
|
|||
|
||||
// 3. colspan (gridSpan) and rowspan (vMerge)
|
||||
|
||||
$section->addTextBreak(1);
|
||||
$section->addPageBreak();
|
||||
$section->addText("Table with colspan and rowspan", $header);
|
||||
|
||||
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|||
$section = $phpWord->addSection();
|
||||
|
||||
// In section
|
||||
$textbox = $section->addTextBox(array('align' => 'left', 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000'));
|
||||
$textbox = $section->addTextBox(array('align' => 'center', 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000'));
|
||||
$textbox->addText('Text box content in section.');
|
||||
$textbox->addText('Another line.');
|
||||
$cell = $textbox->addTable()->addRow()->addCell();
|
||||
|
|
@ -22,7 +22,7 @@ $textbox->addText('Textbox inside table');
|
|||
|
||||
// Inside header with textrun
|
||||
$header = $section->addHeader();
|
||||
$textbox = $header->addTextBox(array('align' => 'center', 'width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
||||
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
||||
$textrun = $textbox->addTextRun();
|
||||
$textrun->addText('TextBox in header. TextBox can contain a TextRun ');
|
||||
$textrun->addText('with bold text', array('bold' => true));
|
||||
|
|
|
|||
|
|
@ -219,7 +219,13 @@ class Html
|
|||
$text = $cNode->nodeValue;
|
||||
}
|
||||
}
|
||||
$object->addListItem($text, $data['listdepth'], $styles['fontStyle'], $styles['listStyle'], $styles['paragraphStyle']);
|
||||
$object->addListItem(
|
||||
$text,
|
||||
$data['listdepth'],
|
||||
$styles['fontStyle'],
|
||||
$styles['listStyle'],
|
||||
$styles['paragraphStyle']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,13 +152,13 @@ abstract class AbstractStyle
|
|||
}
|
||||
|
||||
/**
|
||||
* Set boolean value
|
||||
* Set bool value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param boolean|null $default
|
||||
* @return boolean|null
|
||||
* @param bool $value
|
||||
* @param bool $default
|
||||
* @return bool
|
||||
*/
|
||||
protected function setBoolVal($value, $default = null)
|
||||
protected function setBoolVal($value, $default)
|
||||
{
|
||||
if (!is_bool($value)) {
|
||||
$value = $default;
|
||||
|
|
@ -184,7 +184,7 @@ abstract class AbstractStyle
|
|||
}
|
||||
|
||||
/**
|
||||
* Set float value: Convert string that contains only numeric into integer
|
||||
* Set integer value: Convert string that contains only numeric into integer
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param int|null $default
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setBold($value = false)
|
||||
public function setBold($value = true)
|
||||
{
|
||||
$this->bold = $this->setBoolVal($value, $this->bold);
|
||||
|
||||
|
|
@ -356,7 +356,7 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setItalic($value = false)
|
||||
public function setItalic($value = true)
|
||||
{
|
||||
$this->italic = $this->setBoolVal($value, $this->italic);
|
||||
|
||||
|
|
@ -402,7 +402,7 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setSuperScript($value = false)
|
||||
public function setSuperScript($value = true)
|
||||
{
|
||||
$this->superScript = $this->setBoolVal($value, $this->superScript);
|
||||
$this->toggleFalse($this->subScript, $this->superScript);
|
||||
|
|
@ -426,13 +426,10 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setSubScript($value = false)
|
||||
public function setSubScript($value = true)
|
||||
{
|
||||
$this->subScript = $this->setBoolVal($value, $this->subScript);
|
||||
$this->toggleFalse($this->subScript, $this->superScript);
|
||||
if ($this->subScript) {
|
||||
$this->superScript = false;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -453,7 +450,7 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setStrikethrough($value = false)
|
||||
public function setStrikethrough($value = true)
|
||||
{
|
||||
$this->strikethrough = $this->setBoolVal($value, $this->strikethrough);
|
||||
$this->toggleFalse($this->doubleStrikethrough, $this->strikethrough);
|
||||
|
|
@ -477,7 +474,7 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setDoubleStrikethrough($value = false)
|
||||
public function setDoubleStrikethrough($value = true)
|
||||
{
|
||||
$this->doubleStrikethrough = $this->setBoolVal($value, $this->doubleStrikethrough);
|
||||
$this->toggleFalse($this->strikethrough, $this->doubleStrikethrough);
|
||||
|
|
@ -501,7 +498,7 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setSmallCaps($value = false)
|
||||
public function setSmallCaps($value = true)
|
||||
{
|
||||
$this->smallCaps = $this->setBoolVal($value, $this->smallCaps);
|
||||
$this->toggleFalse($this->allCaps, $this->smallCaps);
|
||||
|
|
@ -525,7 +522,7 @@ class Font extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setAllCaps($value = false)
|
||||
public function setAllCaps($value = true)
|
||||
{
|
||||
$this->allCaps = $this->setBoolVal($value, $this->allCaps);
|
||||
$this->toggleFalse($this->smallCaps, $this->allCaps);
|
||||
|
|
|
|||
|
|
@ -94,9 +94,9 @@ class Image extends AbstractStyle
|
|||
/**
|
||||
* Alignment
|
||||
*
|
||||
* @var string
|
||||
* @var \PhpOffice\PhpWord\Style\Alignment
|
||||
*/
|
||||
private $align;
|
||||
private $alignment;
|
||||
|
||||
/**
|
||||
* Margin Top
|
||||
|
|
@ -154,8 +154,18 @@ class Image extends AbstractStyle
|
|||
*/
|
||||
private $posVerticalRel = self::POSITION_RELATIVE_TO_LINE;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->alignment = new Alignment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get width
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
|
|
@ -166,14 +176,19 @@ class Image extends AbstractStyle
|
|||
* Set width
|
||||
*
|
||||
* @param int $value
|
||||
* @return self
|
||||
*/
|
||||
public function setWidth($value = null)
|
||||
{
|
||||
$this->width = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get height
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
|
|
@ -184,32 +199,40 @@ class Image extends AbstractStyle
|
|||
* Set height
|
||||
*
|
||||
* @param int $value
|
||||
* @return self
|
||||
*/
|
||||
public function setHeight($value = null)
|
||||
{
|
||||
$this->height = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alignment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAlign()
|
||||
{
|
||||
return $this->align;
|
||||
return $this->alignment->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alignment
|
||||
*
|
||||
* @param string $value
|
||||
* @return self
|
||||
*/
|
||||
public function setAlign($value = null)
|
||||
{
|
||||
$this->align = $value;
|
||||
$this->alignment->setValue($value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Margin Top
|
||||
* Get margin top
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
|
@ -219,7 +242,7 @@ class Image extends AbstractStyle
|
|||
}
|
||||
|
||||
/**
|
||||
* Set Margin Top
|
||||
* Set margin top
|
||||
*
|
||||
* @param int $value
|
||||
* @return self
|
||||
|
|
@ -227,11 +250,12 @@ class Image extends AbstractStyle
|
|||
public function setMarginTop($value = null)
|
||||
{
|
||||
$this->marginTop = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Margin Left
|
||||
* Get margin left
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
|
@ -241,7 +265,7 @@ class Image extends AbstractStyle
|
|||
}
|
||||
|
||||
/**
|
||||
* Set Margin Left
|
||||
* Set margin left
|
||||
*
|
||||
* @param int $value
|
||||
* @return self
|
||||
|
|
@ -249,6 +273,7 @@ class Image extends AbstractStyle
|
|||
public function setMarginLeft($value = null)
|
||||
{
|
||||
$this->marginLeft = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ class Paragraph extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setKeepNext($value = false)
|
||||
public function setKeepNext($value = true)
|
||||
{
|
||||
$this->keepNext = $this->setBoolVal($value, $this->keepNext);
|
||||
|
||||
|
|
@ -443,7 +443,7 @@ class Paragraph extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setKeepLines($value = false)
|
||||
public function setKeepLines($value = true)
|
||||
{
|
||||
$this->keepLines = $this->setBoolVal($value, $this->keepLines);
|
||||
|
||||
|
|
@ -466,7 +466,7 @@ class Paragraph extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setPageBreakBefore($value = false)
|
||||
public function setPageBreakBefore($value = true)
|
||||
{
|
||||
$this->pageBreakBefore = $this->setBoolVal($value, $this->pageBreakBefore);
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class Row extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setTblHeader($value = false)
|
||||
public function setTblHeader($value = true)
|
||||
{
|
||||
$this->tblHeader = $this->setBoolVal($value, $this->tblHeader);
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ class Row extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setCantSplit($value = false)
|
||||
public function setCantSplit($value = true)
|
||||
{
|
||||
$this->cantSplit = $this->setBoolVal($value, $this->cantSplit);
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ class Row extends AbstractStyle
|
|||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setExactHeight($value = false)
|
||||
public function setExactHeight($value = true)
|
||||
{
|
||||
$this->exactHeight = $this->setBoolVal($value, $this->exactHeight);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,13 @@ namespace PhpOffice\PhpWord\Writer\HTML\Element;
|
|||
*/
|
||||
class Container extends AbstractElement
|
||||
{
|
||||
/**
|
||||
* Namespace; Can't use __NAMESPACE__ in inherited class (RTF)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element';
|
||||
|
||||
/**
|
||||
* Write container
|
||||
*
|
||||
|
|
@ -40,8 +47,10 @@ class Container extends AbstractElement
|
|||
$content = '';
|
||||
|
||||
$elements = $container->getElements();
|
||||
$elementClass = '';
|
||||
foreach ($elements as $element) {
|
||||
$writerClass = str_replace('\\Element', '\\Writer\\HTML\\Element', get_class($element));
|
||||
$elementClass = get_class($element);
|
||||
$writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass);
|
||||
if (class_exists($writerClass)) {
|
||||
$writer = new $writerClass($this->parentWriter, $element, $withoutP);
|
||||
$content .= $writer->write();
|
||||
|
|
|
|||
|
|
@ -25,29 +25,9 @@ namespace PhpOffice\PhpWord\Writer\RTF\Element;
|
|||
class Container extends \PhpOffice\PhpWord\Writer\HTML\Element\Container
|
||||
{
|
||||
/**
|
||||
* Write container
|
||||
* Namespace; Can't use __NAMESPACE__ in inherited class (RTF)
|
||||
*
|
||||
* @return string
|
||||
* @var string
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$container = $this->element;
|
||||
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
|
||||
return;
|
||||
}
|
||||
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
|
||||
$withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote')) ? true : false;
|
||||
$content = '';
|
||||
|
||||
$elements = $container->getElements();
|
||||
foreach ($elements as $element) {
|
||||
$writerClass = str_replace('\\Element', '\\Writer\\RTF\\Element', get_class($element));
|
||||
if (class_exists($writerClass)) {
|
||||
$writer = new $writerClass($this->parentWriter, $element, $withoutP);
|
||||
$content .= $writer->write();
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
protected $namespace = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
namespace PhpOffice\PhpWord\Writer\RTF\Style;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Alignment;
|
||||
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
|
||||
|
||||
/**
|
||||
* RTF paragraph style writer
|
||||
|
|
|
|||
|
|
@ -38,18 +38,17 @@ class Container extends AbstractElement
|
|||
*/
|
||||
public function write()
|
||||
{
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$container = $this->getElement();
|
||||
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
|
||||
return;
|
||||
}
|
||||
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
|
||||
$withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote', 'ListItemRun')) ? true : false;
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// Loop through elements
|
||||
$elements = $container->getElements();
|
||||
$elementClass = '';
|
||||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
$elementClass = get_class($element);
|
||||
$writerClass = str_replace('PhpOffice\\PhpWord\\Element', $this->namespace, $elementClass);
|
||||
|
|
@ -58,7 +57,6 @@ class Container extends AbstractElement
|
|||
$writer->write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Special case for Cell: They have to contain a w:p element at the end
|
||||
if ($containerClass == 'Cell') {
|
||||
|
|
|
|||
|
|
@ -57,15 +57,8 @@ class Image extends AbstractElement
|
|||
|
||||
if (!$this->withoutP) {
|
||||
$xmlWriter->startElement('w:p');
|
||||
if (!is_null($style->getAlign())) {
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$xmlWriter->startElement('w:jc');
|
||||
$xmlWriter->writeAttribute('w:val', $style->getAlign());
|
||||
$xmlWriter->endElement(); // w:jc
|
||||
$xmlWriter->endElement(); // w:pPr
|
||||
$styleWriter->writeAlignment();
|
||||
}
|
||||
}
|
||||
|
||||
$xmlWriter->startElement('w:r');
|
||||
$xmlWriter->startElement('w:pict');
|
||||
$xmlWriter->startElement('v:shape');
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter;
|
||||
|
||||
/**
|
||||
* Object element writer
|
||||
*
|
||||
|
|
@ -40,17 +42,11 @@ class Object extends AbstractElement
|
|||
$shapeId = md5($rIdObject . '_' . $rIdImage);
|
||||
$objectId = $element->getRelationId() + 1325353440;
|
||||
$style = $element->getStyle();
|
||||
$align = $style->getAlign();
|
||||
$styleWriter = new ImageStyleWriter($xmlWriter, $style);
|
||||
|
||||
if (!$this->withoutP) {
|
||||
$xmlWriter->startElement('w:p');
|
||||
}
|
||||
if (!is_null($align)) {
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$xmlWriter->startElement('w:jc');
|
||||
$xmlWriter->writeAttribute('w:val', $align);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
$styleWriter->writeAlignment();
|
||||
}
|
||||
$xmlWriter->startElement('w:r');
|
||||
$xmlWriter->startElement('w:object');
|
||||
|
|
|
|||
|
|
@ -21,8 +21,10 @@ use PhpOffice\PhpWord\Element\Cell as CellElement;
|
|||
use PhpOffice\PhpWord\Element\Row as RowElement;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
use PhpOffice\PhpWord\Style\Cell as CellStyle;
|
||||
use PhpOffice\PhpWord\Style\Row as RowStyle;
|
||||
use PhpOffice\PhpWord\Style\Table as TableStyle;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Cell as CellStyleWriter;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Row as RowStyleWriter;
|
||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Table as TableStyleWriter;
|
||||
|
||||
/**
|
||||
|
|
@ -109,33 +111,21 @@ class Table extends AbstractElement
|
|||
*/
|
||||
private function writeRow(XMLWriter $xmlWriter, RowElement $row)
|
||||
{
|
||||
$height = $row->getHeight();
|
||||
$rowStyle = $row->getStyle();
|
||||
|
||||
$xmlWriter->startElement('w:tr');
|
||||
if (!is_null($height) || $rowStyle->isTblHeader() || $rowStyle->isCantSplit()) {
|
||||
$xmlWriter->startElement('w:trPr');
|
||||
if (!is_null($height)) {
|
||||
$xmlWriter->startElement('w:trHeight');
|
||||
$xmlWriter->writeAttribute('w:val', $height);
|
||||
$xmlWriter->writeAttribute('w:hRule', ($rowStyle->isExactHeight() ? 'exact' : 'atLeast'));
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
if ($rowStyle->isTblHeader()) {
|
||||
$xmlWriter->startElement('w:tblHeader');
|
||||
$xmlWriter->writeAttribute('w:val', '1');
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
if ($rowStyle->isCantSplit()) {
|
||||
$xmlWriter->startElement('w:cantSplit');
|
||||
$xmlWriter->writeAttribute('w:val', '1');
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
|
||||
// Write style
|
||||
$rowStyle = $row->getStyle();
|
||||
if ($rowStyle instanceof RowStyle) {
|
||||
$styleWriter = new RowStyleWriter($xmlWriter, $rowStyle);
|
||||
$styleWriter->setHeight($row->getHeight());
|
||||
$styleWriter->write();
|
||||
}
|
||||
|
||||
// Write cells
|
||||
foreach ($row->getCells() as $cell) {
|
||||
$this->writeCell($xmlWriter, $cell);
|
||||
}
|
||||
|
||||
$xmlWriter->endElement(); // w:tr
|
||||
}
|
||||
|
||||
|
|
@ -144,20 +134,18 @@ class Table extends AbstractElement
|
|||
*/
|
||||
private function writeCell(XMLWriter $xmlWriter, CellElement $cell)
|
||||
{
|
||||
$cellStyle = $cell->getStyle();
|
||||
|
||||
$xmlWriter->startElement('w:tc');
|
||||
$xmlWriter->startElement('w:tcPr');
|
||||
$xmlWriter->startElement('w:tcW');
|
||||
$xmlWriter->writeAttribute('w:w', $cell->getWidth());
|
||||
$xmlWriter->writeAttribute('w:type', 'dxa');
|
||||
$xmlWriter->endElement(); // w:tcW
|
||||
|
||||
// Write style
|
||||
$cellStyle = $cell->getStyle();
|
||||
if ($cellStyle instanceof CellStyle) {
|
||||
$styleWriter = new CellStyleWriter($xmlWriter, $cellStyle);
|
||||
$styleWriter->setWidth($cell->getWidth());
|
||||
$styleWriter->write();
|
||||
}
|
||||
$xmlWriter->endElement(); // w:tcPr
|
||||
|
||||
// Write content
|
||||
$containerWriter = new Container($xmlWriter, $cell);
|
||||
$containerWriter->write();
|
||||
|
||||
|
|
|
|||
|
|
@ -41,13 +41,7 @@ class TextBox extends AbstractElement
|
|||
|
||||
if (!$this->withoutP) {
|
||||
$xmlWriter->startElement('w:p');
|
||||
if (!is_null($style->getAlign())) {
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$xmlWriter->startElement('w:jc');
|
||||
$xmlWriter->writeAttribute('w:val', $style->getAlign());
|
||||
$xmlWriter->endElement(); // w:jc
|
||||
$xmlWriter->endElement(); // w:pPr
|
||||
}
|
||||
$styleWriter->writeAlignment();
|
||||
}
|
||||
|
||||
$xmlWriter->startElement('w:r');
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ use PhpOffice\PhpWord\Style\Cell as CellStyle;
|
|||
*/
|
||||
class Cell extends AbstractStyle
|
||||
{
|
||||
/**
|
||||
* @var int Cell width
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* Write style
|
||||
*/
|
||||
|
|
@ -37,6 +42,14 @@ class Cell extends AbstractStyle
|
|||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
$xmlWriter->startElement('w:tcPr');
|
||||
|
||||
// Width
|
||||
$xmlWriter->startElement('w:tcW');
|
||||
$xmlWriter->writeAttribute('w:w', $this->width);
|
||||
$xmlWriter->writeAttribute('w:type', 'dxa');
|
||||
$xmlWriter->endElement(); // w:tcW
|
||||
|
||||
// Text direction
|
||||
$textDir = $style->getTextDirection();
|
||||
$xmlWriter->writeElementIf(!is_null($textDir), 'w:textDirection', 'w:val', $textDir);
|
||||
|
|
@ -70,5 +83,17 @@ class Cell extends AbstractStyle
|
|||
$vMerge = $style->getVMerge();
|
||||
$xmlWriter->writeElementIf(!is_null($gridSpan), 'w:gridSpan', 'w:val', $gridSpan);
|
||||
$xmlWriter->writeElementIf(!is_null($vMerge), 'w:vMerge', 'w:val', $vMerge);
|
||||
|
||||
$xmlWriter->endElement(); // w:tcPr
|
||||
}
|
||||
|
||||
/**
|
||||
* Set width
|
||||
*
|
||||
* @param int $value
|
||||
*/
|
||||
public function setWidth($value = null)
|
||||
{
|
||||
$this->width = $value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Alignment as AlignmentStyle;
|
||||
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
||||
|
||||
/**
|
||||
|
|
@ -45,23 +46,6 @@ class Image extends AbstractStyle
|
|||
$this->writeStyle($style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write w10 wrapping
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function writeW10Wrap()
|
||||
{
|
||||
if (is_null($this->w10wrap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$xmlWriter->startElement('w10:wrap');
|
||||
$xmlWriter->writeAttribute('type', $this->w10wrap);
|
||||
$xmlWriter->endElement(); // w10:wrap
|
||||
}
|
||||
|
||||
/**
|
||||
* Write style attribute
|
||||
*/
|
||||
|
|
@ -117,6 +101,38 @@ class Image extends AbstractStyle
|
|||
$xmlWriter->writeAttribute('style', $imageStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write alignment
|
||||
*/
|
||||
public function writeAlignment()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $style->getAlign())));
|
||||
$styleWriter->write();
|
||||
$xmlWriter->endElement(); // w:pPr
|
||||
}
|
||||
|
||||
/**
|
||||
* Write w10 wrapping
|
||||
*/
|
||||
public function writeW10Wrap()
|
||||
{
|
||||
if (is_null($this->w10wrap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$xmlWriter->startElement('w10:wrap');
|
||||
$xmlWriter->writeAttribute('type', $this->w10wrap);
|
||||
$xmlWriter->endElement(); // w10:wrap
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element style
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
<?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.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Row as RowStyle;
|
||||
|
||||
/**
|
||||
* Row style writer
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class Row extends AbstractStyle
|
||||
{
|
||||
/**
|
||||
* @var int Row height
|
||||
*/
|
||||
private $height;
|
||||
|
||||
/**
|
||||
* Write style
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$style = $this->getStyle();
|
||||
if (!$style instanceof \PhpOffice\PhpWord\Style\Row) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
$xmlWriter->startElement('w:trPr');
|
||||
|
||||
if ($this->height !== null) {
|
||||
$xmlWriter->startElement('w:trHeight');
|
||||
$xmlWriter->writeAttribute('w:val', $this->height);
|
||||
$xmlWriter->writeAttribute('w:hRule', ($style->isExactHeight() ? 'exact' : 'atLeast'));
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
$xmlWriter->writeElementIf($style->isTblHeader(), 'w:tblHeader', 'w:val', '1');
|
||||
$xmlWriter->writeElementIf($style->isCantSplit(), 'w:cantSplit', 'w:val', '1');
|
||||
|
||||
$xmlWriter->endElement(); // w:trPr
|
||||
}
|
||||
|
||||
/**
|
||||
* Set height
|
||||
*
|
||||
* @param int $value
|
||||
*/
|
||||
public function setHeight($value = null)
|
||||
{
|
||||
$this->height = $value;
|
||||
}
|
||||
}
|
||||
|
|
@ -59,17 +59,21 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
'size' => PhpWord::DEFAULT_FONT_SIZE,
|
||||
'bold' => false,
|
||||
'italic' => false,
|
||||
'underline' => Font::UNDERLINE_NONE,
|
||||
'superScript' => false,
|
||||
'subScript' => false,
|
||||
'underline' => Font::UNDERLINE_NONE,
|
||||
'strikethrough' => false,
|
||||
'doubleStrikethrough' => false,
|
||||
'smallCaps' => false,
|
||||
'allCaps' => false,
|
||||
'doubleStrikethrough' => false,
|
||||
'color' => PhpWord::DEFAULT_FONT_COLOR,
|
||||
'fgColor' => null,
|
||||
'bgColor' => null,
|
||||
'hint' => PhpWord::DEFAULT_FONT_CONTENT_TYPE,
|
||||
);
|
||||
foreach ($attributes as $key => $default) {
|
||||
$get = "get{$key}";
|
||||
$get = is_bool($default) ? "is{$key}" : "get{$key}";
|
||||
$object->setStyleValue("$key", null);
|
||||
$this->assertEquals($default, $object->$get());
|
||||
$object->setStyleValue("$key", '');
|
||||
|
|
@ -89,10 +93,13 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
'size' => 9,
|
||||
'bold' => true,
|
||||
'italic' => true,
|
||||
'underline' => Font::UNDERLINE_HEAVY,
|
||||
'superScript' => true,
|
||||
'subScript' => false,
|
||||
'underline' => Font::UNDERLINE_HEAVY,
|
||||
'strikethrough' => true,
|
||||
'doubleStrikethrough' => false,
|
||||
'smallCaps' => true,
|
||||
'allCaps' => false,
|
||||
'color' => '999999',
|
||||
'fgColor' => Font::FGCOLOR_YELLOW,
|
||||
'bgColor' => 'FFFF00',
|
||||
|
|
@ -101,7 +108,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
);
|
||||
$object->setStyleByArray($attributes);
|
||||
foreach ($attributes as $key => $value) {
|
||||
$get = "get{$key}";
|
||||
$get = is_bool($value) ? "is{$key}" : "get{$key}";
|
||||
$this->assertEquals($value, $object->$get());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||
$textrun->addTextBreak();
|
||||
$textrun = $section->addTextRun($aStyle);
|
||||
$textrun->addLink('http://test.com');
|
||||
$textrun->addImage($imageSrc, array('align' => 'top'));
|
||||
$textrun->addImage($imageSrc, array('align' => 'center'));
|
||||
$textrun->addFootnote();
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$styles = array(
|
||||
'Alignment', 'Cell', 'Font', 'Image', 'Indentation', 'LineNumbering',
|
||||
'Paragraph', 'Section', 'Shading', 'Spacing', 'Tab', 'Table', 'TextBox'
|
||||
'Paragraph', 'Row', 'Section', 'Shading', 'Spacing', 'Tab', 'Table', 'TextBox'
|
||||
);
|
||||
foreach ($styles as $style) {
|
||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Style\\' . $style;
|
||||
|
|
|
|||
Loading…
Reference in New Issue