Skip to content

Commit c2b54cc

Browse files
Alexmg86troosan
authored andcommitted
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
1 parent 260bb75 commit c2b54cc

File tree

14 files changed

+79
-1
lines changed

14 files changed

+79
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ v0.16.0 (xx dec 2018)
77
----------------------
88
### Added
99
- Add setting Chart Title and Legend visibility @Tom-Magill #1433
10+
- Add support for hidden text @Alexmg86 #1527
1011

1112
### Fixed
1213
- Fix regex in `cloneBlock` function @nicoder #1269

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"php-cs-fixer fix --ansi --dry-run --diff",
4646
"phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
4747
"phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
48-
"@test"
48+
"@test-no-coverage"
4949
],
5050
"fix": [
5151
"php-cs-fixer fix --ansi"

docs/styles.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Available Font style options:
6161
- ``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
6262
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
6363
- ``position``. The text position, raised or lowered, in half points
64+
- ``hidden``. Hidden text, *true* or *false*.
6465

6566
.. _paragraph-style:
6667

samples/Sample_04_Textrun.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
$textrun->addObject('resources/_sheet.xls');
4040
$textrun->addText(' Here is some more text. ');
4141

42+
$textrun = $section->addTextRun();
43+
$textrun->addText('This text is not visible.', array('hidden' => true));
44+
4245
// Save file
4346
echo write($phpWord, basename(__FILE__, '.php'), $writers);
4447
if (!CLI) {

samples/Sample_26_Html.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
<tr><td style="text-align: center;">Cell in parent table</td></tr>
9090
</table>';
9191

92+
$html .= '<p style="margin-top: 240pt;">The text below is not visible, click on show/hide to reveil it:</p>';
93+
$html .= '<p style="display: none">This is hidden text</p>';
94+
9295
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
9396

9497
// Save file

src/PhpWord/Reader/Word2007/AbstractPart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode)
444444
'rtl' => array(self::READ_TRUE, 'w:rtl'),
445445
'lang' => array(self::READ_VALUE, 'w:lang'),
446446
'position' => array(self::READ_VALUE, 'w:position'),
447+
'hidden' => array(self::READ_TRUE, 'w:vanish'),
447448
);
448449

449450
return $this->readStyleDefs($xmlReader, $styleNode, $styleDefs);

src/PhpWord/Reader/Word2007/Styles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function read(PhpWord $phpWord)
6868
if (is_null($name)) {
6969
$name = $xmlReader->getAttribute('w:val', $node, 'w:name');
7070
}
71+
$headingMatches = array();
7172
preg_match('/Heading(\d)/', $name, $headingMatches);
7273
// $default = ($xmlReader->getAttribute('w:default', $node) == 1);
7374
switch ($type) {

src/PhpWord/Shared/Html.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ private static function parseStyle($attribute, $styles)
515515
case 'text-align':
516516
$styles['alignment'] = self::mapAlign($cValue);
517517
break;
518+
case 'display':
519+
$styles['hidden'] = $cValue === 'none';
520+
break;
518521
case 'direction':
519522
$styles['rtl'] = $cValue === 'rtl';
520523
break;

src/PhpWord/Style/Font.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ class Font extends AbstractStyle
252252
*/
253253
private $lang;
254254

255+
/**
256+
* Hidden text
257+
*
258+
* @var bool
259+
* @see http://www.datypic.com/sc/ooxml/e-w_vanish-1.html
260+
*/
261+
private $hidden = false;
262+
255263
/**
256264
* Vertically Raised or Lowered Text
257265
*
@@ -299,6 +307,7 @@ public function getStyleValues()
299307
'smallCaps' => $this->isSmallCaps(),
300308
'allCaps' => $this->isAllCaps(),
301309
'fgColor' => $this->getFgColor(),
310+
'hidden' => $this->isHidden(),
302311
),
303312
'spacing' => array(
304313
'scale' => $this->getScale(),
@@ -938,6 +947,29 @@ public function getParagraphStyle()
938947
return $this->getParagraph();
939948
}
940949

950+
/**
951+
* Get hidden text
952+
*
953+
* @return bool
954+
*/
955+
public function isHidden()
956+
{
957+
return $this->hidden;
958+
}
959+
960+
/**
961+
* Set hidden text
962+
*
963+
* @param bool $value
964+
* @return self
965+
*/
966+
public function setHidden($value = true)
967+
{
968+
$this->hidden = $this->setBoolVal($value, $this->hidden);
969+
970+
return $this;
971+
}
972+
941973
/**
942974
* Get position
943975
*

src/PhpWord/Writer/HTML/Style/Font.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function write()
6060
$css['text-decoration'] .= $this->getValueIf($lineThrough, 'line-through ');
6161
$css['text-transform'] = $this->getValueIf($style->isAllCaps(), 'uppercase');
6262
$css['font-variant'] = $this->getValueIf($style->isSmallCaps(), 'small-caps');
63+
$css['display'] = $this->getValueIf($style->isHidden(), 'none');
6364

6465
$spacing = $style->getSpacing();
6566
$css['letter-spacing'] = $this->getValueIf(!is_null($spacing), ($spacing / 20) . 'pt');

0 commit comments

Comments
 (0)