2014-04-25 10:33:45 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-04-25 10:33:45 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
|
|
|
|
|
2014-05-04 21:16:12 +07:00
|
|
|
use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter;
|
2014-04-25 10:33:45 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Image element writer
|
|
|
|
|
*
|
|
|
|
|
* @since 0.10.0
|
|
|
|
|
*/
|
|
|
|
|
class Image extends Element
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Write element
|
|
|
|
|
*/
|
|
|
|
|
public function write()
|
|
|
|
|
{
|
2014-05-04 15:13:31 +07:00
|
|
|
if ($this->element->isWatermark()) {
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->writeWatermark();
|
|
|
|
|
} else {
|
|
|
|
|
$this->writeImage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write image element
|
|
|
|
|
*/
|
|
|
|
|
private function writeImage()
|
|
|
|
|
{
|
|
|
|
|
$rId = $this->element->getRelationId() + ($this->element->isInSection() ? 6 : 0);
|
|
|
|
|
$style = $this->element->getStyle();
|
2014-05-04 21:16:12 +07:00
|
|
|
$styleWriter = new ImageStyleWriter($this->xmlWriter, $style);
|
2014-04-25 10:33:45 +07:00
|
|
|
|
|
|
|
|
if (!$this->withoutP) {
|
|
|
|
|
$this->xmlWriter->startElement('w:p');
|
2014-05-04 21:16:12 +07:00
|
|
|
if (!is_null($style->getAlign())) {
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->startElement('w:pPr');
|
|
|
|
|
$this->xmlWriter->startElement('w:jc');
|
2014-05-04 21:16:12 +07:00
|
|
|
$this->xmlWriter->writeAttribute('w:val', $style->getAlign());
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->endElement(); // w:jc
|
|
|
|
|
$this->xmlWriter->endElement(); // w:pPr
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-04 21:16:12 +07:00
|
|
|
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->startElement('w:r');
|
|
|
|
|
$this->xmlWriter->startElement('w:pict');
|
|
|
|
|
$this->xmlWriter->startElement('v:shape');
|
|
|
|
|
$this->xmlWriter->writeAttribute('type', '#_x0000_t75');
|
2014-05-04 21:16:12 +07:00
|
|
|
$styleWriter->write();
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->startElement('v:imagedata');
|
|
|
|
|
$this->xmlWriter->writeAttribute('r:id', 'rId' . $rId);
|
|
|
|
|
$this->xmlWriter->writeAttribute('o:title', '');
|
|
|
|
|
$this->xmlWriter->endElement(); // v:imagedata
|
2014-05-04 21:16:12 +07:00
|
|
|
$styleWriter->writeW10Wrap();
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->endElement(); // v:shape
|
|
|
|
|
$this->xmlWriter->endElement(); // w:pict
|
|
|
|
|
$this->xmlWriter->endElement(); // w:r
|
|
|
|
|
|
|
|
|
|
if (!$this->withoutP) {
|
|
|
|
|
$this->xmlWriter->endElement(); // w:p
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Write watermark element
|
|
|
|
|
*/
|
|
|
|
|
private function writeWatermark()
|
|
|
|
|
{
|
|
|
|
|
$rId = $this->element->getRelationId();
|
|
|
|
|
$style = $this->element->getStyle();
|
2014-05-04 21:16:12 +07:00
|
|
|
$style->setPositioning('absolute');
|
|
|
|
|
$styleWriter = new ImageStyleWriter($this->xmlWriter, $style);
|
2014-04-25 10:33:45 +07:00
|
|
|
|
|
|
|
|
$this->xmlWriter->startElement('w:p');
|
|
|
|
|
$this->xmlWriter->startElement('w:r');
|
|
|
|
|
$this->xmlWriter->startElement('w:pict');
|
|
|
|
|
$this->xmlWriter->startElement('v:shape');
|
|
|
|
|
$this->xmlWriter->writeAttribute('type', '#_x0000_t75');
|
2014-05-04 21:16:12 +07:00
|
|
|
$styleWriter->write();
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->startElement('v:imagedata');
|
|
|
|
|
$this->xmlWriter->writeAttribute('r:id', 'rId' . $rId);
|
|
|
|
|
$this->xmlWriter->writeAttribute('o:title', '');
|
|
|
|
|
$this->xmlWriter->endElement(); // v:imagedata
|
|
|
|
|
$this->xmlWriter->endElement(); // v:shape
|
|
|
|
|
$this->xmlWriter->endElement(); // w:pict
|
|
|
|
|
$this->xmlWriter->endElement(); // w:r
|
|
|
|
|
$this->xmlWriter->endElement(); // w:p
|
|
|
|
|
}
|
|
|
|
|
}
|