#196: Ability to add links and page breaks in RTF
This commit is contained in:
parent
f8f98cccab
commit
4b1a16006d
|
|
@ -17,6 +17,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
|
|||
- Table: Ability to add table inside a cell (nested table) - @ivanlanin GH-149
|
||||
- RTF: UTF8 support for RTF: Internal UTF8 text is converted to Unicode before writing - @ivanlanin GH-158
|
||||
- Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237
|
||||
- RTF: Ability to add links and page breaks in RTF - @ivanlanin GH-196
|
||||
|
||||
### Bugfixes
|
||||
|
||||
|
|
|
|||
|
|
@ -73,13 +73,13 @@ Writers
|
|||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Title | ✓ | | | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Link | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Preserve Text | ✓ | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | Page Break | ✓ | | | | |
|
||||
| | Page Break | ✓ | | ✓ | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
| | List | ✓ | | | | |
|
||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||
|
|
|
|||
|
|
@ -84,10 +84,10 @@ Below are the supported features for each file formats.
|
|||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Title | ✓ | | | ✓ | ✓ |
|
||||
| | Link | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Link | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Preserve Text | ✓ | | | | |
|
||||
| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
| | Page Break | ✓ | | | | |
|
||||
| | Page Break | ✓ | | ✓ | | |
|
||||
| | List | ✓ | | | | |
|
||||
| | Table | ✓ | ✓ | | ✓ | ✓ |
|
||||
| | Image | ✓ | ✓ | | ✓ | |
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ $section->addTextBreak(2);
|
|||
$section->addText('I am styled by a font style definition.', 'rStyle');
|
||||
$section->addText('I am styled by a paragraph style definition.', null, 'pStyle');
|
||||
$section->addText('I am styled by both font and paragraph style.', 'rStyle', 'pStyle');
|
||||
$section->addTextBreak();
|
||||
|
||||
$section->addPageBreak();
|
||||
|
||||
// Inline font style
|
||||
$fontStyle['name'] = 'Times New Roman';
|
||||
|
|
@ -36,10 +37,11 @@ $fontStyle['color'] = 'FF0000';
|
|||
$fontStyle['fgColor'] = 'yellow';
|
||||
$fontStyle['smallCaps'] = true;
|
||||
$section->addText('I am inline styled.', $fontStyle);
|
||||
|
||||
$section->addTextBreak();
|
||||
|
||||
// Link
|
||||
$section->addLink('http://www.google.com', null, 'NLink');
|
||||
$section->addLink('http://www.google.com', 'Google');
|
||||
$section->addTextBreak();
|
||||
|
||||
// Image
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||
* word processing documents.
|
||||
*
|
||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||
* General Public License version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please read the LICENSE
|
||||
* file that was distributed with this source code. For the full list of
|
||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\RTF\Element;
|
||||
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
|
||||
/**
|
||||
* Link element RTF writer
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class Link extends AbstractElement
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
$element = $this->element;
|
||||
if (!$element instanceof \PhpOffice\PhpWord\Element\Link) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = '';
|
||||
if (!$this->withoutP) {
|
||||
$content .= '{';
|
||||
}
|
||||
$content .= '{\field {\*\fldinst {HYPERLINK "' . $element->getTarget() . '"}}{\\fldrslt {';
|
||||
$content .= String::toUnicode($element->getText());
|
||||
$content .= '}}}';
|
||||
if (!$this->withoutP) {
|
||||
$content .= '}';
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||
* word processing documents.
|
||||
*
|
||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||
* General Public License version 3 as published by the Free Software Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please read the LICENSE
|
||||
* file that was distributed with this source code. For the full list of
|
||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2010-2014 PHPWord contributors
|
||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer\RTF\Element;
|
||||
|
||||
/**
|
||||
* PageBreak element RTF writer
|
||||
*
|
||||
* @since 0.11.0
|
||||
*/
|
||||
class PageBreak extends AbstractElement
|
||||
{
|
||||
/**
|
||||
* Write element
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function write()
|
||||
{
|
||||
return '\page' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ class Title extends AbstractElement
|
|||
|
||||
$content = '';
|
||||
|
||||
$content .= '\pard\nowidctlpar';
|
||||
$content .= '\pard\nowidctlpar ';
|
||||
$content .= String::toUnicode($this->element->getText());
|
||||
$content .= '\par' . PHP_EOL;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class ElementTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testUnmatchedElements()
|
||||
{
|
||||
$styles = array('Container', 'Text', 'Title');
|
||||
$styles = array('Container', 'Text', 'Title', 'Link');
|
||||
foreach ($styles as $style) {
|
||||
$objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element\\' . $style;
|
||||
$parentWriter = new RTF();
|
||||
|
|
|
|||
Loading…
Reference in New Issue