Açıklama Yok

Frame.php 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. * Frame defines the size and position of an object
  20. *
  21. * Width, height, left/hpos, top/vpos, hrel, vrel, wrap, zindex
  22. *
  23. * @since 0.12.0
  24. * @todo Make existing style (image, textbox, etc) use this style
  25. */
  26. class Frame extends AbstractStyle
  27. {
  28. /**
  29. * Length unit
  30. *
  31. * @const string
  32. */
  33. const UNIT_PT = 'pt'; // Mostly for shapes
  34. const UNIT_PX = 'px'; // Mostly for images
  35. /**
  36. * General positioning options.
  37. *
  38. * @const string
  39. */
  40. const POS_ABSOLUTE = 'absolute';
  41. const POS_RELATIVE = 'relative';
  42. /**
  43. * Horizontal/vertical value
  44. *
  45. * @const string
  46. */
  47. const POS_CENTER = 'center';
  48. const POS_LEFT = 'left';
  49. const POS_RIGHT = 'right';
  50. const POS_TOP = 'top';
  51. const POS_BOTTOM = 'bottom';
  52. const POS_INSIDE = 'inside';
  53. const POS_OUTSIDE = 'outside';
  54. /**
  55. * Position relative to
  56. *
  57. * @const string
  58. */
  59. const POS_RELTO_MARGIN = 'margin';
  60. const POS_RELTO_PAGE = 'page';
  61. const POS_RELTO_COLUMN = 'column'; // horizontal only
  62. const POS_RELTO_CHAR = 'char'; // horizontal only
  63. const POS_RELTO_TEXT = 'text'; // vertical only
  64. const POS_RELTO_LINE = 'line'; // vertical only
  65. const POS_RELTO_LMARGIN = 'left-margin-area'; // horizontal only
  66. const POS_RELTO_RMARGIN = 'right-margin-area'; // horizontal only
  67. const POS_RELTO_TMARGIN = 'top-margin-area'; // vertical only
  68. const POS_RELTO_BMARGIN = 'bottom-margin-area'; // vertical only
  69. const POS_RELTO_IMARGIN = 'inner-margin-area';
  70. const POS_RELTO_OMARGIN = 'outer-margin-area';
  71. /**
  72. * Wrap type
  73. *
  74. * @const string
  75. */
  76. const WRAP_INLINE = 'inline';
  77. const WRAP_SQUARE = 'square';
  78. const WRAP_TIGHT = 'tight';
  79. const WRAP_THROUGH = 'through';
  80. const WRAP_TOPBOTTOM = 'topAndBottom';
  81. const WRAP_BEHIND = 'behind';
  82. const WRAP_INFRONT = 'infront';
  83. /**
  84. * Alignment
  85. *
  86. * @var \PhpOffice\PhpWord\Style\Alignment
  87. */
  88. private $alignment;
  89. /**
  90. * Unit
  91. *
  92. * @var string
  93. */
  94. private $unit = 'pt';
  95. /**
  96. * Width
  97. *
  98. * @var int|float
  99. */
  100. private $width;
  101. /**
  102. * Height
  103. *
  104. * @var int|float
  105. */
  106. private $height;
  107. /**
  108. * Leftmost (horizontal) position
  109. *
  110. * @var int|float
  111. */
  112. private $left = 0;
  113. /**
  114. * Topmost (vertical) position
  115. *
  116. * @var int|float
  117. */
  118. private $top = 0;
  119. /**
  120. * Position type: absolute|relative
  121. *
  122. * @var string
  123. */
  124. private $pos;
  125. /**
  126. * Horizontal position
  127. *
  128. * @var string
  129. */
  130. private $hPos;
  131. /**
  132. * Horizontal position relative to
  133. *
  134. * @var string
  135. */
  136. private $hPosRelTo;
  137. /**
  138. * Vertical position
  139. *
  140. * @var string
  141. */
  142. private $vPos;
  143. /**
  144. * Vertical position relative to
  145. *
  146. * @var string
  147. */
  148. private $vPosRelTo;
  149. /**
  150. * Wrap type
  151. *
  152. * @var string
  153. */
  154. private $wrap;
  155. /**
  156. * Create a new instance
  157. *
  158. * @param array $style
  159. */
  160. public function __construct($style = array())
  161. {
  162. $this->alignment = new Alignment();
  163. $this->setStyleByArray($style);
  164. }
  165. /**
  166. * Get alignment
  167. *
  168. * @return string
  169. */
  170. public function getAlign()
  171. {
  172. return $this->alignment->getValue();
  173. }
  174. /**
  175. * Set alignment
  176. *
  177. * @param string $value
  178. * @return self
  179. */
  180. public function setAlign($value = null)
  181. {
  182. $this->alignment->setValue($value);
  183. return $this;
  184. }
  185. /**
  186. * Get unit
  187. *
  188. * @return string
  189. */
  190. public function getUnit()
  191. {
  192. return $this->unit;
  193. }
  194. /**
  195. * Set unit
  196. *
  197. * @param string $value
  198. * @return self
  199. */
  200. public function setUnit($value)
  201. {
  202. $this->unit = $value;
  203. return $this;
  204. }
  205. /**
  206. * Get width
  207. *
  208. * @return int|float
  209. */
  210. public function getWidth()
  211. {
  212. return $this->width;
  213. }
  214. /**
  215. * Set width
  216. *
  217. * @param int|float $value
  218. * @return self
  219. */
  220. public function setWidth($value = null)
  221. {
  222. $this->width = $this->setNumericVal($value, null);
  223. return $this;
  224. }
  225. /**
  226. * Get height
  227. *
  228. * @return int|float
  229. */
  230. public function getHeight()
  231. {
  232. return $this->height;
  233. }
  234. /**
  235. * Set height
  236. *
  237. * @param int|float $value
  238. * @return self
  239. */
  240. public function setHeight($value = null)
  241. {
  242. $this->height = $this->setNumericVal($value, null);
  243. return $this;
  244. }
  245. /**
  246. * Get left
  247. *
  248. * @return int|float
  249. */
  250. public function getLeft()
  251. {
  252. return $this->left;
  253. }
  254. /**
  255. * Set left
  256. *
  257. * @param int|float $value
  258. * @return self
  259. */
  260. public function setLeft($value = 0)
  261. {
  262. $this->left = $this->setNumericVal($value, 0);
  263. return $this;
  264. }
  265. /**
  266. * Get topmost position
  267. *
  268. * @return int|float
  269. */
  270. public function getTop()
  271. {
  272. return $this->top;
  273. }
  274. /**
  275. * Set topmost position
  276. *
  277. * @param int|float $value
  278. * @return self
  279. */
  280. public function setTop($value = 0)
  281. {
  282. $this->top = $this->setNumericVal($value, 0);
  283. return $this;
  284. }
  285. /**
  286. * Get position type
  287. *
  288. * @return string
  289. */
  290. public function getPos()
  291. {
  292. return $this->pos;
  293. }
  294. /**
  295. * Set position type
  296. *
  297. * @param string $value
  298. * @return self
  299. */
  300. public function setPos($value)
  301. {
  302. $enum = array(
  303. self::POS_ABSOLUTE,
  304. self::POS_RELATIVE,
  305. );
  306. $this->pos = $this->setEnumVal($value, $enum, $this->pos);
  307. return $this;
  308. }
  309. /**
  310. * Get horizontal position
  311. *
  312. * @return string
  313. */
  314. public function getHPos()
  315. {
  316. return $this->hPos;
  317. }
  318. /**
  319. * Set horizontal position
  320. *
  321. * @since 0.12.0 "absolute" option is available.
  322. *
  323. * @param string $value
  324. * @return self
  325. */
  326. public function setHPos($value)
  327. {
  328. $enum = array(
  329. self::POS_ABSOLUTE,
  330. self::POS_LEFT,
  331. self::POS_CENTER,
  332. self::POS_RIGHT,
  333. self::POS_INSIDE,
  334. self::POS_OUTSIDE,
  335. );
  336. $this->hPos = $this->setEnumVal($value, $enum, $this->hPos);
  337. return $this;
  338. }
  339. /**
  340. * Get vertical position
  341. *
  342. * @return string
  343. */
  344. public function getVPos()
  345. {
  346. return $this->vPos;
  347. }
  348. /**
  349. * Set vertical position
  350. *
  351. * @since 0.12.0 "absolute" option is available.
  352. *
  353. * @param string $value
  354. * @return self
  355. */
  356. public function setVPos($value)
  357. {
  358. $enum = array(
  359. self::POS_ABSOLUTE,
  360. self::POS_TOP,
  361. self::POS_CENTER,
  362. self::POS_BOTTOM,
  363. self::POS_INSIDE,
  364. self::POS_OUTSIDE,
  365. );
  366. $this->vPos = $this->setEnumVal($value, $enum, $this->vPos);
  367. return $this;
  368. }
  369. /**
  370. * Get horizontal position relative to
  371. *
  372. * @return string
  373. */
  374. public function getHPosRelTo()
  375. {
  376. return $this->hPosRelTo;
  377. }
  378. /**
  379. * Set horizontal position relative to
  380. *
  381. * @param string $value
  382. * @return self
  383. */
  384. public function setHPosRelTo($value)
  385. {
  386. $enum = array(
  387. self::POS_RELTO_MARGIN,
  388. self::POS_RELTO_PAGE,
  389. self::POS_RELTO_COLUMN,
  390. self::POS_RELTO_CHAR,
  391. self::POS_RELTO_LMARGIN,
  392. self::POS_RELTO_RMARGIN,
  393. self::POS_RELTO_IMARGIN,
  394. self::POS_RELTO_OMARGIN,
  395. );
  396. $this->hPosRelTo = $this->setEnumVal($value, $enum, $this->hPosRelTo);
  397. return $this;
  398. }
  399. /**
  400. * Get vertical position relative to
  401. *
  402. * @return string
  403. */
  404. public function getVPosRelTo()
  405. {
  406. return $this->vPosRelTo;
  407. }
  408. /**
  409. * Set vertical position relative to
  410. *
  411. * @param string $value
  412. * @return self
  413. */
  414. public function setVPosRelTo($value)
  415. {
  416. $enum = array(
  417. self::POS_RELTO_MARGIN,
  418. self::POS_RELTO_PAGE,
  419. self::POS_RELTO_TEXT,
  420. self::POS_RELTO_LINE,
  421. self::POS_RELTO_TMARGIN,
  422. self::POS_RELTO_BMARGIN,
  423. self::POS_RELTO_IMARGIN,
  424. self::POS_RELTO_OMARGIN,
  425. );
  426. $this->vPosRelTo = $this->setEnumVal($value, $enum, $this->vPosRelTo);
  427. return $this;
  428. }
  429. /**
  430. * Get wrap type
  431. *
  432. * @return string
  433. */
  434. public function getWrap()
  435. {
  436. return $this->wrap;
  437. }
  438. /**
  439. * Set wrap type
  440. *
  441. * @param string $value
  442. * @return self
  443. */
  444. public function setWrap($value)
  445. {
  446. $enum = array(
  447. self::WRAP_INLINE,
  448. self::WRAP_SQUARE,
  449. self::WRAP_TIGHT,
  450. self::WRAP_THROUGH,
  451. self::WRAP_TOPBOTTOM,
  452. self::WRAP_BEHIND,
  453. self::WRAP_INFRONT,
  454. );
  455. $this->wrap = $this->setEnumVal($value, $enum, $this->wrap);
  456. return $this;
  457. }
  458. }