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;
|
2014-03-22 10:06:08 +04: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
|
|
|
/**
|
|
|
|
|
* Text element
|
|
|
|
|
*/
|
2014-04-08 00:23:49 +07:00
|
|
|
class Text extends AbstractElement
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Text content
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2014-04-28 23:33:26 +07:00
|
|
|
protected $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-28 23:33:26 +07:00
|
|
|
protected $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-28 23:33:26 +07:00
|
|
|
protected $paragraphStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new Text Element
|
|
|
|
|
*
|
2014-03-09 15:03:53 -04:00
|
|
|
* @param string $text
|
2014-03-30 18:51:25 +07:00
|
|
|
* @param mixed $fontStyle
|
|
|
|
|
* @param mixed $paragraphStyle
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-03-09 15:03:53 -04:00
|
|
|
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-03-09 15:03:53 -04:00
|
|
|
$this->setText($text);
|
|
|
|
|
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
|
|
|
|
|
$this->setFontStyle($fontStyle, $paragraphStyle);
|
|
|
|
|
}
|
2013-12-11 14:45:44 -05:00
|
|
|
|
2014-03-09 15:03:53 -04:00
|
|
|
/**
|
|
|
|
|
* Set Text style
|
|
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @param string|array|\PhpOffice\PhpWord\Style\Font $style
|
|
|
|
|
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
|
|
|
|
* @return string|\PhpOffice\PhpWord\Style\Font
|
2014-03-09 15:03:53 -04:00
|
|
|
*/
|
|
|
|
|
public function setFontStyle($style = null, $paragraphStyle = null)
|
|
|
|
|
{
|
2014-03-22 10:06:08 +04:00
|
|
|
if ($style instanceof Font) {
|
2014-03-09 15:03:53 -04:00
|
|
|
$this->fontStyle = $style;
|
2014-03-09 15:24:13 -04:00
|
|
|
$this->setParagraphStyle($paragraphStyle);
|
2014-03-09 15:03:53 -04:00
|
|
|
} elseif (is_array($style)) {
|
2014-03-22 10:06:08 +04:00
|
|
|
$this->fontStyle = new Font('text', $paragraphStyle);
|
2014-05-07 09:47:02 +07:00
|
|
|
$this->fontStyle->setStyleByArray($style);
|
2014-03-09 15:03:53 -04:00
|
|
|
} elseif (null === $style) {
|
2014-03-22 10:06:08 +04:00
|
|
|
$this->fontStyle = new Font('text', $paragraphStyle);
|
2014-03-09 15:03:53 -04:00
|
|
|
} else {
|
2014-03-09 15:24:13 -04:00
|
|
|
$this->fontStyle = $style;
|
|
|
|
|
$this->setParagraphStyle($paragraphStyle);
|
2014-03-09 15:03:53 -04:00
|
|
|
}
|
2014-04-28 23:33:26 +07:00
|
|
|
|
2014-03-09 15:03:53 -04:00
|
|
|
return $this->fontStyle;
|
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-03-09 15:03:53 -04:00
|
|
|
return $this->fontStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-09 15:03:53 -04:00
|
|
|
* Set Paragraph style
|
2013-12-11 14:45:44 -05:00
|
|
|
*
|
2014-04-16 17:22:30 +04:00
|
|
|
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style
|
|
|
|
|
* @return string|\PhpOffice\PhpWord\Style\Paragraph
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-03-09 15:03:53 -04:00
|
|
|
public function setParagraphStyle($style = null)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2014-03-09 15:03:53 -04:00
|
|
|
if (is_array($style)) {
|
2017-11-04 22:44:12 +01:00
|
|
|
$this->paragraphStyle = new Paragraph();
|
2014-05-07 09:47:02 +07:00
|
|
|
$this->paragraphStyle->setStyleByArray($style);
|
2014-03-22 10:06:08 +04:00
|
|
|
} elseif ($style instanceof Paragraph) {
|
2014-03-09 15:03:53 -04:00
|
|
|
$this->paragraphStyle = $style;
|
|
|
|
|
} elseif (null === $style) {
|
2017-11-04 22:44:12 +01:00
|
|
|
$this->paragraphStyle = new Paragraph();
|
2013-12-11 14:45:44 -05:00
|
|
|
} else {
|
2014-03-09 15:24:13 -04:00
|
|
|
$this->paragraphStyle = $style;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2014-04-28 23:33:26 +07:00
|
|
|
|
2014-03-09 15:03:53 -04:00
|
|
|
return $this->paragraphStyle;
|
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-03-09 15:03:53 -04:00
|
|
|
return $this->paragraphStyle;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-17 07:26:25 +07:00
|
|
|
* Set text content
|
|
|
|
|
*
|
2014-03-09 15:03:53 -04:00
|
|
|
* @param string $text
|
2014-04-28 23:33:26 +07:00
|
|
|
* @return self
|
2013-12-11 14:45:44 -05:00
|
|
|
*/
|
2014-03-09 15:03:53 -04:00
|
|
|
public function setText($text)
|
2013-12-11 14:45:44 -05:00
|
|
|
{
|
2016-01-23 19:16:34 +04:00
|
|
|
$this->text = CommonText::toUTF8($text);
|
2014-04-28 23:33:26 +07:00
|
|
|
|
2014-03-09 15:03:53 -04:00
|
|
|
return $this;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Text content
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getText()
|
|
|
|
|
{
|
2014-03-09 15:03:53 -04:00
|
|
|
return $this->text;
|
2013-12-11 14:45:44 -05:00
|
|
|
}
|
2014-03-11 19:26:56 +07:00
|
|
|
}
|