Merge branch 'develop' into chart
This commit is contained in:
commit
9a5f91afc6
@ -18,6 +18,8 @@ This release added drawing shapes (arc, curve, line, polyline, rect, oval) eleme
|
|||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- Fix rare PclZip/realpath/PHP version problem - @andrew-kzoo GH-261
|
- Fix rare PclZip/realpath/PHP version problem - @andrew-kzoo GH-261
|
||||||
|
- `addHTML` encoding and ampersand fixes for PHP 5.3 - @bskrtich GH-270
|
||||||
|
- Page breaks on titles and tables - @ivanlanin GH-274
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|||||||
@ -65,3 +65,25 @@ Define a numbering style and title styles, and match the two styles (with ``pSty
|
|||||||
$section->addTitle('Heading 1', 1);
|
$section->addTitle('Heading 1', 1);
|
||||||
$section->addTitle('Heading 2', 2);
|
$section->addTitle('Heading 2', 2);
|
||||||
$section->addTitle('Heading 3', 3);
|
$section->addTitle('Heading 3', 3);
|
||||||
|
|
||||||
|
Add a link within a title
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
|
||||||
|
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
|
||||||
|
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
// Textrun
|
||||||
|
$textrun = $section->addTextRun('Heading1');
|
||||||
|
$textrun->addText('The ');
|
||||||
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
|
||||||
|
|
||||||
|
// Link
|
||||||
|
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
|
||||||
|
|||||||
@ -1017,6 +1017,27 @@ $section->addTitle('Heading 2', 2);
|
|||||||
$section->addTitle('Heading 3', 3);
|
$section->addTitle('Heading 3', 3);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Add a link within a title
|
||||||
|
|
||||||
|
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
|
||||||
|
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
|
||||||
|
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
// Textrun
|
||||||
|
$textrun = $section->addTextRun('Heading1');
|
||||||
|
$textrun->addText('The ');
|
||||||
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
|
||||||
|
|
||||||
|
// Link
|
||||||
|
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
|
||||||
|
```
|
||||||
|
|
||||||
# Frequently asked questions
|
# Frequently asked questions
|
||||||
|
|
||||||
## Is this the same with PHPWord that I found in CodePlex?
|
## Is this the same with PHPWord that I found in CodePlex?
|
||||||
|
|||||||
@ -42,9 +42,14 @@ class Html
|
|||||||
* which could be applied when such an element occurs in the parseNode function.
|
* which could be applied when such an element occurs in the parseNode function.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Preprocess: remove all line ends, decode HTML entity, and add body tag for HTML fragments
|
// Preprocess: remove all line ends, decode HTML entity,
|
||||||
|
// fix ampersand and angle brackets and add body tag for HTML fragments
|
||||||
$html = str_replace(array("\n", "\r"), '', $html);
|
$html = str_replace(array("\n", "\r"), '', $html);
|
||||||
$html = html_entity_decode($html);
|
$html = str_replace(array('<', '>', '&'), array('_lt_', '_gt_', '_amp_'), $html);
|
||||||
|
$html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
|
||||||
|
$html = str_replace('&', '&', $html);
|
||||||
|
$html = str_replace(array('_lt_', '_gt_', '_amp_'), array('<', '>', '&'), $html);
|
||||||
|
|
||||||
if ($fullHTML === false) {
|
if ($fullHTML === false) {
|
||||||
$html = '<body>' . $html . '</body>';
|
$html = '<body>' . $html . '</body>';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,13 +50,6 @@ abstract class AbstractElement
|
|||||||
*/
|
*/
|
||||||
protected $withoutP = false;
|
protected $withoutP = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Has page break before
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $pageBreakBefore = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write element
|
* Write element
|
||||||
*/
|
*/
|
||||||
@ -96,26 +89,6 @@ abstract class AbstractElement
|
|||||||
return $this->element;
|
return $this->element;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Has page break before
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function hasPageBreakBefore()
|
|
||||||
{
|
|
||||||
return $this->pageBreakBefore;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set page break before
|
|
||||||
*
|
|
||||||
* @param bool $value
|
|
||||||
*/
|
|
||||||
public function setPageBreakBefore($value = true)
|
|
||||||
{
|
|
||||||
$this->pageBreakBefore = (bool)$value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start w:p DOM element
|
* Start w:p DOM element
|
||||||
*
|
*
|
||||||
@ -129,11 +102,6 @@ abstract class AbstractElement
|
|||||||
if (method_exists($this->element, 'getParagraphStyle')) {
|
if (method_exists($this->element, 'getParagraphStyle')) {
|
||||||
$this->writeParagraphStyle();
|
$this->writeParagraphStyle();
|
||||||
}
|
}
|
||||||
// PageBreak
|
|
||||||
if ($this->pageBreakBefore) {
|
|
||||||
$elementWriter = new PageBreak($this->xmlWriter, new PageBreakElement());
|
|
||||||
$elementWriter->write();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -81,21 +81,9 @@ class Container extends AbstractElement
|
|||||||
$elementClass = substr(get_class($element), strrpos(get_class($element), '\\') + 1);
|
$elementClass = substr(get_class($element), strrpos(get_class($element), '\\') + 1);
|
||||||
$writerClass = $this->namespace . '\\' . $elementClass;
|
$writerClass = $this->namespace . '\\' . $elementClass;
|
||||||
|
|
||||||
// Check it's a page break. No need to write it, instead, flag containers'
|
|
||||||
// pageBreakBefore to be assigned to the next element
|
|
||||||
if ($elementClass == 'PageBreak') {
|
|
||||||
$this->setPageBreakBefore(true);
|
|
||||||
return $elementClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (class_exists($writerClass)) {
|
if (class_exists($writerClass)) {
|
||||||
// Get container's page break before and reset it
|
|
||||||
$pageBreakBefore = $this->hasPageBreakBefore();
|
|
||||||
$this->setPageBreakBefore(false);
|
|
||||||
|
|
||||||
/** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $writer Type hint */
|
/** @var \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement $writer Type hint */
|
||||||
$writer = new $writerClass($xmlWriter, $element, $withoutP);
|
$writer = new $writerClass($xmlWriter, $element, $withoutP);
|
||||||
$writer->setPageBreakBefore($pageBreakBefore);
|
|
||||||
$writer->write();
|
$writer->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,9 +20,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
|||||||
/**
|
/**
|
||||||
* PageBreak element writer
|
* PageBreak element writer
|
||||||
*
|
*
|
||||||
* Originally, page break is rendered as a `w:p`, but this turns out to produce bug #150.
|
|
||||||
* As of 0.11.0, page break is rendered as a `w:r` with `w:br` type "page" and `w:lastRenderedPageBreak`
|
|
||||||
*
|
|
||||||
* @since 0.10.0
|
* @since 0.10.0
|
||||||
*/
|
*/
|
||||||
class PageBreak extends AbstractElement
|
class PageBreak extends AbstractElement
|
||||||
@ -36,11 +33,12 @@ class PageBreak extends AbstractElement
|
|||||||
{
|
{
|
||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
|
|
||||||
|
$xmlWriter->startElement('w:p');
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:br');
|
$xmlWriter->startElement('w:br');
|
||||||
$xmlWriter->writeAttribute('w:type', 'page');
|
$xmlWriter->writeAttribute('w:type', 'page');
|
||||||
$xmlWriter->endElement(); // w:br
|
$xmlWriter->endElement(); // w:br
|
||||||
$xmlWriter->writeElement('w:lastRenderedPageBreak');
|
|
||||||
$xmlWriter->endElement(); // w:r
|
$xmlWriter->endElement(); // w:r
|
||||||
|
$xmlWriter->endElement(); // w:p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,8 @@ class Settings extends AbstractPart
|
|||||||
'w:autofitToFirstFixedWidthCell' => '',
|
'w:autofitToFirstFixedWidthCell' => '',
|
||||||
'w:underlineTabInNumList' => '',
|
'w:underlineTabInNumList' => '',
|
||||||
'w:displayHangulFixedWidth' => '',
|
'w:displayHangulFixedWidth' => '',
|
||||||
'w:splitPgBreakAndParaMark' => '',
|
// Commented for GH-274
|
||||||
|
// 'w:splitPgBreakAndParaMark' => '',
|
||||||
'w:doNotVertAlignCellWithSp' => '',
|
'w:doNotVertAlignCellWithSp' => '',
|
||||||
'w:doNotBreakConstrainedForcedTable' => '',
|
'w:doNotBreakConstrainedForcedTable' => '',
|
||||||
'w:doNotVertAlignInTxbx' => '',
|
'w:doNotVertAlignInTxbx' => '',
|
||||||
|
|||||||
@ -60,6 +60,12 @@ class HtmlTest extends \PHPUnit_Framework_TestCase
|
|||||||
$content .= '<table><tr><th>Header</th><td>Content</td></tr></table>';
|
$content .= '<table><tr><th>Header</th><td>Content</td></tr></table>';
|
||||||
$content .= '<ul><li>Bullet</li><ul><li>Bullet</li></ul></ul>';
|
$content .= '<ul><li>Bullet</li><ul><li>Bullet</li></ul></ul>';
|
||||||
$content .= '<ol><li>Bullet</li></ol>';
|
$content .= '<ol><li>Bullet</li></ol>';
|
||||||
|
$content .= "'Single Quoted Text'";
|
||||||
|
$content .= '"Double Quoted Text"';
|
||||||
|
$content .= '& Ampersand';
|
||||||
|
$content .= '<>“‘’«»‹›';
|
||||||
|
$content .= '&•°…™©®—';
|
||||||
|
$content .= '–   ²³¼½¾';
|
||||||
Html::addHtml($section, $content);
|
Html::addHtml($section, $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -114,15 +114,15 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('page', $element->getAttribute('w:type'));
|
$this->assertEquals('page', $element->getAttribute('w:type'));
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p[5]/w:pPr/w:pStyle');
|
$element = $doc->getElement('/w:document/w:body/w:p[6]/w:pPr/w:pStyle');
|
||||||
$this->assertEquals('Heading1', $element->getAttribute('w:val'));
|
$this->assertEquals('Heading1', $element->getAttribute('w:val'));
|
||||||
|
|
||||||
// List item
|
// List item
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p[6]/w:pPr/w:numPr/w:numId');
|
$element = $doc->getElement('/w:document/w:body/w:p[7]/w:pPr/w:numPr/w:numId');
|
||||||
$this->assertEquals(3, $element->getAttribute('w:val'));
|
$this->assertEquals(3, $element->getAttribute('w:val'));
|
||||||
|
|
||||||
// Object
|
// Object
|
||||||
$element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject');
|
$element = $doc->getElement('/w:document/w:body/w:p[12]/w:r/w:object/o:OLEObject');
|
||||||
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user