PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/backend/modules/mbase2/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/HeaderFooter.php

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