TablePosition.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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\Style;
  18. /**
  19. * TablePosition style
  20. *
  21. * @see http://www.datypic.com/sc/ooxml/e-w_tblpPr-1.html
  22. */
  23. class TablePosition extends AbstractStyle
  24. {
  25. /**
  26. * Vertical anchor constants
  27. *
  28. * @const string
  29. * @see http://www.datypic.com/sc/ooxml/t-w_ST_VAnchor.html
  30. */
  31. const VANCHOR_TEXT = 'text'; // Relative to vertical text extents
  32. const VANCHOR_MARGIN = 'margin'; // Relative to margin
  33. const VANCHOR_PAGE = 'page'; // Relative to page
  34. /**
  35. * Horizontal anchor constants
  36. *
  37. * @const string
  38. * @see http://www.datypic.com/sc/ooxml/t-w_ST_HAnchor.html
  39. */
  40. const HANCHOR_TEXT = 'text'; // Relative to text extents
  41. const HANCHOR_MARGIN = 'margin'; // Relative to margin
  42. const HANCHOR_PAGE = 'page'; // Relative to page
  43. /**
  44. * Horizontal alignment constants
  45. *
  46. * @const string
  47. * @see http://www.datypic.com/sc/ooxml/t-w_ST_XAlign.html
  48. */
  49. const XALIGN_LEFT = 'left'; // Left aligned horizontally
  50. const XALIGN_CENTER = 'center'; // Centered horizontally
  51. const XALIGN_RIGHT = 'right'; // Right aligned horizontally
  52. const XALIGN_INSIDE = 'inside'; // Inside
  53. const XALIGN_OUTSIDE = 'outside'; // Outside
  54. /**
  55. * Vertical alignment constants
  56. *
  57. * @const string
  58. * @see http://www.datypic.com/sc/ooxml/t-w_ST_YAlign.html
  59. */
  60. const YALIGN_INLINE = 'inline'; // In line with text
  61. const YALIGN_TOP = 'top'; // Top
  62. const YALIGN_CENTER = 'center'; // Centered vertically
  63. const YALIGN_BOTTOM = 'bottom'; // Bottom
  64. const YALIGN_INSIDE = 'inside'; // Inside Anchor Extents
  65. const YALIGN_OUTSIDE = 'outside'; // Centered vertically
  66. /**
  67. * Distance from left of table to text
  68. *
  69. * @var int
  70. */
  71. private $leftFromText;
  72. /**
  73. * Distance from right of table to text
  74. *
  75. * @var int
  76. */
  77. private $rightFromText;
  78. /**
  79. * Distance from top of table to text
  80. *
  81. * @var int
  82. */
  83. private $topFromText;
  84. /**
  85. * Distance from bottom of table to text
  86. *
  87. * @var int
  88. */
  89. private $bottomFromText;
  90. /**
  91. * Table vertical anchor
  92. *
  93. * @var string
  94. * @see http://www.datypic.com/sc/ooxml/t-w_ST_VAnchor.html
  95. */
  96. private $vertAnchor;
  97. /**
  98. * Table horizontal anchor
  99. *
  100. * @var string
  101. * @see http://www.datypic.com/sc/ooxml/t-w_ST_HAnchor.html
  102. */
  103. private $horzAnchor;
  104. /**
  105. * Relative horizontal alignment from anchor
  106. *
  107. * @var string
  108. * @see http://www.datypic.com/sc/ooxml/t-w_ST_XAlign.html
  109. */
  110. private $tblpXSpec;
  111. /**
  112. * Absolute horizontal distance from anchor
  113. *
  114. * @var int
  115. */
  116. private $tblpX;
  117. /**
  118. * Relative vertical alignment from anchor
  119. *
  120. * @var string
  121. * @see http://www.datypic.com/sc/ooxml/t-w_ST_YAlign.html
  122. */
  123. private $tblpYSpec;
  124. /**
  125. * Absolute vertical distance from anchor
  126. *
  127. * @var int
  128. */
  129. private $tblpY;
  130. /**
  131. * Create a new instance
  132. *
  133. * @param array $style
  134. */
  135. public function __construct($style = array())
  136. {
  137. $this->setStyleByArray($style);
  138. }
  139. /**
  140. * Get distance from left of table to text
  141. *
  142. * @return int
  143. */
  144. public function getLeftFromText()
  145. {
  146. return $this->leftFromText;
  147. }
  148. /**
  149. * Set distance from left of table to text
  150. *
  151. * @param int $value
  152. * @return self
  153. */
  154. public function setLeftFromText($value = null)
  155. {
  156. $this->leftFromText = $this->setNumericVal($value, $this->leftFromText);
  157. return $this;
  158. }
  159. /**
  160. * Get distance from right of table to text
  161. *
  162. * @return int
  163. */
  164. public function getRightFromText()
  165. {
  166. return $this->rightFromText;
  167. }
  168. /**
  169. * Set distance from right of table to text
  170. *
  171. * @param int $value
  172. * @return self
  173. */
  174. public function setRightFromText($value = null)
  175. {
  176. $this->rightFromText = $this->setNumericVal($value, $this->rightFromText);
  177. return $this;
  178. }
  179. /**
  180. * Get distance from top of table to text
  181. *
  182. * @return int
  183. */
  184. public function getTopFromText()
  185. {
  186. return $this->topFromText;
  187. }
  188. /**
  189. * Set distance from top of table to text
  190. *
  191. * @param int $value
  192. * @return self
  193. */
  194. public function setTopFromText($value = null)
  195. {
  196. $this->topFromText = $this->setNumericVal($value, $this->topFromText);
  197. return $this;
  198. }
  199. /**
  200. * Get distance from bottom of table to text
  201. *
  202. * @return int
  203. */
  204. public function getBottomFromText()
  205. {
  206. return $this->bottomFromText;
  207. }
  208. /**
  209. * Set distance from bottom of table to text
  210. *
  211. * @param int $value
  212. * @return self
  213. */
  214. public function setBottomFromText($value = null)
  215. {
  216. $this->bottomFromText = $this->setNumericVal($value, $this->bottomFromText);
  217. return $this;
  218. }
  219. /**
  220. * Get table vertical anchor
  221. *
  222. * @return string
  223. */
  224. public function getVertAnchor()
  225. {
  226. return $this->vertAnchor;
  227. }
  228. /**
  229. * Set table vertical anchor
  230. *
  231. * @param string $value
  232. * @return self
  233. */
  234. public function setVertAnchor($value = null)
  235. {
  236. $enum = array(
  237. self::VANCHOR_TEXT,
  238. self::VANCHOR_MARGIN,
  239. self::VANCHOR_PAGE,
  240. );
  241. $this->vertAnchor = $this->setEnumVal($value, $enum, $this->vertAnchor);
  242. return $this;
  243. }
  244. /**
  245. * Get table horizontal anchor
  246. *
  247. * @return string
  248. */
  249. public function getHorzAnchor()
  250. {
  251. return $this->horzAnchor;
  252. }
  253. /**
  254. * Set table horizontal anchor
  255. *
  256. * @param string $value
  257. * @return self
  258. */
  259. public function setHorzAnchor($value = null)
  260. {
  261. $enum = array(
  262. self::HANCHOR_TEXT,
  263. self::HANCHOR_MARGIN,
  264. self::HANCHOR_PAGE,
  265. );
  266. $this->horzAnchor = $this->setEnumVal($value, $enum, $this->horzAnchor);
  267. return $this;
  268. }
  269. /**
  270. * Get relative horizontal alignment from anchor
  271. *
  272. * @return string
  273. */
  274. public function getTblpXSpec()
  275. {
  276. return $this->tblpXSpec;
  277. }
  278. /**
  279. * Set relative horizontal alignment from anchor
  280. *
  281. * @param string $value
  282. * @return self
  283. */
  284. public function setTblpXSpec($value = null)
  285. {
  286. $enum = array(
  287. self::XALIGN_LEFT,
  288. self::XALIGN_CENTER,
  289. self::XALIGN_RIGHT,
  290. self::XALIGN_INSIDE,
  291. self::XALIGN_OUTSIDE,
  292. );
  293. $this->tblpXSpec = $this->setEnumVal($value, $enum, $this->tblpXSpec);
  294. return $this;
  295. }
  296. /**
  297. * Get absolute horizontal distance from anchor
  298. *
  299. * @return int
  300. */
  301. public function getTblpX()
  302. {
  303. return $this->tblpX;
  304. }
  305. /**
  306. * Set absolute horizontal distance from anchor
  307. *
  308. * @param int $value
  309. * @return self
  310. */
  311. public function setTblpX($value = null)
  312. {
  313. $this->tblpX = $this->setNumericVal($value, $this->tblpX);
  314. return $this;
  315. }
  316. /**
  317. * Get relative vertical alignment from anchor
  318. *
  319. * @return string
  320. */
  321. public function getTblpYSpec()
  322. {
  323. return $this->tblpYSpec;
  324. }
  325. /**
  326. * Set relative vertical alignment from anchor
  327. *
  328. * @param string $value
  329. * @return self
  330. */
  331. public function setTblpYSpec($value = null)
  332. {
  333. $enum = array(
  334. self::YALIGN_INLINE,
  335. self::YALIGN_TOP,
  336. self::YALIGN_CENTER,
  337. self::YALIGN_BOTTOM,
  338. self::YALIGN_INSIDE,
  339. self::YALIGN_OUTSIDE,
  340. );
  341. $this->tblpYSpec = $this->setEnumVal($value, $enum, $this->tblpYSpec);
  342. return $this;
  343. }
  344. /**
  345. * Get absolute vertical distance from anchor
  346. *
  347. * @return int
  348. */
  349. public function getTblpY()
  350. {
  351. return $this->tblpY;
  352. }
  353. /**
  354. * Set absolute vertical distance from anchor
  355. *
  356. * @param int $value
  357. * @return self
  358. */
  359. public function setTblpY($value = null)
  360. {
  361. $this->tblpY = $this->setNumericVal($value, $this->tblpY);
  362. return $this;
  363. }
  364. }