2012-05-06 18:25:40 +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-06 18:25:40 +02:00
|
|
|
*
|
2017-11-04 22:44:12 +01:00
|
|
|
* @see https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2010-2017 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2012-05-06 18:25:40 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
namespace PhpOffice\PhpWord\Element;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2016-01-23 19:16:34 +04:00
|
|
|
use PhpOffice\Common\Text as CommonText;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\Style\Font;
|
|
|
|
|
use PhpOffice\PhpWord\Style\Paragraph;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Preserve text/field element
|
|
|
|
|
*/
|
2014-04-08 00:23:49 +07:00
|
|
|
class PreserveText extends AbstractElement
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2013-12-11 14:45:44 -05:00
|
|
|
/**
|
|
|
|
|
* Text content
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-04-03 08:44:41 +07:00
|
|
|
private $text;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Text style
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @var string|\PhpOffice\PhpWord\Style\Font
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-04-03 08:44:41 +07:00
|
|
|
private $fontStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Paragraph style
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @var string|\PhpOffice\PhpWord\Style\Paragraph
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-04-03 08:44:41 +07:00
|
|
|
private $paragraphStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new Preserve Text Element
|
|
|
|
|
*
|
2014-03-17 07:26:25 +07:00
|
|
|
* @param string $text
|
2014-05-01 14:37:58 +07:00
|
|
|
* @param mixed $fontStyle
|
|
|
|
|
* @param mixed $paragraphStyle
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-05-01 14:37:58 +07:00
|
|
|
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-06-08 16:44:46 +07:00
|
|
|
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
|
|
|
|
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2016-01-23 19:16:34 +04:00
|
|
|
$this->text = CommonText::toUTF8($text);
|
2014-05-04 00:57:44 +07:00
|
|
|
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
2014-03-09 15:11:51 -04:00
|
|
|
if (isset($matches[0])) {
|
2014-04-03 08:44:41 +07:00
|
|
|
$this->text = $matches;
|
2014-03-09 15:11:51 -04:00
|
|
|
}
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Text style
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @return string|\PhpOffice\PhpWord\Style\Font
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
public function getFontStyle()
|
|
|
|
|
{
|
2014-04-03 08:44:41 +07:00
|
|
|
return $this->fontStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Paragraph style
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @return string|\PhpOffice\PhpWord\Style\Paragraph
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
public function getParagraphStyle()
|
|
|
|
|
{
|
2014-04-03 08:44:41 +07:00
|
|
|
return $this->paragraphStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Text content
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getText()
|
|
|
|
|
{
|
2014-04-03 08:44:41 +07:00
|
|
|
return $this->text;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2012-05-06 18:25:40 +02:00
|
|
|
}
|