getStyle(); if (!$style instanceof ImageStyle) { return; } $this->writeStyle($style); } /** * Write style attribute * * @param \PhpOffice\PhpWord\Style\Image $style */ protected function writeStyle($style) { $xmlWriter = $this->getXmlWriter(); $styles = $this->getElementStyle($style); $imageStyle = $this->assembleStyle($styles); $xmlWriter->writeAttribute('style', $imageStyle); } /** * Write alignment */ public function writeAlignment() { $style = $this->getStyle(); if (!$style instanceof ImageStyle) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:pPr'); $styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $style->getAlign()))); $styleWriter->write(); $xmlWriter->endElement(); // w:pPr } /** * Write w10 wrapping */ public function writeW10Wrap() { if (is_null($this->w10wrap)) { return; } $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w10:wrap'); $xmlWriter->writeAttribute('type', $this->w10wrap); $xmlWriter->endElement(); // w10:wrap } /** * Get element style * * @param \PhpOffice\PhpWord\Style\Image $style * @return array */ protected function getElementStyle(ImageStyle $style) { $styles = array( 'mso-width-percent' => '0', 'mso-height-percent' => '0', 'mso-width-relative' => 'margin', 'mso-height-relative' => 'margin', ); // Dimension $dimensions = array( 'width' => $style->getWidth(), 'height' => $style->getHeight(), 'margin-top' => $style->getMarginTop(), 'margin-left' => $style->getMarginLeft() ); foreach ($dimensions as $key => $value) { if ($value !== null) { $styles[$key] = $value . 'px'; } } // Absolute/relative positioning $positioning = $style->getPositioning(); $styles['position'] = $positioning; if ($positioning !== null) { $styles['mso-position-horizontal'] = $style->getPosHorizontal(); $styles['mso-position-vertical'] = $style->getPosVertical(); $styles['mso-position-horizontal-relative'] = $style->getPosHorizontalRel(); $styles['mso-position-vertical-relative'] = $style->getPosVerticalRel(); } // Wrapping style $wrapping = $style->getWrappingStyle(); if ($wrapping == ImageStyle::WRAPPING_STYLE_INLINE) { // Nothing to do when inline } elseif ($wrapping == ImageStyle::WRAPPING_STYLE_BEHIND) { $styles['z-index'] = -251658752; } else { $styles['z-index'] = 251659264; $styles['mso-position-horizontal'] = 'absolute'; $styles['mso-position-vertical'] = 'absolute'; } // w10 wrapping if ($wrapping == ImageStyle::WRAPPING_STYLE_SQUARE) { $this->w10wrap = 'square'; } elseif ($wrapping == ImageStyle::WRAPPING_STYLE_TIGHT) { $this->w10wrap = 'tight'; } return $styles; } }