table row height rule moved to rowStyle (ivanlanin)

new usage: $table->addRow($height, array("heightRule"=>"exact"));

Signed-off-by: Julien Carignan <julien.carignan@hotmail.com>
This commit is contained in:
Julien Carignan 2014-03-28 13:26:36 -04:00
parent 6796883d43
commit 8363ee27d1
5 changed files with 46 additions and 29 deletions

View File

@ -101,9 +101,9 @@ class PHPWord_Section_Table
* @param int $height
* @param mixed $style
*/
public function addRow($height = null, $style = null, $hRules = null)
public function addRow($height = null, $style = null)
{
$row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style, $hRules);
$row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style);
$this->_rows[] = $row;
return $row;
}

View File

@ -38,13 +38,6 @@ class PHPWord_Section_Table_Row
*/
private $_height = null;
/**
* Row heightRules
*
* @var array
*/
private $_heightRules = array();
/**
* Row style
*
@ -82,12 +75,11 @@ class PHPWord_Section_Table_Row
* @param int $height
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $height = null, $style = null, $hRules = null)
public function __construct($insideOf, $pCount, $height = null, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
$this->_height = $height;
$this->_heightRules = $hRules;
$this->_style = new PHPWord_Style_Row();
if (!is_null($style)) {
@ -146,14 +138,4 @@ class PHPWord_Section_Table_Row
{
return $this->_height;
}
/**
* Get all row height rules
*
* @return array
*/
public function getHeightRules()
{
return $this->_heightRules;
}
}

View File

@ -45,6 +45,13 @@ class PHPWord_Style_Row
*/
private $_cantSplit = false;
/**
* Table row height rule (auto, exact, atLeast)
*
* @var String
*/
private $_heightRule = null;
/**
* Create a new row style
*/
@ -112,4 +119,29 @@ class PHPWord_Style_Row
{
return $this->_cantSplit;
}
/**
* Set heightRule
*
* @param String $pValue
* @return PHPWord_Style_Row
*/
public function setHeightRule($pValue = false)
{
if (!is_string($pValue)) {
$pValue = null;
}
$this->_heightRule = $pValue;
return $this;
}
/**
* Get heightRule
*
* @return heightRule
*/
public function getHeightRule()
{
return $this->_heightRule;
}
}

View File

@ -569,11 +569,11 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
for ($i = 0; $i < $_cRows; $i++) {
$row = $_rows[$i];
$height = $row->getHeight();
$heightRules = $row->getHeightRules();
$height = $row->getHeight();
$rowStyle = $row->getStyle();
$tblHeader = $rowStyle->getTblHeader();
$cantSplit = $rowStyle->getCantSplit();
$heightRule = $rowStyle->getHeightRule();
$objWriter->startElement('w:tr');
@ -581,9 +581,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart
$objWriter->startElement('w:trPr');
if (!is_null($height)) {
$objWriter->startElement('w:trHeight');
if(!is_null($heightRules)) {
if(!is_null($heightRule)) {
$objWriter->startAttribute('w:hRule');
$objWriter->text($heightRules);
$objWriter->text($heightRule);
$objWriter->endAttribute();
}
$objWriter->writeAttribute('w:val', $height);

View File

@ -9,7 +9,9 @@ echo date('H:i:s') , ' Create new PHPWord object' , EOL;
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addText("By default, a table row adds a textbreak after its content (notice the red border), even if the row height is <= height of the content");
$section->addText("By default, when you insert an image, it adds a textbreak after its content.");
$section->addText("If we want a simple border around an image, we wrap the image inside a table->row->cell");
$section->addText("On the image with the red border, even if we set the row height to the height of the image, the textbreak is still there:");
$table1 = $section->addTable(array("cellMargin"=> 0, "cellMarginRight"=> 0, "cellMarginBottom"=> 0, "cellMarginLeft"=> 0));
$table1->addRow(3750);
@ -17,16 +19,17 @@ $cell1 = $table1->addCell(null, array("valign" => "top", "borderSize" => 30, "bo
$cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
$section->addTextBreak();
$section->addText("But if we set the row rule \"exact\", we get rid of the textbreak!");
$section->addText("But if we set the rowStyle hRule \"exact\", the real row height is used, removing the textbreak:");
$table2 = $section->addTable(array("cellMargin"=> 0, "cellMarginRight"=> 0, "cellMarginBottom"=> 0, "cellMarginLeft"=> 0));
$table2->addRow(3750, null, "exact");
$table2->addRow(3750, array("heightRule"=>"exact"));
$cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00"));
$cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
$section->addTextBreak();
$section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.");
$section->addText("So: $"."table2->addRow(3750, null, 'exact');");
$section->addText("So: $"."table2->addRow(3750, array('heightRule'=>'exact'));");
$section->addText("heightRule defaults to 'atLeast' when the row has an height set, and default to 'auto' otherwise");
// Save file
$name = basename(__FILE__, '.php');