Ingen beskrivning

Line.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\Word2007\Element;
  18. use PhpOffice\PhpWord\Element\Line as LineElement;
  19. use PhpOffice\PhpWord\Writer\Word2007\Style\Line as LineStyleWriter;
  20. /**
  21. * Line element writer
  22. *
  23. */
  24. class Line extends AbstractElement
  25. {
  26. /**
  27. * Write element.
  28. *
  29. * @return void
  30. */
  31. public function write()
  32. {
  33. $xmlWriter = $this->getXmlWriter();
  34. $element = $this->getElement();
  35. if (!$element instanceof LineElement) {
  36. return;
  37. }
  38. $style = $element->getStyle();
  39. $styleWriter = new LineStyleWriter($xmlWriter, $style);
  40. $elementId = $element->getElementIndex();
  41. if (!$this->withoutP) {
  42. $xmlWriter->startElement('w:p');
  43. $styleWriter->writeAlignment();
  44. }
  45. $xmlWriter->startElement('w:r');
  46. $xmlWriter->startElement('w:pict');
  47. // Shapetype could be defined for each line separately, but then a unique id would be necessary
  48. if ($elementId == 1) {
  49. $xmlWriter->startElement('v:shapetype');
  50. $xmlWriter->writeAttribute('id', '_x0000_t32');
  51. $xmlWriter->writeAttribute('coordsize', '21600,21600');
  52. $xmlWriter->writeAttribute('o:spt', '32');
  53. $xmlWriter->writeAttribute('o:oned', 't');
  54. $xmlWriter->writeAttribute('path', 'm,l21600,21600e');
  55. $xmlWriter->writeAttribute('filled', 'f');
  56. $xmlWriter->startElement('v:path');
  57. $xmlWriter->writeAttribute('arrowok', 't');
  58. $xmlWriter->writeAttribute('fillok', 'f');
  59. $xmlWriter->writeAttribute('o:connecttype', 'none');
  60. $xmlWriter->endElement(); // v:path
  61. $xmlWriter->startElement('o:lock');
  62. $xmlWriter->writeAttribute('v:ext', 'edit');
  63. $xmlWriter->writeAttribute('shapetype', 't');
  64. $xmlWriter->endElement(); // o:lock
  65. $xmlWriter->endElement(); // v:shapetype
  66. }
  67. $xmlWriter->startElement('v:shape');
  68. $xmlWriter->writeAttribute('id', sprintf('_x0000_s1%1$03d', $elementId));
  69. $xmlWriter->writeAttribute('type', '#_x0000_t32'); //type should correspond to shapetype id
  70. $styleWriter->write();
  71. $styleWriter->writeStroke();
  72. $xmlWriter->endElement(); // v:shape
  73. $xmlWriter->endElement(); // w:pict
  74. $xmlWriter->endElement(); // w:r
  75. $this->endElementP(); // w:p
  76. }
  77. }