New `Indentation` and `Spacing` style; Ability to define first line and right indentation

This commit is contained in:
Ivan Lanin 2014-05-02 13:39:56 +07:00
parent 999a9c5037
commit e613e13478
14 changed files with 841 additions and 455 deletions

View File

@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
## 0.10.0 - Not yet released
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML and PDF writing support is enabled.
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML and PDF writing support is enabled. Basic ODText reader is introduced.
### Features
@ -43,6 +43,8 @@ This release marked heavy refactorings on internal code structure with the creat
- Font: Small caps, all caps, and double strikethrough - @ivanlanin GH-151
- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin GH-199
- Style: Remove `bgColor` from `Font`, `Table`, and `Cell` and put it into the new `Shading` style - @ivanlanin
- Style: New `Indentation` and `Spacing` style - @ivanlanin
- Paragraph: Ability to define first line and right indentation - @ivanlanin
### Bugfixes
@ -63,6 +65,7 @@ This release marked heavy refactorings on internal code structure with the creat
- All current methods on `Media`
- `Element\Link::getLinkSrc` replaced by `Element\Link::getTarget`
- `Element\Link::getLinkName` replaced by `Element\Link::getText`
- `Style\Cell::getDefaultBorderColor`
### Miscellaneous

View File

@ -16,26 +16,26 @@ $section = $phpWord->addSection();
$section->addText('Below are the samples on how to control your paragraph ' .
'pagination. See "Line and Page Break" tab on paragraph properties ' .
'window to see the attribute set by these controls.',
array('bold' => true), null);
array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
$section->addText('Paragraph with widowControl = false (default: true). ' .
'A "widow" is the last line of a paragraph printed by itself at the top ' .
'of a page. An "orphan" is the first line of a paragraph printed by ' .
'itself at the bottom of a page. Set this option to "false" if you want ' .
'to disable this automatic control.',
null, array('widowControl' => false));
null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
$section->addText('Paragraph with keepNext = true (default: false). ' .
'"Keep with next" is used to prevent Word from inserting automatic page ' .
'breaks between paragraphs. Set this option to "true" if you do not want ' .
'your paragraph to be separated with the next paragraph.',
null, array('keepNext' => true));
null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
$section->addText('Paragraph with keepLines = true (default: false). ' .
'"Keep lines together" will prevent Word from inserting an automatic page ' .
'break within a paragraph. Set this option to "true" if you do not want ' .
'all lines of your paragraph to be in the same page.',
null, array('keepLines' => true));
null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
$section->addText('Keep scrolling. More below.');

View File

@ -37,6 +37,8 @@ class Settings
* Applied to:
* - Section: margins, header/footer height, gutter, column spacing
* - Tab: position
* - Indentation: left, right, firstLine, hanging
* - Spacing: before, after
*
* @const int|float
*/

View File

@ -16,9 +16,21 @@ use PhpOffice\PhpWord\Style\Shading;
*/
class Cell extends Border
{
/**
* Text direction constants
*
* @const string
*/
const TEXT_DIR_BTLR = 'btLr';
const TEXT_DIR_TBRL = 'tbRl';
/**
* Default border color
*
* @const string
*/
const DEFAULT_BORDER_COLOR = '000000';
/**
* Vertical align (top, center, both, bottom)
*
@ -33,13 +45,6 @@ class Cell extends Border
*/
private $textDirection;
/**
* Border Default Color
*
* @var string
*/
private $defaultBorderColor;
/**
* colspan
*
@ -64,24 +69,6 @@ class Cell extends Border
*/
private $shading;
/**
* Create a new Cell Style
*/
public function __construct()
{
$this->valign = null;
$this->textDirection = null;
$this->borderTopSize = null;
$this->borderTopColor = null;
$this->borderLeftSize = null;
$this->borderLeftColor = null;
$this->borderRightSize = null;
$this->borderRightColor = null;
$this->borderBottomSize = null;
$this->borderBottomColor = null;
$this->defaultBorderColor = '000000';
}
/**
* Get vertical align
*/
@ -93,11 +80,11 @@ class Cell extends Border
/**
* Set vertical align
*
* @param string $pValue
* @param string $value
*/
public function setVAlign($pValue = null)
public function setVAlign($value = null)
{
$this->valign = $pValue;
$this->valign = $value;
}
/**
@ -111,11 +98,11 @@ class Cell extends Border
/**
* Set text direction
*
* @param string $pValue
* @param string $value
*/
public function setTextDirection($pValue = null)
public function setTextDirection($value = null)
{
$this->textDirection = $pValue;
$this->textDirection = $value;
}
/**
@ -134,29 +121,21 @@ class Cell extends Border
* Set background
*
* @param string $value
* @return \PhpOffice\PhpWord\Style\Table
* @return self
*/
public function setBgColor($value = null)
{
$this->setShading(array('fill' => $value));
}
/**
* Get default border color
*/
public function getDefaultBorderColor()
{
return $this->defaultBorderColor;
return $this->setShading(array('fill' => $value));
}
/**
* Set grid span (colspan)
*
* @param int $pValue
* @param int $value
*/
public function setGridSpan($pValue = null)
public function setGridSpan($value = null)
{
$this->gridSpan = $pValue;
$this->gridSpan = $value;
}
/**
@ -170,11 +149,11 @@ class Cell extends Border
/**
* Set vertical merge (rowspan)
*
* @param string $pValue
* @param string $value
*/
public function setVMerge($pValue = null)
public function setVMerge($value = null)
{
$this->vMerge = $pValue;
$this->vMerge = $value;
}
/**
@ -214,4 +193,15 @@ class Cell extends Border
return $this;
}
/**
* Get default border color
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getDefaultBorderColor()
{
return self::DEFAULT_BORDER_COLOR;
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Style;
/**
* Paragraph indentation style
*
* @link http://www.schemacentral.com/sc/ooxml/t-w_CT_Ind.html
* @since 0.10.0
*/
class Indentation extends AbstractStyle
{
/**
* Left indentation (twip)
*
* @var int|float
*/
private $left = 0;
/**
* Right indentation (twip)
*
* @var int|float
*/
private $right = 0;
/**
* Additional first line indentation (twip)
*
* @var int|float
*/
private $firstLine;
/**
* Indentation removed from first line (twip)
*
* @var int|float
*/
private $hanging;
/**
* Create a new instance
*
* @param array $style
*/
public function __construct($style = array())
{
$this->setStyleByArray($style);
}
/**
* Get left
*
* @return int|float
*/
public function getLeft()
{
return $this->left;
}
/**
* Set left
*
* @param int|float $value
* @return self
*/
public function setLeft($value = null)
{
$this->left = $this->setNumericVal($value, $this->left);
return $this;
}
/**
* Get right
*
* @return int|float
*/
public function getRight()
{
return $this->right;
}
/**
* Set right
*
* @param int|float $value
* @return self
*/
public function setRight($value = null)
{
$this->right = $this->setNumericVal($value, $this->right);
return $this;
}
/**
* Get first line
*
* @return int|float
*/
public function getFirstLine()
{
return $this->firstLine;
}
/**
* Set first line
*
* @param int|float $value
* @return self
*/
public function setFirstLine($value = null)
{
$this->firstLine = $this->setNumericVal($value, $this->firstLine);
return $this;
}
/**
* Get hanging
*
* @return int|float
*/
public function getHanging()
{
return $this->hanging;
}
/**
* Set hanging
*
* @param int|float $value
* @return self
*/
public function setHanging($value = null)
{
$this->hanging = $this->setNumericVal($value, $this->hanging);
return $this;
}
}

View File

@ -11,6 +11,8 @@ namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Exception\InvalidStyleException;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Indentation;
use PhpOffice\PhpWord\Style\Spacing;
/**
* Paragraph style
@ -19,13 +21,6 @@ class Paragraph extends AbstractStyle
{
const LINE_HEIGHT = 240;
/**
* Text line height
*
* @var int
*/
private $lineHeight;
/**
* Paragraph alignment
*
@ -34,25 +29,11 @@ class Paragraph extends AbstractStyle
private $align;
/**
* Space before Paragraph
* Text line height
*
* @var int
*/
private $spaceBefore;
/**
* Space after Paragraph
*
* @var int
*/
private $spaceAfter;
/**
* Spacing between breaks
*
* @var int
*/
private $spacing;
private $lineHeight;
/**
* Set of Custom Tab Stops
@ -61,20 +42,6 @@ class Paragraph extends AbstractStyle
*/
private $tabs = array();
/**
* Indent by how much
*
* @var int
*/
private $indent;
/**
* Hanging by how much
*
* @var int
*/
private $hanging;
/**
* Parent style
*
@ -117,6 +84,20 @@ class Paragraph extends AbstractStyle
*/
private $pageBreakBefore = false;
/**
* Indentation
*
* @var \PhpOffice\PhpWord\Style\Indentation
*/
private $indentation;
/**
* Spacing
*
* @var \PhpOffice\PhpWord\Style\Spacing
*/
private $spacing;
/**
* Set style by array
*
@ -171,296 +152,96 @@ class Paragraph extends AbstractStyle
/**
* Set Paragraph Alignment
*
* @param string $pValue
* @param string $value
* @return self
*/
public function setAlign($pValue = null)
public function setAlign($value = null)
{
if (strtolower($pValue) == 'justify') {
if (strtolower($value) == 'justify') {
// justify becames both
$pValue = 'both';
$value = 'both';
}
$this->align = $pValue;
$this->align = $value;
return $this;
}
/**
* Get Space before Paragraph
* Get space before paragraph
*
* @return integer
*/
public function getSpaceBefore()
{
return $this->spaceBefore;
if (!is_null($this->spacing)) {
return $this->spacing->getBefore();
}
}
/**
* Set Space before Paragraph
* Set space before paragraph
*
* @param int $pValue
* @param int $value
* @return self
*/
public function setSpaceBefore($pValue = null)
public function setSpaceBefore($value = null)
{
$this->spaceBefore = $pValue;
return $this;
return $this->setSpace(array('before' => $value));
}
/**
* Get Space after Paragraph
* Get space after paragraph
*
* @return integer
*/
public function getSpaceAfter()
{
return $this->spaceAfter;
if (!is_null($this->spacing)) {
return $this->spacing->getAfter();
}
}
/**
* Set Space after Paragraph
* Set space after paragraph
*
* @param int $pValue
* @param int $value
* @return self
*/
public function setSpaceAfter($pValue = null)
public function setSpaceAfter($value = null)
{
$this->spaceAfter = $pValue;
return $this;
return $this->setSpace(array('after' => $value));
}
/**
* Get Spacing between breaks
* Get spacing between lines
*
* @return int
*/
public function getSpacing()
{
return $this->spacing;
if (!is_null($this->spacing)) {
return $this->spacing->getLine();
}
}
/**
* Set Spacing between breaks
* Set spacing between lines
*
* @param int $pValue
* @param int $value
* @return self
*/
public function setSpacing($pValue = null)
public function setSpacing($value = null)
{
$this->spacing = $pValue;
return $this;
return $this->setSpace(array('line' => $value));
}
/**
* Get indentation
* Get line height
*
* @return int
* @return int|float
*/
public function getIndent()
public function getLineHeight()
{
return $this->indent;
}
/**
* Set indentation
*
* @param int $pValue
* @return self
*/
public function setIndent($pValue = null)
{
$this->indent = $pValue;
return $this;
}
/**
* Get hanging
*
* @return int
*/
public function getHanging()
{
return $this->hanging;
}
/**
* Set hanging
*
* @param int $pValue
* @return self
*/
public function setHanging($pValue = null)
{
$this->hanging = $pValue;
return $this;
}
/**
* Get tabs
*
* @return \PhpOffice\PhpWord\Style\Tab[]
*/
public function getTabs()
{
return $this->tabs;
}
/**
* Set tabs
*
* @param array $pValue
* @return self
*/
public function setTabs($pValue = null)
{
if (is_array($pValue)) {
$this->tabs = $pValue;
}
return $this;
}
/**
* Get parent style ID
*
* @return string
*/
public function getBasedOn()
{
return $this->basedOn;
}
/**
* Set parent style ID
*
* @param string $pValue
* @return self
*/
public function setBasedOn($pValue = 'Normal')
{
$this->basedOn = $pValue;
return $this;
}
/**
* Get style for next paragraph
*
* @return string
*/
public function getNext()
{
return $this->next;
}
/**
* Set style for next paragraph
*
* @param string $pValue
* @return self
*/
public function setNext($pValue = null)
{
$this->next = $pValue;
return $this;
}
/**
* Get allow first/last line to display on a separate page setting
*
* @return bool
*/
public function getWidowControl()
{
return $this->widowControl;
}
/**
* Set keep paragraph with next paragraph setting
*
* @param bool $pValue
* @return self
*/
public function setWidowControl($pValue = true)
{
if (!is_bool($pValue)) {
$pValue = true;
}
$this->widowControl = $pValue;
return $this;
}
/**
* Get keep paragraph with next paragraph setting
*
* @return bool
*/
public function getKeepNext()
{
return $this->keepNext;
}
/**
* Set keep paragraph with next paragraph setting
*
* @param bool $pValue
* @return self
*/
public function setKeepNext($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->keepNext = $pValue;
return $this;
}
/**
* Get keep all lines on one page setting
*
* @return bool
*/
public function getKeepLines()
{
return $this->keepLines;
}
/**
* Set keep all lines on one page setting
*
* @param bool $pValue
* @return self
*/
public function setKeepLines($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->keepLines = $pValue;
return $this;
}
/**
* Get start paragraph on next page setting
*
* @return bool
*/
public function getPageBreakBefore()
{
return $this->pageBreakBefore;
}
/**
* Set start paragraph on next page setting
*
* @param bool $pValue
* @return self
*/
public function setPageBreakBefore($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->pageBreakBefore = $pValue;
return $this;
return $this->lineHeight;
}
/**
@ -486,12 +267,279 @@ class Paragraph extends AbstractStyle
}
/**
* Get line height
* Get indentation
*
* @return int|float
* @return int
*/
public function getLineHeight()
public function getIndent()
{
return $this->lineHeight;
if (!is_null($this->indentation)) {
return $this->indentation->getLeft();
}
}
/**
* Set indentation
*
* @param int $value
* @return self
*/
public function setIndent($value = null)
{
return $this->setIndentation(array('left' => $value));
}
/**
* Get hanging
*
* @return int
*/
public function getHanging()
{
if (!is_null($this->indentation)) {
return $this->indentation->getHanging();
}
}
/**
* Set hanging
*
* @param int $value
* @return self
*/
public function setHanging($value = null)
{
return $this->setIndentation(array('hanging' => $value));
}
/**
* Get tabs
*
* @return \PhpOffice\PhpWord\Style\Tab[]
*/
public function getTabs()
{
return $this->tabs;
}
/**
* Set tabs
*
* @param array $value
* @return self
*/
public function setTabs($value = null)
{
if (is_array($value)) {
$this->tabs = $value;
}
return $this;
}
/**
* Get parent style ID
*
* @return string
*/
public function getBasedOn()
{
return $this->basedOn;
}
/**
* Set parent style ID
*
* @param string $value
* @return self
*/
public function setBasedOn($value = 'Normal')
{
$this->basedOn = $value;
return $this;
}
/**
* Get style for next paragraph
*
* @return string
*/
public function getNext()
{
return $this->next;
}
/**
* Set style for next paragraph
*
* @param string $value
* @return self
*/
public function setNext($value = null)
{
$this->next = $value;
return $this;
}
/**
* Get allow first/last line to display on a separate page setting
*
* @return bool
*/
public function getWidowControl()
{
return $this->widowControl;
}
/**
* Set keep paragraph with next paragraph setting
*
* @param bool $value
* @return self
*/
public function setWidowControl($value = true)
{
if (!is_bool($value)) {
$value = true;
}
$this->widowControl = $value;
return $this;
}
/**
* Get keep paragraph with next paragraph setting
*
* @return bool
*/
public function getKeepNext()
{
return $this->keepNext;
}
/**
* Set keep paragraph with next paragraph setting
*
* @param bool $value
* @return self
*/
public function setKeepNext($value = false)
{
if (!is_bool($value)) {
$value = false;
}
$this->keepNext = $value;
return $this;
}
/**
* Get keep all lines on one page setting
*
* @return bool
*/
public function getKeepLines()
{
return $this->keepLines;
}
/**
* Set keep all lines on one page setting
*
* @param bool $value
* @return self
*/
public function setKeepLines($value = false)
{
if (!is_bool($value)) {
$value = false;
}
$this->keepLines = $value;
return $this;
}
/**
* Get start paragraph on next page setting
*
* @return bool
*/
public function getPageBreakBefore()
{
return $this->pageBreakBefore;
}
/**
* Set start paragraph on next page setting
*
* @param bool $value
* @return self
*/
public function setPageBreakBefore($value = false)
{
if (!is_bool($value)) {
$value = false;
}
$this->pageBreakBefore = $value;
return $this;
}
/**
* Get shading
*
* @return \PhpOffice\PhpWord\Style\Indentation
*/
public function getIndentation()
{
return $this->indentation;
}
/**
* Set shading
*
* @param array $value
* @return self
*/
public function setIndentation($value = null)
{
if (is_array($value)) {
if (!$this->indentation instanceof Indentation) {
$this->indentation = new Indentation();
}
$this->indentation->setStyleByArray($value);
} else {
$this->indentation = null;
}
return $this;
}
/**
* Get shading
*
* @return \PhpOffice\PhpWord\Style\Spacing
* @todo Rename to getSpacing in 1.0
*/
public function getSpace()
{
return $this->spacing;
}
/**
* Set shading
*
* @param array $value
* @return self
* @todo Rename to setSpacing in 1.0
*/
public function setSpace($value = null)
{
if (is_array($value)) {
if (!$this->spacing instanceof Spacing) {
$this->spacing = new Spacing();
}
$this->spacing->setStyleByArray($value);
} else {
$this->spacing = null;
}
return $this;
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Style;
/**
* Spacing between lines and above/below paragraph style
*
* @link http://www.schemacentral.com/sc/ooxml/t-w_CT_Spacing.html
* @since 0.10.0
*/
class Spacing extends AbstractStyle
{
/**
* Spacing above paragraph (twip)
*
* @var int|float
*/
private $before;
/**
* Spacing below paragraph (twip)
*
* @var int|float
*/
private $after;
/**
* Spacing between lines in paragraph (twip)
*
* @var int|float
*/
private $line;
/**
* Type of spacing between lines
*
* @var string
*/
private $rule = 'auto';
/**
* Create a new instance
*
* @param array $style
*/
public function __construct($style = array())
{
$this->setStyleByArray($style);
}
/**
* Get before
*
* @return int|float
*/
public function getBefore()
{
return $this->before;
}
/**
* Set before
*
* @param int|float $value
* @return self
*/
public function setBefore($value = null)
{
$this->before = $this->setNumericVal($value, $this->before);
return $this;
}
/**
* Get after
*
* @return int|float
*/
public function getAfter()
{
return $this->after;
}
/**
* Set after
*
* @param int|float $value
* @return self
*/
public function setAfter($value = null)
{
$this->after = $this->setNumericVal($value, $this->after);
return $this;
}
/**
* Get line
*
* @return int|float
*/
public function getLine()
{
return $this->line;
}
/**
* Set distance
*
* @param int|float $value
* @return self
*/
public function setLine($value = null)
{
$this->line = $this->setNumericVal($value, $this->line);
return $this;
}
/**
* Get line rule
*
* @return string
*/
public function getRule()
{
return $this->rule;
}
/**
* Set line rule
*
* @param string $value
* @return self
*/
public function setRule($value = null)
{
$this->rule = $value;
return $this;
}
}

View File

@ -56,7 +56,7 @@ abstract class AbstractStyle
* @param int|float $default
* @return int|float
*/
protected function convertTwip($value, $default)
protected function convertTwip($value, $default = 0)
{
$unit = Settings::getMeasurementUnit();
if ($unit == Settings::UNIT_TWIP || $value == $default) {

View File

@ -9,6 +9,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\Style\Cell as CellStyle;
use PhpOffice\PhpWord\Writer\Word2007\Style\Shading;
/**
@ -27,9 +28,6 @@ class Cell extends AbstractStyle
return;
}
$bgColor = $this->style->getBgColor();
$valign = $this->style->getVAlign();
$textDir = $this->style->getTextDirection();
$brdSz = $this->style->getBorderSize();
$brdCol = $this->style->getBorderColor();
$hasBorders = false;
@ -40,49 +38,49 @@ class Cell extends AbstractStyle
}
}
$styles = (!is_null($bgColor) || !is_null($valign) || !is_null($textDir) || $hasBorders) ? true : false;
// Border
if ($hasBorders) {
$mbWriter = new MarginBorder($this->xmlWriter);
$mbWriter->setSizes($brdSz);
$mbWriter->setColors($brdCol);
$mbWriter->setAttributes(array('defaultColor' => CellStyle::DEFAULT_BORDER_COLOR));
if ($styles) {
if (!is_null($textDir)) {
$this->xmlWriter->startElement('w:textDirection');
$this->xmlWriter->writeAttribute('w:val', $textDir);
$this->xmlWriter->endElement();
}
if (!is_null($bgColor)) {
$styleWriter = new Shading($this->xmlWriter, $this->style->getShading());
$styleWriter->write();
}
if (!is_null($valign)) {
$this->xmlWriter->startElement('w:vAlign');
$this->xmlWriter->writeAttribute('w:val', $valign);
$this->xmlWriter->endElement();
}
if ($hasBorders) {
$defaultColor = $this->style->getDefaultBorderColor();
$mbWriter = new MarginBorder($this->xmlWriter);
$mbWriter->setSizes($brdSz);
$mbWriter->setColors($brdCol);
$mbWriter->setAttributes(array('defaultColor' => $defaultColor));
$this->xmlWriter->startElement('w:tcBorders');
$mbWriter->write();
$this->xmlWriter->endElement();
}
}
$gridSpan = $this->style->getGridSpan();
if (!is_null($gridSpan)) {
$this->xmlWriter->startElement('w:gridSpan');
$this->xmlWriter->writeAttribute('w:val', $gridSpan);
$this->xmlWriter->startElement('w:tcBorders');
$mbWriter->write();
$this->xmlWriter->endElement();
}
$vMerge = $this->style->getVMerge();
if (!is_null($vMerge)) {
// Text direction
if (!is_null($this->style->getTextDirection())) {
$this->xmlWriter->startElement('w:textDirection');
$this->xmlWriter->writeAttribute('w:val', $this->style->getTextDirection());
$this->xmlWriter->endElement();
}
// Shading
if (!is_null($this->style->getShading())) {
$styleWriter = new Shading($this->xmlWriter, $this->style->getShading());
$styleWriter->write();
}
// Alignment
if (!is_null($this->style->getVAlign())) {
$this->xmlWriter->startElement('w:vAlign');
$this->xmlWriter->writeAttribute('w:val', $this->style->getVAlign());
$this->xmlWriter->endElement();
}
// Colspan
if (!is_null($this->style->getGridSpan())) {
$this->xmlWriter->startElement('w:gridSpan');
$this->xmlWriter->writeAttribute('w:val', $this->style->getGridSpan());
$this->xmlWriter->endElement();
}
// Row span
if (!is_null($this->style->getVMerge())) {
$this->xmlWriter->startElement('w:vMerge');
$this->xmlWriter->writeAttribute('w:val', $vMerge);
$this->xmlWriter->writeAttribute('w:val', $this->style->getVMerge());
$this->xmlWriter->endElement();
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
/**
* Paragraph indentation style writer
*
* @since 0.10.0
*/
class Indentation extends AbstractStyle
{
/**
* Write style
*/
public function write()
{
if (!($this->style instanceof \PhpOffice\PhpWord\Style\Indentation)) {
return;
}
$this->xmlWriter->startElement('w:ind');
$this->xmlWriter->writeAttribute('w:left', $this->convertTwip($this->style->getLeft()));
$this->xmlWriter->writeAttribute('w:right', $this->convertTwip($this->style->getRight()));
if (!is_null($this->style->getFirstLine())) {
$this->xmlWriter->writeAttribute('w:firstLine', $this->convertTwip($this->style->getFirstLine()));
}
if (!is_null($this->style->getHanging())) {
$this->xmlWriter->writeAttribute('w:hanging', $this->convertTwip($this->style->getHanging()));
}
$this->xmlWriter->endElement();
}
}

View File

@ -10,6 +10,8 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\Writer\Word2007\Style\Tab;
use PhpOffice\PhpWord\Writer\Word2007\Style\Indentation;
use PhpOffice\PhpWord\Writer\Word2007\Style\Spacing;
/**
* Paragraph style writer
@ -62,99 +64,69 @@ class Paragraph extends AbstractStyle
return;
}
$align = $this->style->getAlign();
$spacing = $this->style->getSpacing();
$spaceBefore = $this->style->getSpaceBefore();
$spaceAfter = $this->style->getSpaceAfter();
$indent = $this->style->getIndent();
$hanging = $this->style->getHanging();
$tabs = $this->style->getTabs();
$widowControl = $this->style->getWidowControl();
$keepNext = $this->style->getKeepNext();
$keepLines = $this->style->getKeepLines();
$pageBreakBefore = $this->style->getPageBreakBefore();
if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) ||
!is_null($spaceAfter) || !is_null($indent) || !is_null($hanging) ||
!is_null($tabs) || !is_null($widowControl) || !is_null($keepNext) ||
!is_null($keepLines) || !is_null($pageBreakBefore)) {
if (!$this->withoutPPR) {
$this->xmlWriter->startElement('w:pPr');
}
if (!$this->withoutPPR) {
$this->xmlWriter->startElement('w:pPr');
}
// Alignment
if (!is_null($align)) {
$this->xmlWriter->startElement('w:jc');
$this->xmlWriter->writeAttribute('w:val', $align);
$this->xmlWriter->endElement();
}
// Alignment
if (!is_null($this->style->getAlign())) {
$this->xmlWriter->startElement('w:jc');
$this->xmlWriter->writeAttribute('w:val', $this->style->getAlign());
$this->xmlWriter->endElement();
}
// Indentation
if (!is_null($indent) || !is_null($hanging)) {
$this->xmlWriter->startElement('w:ind');
$this->xmlWriter->writeAttribute('w:firstLine', 0);
if (!is_null($indent)) {
$this->xmlWriter->writeAttribute('w:left', $indent);
}
if (!is_null($hanging)) {
$this->xmlWriter->writeAttribute('w:hanging', $hanging);
}
$this->xmlWriter->endElement();
}
// Indentation
if (!is_null($this->style->getIndentation())) {
$styleWriter = new Indentation($this->xmlWriter, $this->style->getIndentation());
$styleWriter->write();
}
// Spacing
if (!is_null($spaceBefore) || !is_null($spaceAfter) ||
!is_null($spacing)) {
$this->xmlWriter->startElement('w:spacing');
if (!is_null($spaceBefore)) {
$this->xmlWriter->writeAttribute('w:before', $spaceBefore);
}
if (!is_null($spaceAfter)) {
$this->xmlWriter->writeAttribute('w:after', $spaceAfter);
}
if (!is_null($spacing)) {
$this->xmlWriter->writeAttribute('w:line', $spacing);
$this->xmlWriter->writeAttribute('w:lineRule', 'auto');
}
$this->xmlWriter->endElement();
}
// Spacing
if (!is_null($this->style->getSpace())) {
$styleWriter = new Spacing($this->xmlWriter, $this->style->getSpace());
$styleWriter->write();
}
// Pagination
if (!$widowControl) {
$this->xmlWriter->startElement('w:widowControl');
$this->xmlWriter->writeAttribute('w:val', '0');
$this->xmlWriter->endElement();
}
if ($keepNext) {
$this->xmlWriter->startElement('w:keepNext');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
if ($keepLines) {
$this->xmlWriter->startElement('w:keepLines');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
if ($pageBreakBefore) {
$this->xmlWriter->startElement('w:pageBreakBefore');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
// Pagination
if (!$widowControl) {
$this->xmlWriter->startElement('w:widowControl');
$this->xmlWriter->writeAttribute('w:val', '0');
$this->xmlWriter->endElement();
}
if ($keepNext) {
$this->xmlWriter->startElement('w:keepNext');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
if ($keepLines) {
$this->xmlWriter->startElement('w:keepLines');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
if ($pageBreakBefore) {
$this->xmlWriter->startElement('w:pageBreakBefore');
$this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement();
}
// Tabs
if (!empty($tabs)) {
$this->xmlWriter->startElement("w:tabs");
foreach ($tabs as $tab) {
$styleWriter = new Tab($this->xmlWriter, $tab);
$styleWriter->write();
}
$this->xmlWriter->endElement();
// Tabs
$tabs = $this->style->getTabs();
if (!empty($tabs)) {
$this->xmlWriter->startElement("w:tabs");
foreach ($tabs as $tab) {
$styleWriter = new Tab($this->xmlWriter, $tab);
$styleWriter->write();
}
$this->xmlWriter->endElement();
}
if (!$this->withoutPPR) {
$this->xmlWriter->endElement(); // w:pPr
}
if (!$this->withoutPPR) {
$this->xmlWriter->endElement(); // w:pPr
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
/**
* Spacing between lines and above/below paragraph style writer
*
* @since 0.10.0
*/
class Spacing extends AbstractStyle
{
/**
* Write style
*/
public function write()
{
if (!($this->style instanceof \PhpOffice\PhpWord\Style\Spacing)) {
return;
}
$this->xmlWriter->startElement('w:spacing');
if (!is_null($this->style->getBefore())) {
$this->xmlWriter->writeAttribute('w:before', $this->convertTwip($this->style->getBefore()));
}
if (!is_null($this->style->getAfter())) {
$this->xmlWriter->writeAttribute('w:after', $this->convertTwip($this->style->getAfter()));
}
if (!is_null($this->style->getLine())) {
$this->xmlWriter->writeAttribute('w:line', $this->style->getLine());
$this->xmlWriter->writeAttribute('w:lineRule', $this->style->getRule());
}
$this->xmlWriter->endElement();
}
}

View File

@ -28,7 +28,7 @@ class Tab extends AbstractStyle
$this->xmlWriter->startElement("w:tab");
$this->xmlWriter->writeAttribute("w:val", $this->style->getStopType());
$this->xmlWriter->writeAttribute("w:leader", $this->style->getLeader());
$this->xmlWriter->writeAttribute('w:pos', $this->convertTwip($this->style->getPosition(), 0));
$this->xmlWriter->writeAttribute('w:pos', $this->convertTwip($this->style->getPosition()));
$this->xmlWriter->endElement();
}
}

View File

@ -59,11 +59,6 @@ class CellTest extends \PHPUnit_Framework_TestCase
$default = '000000';
$value = 'FF0000';
$this->assertEquals($default, $object->getDefaultBorderColor());
$object->setStyleValue('defaultBorderColor', $value);
$this->assertEquals($value, $object->getDefaultBorderColor());
$object->setStyleValue('borderColor', $value);
$expected = array($value, $value, $value, $value);
$this->assertEquals($expected, $object->getBorderColor());