Section.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\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' . round($style->getPageSizeW()));
  41. $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH()));
  42. $content .= ' ';
  43. $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . round($style->getMarginTop()));
  44. $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . round($style->getMarginRight()));
  45. $content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . round($style->getMarginBottom()));
  46. $content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . round($style->getMarginLeft()));
  47. $content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . round($style->getHeaderHeight()));
  48. $content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight()));
  49. $content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter()));
  50. $content .= $this->getValueIf($style->getPageNumberingStart() !== null, '\pgnstarts' . $style->getPageNumberingStart() . '\pgnrestart');
  51. $content .= ' ';
  52. // Borders
  53. if ($style->hasBorder()) {
  54. $styleWriter = new Border($style);
  55. $styleWriter->setParentWriter($this->getParentWriter());
  56. $styleWriter->setSizes($style->getBorderSize());
  57. $styleWriter->setColors($style->getBorderColor());
  58. $content .= $styleWriter->write();
  59. }
  60. return $content . PHP_EOL;
  61. }
  62. }