Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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;
  18. use PhpOffice\PhpWord\PhpWord;
  19. /**
  20. * RTF writer
  21. *
  22. * @since 0.7.0
  23. */
  24. class RTF extends AbstractWriter implements WriterInterface
  25. {
  26. /**
  27. * Last paragraph style
  28. *
  29. * @var mixed
  30. */
  31. private $lastParagraphStyle;
  32. /**
  33. * Create new instance
  34. *
  35. * @param \PhpOffice\PhpWord\PhpWord $phpWord
  36. */
  37. public function __construct(PhpWord $phpWord = null)
  38. {
  39. $this->setPhpWord($phpWord);
  40. $this->parts = array('Header', 'Document');
  41. foreach ($this->parts as $partName) {
  42. $partClass = get_class($this) . '\\Part\\' . $partName;
  43. if (class_exists($partClass)) {
  44. /** @var \PhpOffice\PhpWord\Writer\RTF\Part\AbstractPart $part Type hint */
  45. $part = new $partClass();
  46. $part->setParentWriter($this);
  47. $this->writerParts[strtolower($partName)] = $part;
  48. }
  49. }
  50. }
  51. /**
  52. * Save content to file.
  53. *
  54. * @param string $filename
  55. * @return void
  56. * @throws \PhpOffice\PhpWord\Exception\Exception
  57. */
  58. public function save($filename = null)
  59. {
  60. $this->writeFile($this->openFile($filename), $this->getContent());
  61. }
  62. /**
  63. * Get content
  64. *
  65. * @return string
  66. * @since 0.11.0
  67. */
  68. private function getContent()
  69. {
  70. $content = '';
  71. $content .= '{';
  72. $content .= '\rtf1' . PHP_EOL;
  73. $content .= $this->getWriterPart('Header')->write();
  74. $content .= $this->getWriterPart('Document')->write();
  75. $content .= '}';
  76. return $content;
  77. }
  78. /**
  79. * Get font table.
  80. *
  81. * @return array
  82. */
  83. public function getFontTable()
  84. {
  85. return $this->getWriterPart('Header')->getFontTable();
  86. }
  87. /**
  88. * Get color table.
  89. *
  90. * @return array
  91. */
  92. public function getColorTable()
  93. {
  94. return $this->getWriterPart('Header')->getColorTable();
  95. }
  96. /**
  97. * Get last paragraph style.
  98. *
  99. * @return mixed
  100. */
  101. public function getLastParagraphStyle()
  102. {
  103. return $this->lastParagraphStyle;
  104. }
  105. /**
  106. * Set last paragraph style.
  107. *
  108. * @param mixed $value
  109. * @return void
  110. */
  111. public function setLastParagraphStyle($value = '')
  112. {
  113. $this->lastParagraphStyle = $value;
  114. }
  115. }