No Description

Section.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Writer\RTF\Style;
  18. use PhpOffice\PhpWord\Style\Section as SectionStyle;
  19. /**
  20. * RTF section style writer
  21. *
  22. * @since 0.12.0
  23. */
  24. class Section extends AbstractStyle
  25. {
  26. /**
  27. * Write style
  28. *
  29. * @return string
  30. */
  31. public function write()
  32. {
  33. $style = $this->getStyle();
  34. if (!$style instanceof SectionStyle) {
  35. return '';
  36. }
  37. $content = '';
  38. $content .= '\sectd ';
  39. // Size & margin
  40. $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . $style->getPageSizeW());
  41. $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . $style->getPageSizeH());
  42. $content .= ' ';
  43. $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . $style->getMarginTop());
  44. $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . $style->getMarginRight());
  45. $content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . $style->getMarginBottom());
  46. $content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . $style->getMarginLeft());
  47. $content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . $style->getHeaderHeight());
  48. $content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . $style->getFooterHeight());
  49. $content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . $style->getGutter());
  50. $content .= ' ';
  51. // Borders
  52. if ($style->hasBorder()) {
  53. $styleWriter = new Border($style);
  54. $styleWriter->setParentWriter($this->getParentWriter());
  55. $styleWriter->setSizes($style->getBorderSize());
  56. $styleWriter->setColors($style->getBorderColor());
  57. $content .= $styleWriter->write();
  58. }
  59. return $content . PHP_EOL;
  60. }
  61. }