/** * Set proportional width/height if one dimension not available. * * @param integer $actualWidth * @param integer $actualHeight * @return void */ private function setProportionalSize($actualWidth, $actualHeight) { $styleWidth = $this->style->getWidth(); $styleHeight = $this->style->getHeight(); if (!($styleWidth && $styleHeight)) { if ($styleWidth == null && $styleHeight == null) { $this->style->setWidth($actualWidth); $this->style->setHeight($actualHeight); } elseif ($styleWidth) { $this->style->setHeight($actualHeight * ($styleWidth / $actualWidth)); } else { $this->style->setWidth($actualWidth * ($styleHeight / $actualHeight)); } } }
/** * Test setWrappingStyle exception * * @expectedException \InvalidArgumentException */ public function testSetWrappingStyleException() { $object = new Image(); $object->setWrappingStyle('foo'); }
/** * 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; }