add support for hidden text (#1527)
* added hidden text word 2007 * update changelog * update documentation * added unit test * docx reader * html reader/writer * odt writer * updated samples
This commit is contained in:
parent
260bb75fc2
commit
c2b54cc343
|
|
@ -7,6 +7,7 @@ v0.16.0 (xx dec 2018)
|
|||
----------------------
|
||||
### Added
|
||||
- Add setting Chart Title and Legend visibility @Tom-Magill #1433
|
||||
- Add support for hidden text @Alexmg86 #1527
|
||||
|
||||
### Fixed
|
||||
- Fix regex in `cloneBlock` function @nicoder #1269
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
"php-cs-fixer fix --ansi --dry-run --diff",
|
||||
"phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
|
||||
"phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
|
||||
"@test"
|
||||
"@test-no-coverage"
|
||||
],
|
||||
"fix": [
|
||||
"php-cs-fixer fix --ansi"
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ Available Font style options:
|
|||
- ``lang``. Language, either a language code like *en-US*, *fr-BE*, etc. or an object (or as an array) if you need to set eastAsian or bidirectional languages
|
||||
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
|
||||
- ``position``. The text position, raised or lowered, in half points
|
||||
- ``hidden``. Hidden text, *true* or *false*.
|
||||
|
||||
.. _paragraph-style:
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ $textrun->addText(' Sample Object: ');
|
|||
$textrun->addObject('resources/_sheet.xls');
|
||||
$textrun->addText(' Here is some more text. ');
|
||||
|
||||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('This text is not visible.', array('hidden' => true));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
|
|
|
|||
|
|
@ -89,6 +89,9 @@ $html .= '<table align="center" style="width: 80%; border: 6px #0000FF double;">
|
|||
<tr><td style="text-align: center;">Cell in parent table</td></tr>
|
||||
</table>';
|
||||
|
||||
$html .= '<p style="margin-top: 240pt;">The text below is not visible, click on show/hide to reveil it:</p>';
|
||||
$html .= '<p style="display: none">This is hidden text</p>';
|
||||
|
||||
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
|
||||
|
||||
// Save file
|
||||
|
|
|
|||
|
|
@ -444,6 +444,7 @@ abstract class AbstractPart
|
|||
'rtl' => array(self::READ_TRUE, 'w:rtl'),
|
||||
'lang' => array(self::READ_VALUE, 'w:lang'),
|
||||
'position' => array(self::READ_VALUE, 'w:position'),
|
||||
'hidden' => array(self::READ_TRUE, 'w:vanish'),
|
||||
);
|
||||
|
||||
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ class Styles extends AbstractPart
|
|||
if (is_null($name)) {
|
||||
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
|
||||
}
|
||||
$headingMatches = array();
|
||||
preg_match('/Heading(\d)/', $name, $headingMatches);
|
||||
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
|
||||
switch ($type) {
|
||||
|
|
|
|||
|
|
@ -515,6 +515,9 @@ class Html
|
|||
case 'text-align':
|
||||
$styles['alignment'] = self::mapAlign($cValue);
|
||||
break;
|
||||
case 'display':
|
||||
$styles['hidden'] = $cValue === 'none';
|
||||
break;
|
||||
case 'direction':
|
||||
$styles['rtl'] = $cValue === 'rtl';
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -252,6 +252,14 @@ class Font extends AbstractStyle
|
|||
*/
|
||||
private $lang;
|
||||
|
||||
/**
|
||||
* Hidden text
|
||||
*
|
||||
* @var bool
|
||||
* @see http://www.datypic.com/sc/ooxml/e-w_vanish-1.html
|
||||
*/
|
||||
private $hidden = false;
|
||||
|
||||
/**
|
||||
* Vertically Raised or Lowered Text
|
||||
*
|
||||
|
|
@ -299,6 +307,7 @@ class Font extends AbstractStyle
|
|||
'smallCaps' => $this->isSmallCaps(),
|
||||
'allCaps' => $this->isAllCaps(),
|
||||
'fgColor' => $this->getFgColor(),
|
||||
'hidden' => $this->isHidden(),
|
||||
),
|
||||
'spacing' => array(
|
||||
'scale' => $this->getScale(),
|
||||
|
|
@ -938,6 +947,29 @@ class Font extends AbstractStyle
|
|||
return $this->getParagraph();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hidden text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden()
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set hidden text
|
||||
*
|
||||
* @param bool $value
|
||||
* @return self
|
||||
*/
|
||||
public function setHidden($value = true)
|
||||
{
|
||||
$this->hidden = $this->setBoolVal($value, $this->hidden);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get position
|
||||
*
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ class Font extends AbstractStyle
|
|||
$css['text-decoration'] .= $this->getValueIf($lineThrough, 'line-through ');
|
||||
$css['text-transform'] = $this->getValueIf($style->isAllCaps(), 'uppercase');
|
||||
$css['font-variant'] = $this->getValueIf($style->isSmallCaps(), 'small-caps');
|
||||
$css['display'] = $this->getValueIf($style->isHidden(), 'none');
|
||||
|
||||
$spacing = $style->getSpacing();
|
||||
$css['letter-spacing'] = $this->getValueIf(!is_null($spacing), ($spacing / 20) . 'pt');
|
||||
|
|
|
|||
|
|
@ -75,6 +75,9 @@ class Font extends AbstractStyle
|
|||
$xmlWriter->writeAttributeIf($style->isSmallCaps(), 'fo:font-variant', 'small-caps');
|
||||
$xmlWriter->writeAttributeIf($style->isAllCaps(), 'fo:text-transform', 'uppercase');
|
||||
|
||||
//Hidden text
|
||||
$xmlWriter->writeAttributeIf($style->isHidden(), 'text:display', 'none');
|
||||
|
||||
// Superscript/subscript
|
||||
$xmlWriter->writeAttributeIf($style->isSuperScript(), 'style:text-position', 'super');
|
||||
$xmlWriter->writeAttributeIf($style->isSubScript(), 'style:text-position', 'sub');
|
||||
|
|
|
|||
|
|
@ -120,6 +120,9 @@ class Font extends AbstractStyle
|
|||
$xmlWriter->writeElementIf($style->isSmallCaps(), 'w:smallCaps');
|
||||
$xmlWriter->writeElementIf($style->isAllCaps(), 'w:caps');
|
||||
|
||||
//Hidden text
|
||||
$xmlWriter->writeElementIf($style->isHidden(), 'w:vanish');
|
||||
|
||||
// Underline
|
||||
$xmlWriter->writeElementIf($style->getUnderline() != 'none', 'w:u', 'w:val', $style->getUnderline());
|
||||
|
||||
|
|
|
|||
|
|
@ -145,4 +145,28 @@ class StyleTest extends AbstractTestReader
|
|||
$this->assertSame(TblWidth::TWIP, $tableStyle->getIndent()->getType());
|
||||
$this->assertSame(2160, $tableStyle->getIndent()->getValue());
|
||||
}
|
||||
|
||||
public function testReadHidden()
|
||||
{
|
||||
$documentXml = '<w:p>
|
||||
<w:r>
|
||||
<w:rPr>
|
||||
<w:vanish/>
|
||||
</w:rPr>
|
||||
<w:t xml:space="preserve">This text is hidden</w:t>
|
||||
</w:r>
|
||||
</w:p>';
|
||||
|
||||
$phpWord = $this->getDocumentFromString(array('document' => $documentXml));
|
||||
|
||||
$elements = $phpWord->getSection(0)->getElements();
|
||||
/** @var \PhpOffice\PhpWord\Element\TextRun $elements */
|
||||
$textRun = $elements[0];
|
||||
$this->assertInstanceOf('PhpOffice\PhpWord\Element\TextRun', $textRun);
|
||||
$this->assertInstanceOf('PhpOffice\PhpWord\Element\Text', $textRun->getElement(0));
|
||||
$this->assertInstanceOf('PhpOffice\PhpWord\Style\Font', $textRun->getElement(0)->getFontStyle());
|
||||
/** @var \PhpOffice\PhpWord\Style\Font $fontStyle */
|
||||
$fontStyle = $textRun->getElement(0)->getFontStyle();
|
||||
$this->assertTrue($fontStyle->isHidden());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ class FontTest extends \PHPUnit\Framework\TestCase
|
|||
'spacing' => null,
|
||||
'kerning' => null,
|
||||
'lang' => null,
|
||||
'hidden' => false,
|
||||
);
|
||||
foreach ($attributes as $key => $default) {
|
||||
$get = is_bool($default) ? "is{$key}" : "get{$key}";
|
||||
|
|
@ -117,6 +118,7 @@ class FontTest extends \PHPUnit\Framework\TestCase
|
|||
'rtl' => true,
|
||||
'noProof' => true,
|
||||
'lang' => new Language(Language::EN_US),
|
||||
'hidden' => true,
|
||||
);
|
||||
$object->setStyleByArray($attributes);
|
||||
foreach ($attributes as $key => $value) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue