PreserveText.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * PHPWord
  4. *
  5. * Copyright (c) 2011 PHPWord
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPWord
  22. * @package PHPWord
  23. * @copyright Copyright (c) 010 PHPWord
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version Beta 0.6.3, 08.07.2011
  26. */
  27. /**
  28. * PHPWord_Section_Footer_PreserveText
  29. *
  30. * @category PHPWord
  31. * @package PHPWord_Section_Footer
  32. * @copyright Copyright (c) 2011 PHPWord
  33. */
  34. class PHPWord_Section_Footer_PreserveText {
  35. /**
  36. * Text content
  37. *
  38. * @var string
  39. */
  40. private $_text;
  41. /**
  42. * Text style
  43. *
  44. * @var PHPWord_Style_Font
  45. */
  46. private $_styleFont;
  47. /**
  48. * Paragraph style
  49. *
  50. * @var PHPWord_Style_Font
  51. */
  52. private $_styleParagraph;
  53. /**
  54. * Create a new Preserve Text Element
  55. *
  56. * @var string $text
  57. * @var mixed $style
  58. */
  59. public function __construct($text = null, $styleFont = null, $styleParagraph = null) {
  60. // Set font style
  61. if(is_array($styleFont)) {
  62. $this->_styleFont = new PHPWord_Style_Font('text');
  63. foreach($styleFont as $key => $value) {
  64. if(substr($key, 0, 1) != '_') {
  65. $key = '_'.$key;
  66. }
  67. $this->_styleFont->setStyleValue($key, $value);
  68. }
  69. } else {
  70. $this->_styleFont = $styleFont;
  71. }
  72. // Set paragraph style
  73. if(is_array($styleParagraph)) {
  74. $this->_styleParagraph = new PHPWord_Style_Paragraph();
  75. foreach($styleParagraph as $key => $value) {
  76. if(substr($key, 0, 1) != '_') {
  77. $key = '_'.$key;
  78. }
  79. $this->_styleParagraph->setStyleValue($key, $value);
  80. }
  81. } else {
  82. $this->_styleParagraph = $styleParagraph;
  83. }
  84. $pattern = '/({.*?})/';
  85. $this->_text = preg_split($pattern, $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  86. return $this;
  87. }
  88. /**
  89. * Get Text style
  90. *
  91. * @return PHPWord_Style_Font
  92. */
  93. public function getFontStyle() {
  94. return $this->_styleFont;
  95. }
  96. /**
  97. * Get Paragraph style
  98. *
  99. * @return PHPWord_Style_Paragraph
  100. */
  101. public function getParagraphStyle() {
  102. return $this->_styleParagraph;
  103. }
  104. /**
  105. * Get Text content
  106. *
  107. * @return string
  108. */
  109. public function getText() {
  110. return $this->_text;
  111. }
  112. }
  113. ?>