2012-05-30 00:07:50 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* 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.
|
2012-05-30 00:07:50 +02:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2012-05-30 00:07:50 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
namespace PhpOffice\PhpWord\Writer;
|
|
|
|
|
|
2014-05-04 21:03:28 +04:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* RTF writer
|
2014-04-17 16:19:23 +07:00
|
|
|
*
|
|
|
|
|
* @since 0.7.0
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-04-08 00:23:49 +07:00
|
|
|
class RTF extends AbstractWriter implements WriterInterface
|
2012-05-30 00:07:50 +02:00
|
|
|
{
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Last paragraph style
|
|
|
|
|
*
|
|
|
|
|
* @var mixed
|
|
|
|
|
*/
|
2014-03-30 16:31:01 +07:00
|
|
|
private $lastParagraphStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
/**
|
2014-05-23 12:48:34 +07:00
|
|
|
* Create new instance
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
public function __construct(PhpWord $phpWord = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
$this->setPhpWord($phpWord);
|
2014-05-23 00:21:22 +07:00
|
|
|
|
|
|
|
|
$this->parts = array('Header', 'Document');
|
|
|
|
|
foreach ($this->parts as $partName) {
|
|
|
|
|
$partClass = get_class($this) . '\\Part\\' . $partName;
|
|
|
|
|
if (class_exists($partClass)) {
|
|
|
|
|
/** @var \PhpOffice\PhpWord\Writer\RTF\Part\AbstractPart $part Type hint */
|
|
|
|
|
$part = new $partClass();
|
|
|
|
|
$part->setParentWriter($this);
|
|
|
|
|
$this->writerParts[strtolower($partName)] = $part;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-25 22:51:14 +07:00
|
|
|
* Save content to file
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
2014-05-07 09:47:02 +07:00
|
|
|
* @param string $filename
|
2014-04-16 17:22:30 +04:00
|
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-05-07 09:47:02 +07:00
|
|
|
public function save($filename = null)
|
2014-05-25 22:51:14 +07:00
|
|
|
{
|
|
|
|
|
$fileHandle = $this->openFile($filename);
|
|
|
|
|
$this->writeFile($fileHandle, $this->getContent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get content
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 0.11.0
|
|
|
|
|
*/
|
|
|
|
|
private function getContent()
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-05-23 00:21:22 +07:00
|
|
|
$content = '';
|
|
|
|
|
|
2014-05-25 22:51:14 +07:00
|
|
|
$content .= '{';
|
|
|
|
|
$content .= '\rtf1' . PHP_EOL;
|
|
|
|
|
$content .= $this->getWriterPart('Header')->write();
|
|
|
|
|
$content .= $this->getWriterPart('Document')->write();
|
|
|
|
|
$content .= '}';
|
|
|
|
|
|
|
|
|
|
return $content;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
2014-04-25 18:01:17 +07:00
|
|
|
/**
|
2014-05-23 00:21:22 +07:00
|
|
|
* Get font table
|
2014-04-25 18:01:17 +07:00
|
|
|
*/
|
2014-05-23 00:21:22 +07:00
|
|
|
public function getFontTable()
|
2014-04-25 18:01:17 +07:00
|
|
|
{
|
2014-05-23 00:21:22 +07:00
|
|
|
return $this->getWriterPart('Header')->getFontTable();
|
2014-04-25 18:01:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-23 00:21:22 +07:00
|
|
|
* Get color table
|
2014-04-25 18:01:17 +07:00
|
|
|
*/
|
2014-05-23 00:21:22 +07:00
|
|
|
public function getColorTable()
|
2014-04-25 18:01:17 +07:00
|
|
|
{
|
2014-05-23 00:21:22 +07:00
|
|
|
return $this->getWriterPart('Header')->getColorTable();
|
2014-04-25 18:01:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-25 23:57:43 +07:00
|
|
|
* Get last paragraph style
|
2014-04-25 18:01:17 +07:00
|
|
|
*/
|
2014-04-25 23:57:43 +07:00
|
|
|
public function getLastParagraphStyle()
|
2014-04-25 18:01:17 +07:00
|
|
|
{
|
2014-04-25 23:57:43 +07:00
|
|
|
return $this->lastParagraphStyle;
|
2014-04-25 18:01:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-25 23:57:43 +07:00
|
|
|
* Set last paragraph style
|
2014-04-25 18:01:17 +07:00
|
|
|
*
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
*/
|
2014-04-25 23:57:43 +07:00
|
|
|
public function setLastParagraphStyle($value = '')
|
2014-04-25 18:01:17 +07:00
|
|
|
{
|
2014-04-25 23:57:43 +07:00
|
|
|
$this->lastParagraphStyle = $value;
|
2014-04-25 18:01:17 +07:00
|
|
|
}
|
2014-03-11 19:26:56 +07:00
|
|
|
}
|