PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/src/PhpWord/Style/Section.php

https://github.com/cyrillkalita/PHPWord
PHP | 525 lines | 177 code | 63 blank | 285 comment | 3 complexity | 0314e31af9d403c21f8123281274fefc 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. * Section settings
  20. */
  21. class Section extends Border
  22. {
  23. /**
  24. * Page orientation
  25. *
  26. * @const string
  27. */
  28. const ORIENTATION_PORTRAIT = 'portrait';
  29. const ORIENTATION_LANDSCAPE = 'landscape';
  30. /**
  31. * Page default constants
  32. *
  33. * @const int|float
  34. */
  35. const DEFAULT_WIDTH = 11906; // In twip
  36. const DEFAULT_HEIGHT = 16838; // In twip
  37. const DEFAULT_MARGIN = 1440; // In twip
  38. const DEFAULT_GUTTER = 0; // In twip
  39. const DEFAULT_HEADER_HEIGHT = 720; // In twip
  40. const DEFAULT_FOOTER_HEIGHT = 720; // In twip
  41. const DEFAULT_COLUMN_COUNT = 1;
  42. const DEFAULT_COLUMN_SPACING = 720; // In twip
  43. /**
  44. * Page Orientation
  45. *
  46. * @var string
  47. * @link http://www.schemacentral.com/sc/ooxml/a-w_orient-1.html
  48. */
  49. private $orientation = self::ORIENTATION_PORTRAIT;
  50. /**
  51. * Page Size Width
  52. *
  53. * @var int|float
  54. */
  55. private $pageSizeW = self::DEFAULT_WIDTH;
  56. /**
  57. * Page Size Height
  58. *
  59. * @var int|float
  60. */
  61. private $pageSizeH = self::DEFAULT_HEIGHT;
  62. /**
  63. * Top margin spacing
  64. *
  65. * @var int|float
  66. */
  67. private $marginTop = self::DEFAULT_MARGIN;
  68. /**
  69. * Left margin spacing
  70. *
  71. * @var int|float
  72. */
  73. private $marginLeft = self::DEFAULT_MARGIN;
  74. /**
  75. * Right margin spacing
  76. *
  77. * @var int|float
  78. */
  79. private $marginRight = self::DEFAULT_MARGIN;
  80. /**
  81. * Bottom margin spacing
  82. *
  83. * @var int|float
  84. */
  85. private $marginBottom = self::DEFAULT_MARGIN;
  86. /**
  87. * Page gutter spacing
  88. *
  89. * @var int|float
  90. * @link http://www.schemacentral.com/sc/ooxml/e-w_pgMar-1.html
  91. */
  92. private $gutter = self::DEFAULT_GUTTER;
  93. /**
  94. * Header height
  95. *
  96. * @var int|float
  97. */
  98. private $headerHeight = self::DEFAULT_HEADER_HEIGHT;
  99. /**
  100. * Footer height
  101. *
  102. * @var int|float
  103. */
  104. private $footerHeight = self::DEFAULT_FOOTER_HEIGHT;
  105. /**
  106. * Page Numbering Start
  107. *
  108. * @var int
  109. */
  110. private $pageNumberingStart;
  111. /**
  112. * Section columns count
  113. *
  114. * @var int
  115. */
  116. private $colsNum = self::DEFAULT_COLUMN_COUNT;
  117. /**
  118. * Section spacing between columns
  119. *
  120. * @var int|float
  121. */
  122. private $colsSpace = self::DEFAULT_COLUMN_SPACING;
  123. /**
  124. * Section break type
  125. *
  126. * Options:
  127. * - nextPage: Next page section break
  128. * - nextColumn: Column section break
  129. * - continuous: Continuous section break
  130. * - evenPage: Even page section break
  131. * - oddPage: Odd page section break
  132. *
  133. * @var string
  134. */
  135. private $breakType;
  136. /**
  137. * Line numbering
  138. *
  139. * @var \PhpOffice\PhpWord\Style\LineNumbering
  140. * @link http://www.schemacentral.com/sc/ooxml/e-w_lnNumType-1.html
  141. */
  142. private $lineNumbering;
  143. /**
  144. * Set Setting Value
  145. *
  146. * @param string $key
  147. * @param string $value
  148. * @return self
  149. */
  150. public function setSettingValue($key, $value)
  151. {
  152. return $this->setStyleValue($key, $value);
  153. }
  154. /**
  155. * Set orientation
  156. *
  157. * @param string $value
  158. * @return self
  159. */
  160. public function setOrientation($value = null)
  161. {
  162. $enum = array(self::ORIENTATION_PORTRAIT, self::ORIENTATION_LANDSCAPE);
  163. $this->orientation = $this->setEnumVal($value, $enum, $this->orientation);
  164. /** @var int|float $longSide Type hint */
  165. $longSide = $this->pageSizeW >= $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH;
  166. /** @var int|float $shortSide Type hint */
  167. $shortSide = $this->pageSizeW < $this->pageSizeH ? $this->pageSizeW : $this->pageSizeH;
  168. if ($this->orientation == self::ORIENTATION_PORTRAIT) {
  169. $this->pageSizeW = $shortSide;
  170. $this->pageSizeH = $longSide;
  171. } else {
  172. $this->pageSizeW = $longSide;
  173. $this->pageSizeH = $shortSide;
  174. }
  175. return $this;
  176. }
  177. /**
  178. * Get Page Orientation
  179. *
  180. * @return string
  181. */
  182. public function getOrientation()
  183. {
  184. return $this->orientation;
  185. }
  186. /**
  187. * Set Portrait Orientation
  188. *
  189. * @return self
  190. */
  191. public function setPortrait()
  192. {
  193. return $this->setOrientation(self::ORIENTATION_PORTRAIT);
  194. }
  195. /**
  196. * Set Landscape Orientation
  197. *
  198. * @return self
  199. */
  200. public function setLandscape()
  201. {
  202. return $this->setOrientation(self::ORIENTATION_LANDSCAPE);
  203. }
  204. /**
  205. * Get Page Size Width
  206. *
  207. * @return int|float
  208. */
  209. public function getPageSizeW()
  210. {
  211. return $this->pageSizeW;
  212. }
  213. /**
  214. * Get Page Size Height
  215. *
  216. * @return int|float
  217. */
  218. public function getPageSizeH()
  219. {
  220. return $this->pageSizeH;
  221. }
  222. /**
  223. * Get Margin Top
  224. *
  225. * @return int|float
  226. */
  227. public function getMarginTop()
  228. {
  229. return $this->marginTop;
  230. }
  231. /**
  232. * Set Margin Top
  233. *
  234. * @param int|float $value
  235. * @return self
  236. */
  237. public function setMarginTop($value = null)
  238. {
  239. $this->marginTop = $this->setNumericVal($value, self::DEFAULT_MARGIN);
  240. return $this;
  241. }
  242. /**
  243. * Get Margin Left
  244. *
  245. * @return int|float
  246. */
  247. public function getMarginLeft()
  248. {
  249. return $this->marginLeft;
  250. }
  251. /**
  252. * Set Margin Left
  253. *
  254. * @param int|float $value
  255. * @return self
  256. */
  257. public function setMarginLeft($value = null)
  258. {
  259. $this->marginLeft = $this->setNumericVal($value, self::DEFAULT_MARGIN);
  260. return $this;
  261. }
  262. /**
  263. * Get Margin Right
  264. *
  265. * @return int|float
  266. */
  267. public function getMarginRight()
  268. {
  269. return $this->marginRight;
  270. }
  271. /**
  272. * Set Margin Right
  273. *
  274. * @param int|float $value
  275. * @return self
  276. */
  277. public function setMarginRight($value = null)
  278. {
  279. $this->marginRight = $this->setNumericVal($value, self::DEFAULT_MARGIN);
  280. return $this;
  281. }
  282. /**
  283. * Get Margin Bottom
  284. *
  285. * @return int|float
  286. */
  287. public function getMarginBottom()
  288. {
  289. return $this->marginBottom;
  290. }
  291. /**
  292. * Set Margin Bottom
  293. *
  294. * @param int|float $value
  295. * @return self
  296. */
  297. public function setMarginBottom($value = null)
  298. {
  299. $this->marginBottom = $this->setNumericVal($value, self::DEFAULT_MARGIN);
  300. return $this;
  301. }
  302. /**
  303. * Get gutter
  304. *
  305. * @return int|float
  306. */
  307. public function getGutter()
  308. {
  309. return $this->gutter;
  310. }
  311. /**
  312. * Set gutter
  313. *
  314. * @param int|float $value
  315. * @return self
  316. */
  317. public function setGutter($value = null)
  318. {
  319. $this->gutter = $this->setNumericVal($value, self::DEFAULT_GUTTER);
  320. return $this;
  321. }
  322. /**
  323. * Get Header Height
  324. *
  325. * @return int|float
  326. */
  327. public function getHeaderHeight()
  328. {
  329. return $this->headerHeight;
  330. }
  331. /**
  332. * Set Header Height
  333. *
  334. * @param int|float $value
  335. * @return self
  336. */
  337. public function setHeaderHeight($value = null)
  338. {
  339. $this->headerHeight = $this->setNumericVal($value, self::DEFAULT_HEADER_HEIGHT);
  340. return $this;
  341. }
  342. /**
  343. * Get Footer Height
  344. *
  345. * @return int|float
  346. */
  347. public function getFooterHeight()
  348. {
  349. return $this->footerHeight;
  350. }
  351. /**
  352. * Set Footer Height
  353. *
  354. * @param int|float $value
  355. * @return self
  356. */
  357. public function setFooterHeight($value = null)
  358. {
  359. $this->footerHeight = $this->setNumericVal($value, self::DEFAULT_FOOTER_HEIGHT);
  360. return $this;
  361. }
  362. /**
  363. * Get page numbering start
  364. *
  365. * @return null|int
  366. */
  367. public function getPageNumberingStart()
  368. {
  369. return $this->pageNumberingStart;
  370. }
  371. /**
  372. * Set page numbering start
  373. *
  374. * @param null|int $pageNumberingStart
  375. * @return self
  376. */
  377. public function setPageNumberingStart($pageNumberingStart = null)
  378. {
  379. $this->pageNumberingStart = $pageNumberingStart;
  380. return $this;
  381. }
  382. /**
  383. * Get Section Columns Count
  384. *
  385. * @return int
  386. */
  387. public function getColsNum()
  388. {
  389. return $this->colsNum;
  390. }
  391. /**
  392. * Set Section Columns Count
  393. *
  394. * @param int $value
  395. * @return self
  396. */
  397. public function setColsNum($value = null)
  398. {
  399. $this->colsNum = $this->setIntVal($value, self::DEFAULT_COLUMN_COUNT);
  400. return $this;
  401. }
  402. /**
  403. * Get Section Space Between Columns
  404. *
  405. * @return int|float
  406. */
  407. public function getColsSpace()
  408. {
  409. return $this->colsSpace;
  410. }
  411. /**
  412. * Set Section Space Between Columns
  413. *
  414. * @param int|float $value
  415. * @return self
  416. */
  417. public function setColsSpace($value = null)
  418. {
  419. $this->colsSpace = $this->setNumericVal($value, self::DEFAULT_COLUMN_SPACING);
  420. return $this;
  421. }
  422. /**
  423. * Get Break Type
  424. *
  425. * @return string
  426. */
  427. public function getBreakType()
  428. {
  429. return $this->breakType;
  430. }
  431. /**
  432. * Set Break Type
  433. *
  434. * @param string $value
  435. * @return self
  436. */
  437. public function setBreakType($value = null)
  438. {
  439. $this->breakType = $value;
  440. return $this;
  441. }
  442. /**
  443. * Get line numbering
  444. *
  445. * @return \PhpOffice\PhpWord\Style\LineNumbering
  446. */
  447. public function getLineNumbering()
  448. {
  449. return $this->lineNumbering;
  450. }
  451. /**
  452. * Set line numbering
  453. *
  454. * @param mixed $value
  455. * @return self
  456. */
  457. public function setLineNumbering($value = null)
  458. {
  459. $this->setObjectVal($value, 'LineNumbering', $this->lineNumbering);
  460. return $this;
  461. }
  462. }