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
|
2018-03-08 23:52:25 +01:00
|
|
|
* @copyright 2010-2018 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
|
|
|
|
2021-01-01 16:09:16 +01:00
|
|
|
use PhpOffice\PhpWord\Shared\Text as SharedText;
|
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
|
|
|
|
|
*
|
2018-07-14 03:28:09 +02:00
|
|
|
* @var string|array
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
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
|
|
|
|
2021-01-01 16:09:16 +01:00
|
|
|
$this->text = SharedText::toUTF8($text);
|
2022-06-08 14:14:25 +02:00
|
|
|
$matches = preg_split('/({.*?})/', $this->text, -1, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*
|
2018-07-14 03:28:09 +02:00
|
|
|
* @return string|array
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
}
|