Няма описание

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\Alignment;
  19. /**
  20. * RTF paragraph style writer
  21. *
  22. * @since 0.11.0
  23. */
  24. class Paragraph extends AbstractStyle
  25. {
  26. /**
  27. * Depth of table container nested level; Primarily used for RTF writer/reader
  28. *
  29. * 0 = Not in a table; 1 = in a table; 2 = in a table inside another table, etc.
  30. *
  31. * @var int
  32. */
  33. private $nestedLevel = 0;
  34. /**
  35. * Write style
  36. *
  37. * @return string
  38. */
  39. public function write()
  40. {
  41. $style = $this->getStyle();
  42. if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
  43. return '';
  44. }
  45. $alignments = array(
  46. Alignment::ALIGN_LEFT => '\ql',
  47. Alignment::ALIGN_RIGHT => '\qr',
  48. Alignment::ALIGN_CENTER => '\qc',
  49. Alignment::ALIGN_BOTH => '\qj',
  50. );
  51. $align = $style->getAlign();
  52. $spaceAfter = $style->getSpaceAfter();
  53. $spaceBefore = $style->getSpaceBefore();
  54. $content = '';
  55. if ($this->nestedLevel == 0) {
  56. $content .= '\pard\nowidctlpar ';
  57. }
  58. if (isset($alignments[$align])) {
  59. $content .= $alignments[$align];
  60. }
  61. $content .= $this->getValueIf($spaceBefore !== null, '\sb' . $spaceBefore);
  62. $content .= $this->getValueIf($spaceAfter !== null, '\sa' . $spaceAfter);
  63. return $content;
  64. }
  65. /**
  66. * Set nested level.
  67. *
  68. * @param int $value
  69. * @return void
  70. */
  71. public function setNestedLevel($value)
  72. {
  73. $this->nestedLevel = $value;
  74. }
  75. }