暫無描述

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\Writer\Word2007\Style\Image as ImageStyleWriter;
  19. /**
  20. * Object element writer
  21. *
  22. * @since 0.10.0
  23. */
  24. class Object extends AbstractElement
  25. {
  26. /**
  27. * Write object element.
  28. *
  29. * @return void
  30. */
  31. public function write()
  32. {
  33. $xmlWriter = $this->getXmlWriter();
  34. $element = $this->getElement();
  35. if (!$element instanceof \PhpOffice\PhpWord\Element\Object) {
  36. return;
  37. }
  38. $rIdObject = $element->getRelationId() + ($element->isInSection() ? 6 : 0);
  39. $rIdImage = $element->getImageRelationId() + ($element->isInSection() ? 6 : 0);
  40. $shapeId = md5($rIdObject . '_' . $rIdImage);
  41. $objectId = $element->getRelationId() + 1325353440;
  42. $style = $element->getStyle();
  43. $styleWriter = new ImageStyleWriter($xmlWriter, $style);
  44. if (!$this->withoutP) {
  45. $xmlWriter->startElement('w:p');
  46. $styleWriter->writeAlignment();
  47. }
  48. $xmlWriter->startElement('w:r');
  49. $xmlWriter->startElement('w:object');
  50. $xmlWriter->writeAttribute('w:dxaOrig', '249');
  51. $xmlWriter->writeAttribute('w:dyaOrig', '160');
  52. // Icon
  53. $xmlWriter->startElement('v:shape');
  54. $xmlWriter->writeAttribute('id', $shapeId);
  55. $xmlWriter->writeAttribute('type', '#_x0000_t75');
  56. $xmlWriter->writeAttribute('style', 'width:104px;height:67px');
  57. $xmlWriter->writeAttribute('o:ole', '');
  58. $xmlWriter->startElement('v:imagedata');
  59. $xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage);
  60. $xmlWriter->writeAttribute('o:title', '');
  61. $xmlWriter->endElement(); // v:imagedata
  62. $xmlWriter->endElement(); // v:shape
  63. // Object
  64. $xmlWriter->startElement('o:OLEObject');
  65. $xmlWriter->writeAttribute('Type', 'Embed');
  66. $xmlWriter->writeAttribute('ProgID', 'Package');
  67. $xmlWriter->writeAttribute('ShapeID', $shapeId);
  68. $xmlWriter->writeAttribute('DrawAspect', 'Icon');
  69. $xmlWriter->writeAttribute('ObjectID', '_' . $objectId);
  70. $xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject);
  71. $xmlWriter->endElement(); // o:OLEObject
  72. $xmlWriter->endElement(); // w:object
  73. $xmlWriter->endElement(); // w:r
  74. $this->endElementP(); // w:p
  75. }
  76. }