Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ This is the last version to support PHP 5.3
- Padded the $args array to remove error - @kaigoh #1150, @reformed #870
- Fix incorrect image size between windows and mac - @bskrtich #874
- Fix adding HTML table to document - @mogilvie @arivanbastos #324
- Fix parsing on/off values (w:val="true|false|1|0|on|off") - @troosan #1221 #1219

### Deprecated
- PhpWord->getProtection(), get it from the settings instead PhpWord->getSettings()->getDocumentProtection();
Expand Down
1 change: 1 addition & 0 deletions src/PhpWord/Element/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Comment element
* @see http://datypic.com/sc/ooxml/t-w_CT_Comment.html
*/
class Comment extends TrackChange
{
Expand Down
1 change: 1 addition & 0 deletions src/PhpWord/Element/TrackChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* TrackChange element
* @see http://datypic.com/sc/ooxml/t-w_CT_TrackChange.html
*/
class TrackChange extends AbstractContainer
{
Expand Down
22 changes: 17 additions & 5 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent,
// $rIdIcon = $xmlReader->getAttribute('r:id', $domNode, 'w:object/v:shape/v:imagedata');
$target = $this->getMediaTarget($docPart, $rId);
if (!is_null($target)) {
$textContent = "<Object: {$target}>";
$textContent = "&lt;Object: {$target}>";
$parent->addText($textContent, $fontStyle, $paragraphStyle);
}
} else {
Expand Down Expand Up @@ -384,7 +384,7 @@ protected function readTableStyle(XMLReader $xmlReader, \DOMElement $domNode)
{
$style = null;
$margins = array('top', 'left', 'bottom', 'right');
$borders = $margins + array('insideH', 'insideV');
$borders = array_merge($margins, array('insideH', 'insideV'));

if ($xmlReader->elementExists('w:tblPr', $domNode)) {
if ($xmlReader->elementExists('w:tblPr/w:tblStyle', $domNode)) {
Expand Down Expand Up @@ -422,7 +422,7 @@ private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode)
'textDirection' => array(self::READ_VALUE, 'w:textDirection'),
'gridSpan' => array(self::READ_VALUE, 'w:gridSpan'),
'vMerge' => array(self::READ_VALUE, 'w:vMerge'),
'bgColor' => array(self::READ_VALUE, 'w:shd/w:fill'),
'bgColor' => array(self::READ_VALUE, 'w:shd', 'w:fill'),
);

return $this->readStyleDefs($xmlReader, $domNode, $styleDefs);
Expand Down Expand Up @@ -477,16 +477,28 @@ private function readStyleDef($method, $attributeValue, $expected)
if (self::READ_SIZE == $method) {
$style = $attributeValue / 2;
} elseif (self::READ_TRUE == $method) {
$style = true;
$style = $this->isOn($attributeValue);
} elseif (self::READ_FALSE == $method) {
$style = false;
$style = !$this->isOn($attributeValue);
} elseif (self::READ_EQUAL == $method) {
$style = $attributeValue == $expected;
}

return $style;
}

/**
* Parses the value of the on/off value, null is considered true as it means the w:val attribute was not present
*
* @see http://www.datypic.com/sc/ooxml/t-w_ST_OnOff.html
* @param string $value
* @return bool
*/
private function isOn($value = null)
{
return $value == null || $value == '1' || $value == 'true' || $value == 'on';
}

/**
* Returns the target of image, object, or link as stored in ::readMainRels
*
Expand Down
8 changes: 8 additions & 0 deletions tests/PhpWord/Reader/Word2007Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace PhpOffice\PhpWord\Reader;

use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\TestHelperDOCX;

/**
* Test class for PhpOffice\PhpWord\Reader\Word2007
Expand Down Expand Up @@ -54,6 +55,13 @@ public function testLoad()
{
$filename = __DIR__ . '/../_files/documents/reader.docx';
$phpWord = IOFactory::load($filename);

$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $phpWord);
$this->assertTrue($phpWord->getSettings()->hasDoNotTrackMoves());
$this->assertFalse($phpWord->getSettings()->hasDoNotTrackFormatting());
$this->assertEquals(100, $phpWord->getSettings()->getZoom());

$doc = TestHelperDOCX::getDocument($phpWord);
$this->assertFalse($doc->elementExists('/w:document/w:body/w:p/w:r[w:t/node()="italics"]/w:rPr/w:b'));
}
}
Binary file modified tests/PhpWord/_files/documents/reader.docx
Binary file not shown.
1 change: 1 addition & 0 deletions tests/PhpWord/_includes/XmlDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function getNodeList($path, $file = 'word/document.xml')

if (null === $this->xpath) {
$this->xpath = new \DOMXpath($this->dom);
$this->xpath->registerNamespace('w14', 'http://schemas.microsoft.com/office/word/2010/wordml');
}

return $this->xpath->query($path);
Expand Down