Frame.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. use PhpOffice\PhpWord\SimpleType\Jc;
  19. /**
  20. * Frame defines the size and position of an object
  21. *
  22. * Width, height, left/hpos, top/vpos, hrel, vrel, wrap, zindex
  23. *
  24. * @since 0.12.0
  25. * @todo Make existing style (image, textbox, etc) use this style
  26. */
  27. class Frame extends AbstractStyle
  28. {
  29. /**
  30. * Length unit
  31. *
  32. * @const string
  33. */
  34. const UNIT_PT = 'pt'; // Mostly for shapes
  35. const UNIT_PX = 'px'; // Mostly for images
  36. /**
  37. * General positioning options.
  38. *
  39. * @const string
  40. */
  41. const POS_ABSOLUTE = 'absolute';
  42. const POS_RELATIVE = 'relative';
  43. /**
  44. * Horizontal/vertical value
  45. *
  46. * @const string
  47. */
  48. const POS_CENTER = 'center';
  49. const POS_LEFT = 'left';
  50. const POS_RIGHT = 'right';
  51. const POS_TOP = 'top';
  52. const POS_BOTTOM = 'bottom';
  53. const POS_INSIDE = 'inside';
  54. const POS_OUTSIDE = 'outside';
  55. /**
  56. * Position relative to
  57. *
  58. * @const string
  59. */
  60. const POS_RELTO_MARGIN = 'margin';
  61. const POS_RELTO_PAGE = 'page';
  62. const POS_RELTO_COLUMN = 'column'; // horizontal only
  63. const POS_RELTO_CHAR = 'char'; // horizontal only
  64. const POS_RELTO_TEXT = 'text'; // vertical only
  65. const POS_RELTO_LINE = 'line'; // vertical only
  66. const POS_RELTO_LMARGIN = 'left-margin-area'; // horizontal only
  67. const POS_RELTO_RMARGIN = 'right-margin-area'; // horizontal only
  68. const POS_RELTO_TMARGIN = 'top-margin-area'; // vertical only
  69. const POS_RELTO_BMARGIN = 'bottom-margin-area'; // vertical only
  70. const POS_RELTO_IMARGIN = 'inner-margin-area';
  71. const POS_RELTO_OMARGIN = 'outer-margin-area';
  72. /**
  73. * Wrap type
  74. *
  75. * @const string
  76. */
  77. const WRAP_INLINE = 'inline';
  78. const WRAP_SQUARE = 'square';
  79. const WRAP_TIGHT = 'tight';
  80. const WRAP_THROUGH = 'through';
  81. const WRAP_TOPBOTTOM = 'topAndBottom';
  82. const WRAP_BEHIND = 'behind';
  83. const WRAP_INFRONT = 'infront';
  84. /**
  85. * @var string
  86. */
  87. private $alignment = '';
  88. /**
  89. * Unit
  90. *
  91. * @var string
  92. */
  93. private $unit = 'pt';
  94. /**
  95. * Width
  96. *
  97. * @var int|float
  98. */
  99. private $width;
  100. /**
  101. * Height
  102. *
  103. * @var int|float
  104. */
  105. private $height;
  106. /**
  107. * Leftmost (horizontal) position
  108. *
  109. * @var int|float
  110. */
  111. private $left = 0;
  112. /**
  113. * Topmost (vertical) position
  114. *
  115. * @var int|float
  116. */
  117. private $top = 0;
  118. /**
  119. * Position type: absolute|relative
  120. *
  121. * @var string
  122. */
  123. private $pos;
  124. /**
  125. * Horizontal position
  126. *
  127. * @var string
  128. */
  129. private $hPos;
  130. /**
  131. * Horizontal position relative to
  132. *
  133. * @var string
  134. */
  135. private $hPosRelTo;
  136. /**
  137. * Vertical position
  138. *
  139. * @var string
  140. */
  141. private $vPos;
  142. /**
  143. * Vertical position relative to
  144. *
  145. * @var string
  146. */
  147. private $vPosRelTo;
  148. /**
  149. * Wrap type
  150. *
  151. * @var string
  152. */
  153. private $wrap;
  154. /**
  155. * Top wrap distance
  156. *
  157. * @var float
  158. */
  159. private $wrapDistanceTop;
  160. /**
  161. * Bottom wrap distance
  162. *
  163. * @var float
  164. */
  165. private $wrapDistanceBottom;
  166. /**
  167. * Left wrap distance
  168. *
  169. * @var float
  170. */
  171. private $wrapDistanceLeft;
  172. /**
  173. * Right wrap distance
  174. *
  175. * @var float
  176. */
  177. private $wrapDistanceRight;
  178. /**
  179. * Vertically raised or lowered text
  180. *
  181. * @var int
  182. * @see http://www.datypic.com/sc/ooxml/e-w_position-1.html
  183. */
  184. private $position;
  185. /**
  186. * Create a new instance
  187. *
  188. * @param array $style
  189. */
  190. public function __construct($style = array())
  191. {
  192. $this->setStyleByArray($style);
  193. }
  194. /**
  195. * @since 0.13.0
  196. *
  197. * @return string
  198. */
  199. public function getAlignment()
  200. {
  201. return $this->alignment;
  202. }
  203. /**
  204. * @since 0.13.0
  205. *
  206. * @param string $value
  207. *
  208. * @return self
  209. */
  210. public function setAlignment($value)
  211. {
  212. if (Jc::isValid($value)) {
  213. $this->alignment = $value;
  214. }
  215. return $this;
  216. }
  217. /**
  218. * @deprecated 0.13.0 Use the `getAlignment` method instead.
  219. *
  220. * @return string
  221. *
  222. * @codeCoverageIgnore
  223. */
  224. public function getAlign()
  225. {
  226. return $this->getAlignment();
  227. }
  228. /**
  229. * @deprecated 0.13.0 Use the `setAlignment` method instead.
  230. *
  231. * @param string $value
  232. *
  233. * @return self
  234. *
  235. * @codeCoverageIgnore
  236. */
  237. public function setAlign($value = null)
  238. {
  239. return $this->setAlignment($value);
  240. }
  241. /**
  242. * Get unit
  243. *
  244. * @return string
  245. */
  246. public function getUnit()
  247. {
  248. return $this->unit;
  249. }
  250. /**
  251. * Set unit
  252. *
  253. * @param string $value
  254. * @return self
  255. */
  256. public function setUnit($value)
  257. {
  258. $this->unit = $value;
  259. return $this;
  260. }
  261. /**
  262. * Get width
  263. *
  264. * @return int|float
  265. */
  266. public function getWidth()
  267. {
  268. return $this->width;
  269. }
  270. /**
  271. * Set width
  272. *
  273. * @param int|float $value
  274. * @return self
  275. */
  276. public function setWidth($value = null)
  277. {
  278. $this->width = $this->setNumericVal($value, null);
  279. return $this;
  280. }
  281. /**
  282. * Get height
  283. *
  284. * @return int|float
  285. */
  286. public function getHeight()
  287. {
  288. return $this->height;
  289. }
  290. /**
  291. * Set height
  292. *
  293. * @param int|float $value
  294. * @return self
  295. */
  296. public function setHeight($value = null)
  297. {
  298. $this->height = $this->setNumericVal($value, null);
  299. return $this;
  300. }
  301. /**
  302. * Get left
  303. *
  304. * @return int|float
  305. */
  306. public function getLeft()
  307. {
  308. return $this->left;
  309. }
  310. /**
  311. * Set left
  312. *
  313. * @param int|float $value
  314. * @return self
  315. */
  316. public function setLeft($value = 0)
  317. {
  318. $this->left = $this->setNumericVal($value, 0);
  319. return $this;
  320. }
  321. /**
  322. * Get topmost position
  323. *
  324. * @return int|float
  325. */
  326. public function getTop()
  327. {
  328. return $this->top;
  329. }
  330. /**
  331. * Set topmost position
  332. *
  333. * @param int|float $value
  334. * @return self
  335. */
  336. public function setTop($value = 0)
  337. {
  338. $this->top = $this->setNumericVal($value, 0);
  339. return $this;
  340. }
  341. /**
  342. * Get position type
  343. *
  344. * @return string
  345. */
  346. public function getPos()
  347. {
  348. return $this->pos;
  349. }
  350. /**
  351. * Set position type
  352. *
  353. * @param string $value
  354. * @return self
  355. */
  356. public function setPos($value)
  357. {
  358. $enum = array(
  359. self::POS_ABSOLUTE,
  360. self::POS_RELATIVE,
  361. );
  362. $this->pos = $this->setEnumVal($value, $enum, $this->pos);
  363. return $this;
  364. }
  365. /**
  366. * Get horizontal position
  367. *
  368. * @return string
  369. */
  370. public function getHPos()
  371. {
  372. return $this->hPos;
  373. }
  374. /**
  375. * Set horizontal position
  376. *
  377. * @since 0.12.0 "absolute" option is available.
  378. *
  379. * @param string $value
  380. * @return self
  381. */
  382. public function setHPos($value)
  383. {
  384. $enum = array(
  385. self::POS_ABSOLUTE,
  386. self::POS_LEFT,
  387. self::POS_CENTER,
  388. self::POS_RIGHT,
  389. self::POS_INSIDE,
  390. self::POS_OUTSIDE,
  391. );
  392. $this->hPos = $this->setEnumVal($value, $enum, $this->hPos);
  393. return $this;
  394. }
  395. /**
  396. * Get vertical position
  397. *
  398. * @return string
  399. */
  400. public function getVPos()
  401. {
  402. return $this->vPos;
  403. }
  404. /**
  405. * Set vertical position
  406. *
  407. * @since 0.12.0 "absolute" option is available.
  408. *
  409. * @param string $value
  410. * @return self
  411. */
  412. public function setVPos($value)
  413. {
  414. $enum = array(
  415. self::POS_ABSOLUTE,
  416. self::POS_TOP,
  417. self::POS_CENTER,
  418. self::POS_BOTTOM,
  419. self::POS_INSIDE,
  420. self::POS_OUTSIDE,
  421. );
  422. $this->vPos = $this->setEnumVal($value, $enum, $this->vPos);
  423. return $this;
  424. }
  425. /**
  426. * Get horizontal position relative to
  427. *
  428. * @return string
  429. */
  430. public function getHPosRelTo()
  431. {
  432. return $this->hPosRelTo;
  433. }
  434. /**
  435. * Set horizontal position relative to
  436. *
  437. * @param string $value
  438. * @return self
  439. */
  440. public function setHPosRelTo($value)
  441. {
  442. $enum = array(
  443. self::POS_RELTO_MARGIN,
  444. self::POS_RELTO_PAGE,
  445. self::POS_RELTO_COLUMN,
  446. self::POS_RELTO_CHAR,
  447. self::POS_RELTO_LMARGIN,
  448. self::POS_RELTO_RMARGIN,
  449. self::POS_RELTO_IMARGIN,
  450. self::POS_RELTO_OMARGIN,
  451. );
  452. $this->hPosRelTo = $this->setEnumVal($value, $enum, $this->hPosRelTo);
  453. return $this;
  454. }
  455. /**
  456. * Get vertical position relative to
  457. *
  458. * @return string
  459. */
  460. public function getVPosRelTo()
  461. {
  462. return $this->vPosRelTo;
  463. }
  464. /**
  465. * Set vertical position relative to
  466. *
  467. * @param string $value
  468. * @return self
  469. */
  470. public function setVPosRelTo($value)
  471. {
  472. $enum = array(
  473. self::POS_RELTO_MARGIN,
  474. self::POS_RELTO_PAGE,
  475. self::POS_RELTO_TEXT,
  476. self::POS_RELTO_LINE,
  477. self::POS_RELTO_TMARGIN,
  478. self::POS_RELTO_BMARGIN,
  479. self::POS_RELTO_IMARGIN,
  480. self::POS_RELTO_OMARGIN,
  481. );
  482. $this->vPosRelTo = $this->setEnumVal($value, $enum, $this->vPosRelTo);
  483. return $this;
  484. }
  485. /**
  486. * Get wrap type
  487. *
  488. * @return string
  489. */
  490. public function getWrap()
  491. {
  492. return $this->wrap;
  493. }
  494. /**
  495. * Set wrap type
  496. *
  497. * @param string $value
  498. * @return self
  499. */
  500. public function setWrap($value)
  501. {
  502. $enum = array(
  503. self::WRAP_INLINE,
  504. self::WRAP_SQUARE,
  505. self::WRAP_TIGHT,
  506. self::WRAP_THROUGH,
  507. self::WRAP_TOPBOTTOM,
  508. self::WRAP_BEHIND,
  509. self::WRAP_INFRONT,
  510. );
  511. $this->wrap = $this->setEnumVal($value, $enum, $this->wrap);
  512. return $this;
  513. }
  514. /**
  515. * Get top distance from text wrap
  516. *
  517. * @return float
  518. */
  519. public function getWrapDistanceTop()
  520. {
  521. return $this->wrapDistanceTop;
  522. }
  523. /**
  524. * Set top distance from text wrap
  525. *
  526. * @param int $value
  527. * @return self
  528. */
  529. public function setWrapDistanceTop($value = null)
  530. {
  531. $this->wrapDistanceTop = $this->setFloatVal($value, null);
  532. return $this;
  533. }
  534. /**
  535. * Get bottom distance from text wrap
  536. *
  537. * @return float
  538. */
  539. public function getWrapDistanceBottom()
  540. {
  541. return $this->wrapDistanceBottom;
  542. }
  543. /**
  544. * Set bottom distance from text wrap
  545. *
  546. * @param float $value
  547. * @return self
  548. */
  549. public function setWrapDistanceBottom($value = null)
  550. {
  551. $this->wrapDistanceBottom = $this->setFloatVal($value, null);
  552. return $this;
  553. }
  554. /**
  555. * Get left distance from text wrap
  556. *
  557. * @return float
  558. */
  559. public function getWrapDistanceLeft()
  560. {
  561. return $this->wrapDistanceLeft;
  562. }
  563. /**
  564. * Set left distance from text wrap
  565. *
  566. * @param float $value
  567. * @return self
  568. */
  569. public function setWrapDistanceLeft($value = null)
  570. {
  571. $this->wrapDistanceLeft = $this->setFloatVal($value, null);
  572. return $this;
  573. }
  574. /**
  575. * Get right distance from text wrap
  576. *
  577. * @return float
  578. */
  579. public function getWrapDistanceRight()
  580. {
  581. return $this->wrapDistanceRight;
  582. }
  583. /**
  584. * Set right distance from text wrap
  585. *
  586. * @param float $value
  587. * @return self
  588. */
  589. public function setWrapDistanceRight($value = null)
  590. {
  591. $this->wrapDistanceRight = $this->setFloatVal($value, null);
  592. return $this;
  593. }
  594. /**
  595. * Get position
  596. *
  597. * @return int
  598. */
  599. public function getPosition()
  600. {
  601. return $this->position;
  602. }
  603. /**
  604. * Set position
  605. *
  606. * @param int $value
  607. * @return self
  608. */
  609. public function setPosition($value = null)
  610. {
  611. $this->position = $this->setIntVal($value, null);
  612. return $this;
  613. }
  614. }