No Description

PreserveText.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Element;
  18. use PhpOffice\PhpWord\Shared\String;
  19. use PhpOffice\PhpWord\Style\Font;
  20. use PhpOffice\PhpWord\Style\Paragraph;
  21. /**
  22. * Preserve text/field element
  23. */
  24. class PreserveText extends AbstractElement
  25. {
  26. /**
  27. * Text content
  28. *
  29. * @var string
  30. */
  31. private $text;
  32. /**
  33. * Text style
  34. *
  35. * @var string|\PhpOffice\PhpWord\Style\Font
  36. */
  37. private $fontStyle;
  38. /**
  39. * Paragraph style
  40. *
  41. * @var string|\PhpOffice\PhpWord\Style\Paragraph
  42. */
  43. private $paragraphStyle;
  44. /**
  45. * Create a new Preserve Text Element
  46. *
  47. * @param string $text
  48. * @param mixed $fontStyle
  49. * @param mixed $paragraphStyle
  50. * @return self
  51. */
  52. public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
  53. {
  54. $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
  55. $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
  56. $this->text = String::toUTF8($text);
  57. $matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  58. if (isset($matches[0])) {
  59. $this->text = $matches;
  60. }
  61. return $this;
  62. }
  63. /**
  64. * Get Text style
  65. *
  66. * @return string|\PhpOffice\PhpWord\Style\Font
  67. */
  68. public function getFontStyle()
  69. {
  70. return $this->fontStyle;
  71. }
  72. /**
  73. * Get Paragraph style
  74. *
  75. * @return string|\PhpOffice\PhpWord\Style\Paragraph
  76. */
  77. public function getParagraphStyle()
  78. {
  79. return $this->paragraphStyle;
  80. }
  81. /**
  82. * Get Text content
  83. *
  84. * @return string
  85. */
  86. public function getText()
  87. {
  88. return $this->text;
  89. }
  90. }