No Description

Title.php 2.0KB

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;
  20. /**
  21. * Title element
  22. */
  23. class Title extends AbstractElement
  24. {
  25. /**
  26. * Title Text content
  27. *
  28. * @var string
  29. */
  30. private $text;
  31. /**
  32. * Title depth
  33. *
  34. * @var int
  35. */
  36. private $depth = 1;
  37. /**
  38. * Name of the heading style, e.g. 'Heading1'
  39. *
  40. * @var string
  41. */
  42. private $style;
  43. /**
  44. * Is part of collection
  45. *
  46. * @var bool
  47. */
  48. protected $collectionRelation = true;
  49. /**
  50. * Create a new Title Element
  51. *
  52. * @param string $text
  53. * @param int $depth
  54. */
  55. public function __construct($text, $depth = 1)
  56. {
  57. $this->text = String::toUTF8($text);
  58. $this->depth = $depth;
  59. if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) {
  60. $this->style = "Heading{$this->depth}";
  61. }
  62. return $this;
  63. }
  64. /**
  65. * Get Title Text content
  66. *
  67. * @return string
  68. */
  69. public function getText()
  70. {
  71. return $this->text;
  72. }
  73. /**
  74. * Get depth
  75. *
  76. * @return integer
  77. */
  78. public function getDepth()
  79. {
  80. return $this->depth;
  81. }
  82. /**
  83. * Get Title style
  84. *
  85. * @return string
  86. */
  87. public function getStyle()
  88. {
  89. return $this->style;
  90. }
  91. }