Skip to content

Commit

Permalink
Merge branch 'develop' into feature-add-table-indent-option
Browse files Browse the repository at this point in the history
  • Loading branch information
troosan authored Apr 14, 2018
2 parents 081c672 + dd27f66 commit b394247
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ v0.15.0 (?? ??? 2018)
- Added support for Image text wrapping distance @troosan #1310
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
- Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576
- Add support for table indent (tblInd) @Trainmaster
- Add support for table indent (tblInd) @Trainmaster #1343
- Added parsing of internal links in HTML reader @lalop #1336

### Fixed
- Fix reading of docx default style - @troosan #1238
Expand All @@ -36,6 +37,7 @@ v0.15.0 (?? ??? 2018)

### Changed
- Remove zend-stdlib dependency @Trainmaster #1284
- The default unit for `\PhpOffice\PhpWord\Style\Image` changed from `px` to `pt`.


v0.14.0 (29 Dec 2017)
Expand Down
6 changes: 3 additions & 3 deletions docs/elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ To add an image, use the ``addImage`` method to sections, headers, footers, text
$section->addImage($src, [$style]);
- ``$src``. String path to a local image, URL of a remote image or the image data, as a string.
- ``$src``. String path to a local image, URL of a remote image or the image data, as a string. Warning: Do not pass user-generated strings here, as that would allow an attacker to read arbitrary files or perform server-side request forgery by passing file paths or URLs instead of image data.
- ``$style``. See :ref:`image-style`.

Examples:
Expand Down Expand Up @@ -435,8 +435,8 @@ Available line style attributes:
- ``dash``. Line types: dash, rounddot, squaredot, dashdot, longdash, longdashdot, longdashdotdot.
- ``beginArrow``. Start type of arrow: block, open, classic, diamond, oval.
- ``endArrow``. End type of arrow: block, open, classic, diamond, oval.
- ``width``. Line-object width in pt.
- ``height``. Line-object height in pt.
- ``width``. Line-object width in *pt*.
- ``height``. Line-object height in *pt*.
- ``flip``. Flip the line element: true, false.

Chart
Expand Down
4 changes: 2 additions & 2 deletions docs/styles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ Image
Available Image style options:

- ``alignment``. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
- ``height``. Height in pixels.
- ``height``. Height in *pt*.
- ``marginLeft``. Left margin in inches, can be negative.
- ``marginTop``. Top margin in inches, can be negative.
- ``width``. Width in pixels.
- ``width``. Width in *pt*.
- ``wrappingStyle``. Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*.
- ``wrapDistanceTop``. Top text wrapping in pixels.
- ``wrapDistanceBottom``. Bottom text wrapping in pixels.
Expand Down
2 changes: 1 addition & 1 deletion samples/Sample_Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function write($phpWord, $filename, $writers)
* Get ending notes
*
* @param array $writers
*
* @param mixed $filename
* @return string
*/
function getEndingNotes($writers, $filename)
Expand Down
6 changes: 6 additions & 0 deletions src/PhpWord/Shared/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Html
* Add HTML parts.
*
* Note: $stylesheet parameter is removed to avoid PHPMD error for unused parameter
* Warning: Do not pass user-generated HTML here, as that would allow an attacker to read arbitrary
* files or perform server-side request forgery by passing local file paths or URLs in <img>.
*
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element Where the parts need to be added
* @param string $html The code to parse
Expand Down Expand Up @@ -721,6 +723,10 @@ private static function parseLink($node, $element, &$styles)
}
self::parseInlineStyle($node, $styles['font']);

if (strpos($target, '#') === 0) {
return $element->addLink(substr($target, 1), $node->textContent, $styles['font'], $styles['paragraph'], true);
}

return $element->addLink($target, $node->textContent, $styles['font'], $styles['paragraph']);
}
}
16 changes: 16 additions & 0 deletions tests/PhpWord/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function testParseLineHeight()
$section = $phpWord->addSection();
Html::addHtml($section, '<p style="line-height: 1.5;">test</p>');
Html::addHtml($section, '<p style="line-height: 15pt;">test</p>');
Html::addHtml($section, '<p style="line-height: 120%;">test</p>');

$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
Expand All @@ -134,6 +135,10 @@ public function testParseLineHeight()
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[2]/w:pPr/w:spacing'));
$this->assertEquals(300, $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:spacing', 'w:line'));
$this->assertEquals(LineSpacingRule::EXACT, $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:spacing', 'w:lineRule'));

$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:pPr/w:spacing'));
$this->assertEquals(Paragraph::LINE_HEIGHT * 1.2, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:line'));
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:lineRule'));
}

/**
Expand Down Expand Up @@ -453,6 +458,17 @@ public function testParseLink()

$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
$this->assertEquals('link text', $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t')->nodeValue);

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addBookmark('bookmark');
$html = '<p><a href="#bookmark">internal link text</a></p>';
Html::addHtml($section, $html);
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');

$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
$this->assertTrue($doc->getElement('/w:document/w:body/w:p/w:hyperlink')->hasAttribute('w:anchor'));
$this->assertEquals('bookmark', $doc->getElement('/w:document/w:body/w:p/w:hyperlink')->getAttribute('w:anchor'));
}

public function testParseMalformedStyleIsIgnored()
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpWord/Writer/Word2007/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function testChartElements()
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$style = array('width' => 1000000, 'height' => 1000000);
$style = array('width' => 1000000, 'height' => 1000000, 'showAxisLabels' => true, 'showGridX' => true, 'showGridY' => true);

$chartTypes = array('pie', 'doughnut', 'bar', 'line', 'area', 'scatter', 'radar');
$categories = array('A', 'B', 'C', 'D', 'E');
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpWord/Writer/Word2007/Style/FontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testFontRTL()
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true));
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true, 'lang' => 'ar-DZ'));
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');

$file = 'word/document.xml';
Expand Down

0 comments on commit b394247

Please sign in to comment.