Merge branch 'develop' into chart

This commit is contained in:
Ivan Lanin 2014-06-12 12:17:49 +07:00
commit 9a5f91afc6
10 changed files with 65 additions and 54 deletions

View File

@ -18,6 +18,8 @@ This release added drawing shapes (arc, curve, line, polyline, rect, oval) eleme
### Bugfixes
- 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

View File

@ -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 2', 2);
$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');

View File

@ -1017,6 +1017,27 @@ $section->addTitle('Heading 2', 2);
$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
## Is this the same with PHPWord that I found in CodePlex?

View File

@ -42,9 +42,14 @@ class Html
* 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 = 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) {
$html = '<body>' . $html . '</body>';
}

View File

@ -50,13 +50,6 @@ abstract class AbstractElement
*/
protected $withoutP = false;
/**
* Has page break before
*
* @var bool
*/
private $pageBreakBefore = false;
/**
* Write element
*/
@ -96,26 +89,6 @@ abstract class AbstractElement
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
*
@ -129,11 +102,6 @@ abstract class AbstractElement
if (method_exists($this->element, 'getParagraphStyle')) {
$this->writeParagraphStyle();
}
// PageBreak
if ($this->pageBreakBefore) {
$elementWriter = new PageBreak($this->xmlWriter, new PageBreakElement());
$elementWriter->write();
}
}
}

View File

@ -81,21 +81,9 @@ class Container extends AbstractElement
$elementClass = substr(get_class($element), strrpos(get_class($element), '\\') + 1);
$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)) {
// 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 */
$writer = new $writerClass($xmlWriter, $element, $withoutP);
$writer->setPageBreakBefore($pageBreakBefore);
$writer->write();
}

View File

@ -20,9 +20,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Element;
/**
* 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
*/
class PageBreak extends AbstractElement
@ -36,11 +33,12 @@ class PageBreak extends AbstractElement
{
$xmlWriter = $this->getXmlWriter();
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:br');
$xmlWriter->writeAttribute('w:type', 'page');
$xmlWriter->endElement(); // w:br
$xmlWriter->writeElement('w:lastRenderedPageBreak');
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
}
}

View File

@ -50,7 +50,8 @@ class Settings extends AbstractPart
'w:autofitToFirstFixedWidthCell' => '',
'w:underlineTabInNumList' => '',
'w:displayHangulFixedWidth' => '',
'w:splitPgBreakAndParaMark' => '',
// Commented for GH-274
// 'w:splitPgBreakAndParaMark' => '',
'w:doNotVertAlignCellWithSp' => '',
'w:doNotBreakConstrainedForcedTable' => '',
'w:doNotVertAlignInTxbx' => '',

View File

@ -60,6 +60,12 @@ class HtmlTest extends \PHPUnit_Framework_TestCase
$content .= '<table><tr><th>Header</th><td>Content</td></tr></table>';
$content .= '<ul><li>Bullet</li><ul><li>Bullet</li></ul></ul>';
$content .= '<ol><li>Bullet</li></ol>';
$content .= "'Single Quoted Text'";
$content .= '"Double Quoted Text"';
$content .= '& Ampersand';
$content .= '&lt;&gt;&ldquo;&lsquo;&rsquo;&laquo;&raquo;&lsaquo;&rsaquo;';
$content .= '&amp;&bull;&deg;&hellip;&trade;&copy;&reg;&mdash;';
$content .= '&ndash;&nbsp;&emsp;&ensp;&sup2;&sup3;&frac14;&frac12;&frac34;';
Html::addHtml($section, $content);
}
}

View File

@ -114,15 +114,15 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('page', $element->getAttribute('w:type'));
// 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'));
// 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'));
// 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'));
}