Bez popisu

Chart.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Chart as ChartElement;
  19. /**
  20. * Chart element writer
  21. *
  22. * @since 0.12.0
  23. */
  24. class Chart 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 ChartElement) {
  36. return;
  37. }
  38. $rId = $element->getRelationId();
  39. $style = $element->getStyle();
  40. if (!$this->withoutP) {
  41. $xmlWriter->startElement('w:p');
  42. }
  43. $xmlWriter->startElement('w:r');
  44. $xmlWriter->startElement('w:drawing');
  45. $xmlWriter->startElement('wp:inline');
  46. // EMU
  47. $xmlWriter->writeElementBlock('wp:extent', array('cx' => $style->getWidth(), 'cy' => $style->getHeight()));
  48. $xmlWriter->writeElementBlock('wp:docPr', array('id' => $rId, 'name' => "Chart{$rId}"));
  49. $xmlWriter->startElement('a:graphic');
  50. $xmlWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
  51. $xmlWriter->startElement('a:graphicData');
  52. $xmlWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
  53. $xmlWriter->startElement('c:chart');
  54. $xmlWriter->writeAttribute('r:id', "rId{$rId}");
  55. $xmlWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
  56. $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
  57. $xmlWriter->endElement(); // c:chart
  58. $xmlWriter->endElement(); // a:graphicData
  59. $xmlWriter->endElement(); // a:graphic
  60. $xmlWriter->endElement(); // wp:inline
  61. $xmlWriter->endElement(); // w:drawing
  62. $xmlWriter->endElement(); // w:r
  63. $this->endElementP(); // w:p
  64. }
  65. }