New function PHPWord_Style_Paragraph::setTabs() and unit test for PHPWord_Style_Paragraph
This commit is contained in:
parent
537f49eeb4
commit
d177b4744b
|
|
@ -145,24 +145,21 @@ class PHPWord_Style_Paragraph
|
||||||
/**
|
/**
|
||||||
* Set Style value
|
* Set Style value
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public function setStyleValue($key, $value)
|
public function setStyleValue($key, $value)
|
||||||
{
|
{
|
||||||
if ($key == '_indent') {
|
if ($key == '_indent' || $key == '_hanging') {
|
||||||
$value = $value * 720; // 720 twips per indent
|
|
||||||
}
|
|
||||||
if ($key == '_hanging') {
|
|
||||||
$value = $value * 720;
|
$value = $value * 720;
|
||||||
}
|
}
|
||||||
if ($key == '_spacing') {
|
if ($key == '_spacing') {
|
||||||
$value += 240; // because line height of 1 matches 240 twips
|
$value += 240; // because line height of 1 matches 240 twips
|
||||||
}
|
}
|
||||||
if ($key === '_tabs') {
|
$method = 'set' . ucwords(substr($key, 1));
|
||||||
$value = new PHPWord_Style_Tabs($value);
|
if (method_exists($this, $method)) {
|
||||||
|
$this->$method($value);
|
||||||
}
|
}
|
||||||
$this->$key = $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -311,6 +308,20 @@ class PHPWord_Style_Paragraph
|
||||||
return $this->_tabs;
|
return $this->_tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set tabs
|
||||||
|
*
|
||||||
|
* @param array $pValue
|
||||||
|
* @return PHPWord_Style_Paragraph
|
||||||
|
*/
|
||||||
|
public function setTabs($pValue = null)
|
||||||
|
{
|
||||||
|
if (is_array($pValue)) {
|
||||||
|
$this->_tabs = new PHPWord_Style_Tabs($pValue);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get parent style ID
|
* Get parent style ID
|
||||||
*
|
*
|
||||||
|
|
@ -374,7 +385,7 @@ class PHPWord_Style_Paragraph
|
||||||
public function setWidowControl($pValue = true)
|
public function setWidowControl($pValue = true)
|
||||||
{
|
{
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = true;
|
||||||
}
|
}
|
||||||
$this->_widowControl = $pValue;
|
$this->_widowControl = $pValue;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -396,7 +407,7 @@ class PHPWord_Style_Paragraph
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Paragraph
|
* @return PHPWord_Style_Paragraph
|
||||||
*/
|
*/
|
||||||
public function setKeepNext($pValue = true)
|
public function setKeepNext($pValue = false)
|
||||||
{
|
{
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
|
|
@ -421,7 +432,7 @@ class PHPWord_Style_Paragraph
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Paragraph
|
* @return PHPWord_Style_Paragraph
|
||||||
*/
|
*/
|
||||||
public function setKeepLines($pValue = true)
|
public function setKeepLines($pValue = false)
|
||||||
{
|
{
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
|
|
@ -446,7 +457,7 @@ class PHPWord_Style_Paragraph
|
||||||
* @param bool $pValue
|
* @param bool $pValue
|
||||||
* @return PHPWord_Style_Paragraph
|
* @return PHPWord_Style_Paragraph
|
||||||
*/
|
*/
|
||||||
public function setPageBreakBefore($pValue = true)
|
public function setPageBreakBefore($pValue = false)
|
||||||
{
|
{
|
||||||
if (!is_bool($pValue)) {
|
if (!is_bool($pValue)) {
|
||||||
$pValue = false;
|
$pValue = false;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
<?php
|
||||||
|
namespace PHPWord\Tests;
|
||||||
|
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
use PHPWord_Style_Paragraph;
|
||||||
|
use PHPWord_Style_Tab;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PHPWord_Style_ParagraphTest
|
||||||
|
*
|
||||||
|
* @package PHPWord\Tests
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
*/
|
||||||
|
class PHPWord_Style_ParagraphTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test setting style values with null or empty value
|
||||||
|
*/
|
||||||
|
public function testSetStyleValueWithNullOrEmpty()
|
||||||
|
{
|
||||||
|
$object = new PHPWord_Style_Paragraph();
|
||||||
|
|
||||||
|
$attributes = array(
|
||||||
|
'tabs' => null,
|
||||||
|
'widowControl' => true,
|
||||||
|
'keepNext' => false,
|
||||||
|
'keepLines' => false,
|
||||||
|
'pageBreakBefore' => false,
|
||||||
|
);
|
||||||
|
foreach ($attributes as $key => $default) {
|
||||||
|
$method = 'get' . ucwords($key);
|
||||||
|
$object->setStyleValue("_$key", null);
|
||||||
|
$this->assertEquals($default, $object->$method());
|
||||||
|
$object->setStyleValue("_$key", '');
|
||||||
|
$this->assertEquals($default, $object->$method());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test setting style values with normal value
|
||||||
|
*/
|
||||||
|
public function testSetStyleValueNormal()
|
||||||
|
{
|
||||||
|
$object = new PHPWord_Style_Paragraph();
|
||||||
|
|
||||||
|
$attributes = array(
|
||||||
|
'align' => 'justify',
|
||||||
|
'spaceAfter' => 240,
|
||||||
|
'spaceBefore' => 240,
|
||||||
|
'indent' => 1,
|
||||||
|
'hanging' => 1,
|
||||||
|
'spacing' => 120,
|
||||||
|
'basedOn' => 'Normal',
|
||||||
|
'next' => 'Normal',
|
||||||
|
'widowControl' => false,
|
||||||
|
'keepNext' => true,
|
||||||
|
'keepLines' => true,
|
||||||
|
'pageBreakBefore' => true,
|
||||||
|
);
|
||||||
|
foreach ($attributes as $key => $value) {
|
||||||
|
$method = 'get' . ucwords($key);
|
||||||
|
$object->setStyleValue("_$key", $value);
|
||||||
|
if ($key == 'align') {
|
||||||
|
if ($value == 'justify') {
|
||||||
|
$value = 'both';
|
||||||
|
}
|
||||||
|
} elseif ($key == 'indent' || $key == 'hanging') {
|
||||||
|
$value = $value * 720;
|
||||||
|
} elseif ($key == 'spacing') {
|
||||||
|
$value += 240;
|
||||||
|
}
|
||||||
|
$this->assertEquals($value, $object->$method());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test tabs
|
||||||
|
*/
|
||||||
|
public function testTabs()
|
||||||
|
{
|
||||||
|
$object = new PHPWord_Style_Paragraph();
|
||||||
|
$object->setTabs(array(
|
||||||
|
new PHPWord_Style_Tab('left', 1550),
|
||||||
|
new PHPWord_Style_Tab('right', 5300),
|
||||||
|
));
|
||||||
|
$this->assertInstanceOf('PHPWord_Style_Tabs', $object->getTabs());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -48,6 +48,7 @@ Changes in branch for release 0.7.1 :
|
||||||
- General: (ivanlanin) GH-93 - General: PHPWord_Style_Font refactoring
|
- General: (ivanlanin) GH-93 - General: PHPWord_Style_Font refactoring
|
||||||
- General: (ivanlanin) GH-93 - Font: Use points instead of halfpoints internally. Conversion to halfpoints done during XML Writing.
|
- General: (ivanlanin) GH-93 - Font: Use points instead of halfpoints internally. Conversion to halfpoints done during XML Writing.
|
||||||
- Bugfix: (ivanlanin) GH-94 - General: PHPWord_Shared_Drawing::centimetersToPixels() conversion
|
- Bugfix: (ivanlanin) GH-94 - General: PHPWord_Shared_Drawing::centimetersToPixels() conversion
|
||||||
|
- Feature: (ivanlanin) - Paragraph: setTabs() function
|
||||||
- QA: (Progi1984) - UnitTests
|
- QA: (Progi1984) - UnitTests
|
||||||
|
|
||||||
Changes in branch for release 0.7.0 :
|
Changes in branch for release 0.7.0 :
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue