implement paragraph textAlignment
This commit is contained in:
parent
92fc54992a
commit
200d846f61
|
|
@ -0,0 +1,45 @@
|
|||
<?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.
|
||||
*
|
||||
* @see https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2017 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\SimpleType;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\AbstractEnum;
|
||||
|
||||
/**
|
||||
* Magnification Preset Values
|
||||
*
|
||||
* @since 0.14.0
|
||||
*
|
||||
* @see http://www.datypic.com/sc/ooxml/t-w_ST_TextAlignment.html
|
||||
*/
|
||||
final class TextAlignment extends AbstractEnum
|
||||
{
|
||||
//Align Text at Top
|
||||
const TOP = 'top';
|
||||
|
||||
//Align Text at Center
|
||||
const CENTER = 'center';
|
||||
|
||||
//Align Text at Baseline
|
||||
const BASELINE = 'baseline';
|
||||
|
||||
//Align Text at Bottom
|
||||
const BOTTOM = 'bottom';
|
||||
|
||||
//Automatically Determine Alignment
|
||||
const AUTO = 'auto';
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ namespace PhpOffice\PhpWord\Style;
|
|||
use PhpOffice\Common\Text;
|
||||
use PhpOffice\PhpWord\Exception\InvalidStyleException;
|
||||
use PhpOffice\PhpWord\SimpleType\Jc;
|
||||
use PhpOffice\PhpWord\SimpleType\TextAlignment;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
|
|
@ -172,6 +173,13 @@ class Paragraph extends Border
|
|||
*/
|
||||
private $bidi = false;
|
||||
|
||||
/**
|
||||
* Vertical Character Alignment on Line
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $textAlignment;
|
||||
|
||||
/**
|
||||
* Set Style value
|
||||
*
|
||||
|
|
@ -224,6 +232,7 @@ class Paragraph extends Border
|
|||
'shading' => $this->getShading(),
|
||||
'contextualSpacing' => $this->hasContextualSpacing(),
|
||||
'bidi' => $this->isBidi(),
|
||||
'textAlignment' => $this->getTextAlignment(),
|
||||
);
|
||||
|
||||
return $styles;
|
||||
|
|
@ -794,4 +803,28 @@ class Paragraph extends Border
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get textAlignment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTextAlignment()
|
||||
{
|
||||
return $this->textAlignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set textAlignment
|
||||
*
|
||||
* @param string $textAlignment
|
||||
* @return self
|
||||
*/
|
||||
public function setTextAlignment($textAlignment)
|
||||
{
|
||||
TextAlignment::validate($textAlignment);
|
||||
$this->textAlignment = $textAlignment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,6 +109,9 @@ class Paragraph extends AbstractStyle
|
|||
//Paragraph contextualSpacing
|
||||
$xmlWriter->writeElementIf($styles['contextualSpacing'] === true, 'w:contextualSpacing');
|
||||
|
||||
//Paragraph contextualSpacing
|
||||
$xmlWriter->writeElementIf($styles['textAlignment'] !== null, 'w:textAlignment', 'w:val', $styles['textAlignment']);
|
||||
|
||||
// Child style: alignment, indentation, spacing, and shading
|
||||
$this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']);
|
||||
$this->writeChildStyle($xmlWriter, 'Spacing', $styles['spacing']);
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($createFunction, $image->getImageCreateFunction());
|
||||
$this->assertEquals($imageFunction, $image->getImageFunction());
|
||||
$this->assertFalse($image->isMemImage());
|
||||
$this->assertNotNull($image->getImageStringData());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
'doubleStrikethrough' => false,
|
||||
'smallCaps' => false,
|
||||
'allCaps' => false,
|
||||
'rtl' => false,
|
||||
'fgColor' => null,
|
||||
'bgColor' => null,
|
||||
'scale' => null,
|
||||
|
|
@ -113,6 +114,8 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
'scale' => 150,
|
||||
'spacing' => 240,
|
||||
'kerning' => 10,
|
||||
'rtl' => true,
|
||||
'lang' => new Language(Language::EN_US),
|
||||
);
|
||||
$object->setStyleByArray($attributes);
|
||||
foreach ($attributes as $key => $value) {
|
||||
|
|
@ -173,4 +176,15 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
$object = new Font();
|
||||
$object->setLineHeight('a');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting the language as a string
|
||||
*/
|
||||
public function testSetLangAsString()
|
||||
{
|
||||
$object = new Font();
|
||||
$object->setLang(Language::FR_BE);
|
||||
$this->assertInstanceOf('PhpOffice\PhpWord\Style\Language', $object->getLang());
|
||||
$this->assertEquals(Language::FR_BE, $object->getLang()->getLatin());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
|||
'keepLines' => true,
|
||||
'pageBreakBefore' => true,
|
||||
'contextualSpacing' => true,
|
||||
'textAlignment' => 'auto',
|
||||
'bidi' => true,
|
||||
);
|
||||
foreach ($attributes as $key => $value) {
|
||||
|
|
@ -114,7 +115,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$object = new Paragraph();
|
||||
|
||||
$attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter');
|
||||
$attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter', 'textAlignment');
|
||||
foreach ($attributes as $key) {
|
||||
$get = $this->findGetter($key, null, $object);
|
||||
$this->assertNull($object->$get());
|
||||
|
|
|
|||
|
|
@ -17,13 +17,13 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\Word2007\Part;
|
||||
|
||||
use PhpOffice\PhpWord\ComplexType\ProofState;
|
||||
use PhpOffice\PhpWord\ComplexType\TrackChangesView;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Settings;
|
||||
use PhpOffice\PhpWord\SimpleType\Zoom;
|
||||
use PhpOffice\PhpWord\Style\Language;
|
||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||
use PhpOffice\PhpWord\ComplexType\ProofState;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
|
||||
|
|
|
|||
Loading…
Reference in New Issue