PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/src/PhpWord/Style/Tab.php

https://github.com/navnorth/PHPWord
PHP | 173 lines | 71 code | 17 blank | 85 comment | 0 complexity | ecabfc8a39429d60a98d0a81c7311016 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  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\Style;
  18. /**
  19. * Tab style
  20. */
  21. class Tab extends AbstractStyle
  22. {
  23. /**
  24. * Tab stop types
  25. *
  26. * @const string
  27. */
  28. const TAB_STOP_CLEAR = 'clear';
  29. const TAB_STOP_LEFT = 'left';
  30. const TAB_STOP_CENTER = 'center';
  31. const TAB_STOP_RIGHT = 'right';
  32. const TAB_STOP_DECIMAL = 'decimal';
  33. const TAB_STOP_BAR = 'bar';
  34. const TAB_STOP_NUM = 'num';
  35. /**
  36. * Tab leader types
  37. *
  38. * @const string
  39. */
  40. const TAB_LEADER_NONE = 'none';
  41. const TAB_LEADER_DOT = 'dot';
  42. const TAB_LEADER_HYPHEN = 'hyphen';
  43. const TAB_LEADER_UNDERSCORE = 'underscore';
  44. const TAB_LEADER_HEAVY = 'heavy';
  45. const TAB_LEADER_MIDDLEDOT = 'middleDot';
  46. /**
  47. * Tab stop type
  48. *
  49. * @var string
  50. */
  51. private $type = self::TAB_STOP_CLEAR;
  52. /**
  53. * Tab leader character
  54. *
  55. * @var string
  56. */
  57. private $leader = self::TAB_LEADER_NONE;
  58. /**
  59. * Tab stop position (twip)
  60. *
  61. * @var int|float
  62. */
  63. private $position = 0;
  64. /**
  65. * Create a new instance of Tab. Both $type and $leader
  66. * must conform to the values put forth in the schema. If they do not
  67. * they will be changed to default values.
  68. *
  69. * @param string $type Defaults to 'clear' if value is not possible.
  70. * @param int $position Must be numeric; otherwise defaults to 0.
  71. * @param string $leader Defaults to null if value is not possible.
  72. */
  73. public function __construct($type = null, $position = 0, $leader = null)
  74. {
  75. $stopTypes = array(
  76. self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT,self::TAB_STOP_CENTER,
  77. self::TAB_STOP_RIGHT, self::TAB_STOP_DECIMAL, self::TAB_STOP_BAR, self::TAB_STOP_NUM
  78. );
  79. $leaderTypes = array(
  80. self::TAB_LEADER_NONE, self::TAB_LEADER_DOT, self::TAB_LEADER_HYPHEN,
  81. self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT
  82. );
  83. $this->type = $this->setEnumVal($type, $stopTypes, $this->type);
  84. $this->position = $this->setNumericVal($position, $this->position);
  85. $this->leader = $this->setEnumVal($leader, $leaderTypes, $this->leader);
  86. }
  87. /**
  88. * Get stop type
  89. *
  90. * @return string
  91. */
  92. public function getType()
  93. {
  94. return $this->type;
  95. }
  96. /**
  97. * Set stop type
  98. *
  99. * @param string $value
  100. * @return self
  101. */
  102. public function setType($value)
  103. {
  104. $enum = array(
  105. self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT, self::TAB_STOP_CENTER,
  106. self::TAB_STOP_RIGHT, self::TAB_STOP_DECIMAL, self::TAB_STOP_BAR,
  107. self::TAB_STOP_NUM,
  108. );
  109. $this->type = $this->setEnumVal($value, $enum, $this->type);
  110. return $this;
  111. }
  112. /**
  113. * Get leader
  114. *
  115. * @return string
  116. */
  117. public function getLeader()
  118. {
  119. return $this->leader;
  120. }
  121. /**
  122. * Set leader
  123. *
  124. * @param string $value
  125. * @return self
  126. */
  127. public function setLeader($value)
  128. {
  129. $enum = array(
  130. self::TAB_LEADER_NONE, self::TAB_LEADER_DOT, self::TAB_LEADER_HYPHEN,
  131. self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT,
  132. );
  133. $this->leader = $this->setEnumVal($value, $enum, $this->leader);
  134. return $this;
  135. }
  136. /**
  137. * Get position
  138. *
  139. * @return int|float
  140. */
  141. public function getPosition()
  142. {
  143. return $this->position;
  144. }
  145. /**
  146. * Set position
  147. *
  148. * @param int|float $value
  149. * @return self
  150. */
  151. public function setPosition($value)
  152. {
  153. $this->position = $this->setNumericVal($value, $this->position);
  154. return $this;
  155. }
  156. }