TextBreak.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * @see https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2018 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Element;
  18. use PhpOffice\PhpWord\Style\Font;
  19. use PhpOffice\PhpWord\Style\Paragraph;
  20. /**
  21. * Text break element
  22. */
  23. class TextBreak extends AbstractElement
  24. {
  25. /**
  26. * Paragraph style
  27. *
  28. * @var string|\PhpOffice\PhpWord\Style\Paragraph
  29. */
  30. private $paragraphStyle = null;
  31. /**
  32. * Text style
  33. *
  34. * @var string|\PhpOffice\PhpWord\Style\Font
  35. */
  36. private $fontStyle = null;
  37. /**
  38. * Create a new TextBreak Element
  39. *
  40. * @param mixed $fontStyle
  41. * @param mixed $paragraphStyle
  42. */
  43. public function __construct($fontStyle = null, $paragraphStyle = null)
  44. {
  45. if (!is_null($paragraphStyle)) {
  46. $paragraphStyle = $this->setParagraphStyle($paragraphStyle);
  47. }
  48. if (!is_null($fontStyle)) {
  49. $this->setFontStyle($fontStyle, $paragraphStyle);
  50. }
  51. }
  52. /**
  53. * Set Text style
  54. *
  55. * @param mixed $style
  56. * @param mixed $paragraphStyle
  57. * @return string|\PhpOffice\PhpWord\Style\Font
  58. */
  59. public function setFontStyle($style = null, $paragraphStyle = null)
  60. {
  61. if ($style instanceof Font) {
  62. $this->fontStyle = $style;
  63. $this->setParagraphStyle($paragraphStyle);
  64. } elseif (is_array($style)) {
  65. $this->fontStyle = new Font('text', $paragraphStyle);
  66. $this->fontStyle->setStyleByArray($style);
  67. } else {
  68. $this->fontStyle = $style;
  69. $this->setParagraphStyle($paragraphStyle);
  70. }
  71. return $this->fontStyle;
  72. }
  73. /**
  74. * Get Text style
  75. *
  76. * @return string|\PhpOffice\PhpWord\Style\Font
  77. */
  78. public function getFontStyle()
  79. {
  80. return $this->fontStyle;
  81. }
  82. /**
  83. * Set Paragraph style
  84. *
  85. * @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style
  86. * @return string|\PhpOffice\PhpWord\Style\Paragraph
  87. */
  88. public function setParagraphStyle($style = null)
  89. {
  90. if (is_array($style)) {
  91. $this->paragraphStyle = new Paragraph();
  92. $this->paragraphStyle->setStyleByArray($style);
  93. } elseif ($style instanceof Paragraph) {
  94. $this->paragraphStyle = $style;
  95. } else {
  96. $this->paragraphStyle = $style;
  97. }
  98. return $this->paragraphStyle;
  99. }
  100. /**
  101. * Get Paragraph style
  102. *
  103. * @return string|\PhpOffice\PhpWord\Style\Paragraph
  104. */
  105. public function getParagraphStyle()
  106. {
  107. return $this->paragraphStyle;
  108. }
  109. /**
  110. * Has font/paragraph style defined
  111. *
  112. * @return bool
  113. */
  114. public function hasStyle()
  115. {
  116. return !is_null($this->fontStyle) || !is_null($this->paragraphStyle);
  117. }
  118. }