correctly parse on/off values (w:val="true|false|1|0|on|off")
This commit is contained in:
parent
194e5c47e4
commit
253b060241
|
|
@ -223,7 +223,7 @@ abstract class AbstractPart
|
|||
// $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 = "<Object: {$target}>";
|
||||
$parent->addText($textContent, $fontStyle, $paragraphStyle);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -477,9 +477,9 @@ abstract class AbstractPart
|
|||
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;
|
||||
}
|
||||
|
|
@ -487,6 +487,18 @@ abstract class AbstractPart
|
|||
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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
namespace PhpOffice\PhpWord\Reader;
|
||||
|
||||
use PhpOffice\PhpWord\IOFactory;
|
||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Reader\Word2007
|
||||
|
|
@ -54,6 +55,13 @@ class Word2007Test extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$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 not shown.
|
|
@ -97,6 +97,7 @@ class XmlDocument
|
|||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue