PageRenderTime 28ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/plugin/phpexcel/PHPExcel/Worksheet/HeaderFooter.php

https://bitbucket.org/chamilo/chamilo-dev/
PHP | 501 lines | 169 code | 40 blank | 292 comment | 9 complexity | d339fbea1af2aacdcaa067513aedd85d MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Worksheet
  23. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.6, 2011-02-27
  26. */
  27. /**
  28. * PHPExcel_Worksheet_HeaderFooter
  29. *
  30. * <code>
  31. * Header/Footer Formatting Syntax taken from Office Open XML Part 4 - Markup Language Reference, page 1970:
  32. *
  33. * There are a number of formatting codes that can be written inline with the actual header / footer text, which
  34. * affect the formatting in the header or footer.
  35. *
  36. * Example: This example shows the text "Center Bold Header" on the first line (center section), and the date on
  37. * the second line (center section).
  38. * &CCenter &"-,Bold"Bold&"-,Regular"Header_x000A_&D
  39. *
  40. * General Rules:
  41. * There is no required order in which these codes must appear.
  42. *
  43. * The first occurrence of the following codes turns the formatting ON, the second occurrence turns it OFF again:
  44. * - strikethrough
  45. * - superscript
  46. * - subscript
  47. * Superscript and subscript cannot both be ON at same time. Whichever comes first wins and the other is ignored,
  48. * while the first is ON.
  49. * &L - code for "left section" (there are three header / footer locations, "left", "center", and "right"). When
  50. * two or more occurrences of this section marker exist, the contents from all markers are concatenated, in the
  51. * order of appearance, and placed into the left section.
  52. * &P - code for "current page #"
  53. * &N - code for "total pages"
  54. * &font size - code for "text font size", where font size is a font size in points.
  55. * &K - code for "text font color"
  56. * RGB Color is specified as RRGGBB
  57. * Theme Color is specifed as TTSNN where TT is the theme color Id, S is either "+" or "-" of the tint/shade
  58. * value, NN is the tint/shade value.
  59. * &S - code for "text strikethrough" on / off
  60. * &X - code for "text super script" on / off
  61. * &Y - code for "text subscript" on / off
  62. * &C - code for "center section". When two or more occurrences of this section marker exist, the contents
  63. * from all markers are concatenated, in the order of appearance, and placed into the center section.
  64. *
  65. * &D - code for "date"
  66. * &T - code for "time"
  67. * &G - code for "picture as background"
  68. * &U - code for "text single underline"
  69. * &E - code for "double underline"
  70. * &R - code for "right section". When two or more occurrences of this section marker exist, the contents
  71. * from all markers are concatenated, in the order of appearance, and placed into the right section.
  72. * &Z - code for "this workbook's file path"
  73. * &F - code for "this workbook's file name"
  74. * &A - code for "sheet tab name"
  75. * &+ - code for add to page #.
  76. * &- - code for subtract from page #.
  77. * &"font name,font type" - code for "text font name" and "text font type", where font name and font type
  78. * are strings specifying the name and type of the font, separated by a comma. When a hyphen appears in font
  79. * name, it means "none specified". Both of font name and font type can be localized values.
  80. * &"-,Bold" - code for "bold font style"
  81. * &B - also means "bold font style".
  82. * &"-,Regular" - code for "regular font style"
  83. * &"-,Italic" - code for "italic font style"
  84. * &I - also means "italic font style"
  85. * &"-,Bold Italic" code for "bold italic font style"
  86. * &O - code for "outline style"
  87. * &H - code for "shadow style"
  88. * </code>
  89. *
  90. * @category PHPExcel
  91. * @package PHPExcel_Worksheet
  92. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  93. */
  94. class PHPExcel_Worksheet_HeaderFooter
  95. {
  96. /* Header/footer image location */
  97. const IMAGE_HEADER_LEFT = 'LH';
  98. const IMAGE_HEADER_CENTER = 'CH';
  99. const IMAGE_HEADER_RIGHT = 'RH';
  100. const IMAGE_FOOTER_LEFT = 'LF';
  101. const IMAGE_FOOTER_CENTER = 'CF';
  102. const IMAGE_FOOTER_RIGHT = 'RF';
  103. /**
  104. * OddHeader
  105. *
  106. * @var string
  107. */
  108. private $_oddHeader = '';
  109. /**
  110. * OddFooter
  111. *
  112. * @var string
  113. */
  114. private $_oddFooter = '';
  115. /**
  116. * EvenHeader
  117. *
  118. * @var string
  119. */
  120. private $_evenHeader = '';
  121. /**
  122. * EvenFooter
  123. *
  124. * @var string
  125. */
  126. private $_evenFooter = '';
  127. /**
  128. * FirstHeader
  129. *
  130. * @var string
  131. */
  132. private $_firstHeader = '';
  133. /**
  134. * FirstFooter
  135. *
  136. * @var string
  137. */
  138. private $_firstFooter = '';
  139. /**
  140. * Different header for Odd/Even, defaults to false
  141. *
  142. * @var boolean
  143. */
  144. private $_differentOddEven = false;
  145. /**
  146. * Different header for first page, defaults to false
  147. *
  148. * @var boolean
  149. */
  150. private $_differentFirst = false;
  151. /**
  152. * Scale with document, defaults to true
  153. *
  154. * @var boolean
  155. */
  156. private $_scaleWithDocument = true;
  157. /**
  158. * Align with margins, defaults to true
  159. *
  160. * @var boolean
  161. */
  162. private $_alignWithMargins = true;
  163. /**
  164. * Header/footer images
  165. *
  166. * @var PHPExcel_Worksheet_HeaderFooterDrawing[]
  167. */
  168. private $_headerFooterImages = array();
  169. /**
  170. * Create a new PHPExcel_Worksheet_HeaderFooter
  171. */
  172. public function __construct()
  173. {
  174. }
  175. /**
  176. * Get OddHeader
  177. *
  178. * @return string
  179. */
  180. public function getOddHeader()
  181. {
  182. return $this->_oddHeader;
  183. }
  184. /**
  185. * Set OddHeader
  186. *
  187. * @param string $pValue
  188. * @return PHPExcel_Worksheet_HeaderFooter
  189. */
  190. public function setOddHeader($pValue)
  191. {
  192. $this->_oddHeader = $pValue;
  193. return $this;
  194. }
  195. /**
  196. * Get OddFooter
  197. *
  198. * @return string
  199. */
  200. public function getOddFooter()
  201. {
  202. return $this->_oddFooter;
  203. }
  204. /**
  205. * Set OddFooter
  206. *
  207. * @param string $pValue
  208. * @return PHPExcel_Worksheet_HeaderFooter
  209. */
  210. public function setOddFooter($pValue)
  211. {
  212. $this->_oddFooter = $pValue;
  213. return $this;
  214. }
  215. /**
  216. * Get EvenHeader
  217. *
  218. * @return string
  219. */
  220. public function getEvenHeader()
  221. {
  222. return $this->_evenHeader;
  223. }
  224. /**
  225. * Set EvenHeader
  226. *
  227. * @param string $pValue
  228. * @return PHPExcel_Worksheet_HeaderFooter
  229. */
  230. public function setEvenHeader($pValue)
  231. {
  232. $this->_evenHeader = $pValue;
  233. return $this;
  234. }
  235. /**
  236. * Get EvenFooter
  237. *
  238. * @return string
  239. */
  240. public function getEvenFooter()
  241. {
  242. return $this->_evenFooter;
  243. }
  244. /**
  245. * Set EvenFooter
  246. *
  247. * @param string $pValue
  248. * @return PHPExcel_Worksheet_HeaderFooter
  249. */
  250. public function setEvenFooter($pValue)
  251. {
  252. $this->_evenFooter = $pValue;
  253. return $this;
  254. }
  255. /**
  256. * Get FirstHeader
  257. *
  258. * @return string
  259. */
  260. public function getFirstHeader()
  261. {
  262. return $this->_firstHeader;
  263. }
  264. /**
  265. * Set FirstHeader
  266. *
  267. * @param string $pValue
  268. * @return PHPExcel_Worksheet_HeaderFooter
  269. */
  270. public function setFirstHeader($pValue)
  271. {
  272. $this->_firstHeader = $pValue;
  273. return $this;
  274. }
  275. /**
  276. * Get FirstFooter
  277. *
  278. * @return string
  279. */
  280. public function getFirstFooter()
  281. {
  282. return $this->_firstFooter;
  283. }
  284. /**
  285. * Set FirstFooter
  286. *
  287. * @param string $pValue
  288. * @return PHPExcel_Worksheet_HeaderFooter
  289. */
  290. public function setFirstFooter($pValue)
  291. {
  292. $this->_firstFooter = $pValue;
  293. return $this;
  294. }
  295. /**
  296. * Get DifferentOddEven
  297. *
  298. * @return boolean
  299. */
  300. public function getDifferentOddEven()
  301. {
  302. return $this->_differentOddEven;
  303. }
  304. /**
  305. * Set DifferentOddEven
  306. *
  307. * @param boolean $pValue
  308. * @return PHPExcel_Worksheet_HeaderFooter
  309. */
  310. public function setDifferentOddEven($pValue = false)
  311. {
  312. $this->_differentOddEven = $pValue;
  313. return $this;
  314. }
  315. /**
  316. * Get DifferentFirst
  317. *
  318. * @return boolean
  319. */
  320. public function getDifferentFirst()
  321. {
  322. return $this->_differentFirst;
  323. }
  324. /**
  325. * Set DifferentFirst
  326. *
  327. * @param boolean $pValue
  328. * @return PHPExcel_Worksheet_HeaderFooter
  329. */
  330. public function setDifferentFirst($pValue = false)
  331. {
  332. $this->_differentFirst = $pValue;
  333. return $this;
  334. }
  335. /**
  336. * Get ScaleWithDocument
  337. *
  338. * @return boolean
  339. */
  340. public function getScaleWithDocument()
  341. {
  342. return $this->_scaleWithDocument;
  343. }
  344. /**
  345. * Set ScaleWithDocument
  346. *
  347. * @param boolean $pValue
  348. * @return PHPExcel_Worksheet_HeaderFooter
  349. */
  350. public function setScaleWithDocument($pValue = true)
  351. {
  352. $this->_scaleWithDocument = $pValue;
  353. return $this;
  354. }
  355. /**
  356. * Get AlignWithMargins
  357. *
  358. * @return boolean
  359. */
  360. public function getAlignWithMargins()
  361. {
  362. return $this->_alignWithMargins;
  363. }
  364. /**
  365. * Set AlignWithMargins
  366. *
  367. * @param boolean $pValue
  368. * @return PHPExcel_Worksheet_HeaderFooter
  369. */
  370. public function setAlignWithMargins($pValue = true)
  371. {
  372. $this->_alignWithMargins = $pValue;
  373. return $this;
  374. }
  375. /**
  376. * Add header/footer image
  377. *
  378. * @param PHPExcel_Worksheet_HeaderFooterDrawing $image
  379. * @param string $location
  380. * @throws Exception
  381. * @return PHPExcel_Worksheet_HeaderFooter
  382. */
  383. public function addImage(PHPExcel_Worksheet_HeaderFooterDrawing $image = null, $location = self::IMAGE_HEADER_LEFT)
  384. {
  385. $this->_headerFooterImages[$location] = $image;
  386. return $this;
  387. }
  388. /**
  389. * Remove header/footer image
  390. *
  391. * @param string $location
  392. * @throws Exception
  393. * @return PHPExcel_Worksheet_HeaderFooter
  394. */
  395. public function removeImage($location = self::IMAGE_HEADER_LEFT)
  396. {
  397. if (isset($this->_headerFooterImages[$location]))
  398. {
  399. unset($this->_headerFooterImages[$location]);
  400. }
  401. return $this;
  402. }
  403. /**
  404. * Set header/footer images
  405. *
  406. * @param PHPExcel_Worksheet_HeaderFooterDrawing[] $images
  407. * @throws Exception
  408. * @return PHPExcel_Worksheet_HeaderFooter
  409. */
  410. public function setImages($images)
  411. {
  412. if (! is_array($images))
  413. {
  414. throw new Exception('Invalid parameter!');
  415. }
  416. $this->_headerFooterImages = $images;
  417. return $this;
  418. }
  419. /**
  420. * Get header/footer images
  421. *
  422. * @return PHPExcel_Worksheet_HeaderFooterDrawing[]
  423. */
  424. public function getImages()
  425. {
  426. // Sort array
  427. $images = array();
  428. if (isset($this->_headerFooterImages[self :: IMAGE_HEADER_LEFT]))
  429. $images[self :: IMAGE_HEADER_LEFT] = $this->_headerFooterImages[self :: IMAGE_HEADER_LEFT];
  430. if (isset($this->_headerFooterImages[self :: IMAGE_HEADER_CENTER]))
  431. $images[self :: IMAGE_HEADER_CENTER] = $this->_headerFooterImages[self :: IMAGE_HEADER_CENTER];
  432. if (isset($this->_headerFooterImages[self :: IMAGE_HEADER_RIGHT]))
  433. $images[self :: IMAGE_HEADER_RIGHT] = $this->_headerFooterImages[self :: IMAGE_HEADER_RIGHT];
  434. if (isset($this->_headerFooterImages[self :: IMAGE_FOOTER_LEFT]))
  435. $images[self :: IMAGE_FOOTER_LEFT] = $this->_headerFooterImages[self :: IMAGE_FOOTER_LEFT];
  436. if (isset($this->_headerFooterImages[self :: IMAGE_FOOTER_CENTER]))
  437. $images[self :: IMAGE_FOOTER_CENTER] = $this->_headerFooterImages[self :: IMAGE_FOOTER_CENTER];
  438. if (isset($this->_headerFooterImages[self :: IMAGE_FOOTER_RIGHT]))
  439. $images[self :: IMAGE_FOOTER_RIGHT] = $this->_headerFooterImages[self :: IMAGE_FOOTER_RIGHT];
  440. $this->_headerFooterImages = $images;
  441. return $this->_headerFooterImages;
  442. }
  443. /**
  444. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  445. */
  446. public function __clone()
  447. {
  448. $vars = get_object_vars($this);
  449. foreach ($vars as $key => $value)
  450. {
  451. if (is_object($value))
  452. {
  453. $this->$key = clone $value;
  454. }
  455. else
  456. {
  457. $this->$key = $value;
  458. }
  459. }
  460. }
  461. }