Merge branch 'development' into develop

Conflicts:
	tests/PhpWord/Writer/Word2007/Part/SettingsTest.php
This commit is contained in:
troosan 2017-07-04 15:38:01 +02:00
commit a6c6f9faa1
21 changed files with 386 additions and 115 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ composer.lock
composer.phar composer.phar
vendor vendor
/report /report
/build
/samples/resources /samples/resources
/samples/results /samples/results
/.settings /.settings

View File

@ -109,8 +109,8 @@ Zip class
By default, PHPWord uses `Zip extension <http://php.net/manual/en/book.zip.php>`__ By default, PHPWord uses `Zip extension <http://php.net/manual/en/book.zip.php>`__
to deal with ZIP compressed archives and files inside them. If you can't have to deal with ZIP compressed archives and files inside them. If you can't have
Zip extension installed on your server, you can use pure PHP library Zip extension installed on your server, you can use pure PHP library
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which is
included with PHPWord. included in PHPWord.
.. code-block:: php .. code-block:: php
@ -130,6 +130,17 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); \PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
Spelling and grammatical checks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default spelling and grammatical errors are shown as soon as you open a word document.
For big documents this can slow down the opening of the document. You can hide the spelling and/or grammatical errors with:
.. code-block:: php
\PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true);
\PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true);
Default font Default font
~~~~~~~~~~~~ ~~~~~~~~~~~~

View File

@ -77,6 +77,7 @@ See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
- ``spaceAfter``. Space after paragraph. - ``spaceAfter``. Space after paragraph.
- ``tabs``. Set of custom tab stops. - ``tabs``. Set of custom tab stops.
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*. - ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.
.. _table-style: .. _table-style:

View File

@ -1,5 +1,6 @@
<?php <?php
use PhpOffice\PhpWord\SimpleType\FootnoteProperties; use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
@ -50,7 +51,7 @@ $footnote = $section->addFootnote();
$footnote->addText('The reference for this is wrapped in its own line'); $footnote->addText('The reference for this is wrapped in its own line');
$footnoteProperties = new FootnoteProperties(); $footnoteProperties = new FootnoteProperties();
$footnoteProperties->setNumFmt(FootnoteProperties::NUMBER_FORMAT_UPPER_ROMAN); $footnoteProperties->setNumFmt(NumberFormat::DECIMAL_ENCLOSED_CIRCLE);
$section->setFootnoteProperties($footnoteProperties); $section->setFootnoteProperties($footnoteProperties);
// Save file // Save file

View File

@ -107,22 +107,22 @@ $table->addCell(null, $cellRowContinue);
$section->addPageBreak(); $section->addPageBreak();
$section->addText('Table with colspan and rowspan', $header); $section->addText('Table with colspan and rowspan', $header);
$styleTable = ['borderSize' => 6, 'borderColor' => '999999']; $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
$phpWord->addTableStyle('Colspan Rowspan', $styleTable); $phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan'); $table = $section->addTable('Colspan Rowspan');
$row = $table->addRow(); $row = $table->addRow();
$row->addCell(null, ['vMerge' => 'restart'])->addText('A'); $row->addCell(null, array('vMerge' => 'restart'))->addText('A');
$row->addCell(null, ['gridSpan' => 2, 'vMerge' => 'restart',])->addText('B'); $row->addCell(null, array('gridSpan' => 2, 'vMerge' => 'restart',))->addText('B');
$row->addCell()->addText('1'); $row->addCell()->addText('1');
$row = $table->addRow(); $row = $table->addRow();
$row->addCell(null, ['vMerge' => 'continue']); $row->addCell(null, array('vMerge' => 'continue'));
$row->addCell(null, ['vMerge' => 'continue','gridSpan' => 2,]); $row->addCell(null, array('vMerge' => 'continue','gridSpan' => 2,));
$row->addCell()->addText('2'); $row->addCell()->addText('2');
$row = $table->addRow(); $row = $table->addRow();
$row->addCell(null, ['vMerge' => 'continue']); $row->addCell(null, array('vMerge' => 'continue'));
$row->addCell()->addText('C'); $row->addCell()->addText('C');
$row->addCell()->addText('D'); $row->addCell()->addText('D');
$row->addCell()->addText('3'); $row->addCell()->addText('3');

View File

@ -14,7 +14,9 @@
* @copyright 2010-2016 PHPWord contributors * @copyright 2010-2016 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
namespace PhpOffice\PhpWord\SimpleType; namespace PhpOffice\PhpWord\ComplexType;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
/** /**
* Footnote properties * Footnote properties
@ -28,17 +30,6 @@ final class FootnoteProperties
const RESTART_NUMBER_EACH_SECTION = 'eachSect'; const RESTART_NUMBER_EACH_SECTION = 'eachSect';
const RESTART_NUMBER_EACH_PAGE = 'eachPage'; const RESTART_NUMBER_EACH_PAGE = 'eachPage';
const NUMBER_FORMAT_DECIMAL = 'decimal';
const NUMBER_FORMAT_UPPER_ROMAN = 'upperRoman';
const NUMBER_FORMAT_LOWER_ROMAN = 'lowerRoman';
const NUMBER_FORMAT_UPPER_LETTER = 'upperLetter';
const NUMBER_FORMAT_LOWER_LETTER = 'lowerLetter';
const NUMBER_FORMAT_ORDINAL = 'ordinal';
const NUMBER_FORMAT_CARDINAL_TEXT = 'cardinalText';
const NUMBER_FORMAT_ORDINAL_TEXT = 'ordinalText';
const NUMBER_FORMAT_NONE = 'none';
const NUMBER_FORMAT_BULLET = 'bullet';
const POSITION_PAGE_BOTTOM = 'pageBottom'; const POSITION_PAGE_BOTTOM = 'pageBottom';
const POSITION_BENEATH_TEXT = 'beneathText'; const POSITION_BENEATH_TEXT = 'beneathText';
const POSITION_SECTION_END = 'sectEnd'; const POSITION_SECTION_END = 'sectEnd';
@ -52,7 +43,7 @@ final class FootnoteProperties
private $pos; private $pos;
/** /**
* Footnote Numbering Format * Footnote Numbering Format w:numFmt, one of PhpOffice\PhpWord\SimpleType\NumberFormat
* *
* @var string * @var string
*/ */
@ -61,7 +52,7 @@ final class FootnoteProperties
/** /**
* Footnote and Endnote Numbering Starting Value * Footnote and Endnote Numbering Starting Value
* *
* @var decimal * @var double
*/ */
private $numStart; private $numStart;
@ -72,11 +63,23 @@ final class FootnoteProperties
*/ */
private $numRestart; private $numRestart;
/**
* Get the Footnote Positioning Location
*
* @return string
*/
public function getPos() public function getPos()
{ {
return $this->pos; return $this->pos;
} }
/**
* Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd)
*
* @param string $pos
* @throws \InvalidArgumentException
* @return self
*/
public function setPos($pos) public function setPos($pos)
{ {
$position = array( $position = array(
@ -91,50 +94,71 @@ final class FootnoteProperties
} else { } else {
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $position) . " possible"); throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $position) . " possible");
} }
return $this;
} }
/**
* Get the Footnote Numbering Format
*
* @return string
*/
public function getNumFmt() public function getNumFmt()
{ {
return $this->numFmt; return $this->numFmt;
} }
/**
* Set the Footnote Numbering Format
*
* @param string $numFmt One of NumberFormat
* @return self
*/
public function setNumFmt($numFmt) public function setNumFmt($numFmt)
{ {
$numberFormat = array( NumberFormat::validate($numFmt);
self::NUMBER_FORMAT_DECIMAL, $this->numFmt = $numFmt;
self::NUMBER_FORMAT_UPPER_ROMAN, return $this;
self::NUMBER_FORMAT_LOWER_ROMAN,
self::NUMBER_FORMAT_UPPER_LETTER,
self::NUMBER_FORMAT_LOWER_LETTER,
self::NUMBER_FORMAT_ORDINAL,
self::NUMBER_FORMAT_CARDINAL_TEXT,
self::NUMBER_FORMAT_ORDINAL_TEXT,
self::NUMBER_FORMAT_NONE,
self::NUMBER_FORMAT_BULLET
);
if (in_array($numFmt, $numberFormat)) {
$this->numFmt = $numFmt;
} else {
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $numberFormat) . " possible");
}
} }
/**
* Get the Footnote Numbering Format
*
* @return double
*/
public function getNumStart() public function getNumStart()
{ {
return $this->numStart; return $this->numStart;
} }
/**
* Set the Footnote Numbering Format
*
* @param double $numStart
* @return self
*/
public function setNumStart($numStart) public function setNumStart($numStart)
{ {
$this->numStart = $numStart; $this->numStart = $numStart;
return $this;
} }
/**
* Get the Footnote and Endnote Numbering Starting Value
*
* @return string
*/
public function getNumRestart() public function getNumRestart()
{ {
return $this->numRestart; return $this->numRestart;
} }
/**
* Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage)
*
* @param string $numRestart
* @throws \InvalidArgumentException
* @return self
*/
public function setNumRestart($numRestart) public function setNumRestart($numRestart)
{ {
$restartNumbers = array( $restartNumbers = array(
@ -148,5 +172,6 @@ final class FootnoteProperties
} else { } else {
throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $restartNumbers) . " possible"); throw new \InvalidArgumentException("Invalid value, on of " . implode(', ', $restartNumbers) . " possible");
} }
return $this;
} }
} }

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
use PhpOffice\PhpWord\Style\Section as SectionStyle; use PhpOffice\PhpWord\Style\Section as SectionStyle;
use PhpOffice\PhpWord\SimpleType\FootnoteProperties;
class Section extends AbstractContainer class Section extends AbstractContainer
{ {

View File

@ -167,14 +167,11 @@ abstract class AbstractPart
$parent->addTextBreak(null, $paragraphStyle); $parent->addTextBreak(null, $paragraphStyle);
} else { } else {
$nodes = $xmlReader->getElements('*', $domNode); $nodes = $xmlReader->getElements('*', $domNode);
if ($runLinkCount > 1) {
$parent = $parent->addTextRun($paragraphStyle);
}
foreach ($nodes as $node) { foreach ($nodes as $node) {
$this->readRun( $this->readRun($xmlReader, $node, $parent, $docPart, $paragraphStyle);
$xmlReader,
$node,
($runLinkCount > 1) ? $parent->addTextRun($paragraphStyle) : $parent,
$docPart,
$paragraphStyle
);
} }
} }
} }

View File

@ -113,10 +113,10 @@ class Document extends AbstractPart
'orientation' => array(self::READ_VALUE, 'w:pgSz', 'w:orient'), 'orientation' => array(self::READ_VALUE, 'w:pgSz', 'w:orient'),
'colsNum' => array(self::READ_VALUE, 'w:cols', 'w:num'), 'colsNum' => array(self::READ_VALUE, 'w:cols', 'w:num'),
'colsSpace' => array(self::READ_VALUE, 'w:cols', 'w:space'), 'colsSpace' => array(self::READ_VALUE, 'w:cols', 'w:space'),
'topMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:top'), 'marginTop' => array(self::READ_VALUE, 'w:pgMar', 'w:top'),
'leftMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:left'), 'marginLeft' => array(self::READ_VALUE, 'w:pgMar', 'w:left'),
'bottomMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:bottom'), 'marginBottom' => array(self::READ_VALUE, 'w:pgMar', 'w:bottom'),
'rightMargin' => array(self::READ_VALUE, 'w:pgMar', 'w:right'), 'marginRight' => array(self::READ_VALUE, 'w:pgMar', 'w:right'),
'headerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:header'), 'headerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:header'),
'footerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:footer'), 'footerHeight' => array(self::READ_VALUE, 'w:pgMar', 'w:footer'),
'gutter' => array(self::READ_VALUE, 'w:pgMar', 'w:gutter'), 'gutter' => array(self::READ_VALUE, 'w:pgMar', 'w:gutter'),

View File

@ -0,0 +1,35 @@
<?php
namespace PhpOffice\PhpWord\Shared;
abstract class AbstractEnum
{
private static $constCacheArray = null;
private static function getConstants()
{
if (self::$constCacheArray == null) {
self::$constCacheArray = array();
}
$calledClass = get_called_class();
if (! array_key_exists($calledClass, self::$constCacheArray)) {
$reflect = new \ReflectionClass($calledClass);
self::$constCacheArray[$calledClass] = $reflect->getConstants();
}
return self::$constCacheArray[$calledClass];
}
public static function values()
{
return array_values(self::getConstants());
}
public static function validate($value)
{
$values = array_values(self::getConstants());
if (!in_array($value, $values, true)) {
$calledClass = get_called_class();
throw new \InvalidArgumentException("$value is not a valid value for $calledClass, possible values are " . implode(', ', $values));
}
}
}

View File

@ -0,0 +1,153 @@
<?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-2016 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\SimpleType;
use PhpOffice\PhpWord\Shared\AbstractEnum;
/**
* Numbering Format.
*
* @since 0.14.0
*
* @see http://www.datypic.com/sc/ooxml/t-w_ST_NumberFormat.html.
*
* @codeCoverageIgnore
*/
final class NumberFormat extends AbstractEnum
{
//Decimal Numbers
const DECIMAL = 'decimal';
//Uppercase Roman Numerals
const UPPER_ROMAN = 'upperRoman';
//Lowercase Roman Numerals
const LOWER_ROMAN = 'lowerRoman';
//Uppercase Latin Alphabet
const UPPER_LETTER = 'upperLetter';
//Lowercase Latin Alphabet
const LOWER_LETTER = 'lowerLetter';
//Ordinal
const ORDINAL = 'ordinal';
//Cardinal Text
const CARDINAL_TEXT = 'cardinalText';
//Ordinal Text
const ORDINAL_TEXT = 'ordinalText';
//Hexadecimal Numbering
const HEX = 'hex';
//Chicago Manual of Style
const CHICAGO = 'chicago';
//Ideographs
const IDEOGRAPH_DIGITAL = 'ideographDigital';
//Japanese Counting System
const JAPANESE_COUNTING = 'japaneseCounting';
//AIUEO Order Hiragana
const AIUEO = 'aiueo';
//Iroha Ordered Katakana
const IROHA = 'iroha';
//Double Byte Arabic Numerals
const DECIMAL_FULL_WIDTH = 'decimalFullWidth';
//Single Byte Arabic Numerals
const DECIMAL_HALF_WIDTH = 'decimalHalfWidth';
//Japanese Legal Numbering
const JAPANESE_LEGAL = 'japaneseLegal';
//Japanese Digital Ten Thousand Counting System
const JAPANESE_DIGITAL_TEN_THOUSAND = 'japaneseDigitalTenThousand';
//Decimal Numbers Enclosed in a Circle
const DECIMAL_ENCLOSED_CIRCLE = 'decimalEnclosedCircle';
//Double Byte Arabic Numerals Alternate
const DECIMAL_FULL_WIDTH2 = 'decimalFullWidth2';
//Full-Width AIUEO Order Hiragana
const AIUEO_FULL_WIDTH = 'aiueoFullWidth';
//Full-Width Iroha Ordered Katakana
const IROHA_FULL_WIDTH = 'irohaFullWidth';
//Initial Zero Arabic Numerals
const DECIMAL_ZERO = 'decimalZero';
//Bullet
const BULLET = 'bullet';
//Korean Ganada Numbering
const GANADA = 'ganada';
//Korean Chosung Numbering
const CHOSUNG = 'chosung';
//Decimal Numbers Followed by a Period
const DECIMAL_ENCLOSED_FULL_STOP = 'decimalEnclosedFullstop';
//Decimal Numbers Enclosed in Parenthesis
const DECIMAL_ENCLOSED_PAREN = 'decimalEnclosedParen';
//Decimal Numbers Enclosed in a Circle
const DECIMAL_ENCLOSED_CIRCLE_CHINESE = 'decimalEnclosedCircleChinese';
//Ideographs Enclosed in a Circle
const IDEOGRAPHENCLOSEDCIRCLE = 'ideographEnclosedCircle';
//Traditional Ideograph Format
const IDEOGRAPH_TRADITIONAL = 'ideographTraditional';
//Zodiac Ideograph Format
const IDEOGRAPH_ZODIAC = 'ideographZodiac';
//Traditional Zodiac Ideograph Format
const IDEOGRAPH_ZODIAC_TRADITIONAL = 'ideographZodiacTraditional';
//Taiwanese Counting System
const TAIWANESE_COUNTING = 'taiwaneseCounting';
//Traditional Legal Ideograph Format
const IDEOGRAPH_LEGAL_TRADITIONAL = 'ideographLegalTraditional';
//Taiwanese Counting Thousand System
const TAIWANESE_COUNTING_THOUSAND = 'taiwaneseCountingThousand';
//Taiwanese Digital Counting System
const TAIWANESE_DIGITAL = 'taiwaneseDigital';
//Chinese Counting System
const CHINESE_COUNTING = 'chineseCounting';
//Chinese Legal Simplified Format
const CHINESE_LEGAL_SIMPLIFIED = 'chineseLegalSimplified';
//Chinese Counting Thousand System
const CHINESE_COUNTING_THOUSAND = 'chineseCountingThousand';
//Korean Digital Counting System
const KOREAN_DIGITAL = 'koreanDigital';
//Korean Counting System
const KOREAN_COUNTING = 'koreanCounting';
//Korean Legal Numbering
const KOREAN_LEGAL = 'koreanLegal';
//Korean Digital Counting System Alternate
const KOREAN_DIGITAL2 = 'koreanDigital2';
//Vietnamese Numerals
const VIETNAMESE_COUNTING = 'vietnameseCounting';
//Lowercase Russian Alphabet
const RUSSIAN_LOWER = 'russianLower';
//Uppercase Russian Alphabet
const RUSSIAN_UPPER = 'russianUpper';
//No Numbering
const NONE = 'none';
//Number With Dashes
const NUMBER_IN_DASH = 'numberInDash';
//Hebrew Numerals
const HEBREW1 = 'hebrew1';
//Hebrew Alphabet
const HEBREW2 = 'hebrew2';
//Arabic Alphabet
const ARABIC_ALPHA = 'arabicAlpha';
//Arabic Abjad Numerals
const ARABIC_ABJAD = 'arabicAbjad';
//Hindi Vowels
const HINDI_VOWELS = 'hindiVowels';
//Hindi Consonants
const HINDI_CONSONANTS = 'hindiConsonants';
//Hindi Numbers
const HINDI_NUMBERS = 'hindiNumbers';
//Hindi Counting System
const HINDI_COUNTING = 'hindiCounting';
//Thai Letters
const THAI_LETTERS = 'thaiLetters';
//Thai Numerals
const THAI_NUMBERS = 'thaiNumbers';
//Thai Counting System
const THAI_COUNTING = 'thaiCounting';
}

View File

@ -18,6 +18,7 @@
namespace PhpOffice\PhpWord\Style; namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
/** /**
* Numbering level definition * Numbering level definition
@ -43,7 +44,7 @@ class NumberingLevel extends AbstractStyle
private $start = 1; private $start = 1;
/** /**
* Numbering format bullet|decimal|upperRoman|lowerRoman|upperLetter|lowerLetter * Numbering format w:numFmt, one of PhpOffice\PhpWord\SimpleType\NumberFormat
* *
* @var string * @var string
* @link http://www.schemacentral.com/sc/ooxml/t-w_ST_NumberFormat.html * @link http://www.schemacentral.com/sc/ooxml/t-w_ST_NumberFormat.html
@ -67,7 +68,7 @@ class NumberingLevel extends AbstractStyle
private $pStyle; private $pStyle;
/** /**
* Content between numbering symbol and paragraph text * Content between numbering symbol and paragraph text w:suff
* *
* @var string tab|space|nothing * @var string tab|space|nothing
* @link http://www.schemacentral.com/sc/ooxml/e-w_suff-1.html * @link http://www.schemacentral.com/sc/ooxml/e-w_suff-1.html
@ -83,7 +84,9 @@ class NumberingLevel extends AbstractStyle
private $text; private $text;
/** /**
* @var string * Justification, w:lvlJc
*
* @var string, one of PhpOffice\PhpWord\SimpleType\Jc
*/ */
private $alignment = ''; private $alignment = '';
@ -185,13 +188,12 @@ class NumberingLevel extends AbstractStyle
*/ */
public function setFormat($value) public function setFormat($value)
{ {
$enum = array('bullet', 'decimal', 'upperRoman', 'lowerRoman', 'upperLetter', 'lowerLetter'); $this->format = $this->setEnumVal($value, NumberFormat::values(), $this->format);
$this->format = $this->setEnumVal($value, $enum, $this->format);
return $this; return $this;
} }
/** /**
* Get start * Get restart
* *
* @return integer * @return integer
*/ */
@ -201,7 +203,7 @@ class NumberingLevel extends AbstractStyle
} }
/** /**
* Set start * Set restart
* *
* @param integer $value * @param integer $value
* @return self * @return self

View File

@ -157,6 +157,13 @@ class Paragraph extends Border
* @var \PhpOffice\PhpWord\Style\Shading * @var \PhpOffice\PhpWord\Style\Shading
*/ */
private $shading; private $shading;
/**
* Ignore Spacing Above and Below When Using Identical Styles
*
* @var bool
*/
private $contextualSpacing = false;
/** /**
* Set Style value * Set Style value
@ -208,6 +215,7 @@ class Paragraph extends Border
), ),
'tabs' => $this->getTabs(), 'tabs' => $this->getTabs(),
'shading' => $this->getShading(), 'shading' => $this->getShading(),
'contextualSpacing' => $this->hasContextualSpacing(),
); );
return $styles; return $styles;
@ -731,4 +739,27 @@ class Paragraph extends Border
return $this; return $this;
} }
/**
* Get contextualSpacing
*
* @return bool
*/
public function hasContextualSpacing()
{
return $this->contextualSpacing;
}
/**
* Set contextualSpacing
*
* @param bool $contextualSpacing
* @return self
*/
public function setContextualSpacing($contextualSpacing)
{
$this->contextualSpacing = $contextualSpacing;
return $this;
}
} }

View File

@ -37,21 +37,16 @@ class Image extends Text
if (!$this->element instanceof ImageElement) { if (!$this->element instanceof ImageElement) {
return ''; return '';
} }
/** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */
$parentWriter = $this->parentWriter;
$content = ''; $content = '';
if (!$parentWriter->isPdf()) { $imageData = $this->element->getImageStringData(true);
$imageData = $this->element->getImageStringData(true); if ($imageData !== null) {
if ($imageData !== null) { $styleWriter = new ImageStyleWriter($this->element->getStyle());
$styleWriter = new ImageStyleWriter($this->element->getStyle()); $style = $styleWriter->write();
$style = $styleWriter->write(); $imageData = 'data:' . $this->element->getImageType() . ';base64,' . $imageData;
$imageData = 'data:' . $this->element->getImageType() . ';base64,' . $imageData;
$content .= $this->writeOpening(); $content .= $this->writeOpening();
$content .= "<img border=\"0\" style=\"{$style}\" src=\"{$imageData}\"/>"; $content .= "<img border=\"0\" style=\"{$style}\" src=\"{$imageData}\"/>";
$content .= $this->writeClosing(); $content .= $this->writeClosing();
}
} }
return $content; return $content;

View File

@ -21,7 +21,6 @@ use PhpOffice\Common\XMLWriter;
use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Element\Container;
use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter;
use PhpOffice\PhpWord\SimpleType\FootnoteProperties;
/** /**
* Word2007 document part writer: word/document.xml * Word2007 document part writer: word/document.xml

View File

@ -106,6 +106,9 @@ class Paragraph extends AbstractStyle
} }
$xmlWriter->endElement(); $xmlWriter->endElement();
} }
//Paragraph contextualSpacing
$xmlWriter->writeElementIf($styles['contextualSpacing'] === true, 'w:contextualSpacing');
// Child style: alignment, indentation, spacing, and shading // Child style: alignment, indentation, spacing, and shading
$this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']); $this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']);

View File

@ -15,9 +15,10 @@
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
namespace PhpOffice\PhpWord\SimpleType; namespace PhpOffice\PhpWord\ComplexType;
use PhpOffice\PhpWord\SimpleType\FootnoteProperties; use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
/** /**
* Test class for PhpOffice\PhpWord\SimpleType\FootnoteProperties * Test class for PhpOffice\PhpWord\SimpleType\FootnoteProperties
@ -34,12 +35,12 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
{ {
$footnoteProp = new FootnoteProperties(); $footnoteProp = new FootnoteProperties();
$footnoteProp->setPos(FootnoteProperties::POSITION_DOC_END); $footnoteProp->setPos(FootnoteProperties::POSITION_DOC_END);
$footnoteProp->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN); $footnoteProp->setNumFmt(NumberFormat::LOWER_ROMAN);
$footnoteProp->setNumStart(2); $footnoteProp->setNumStart(2);
$footnoteProp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE); $footnoteProp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
$this->assertEquals(FootnoteProperties::POSITION_DOC_END, $footnoteProp->getPos()); $this->assertEquals(FootnoteProperties::POSITION_DOC_END, $footnoteProp->getPos());
$this->assertEquals(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN, $footnoteProp->getNumFmt()); $this->assertEquals(NumberFormat::LOWER_ROMAN, $footnoteProp->getNumFmt());
$this->assertEquals(2, $footnoteProp->getNumStart()); $this->assertEquals(2, $footnoteProp->getNumStart());
$this->assertEquals(FootnoteProperties::RESTART_NUMBER_EACH_PAGE, $footnoteProp->getNumRestart()); $this->assertEquals(FootnoteProperties::RESTART_NUMBER_EACH_PAGE, $footnoteProp->getNumRestart());
} }
@ -52,7 +53,7 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
public function testWrongPos() public function testWrongPos()
{ {
$footnoteProp= new FootnoteProperties(); $footnoteProp= new FootnoteProperties();
$footnoteProp->setPos(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN); $footnoteProp->setPos(NumberFormat::LOWER_ROMAN);
} }
/** /**
@ -74,6 +75,6 @@ class FootnotePropertiesTest extends \PHPUnit_Framework_TestCase
public function testWrongNumRestart() public function testWrongNumRestart()
{ {
$footnoteProp= new FootnoteProperties(); $footnoteProp= new FootnoteProperties();
$footnoteProp->setNumRestart(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN); $footnoteProp->setNumRestart(NumberFormat::LOWER_ROMAN);
} }
} }

View File

@ -43,13 +43,14 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
$object = new Paragraph(); $object = new Paragraph();
$attributes = array( $attributes = array(
'widowControl' => true, 'widowControl' => true,
'keepNext' => false, 'keepNext' => false,
'keepLines' => false, 'keepLines' => false,
'pageBreakBefore' => false, 'pageBreakBefore' => false,
'contextualSpacing' => false,
); );
foreach ($attributes as $key => $default) { foreach ($attributes as $key => $default) {
$get = "get{$key}"; $get = $this->findGetter($key, $default, $object);
$object->setStyleValue($key, null); $object->setStyleValue($key, null);
$this->assertEquals($default, $object->$get()); $this->assertEquals($default, $object->$get());
$object->setStyleValue($key, ''); $object->setStyleValue($key, '');
@ -65,22 +66,23 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
$object = new Paragraph(); $object = new Paragraph();
$attributes = array( $attributes = array(
'spaceAfter' => 240, 'spaceAfter' => 240,
'spaceBefore' => 240, 'spaceBefore' => 240,
'indent' => 1, 'indent' => 1,
'hanging' => 1, 'hanging' => 1,
'spacing' => 120, 'spacing' => 120,
'basedOn' => 'Normal', 'basedOn' => 'Normal',
'next' => 'Normal', 'next' => 'Normal',
'numStyle' => 'numStyle', 'numStyle' => 'numStyle',
'numLevel' => 1, 'numLevel' => 1,
'widowControl' => false, 'widowControl' => false,
'keepNext' => true, 'keepNext' => true,
'keepLines' => true, 'keepLines' => true,
'pageBreakBefore' => true, 'pageBreakBefore' => true,
'contextualSpacing' => true,
); );
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
$get = "get{$key}"; $get = $this->findGetter($key, $value, $object);
$object->setStyleValue("$key", $value); $object->setStyleValue("$key", $value);
if ('indent' == $key || 'hanging' == $key) { if ('indent' == $key || 'hanging' == $key) {
$value = $value * 720; $value = $value * 720;
@ -91,6 +93,18 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
} }
} }
private function findGetter($key, $value, $object)
{
if (is_bool($value)) {
if (method_exists($object, "is{$key}")) {
return "is{$key}";
} else if (method_exists($object, "has{$key}")) {
return "has{$key}";
}
}
return "get{$key}";
}
/** /**
* Test get null style value * Test get null style value
*/ */
@ -100,7 +114,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
$attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter'); $attributes = array('spacing', 'indent', 'hanging', 'spaceBefore', 'spaceAfter');
foreach ($attributes as $key) { foreach ($attributes as $key) {
$get = "get{$key}"; $get = $this->findGetter($key, null, $object);
$this->assertNull($object->$get()); $this->assertNull($object->$get());
} }
} }

View File

@ -16,11 +16,12 @@
*/ */
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\TestHelperDOCX; use PhpOffice\PhpWord\TestHelperDOCX;
use PhpOffice\PhpWord\SimpleType\FootnoteProperties; use PhpOffice\PhpWord\SimpleType\NumberFormat;
/** /**
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Document * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Document
@ -65,7 +66,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
{ {
$properties = new FootnoteProperties(); $properties = new FootnoteProperties();
$properties->setPos(FootnoteProperties::POSITION_DOC_END); $properties->setPos(FootnoteProperties::POSITION_DOC_END);
$properties->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN); $properties->setNumFmt(NumberFormat::LOWER_ROMAN);
$properties->setNumStart(1); $properties->setNumStart(1);
$properties->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE); $properties->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
@ -79,7 +80,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(FootnoteProperties::POSITION_DOC_END, $element->getAttribute('w:val')); $this->assertEquals(FootnoteProperties::POSITION_DOC_END, $element->getAttribute('w:val'));
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:footnotePr/w:numFmt'); $element = $doc->getElement('/w:document/w:body/w:sectPr/w:footnotePr/w:numFmt');
$this->assertEquals(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN, $element->getAttribute('w:val')); $this->assertEquals(NumberFormat::LOWER_ROMAN, $element->getAttribute('w:val'));
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:footnotePr/w:numStart'); $element = $doc->getElement('/w:document/w:body/w:sectPr/w:footnotePr/w:numStart');
$this->assertEquals(1, $element->getAttribute('w:val')); $this->assertEquals(1, $element->getAttribute('w:val'));

View File

@ -19,6 +19,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\TestHelperDOCX; use PhpOffice\PhpWord\TestHelperDOCX;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
/** /**
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Numbering * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Numbering
@ -52,7 +53,7 @@ class NumberingTest extends \PHPUnit_Framework_TestCase
'levels' => array( 'levels' => array(
array( array(
'start' => 1, 'start' => 1,
'format' => 'decimal', 'format' => NumberFormat::DECIMAL,
'restart' => 1, 'restart' => 1,
'suffix' => 'space', 'suffix' => 'space',
'text' => '%1.', 'text' => '%1.',

View File

@ -74,11 +74,11 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testLanguage() public function testLanguage()
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml'; $file = 'word/settings.xml';
$path = '/w:settings/w:themeFontLang'; $path = '/w:settings/w:themeFontLang';
$this->assertTrue($doc->elementExists($path, $file)); $this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file); $element = $doc->getElement($path, $file);
@ -93,11 +93,11 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
Settings::setSpellingErrorsHidden(true); Settings::setSpellingErrorsHidden(true);
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml'; $file = 'word/settings.xml';
$path = '/w:settings/w:hideSpellingErrors'; $path = '/w:settings/w:hideSpellingErrors';
$this->assertTrue($doc->elementExists($path, $file)); $this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file); $element = $doc->getElement($path, $file);
@ -112,14 +112,14 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
Settings::setEvenAndOddHeaders(true); Settings::setEvenAndOddHeaders(true);
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$file = 'word/settings.xml'; $file = 'word/settings.xml';
$path = '/w:settings/w:evenAndOddHeaders'; $path = '/w:settings/w:evenAndOddHeaders';
$this->assertTrue($doc->elementExists($path, $file)); $this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file); $element = $doc->getElement($path, $file);
$this->assertEquals('true', $element->getAttribute('w:val')); $this->assertEquals('true', $element->getAttribute('w:val'));
} }