Açıklama Yok

Section.php 12KB

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