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 @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions docs/styles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 3 additions & 0 deletions samples/Sample_04_Textrun.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
$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) {
Expand Down
3 changes: 3 additions & 0 deletions samples/Sample_26_Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<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
Expand Down
1 change: 1 addition & 0 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode)
'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);
Expand Down
1 change: 1 addition & 0 deletions src/PhpWord/Reader/Word2007/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function read(PhpWord $phpWord)
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) {
Expand Down
3 changes: 3 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ private static function parseStyle($attribute, $styles)
case 'text-align':
$styles['alignment'] = self::mapAlign($cValue);
break;
case 'display':
$styles['hidden'] = $cValue === 'none';
break;
case 'direction':
$styles['rtl'] = $cValue === 'rtl';
break;
Expand Down
32 changes: 32 additions & 0 deletions src/PhpWord/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -299,6 +307,7 @@ public function getStyleValues()
'smallCaps' => $this->isSmallCaps(),
'allCaps' => $this->isAllCaps(),
'fgColor' => $this->getFgColor(),
'hidden' => $this->isHidden(),
),
'spacing' => array(
'scale' => $this->getScale(),
Expand Down Expand Up @@ -938,6 +947,29 @@ public function getParagraphStyle()
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
*
Expand Down
1 change: 1 addition & 0 deletions src/PhpWord/Writer/HTML/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function write()
$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');
Expand Down
3 changes: 3 additions & 0 deletions src/PhpWord/Writer/ODText/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function write()
$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');
Expand Down
3 changes: 3 additions & 0 deletions src/PhpWord/Writer/Word2007/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private function writeStyle()
$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());

Expand Down
24 changes: 24 additions & 0 deletions tests/PhpWord/Reader/Word2007/StyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,28 @@ public function testReadIndent()
$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());
}
}
2 changes: 2 additions & 0 deletions tests/PhpWord/Style/FontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function testSetStyleValueWithNullOrEmpty()
'spacing' => null,
'kerning' => null,
'lang' => null,
'hidden' => false,
);
foreach ($attributes as $key => $default) {
$get = is_bool($default) ? "is{$key}" : "get{$key}";
Expand Down Expand Up @@ -117,6 +118,7 @@ public function testSetStyleValueNormal()
'rtl' => true,
'noProof' => true,
'lang' => new Language(Language::EN_US),
'hidden' => true,
);
$object->setStyleByArray($attributes);
foreach ($attributes as $key => $value) {
Expand Down