From 9c11067720f905486550c7aed4cc6530cb1d4980 Mon Sep 17 00:00:00 2001 From: Bas-Jan 't Jong Date: Sat, 3 May 2014 10:08:39 +0200 Subject: [PATCH 1/4] Added Image relative and absolute positioning --- src/PhpWord/Style/Image.php | 240 +++++++++++++++++- src/PhpWord/Writer/Word2007/Element/Image.php | 31 ++- 2 files changed, 263 insertions(+), 8 deletions(-) diff --git a/src/PhpWord/Style/Image.php b/src/PhpWord/Style/Image.php index f21e667408..7aabdeb2ff 100644 --- a/src/PhpWord/Style/Image.php +++ b/src/PhpWord/Style/Image.php @@ -19,7 +19,32 @@ class Image extends AbstractStyle const WRAPPING_STYLE_TIGHT = 'tight'; const WRAPPING_STYLE_BEHIND = 'behind'; const WRAPPING_STYLE_INFRONT = 'infront'; - + const POSITION_HORIZONTAL_LEFT = 'left'; + const POSITION_HORIZONTAL_CENTER = 'centered'; + const POSITION_HORIZONTAL_RIGHT = 'right'; + const POSITION_VERTICAL_TOP = 'top'; + const POSITION_VERTICAL_CENTER = 'center'; + const POSITION_VERTICAL_BOTTOM = 'bottom'; + const POSITION_VERTICAL_INSIDE = 'inside'; + const POSITION_VERTICAL_OUTSIDE = 'outside'; + const POSITION_HORIZONTAL_RELATIVE_MARGIN = 'margin'; + const POSITION_HORIZONTAL_RELATIVE_PAGE = 'page'; + const POSITION_HORIZONTAL_RELATIVE_COLUMN = 'column'; + const POSITION_HORIZONTAL_RELATIVE_CHAR = 'char'; + const POSITION_HORIZONTAL_RELATIVE_LMARGIN = 'left-margin-area'; + const POSITION_HORIZONTAL_RELATIVE_RMARGIN = 'right-margin-area'; + const POSITION_HORIZONTAL_RELATIVE_IMARGIN = 'inner-margin-area'; + const POSITION_HORIZONTAL_RELATIVE_OMARGIN = 'outer-margin-area'; + const POSITION_VERTICAL_RELATIVE_MARGIN = 'margin'; + const POSITION_VERTICAL_RELATIVE_PAGE = 'page'; + const POSITION_VERTICAL_RELATIVE_LINE = 'line'; + const POSITION_VERTICAL_RELATIVE_TMARGIN = 'top-margin-area'; + const POSITION_VERTICAL_RELATIVE_BMARGIN = 'bottom-margin-area'; + const POSITION_VERTICAL_RELATIVE_IMARGIN = 'inner-margin-area'; + const POSITION_VERTICAL_RELATIVE_OMARGIN = 'outer-margin-area'; + const POSITION_RELATIVE = 'relative'; + const POSITION_ABSOLUTE = 'absolute'; + /** * Image width * @@ -62,6 +87,42 @@ class Image extends AbstractStyle */ private $wrappingStyle; + /** + * Horizontal alignment + * + * @var string + */ + private $posHorizontal; + + /** + * Horizontal Relation + * + * @var string + */ + private $posHorizontalRel; + + /** + * Vertical alignment + * + * @var string + */ + private $posVertical; + + /** + * Vertical Relation + * + * @var string + */ + private $posVerticalRel; + + /** + * Positioning type (Relative or Absolute) + * + * @var string + */ + private $positioning; + + /** * Create new image style */ @@ -73,6 +134,11 @@ public function __construct() $this->marginTop = null; $this->marginLeft = null; $this->setWrappingStyle(self::WRAPPING_STYLE_INLINE); + $this->setPositioning(self::POSITION_RELATIVE); + $this->setPosHorizontal(self::POSITION_HORIZONTAL_LEFT); + $this->setPosHorizontalRel(self::POSITION_HORIZONTAL_RELATIVE_CHAR); + $this->setPosVertical(self::POSITION_VERTICAL_TOP); + $this->setPosVerticalRel(self::POSITION_VERTICAL_RELATIVE_LINE); } /** @@ -205,4 +271,176 @@ public function getWrappingStyle() { return $this->wrappingStyle; } + + /** + * Set positioning type + * + * @param string $positioning + * @throws \InvalidArgumentException + * @return $this + */ + + public function setPositioning($positioning) + { + switch ($positioning) { + case self::POSITION_RELATIVE: + case self::POSITION_ABSOLUTE: + $this->positioning = $positioning; + break; + default: + throw new InvalidArgumentException('Positioning does not exists'); + break; + } + return $this; + } + + /** + * Get positioning type + * + * @return string + */ + public function getPositioning() + { + return $this->positioning; + } + + /** + * Set horizontal alignment + * + * @param string $alignment + * @throws \InvalidArgumentException + * @return $this + */ + public function setPosHorizontal($alignment) + { + switch ($alignment) { + case self::POSITION_HORIZONTAL_LEFT: + case self::POSITION_HORIZONTAL_CENTER: + case self::POSITION_HORIZONTAL_RIGHT: + $this->posHorizontal = $alignment; + break; + default: + throw new InvalidArgumentException('Horizontal alignment does not exists'); + break; + } + return $this; + } + + /** + * Get horizontal alignment + * + * @return string + */ + public function getPosHorizontal() + { + return $this->posHorizontal; + } + + /** + * Set vertical alignment + * + * @param string $alignment + * @throws \InvalidArgumentException + * @return $this + */ + + public function setPosVertical($alignment) + { + switch ($alignment) { + case self::POSITION_VERTICAL_TOP: + case self::POSITION_VERTICAL_CENTER: + case self::POSITION_VERTICAL_BOTTOM: + case self::POSITION_VERTICAL_INSIDE: + case self::POSITION_VERTICAL_OUTSIDE: + $this->posVertical = $alignment; + break; + default: + throw new InvalidArgumentException('Vertical alignment does not exists'); + break; + } + return $this; + } + + /** + * Get vertical alignment + * + * @return string + */ + public function getPosVertical() + { + return $this->posVertical; + } + + /** + * Set horizontal relation + * + * @param string $relto + * @throws \InvalidArgumentException + * @return $this + */ + public function setPosHorizontalRel($relto) + { + switch ($relto) { + case self::POSITION_HORIZONTAL_RELATIVE_MARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_PAGE: + case self::POSITION_HORIZONTAL_RELATIVE_COLUMN: + case self::POSITION_HORIZONTAL_RELATIVE_CHAR: + case self::POSITION_HORIZONTAL_RELATIVE_LMARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_RMARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_IMARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_OMARGIN: + $this->posHorizontalRel = $relto; + break; + default: + throw new InvalidArgumentException('Horizontal relation does not exists'); + break; + } + return $this; + } + + /** + * Get horizontal relation + * + * @return string + */ + public function getPosHorizontalRel() + { + return $this->posHorizontalRel; + } + + /** + * Set vertical relation + * + * @param string $relto + * @throws \InvalidArgumentException + * @return $this + */ + public function setPosVerticalRel($relto) + { + switch ($relto) { + case self::POSITION_VERTICAL_RELATIVE_MARGIN: + case self::POSITION_VERTICAL_RELATIVE_PAGE: + case self::POSITION_VERTICAL_RELATIVE_LINE: + case self::POSITION_VERTICAL_RELATIVE_TMARGIN: + case self::POSITION_VERTICAL_RELATIVE_BMARGIN: + case self::POSITION_VERTICAL_RELATIVE_IMARGIN: + case self::POSITION_VERTICAL_RELATIVE_OMARGIN: + $this->posVerticalRel = $relto; + break; + default: + throw new InvalidArgumentException('Vertical relation does not exists'); + break; + } + return $this; + } + + /** + * Get vertical relation + * + * @return string + */ + public function getPosVerticalRel() + { + return $this->posVerticalRel; + } } diff --git a/src/PhpWord/Writer/Word2007/Element/Image.php b/src/PhpWord/Writer/Word2007/Element/Image.php index e944b7af53..80b71121da 100644 --- a/src/PhpWord/Writer/Word2007/Element/Image.php +++ b/src/PhpWord/Writer/Word2007/Element/Image.php @@ -44,6 +44,7 @@ private function writeImage() $marginTop = $style->getMarginTop(); $marginLeft = $style->getMarginLeft(); $wrappingStyle = $style->getWrappingStyle(); + $positioning = $style->getPositioning(); $w10wrapType = null; $imgStyle = ''; if (null !== $width) { @@ -53,28 +54,44 @@ private function writeImage() $imgStyle .= 'height:' . $height . 'px;'; } if (null !== $marginTop) { - $imgStyle .= 'margin-top:' . $marginTop . 'in;'; + $imgStyle .= 'margin-top:' . $marginTop . 'px;'; } if (null !== $marginLeft) { - $imgStyle .= 'margin-left:' . $marginLeft . 'in;'; + $imgStyle .= 'margin-left:' . $marginLeft . 'px;'; } + $imgStyle.='position:absolute;mso-width-percent:0;mso-height-percent:0;mso-width-relative:margin;mso-height-relative:margin;'; + switch ($positioning) { + case ImageStyle::POSITION_RELATIVE: + $imgStyle.='mso-position-horizontal:'.$style->getPosHorizontal().';'; + $imgStyle.='mso-position-horizontal-relative:'.$style->getPosHorizontalRel().';'; + $imgStyle.='mso-position-vertical:'.$style->getPosVertical().';'; + $imgStyle.='mso-position-vertical-relative:'.$style->getPosVerticalRel().';'; + $imgStyle.='margin-left:0;margin-top:0;'; + break; + + case ImageStyle::POSITION_ABSOLUTE: + $imgStyle.='mso-position-horizontal-relative:page;'; + $imgStyle.='mso-position-vertical-relative:page;'; + break; + } + switch ($wrappingStyle) { case ImageStyle::WRAPPING_STYLE_BEHIND: - $imgStyle .= 'position:absolute;z-index:-251658752;'; + $imgStyle .= 'z-index:-251658752;'; break; case ImageStyle::WRAPPING_STYLE_INFRONT: - $imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; + $imgStyle .= 'z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; break; case ImageStyle::WRAPPING_STYLE_SQUARE: - $imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; + $imgStyle .= 'z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; $w10wrapType = 'square'; break; case ImageStyle::WRAPPING_STYLE_TIGHT: - $imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; + $imgStyle .= 'z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; $w10wrapType = 'tight'; break; } - + if (!$this->withoutP) { $this->xmlWriter->startElement('w:p'); if (!is_null($align)) { From 2187954b565acf4ae661c0715892136897125618 Mon Sep 17 00:00:00 2001 From: Bas-Jan 't Jong Date: Sun, 4 May 2014 10:16:28 +0200 Subject: [PATCH 2/4] Fixed bug in header, wherein all images were assigned to the first header in a section. This resulted in a corrupt DOCX --- src/PhpWord/Element/AbstractContainer.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 8af70d421d..b90f6d728a 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -249,7 +249,6 @@ public function addImage($src, $style = null, $isWatermark = false) $rId = Media::addElement($elementDocPart, 'image', $src, $image); $image->setRelationId($rId); $this->addElement($image); - return $image; } @@ -413,7 +412,7 @@ private function checkElementDocPart() $docPart = $isCellTextrun ? $this->getDocPart() : $this->container; $docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId; $inHeaderFooter = ($docPart == 'header' || $docPart == 'footer'); - + $docPartId = $inHeaderFooter ? $this->getDocPartId() : $docPartId; return $inHeaderFooter ? $docPart . $docPartId : $docPart; } From 15dcb384c64167fb33a6ac5f2989fc7bf513d134 Mon Sep 17 00:00:00 2001 From: Bas-Jan 't Jong Date: Sun, 4 May 2014 10:34:40 +0200 Subject: [PATCH 3/4] Messed up something. Resetting --- src/PhpWord/Element/AbstractContainer.php | 1 - src/PhpWord/Style/Image.php | 281 ++++++++++-------- src/PhpWord/Writer/Word2007/Element/Image.php | 30 +- 3 files changed, 169 insertions(+), 143 deletions(-) diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index b90f6d728a..ea3450a5fa 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -412,7 +412,6 @@ private function checkElementDocPart() $docPart = $isCellTextrun ? $this->getDocPart() : $this->container; $docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId; $inHeaderFooter = ($docPart == 'header' || $docPart == 'footer'); - $docPartId = $inHeaderFooter ? $this->getDocPartId() : $docPartId; return $inHeaderFooter ? $docPart . $docPartId : $docPart; } diff --git a/src/PhpWord/Style/Image.php b/src/PhpWord/Style/Image.php index 7aabdeb2ff..a035be6ea3 100644 --- a/src/PhpWord/Style/Image.php +++ b/src/PhpWord/Style/Image.php @@ -1,4 +1,5 @@ width = null; - $this->height = null; - $this->align = null; - $this->marginTop = null; - $this->marginLeft = null; - $this->setWrappingStyle(self::WRAPPING_STYLE_INLINE); - $this->setPositioning(self::POSITION_RELATIVE); - $this->setPosHorizontal(self::POSITION_HORIZONTAL_LEFT); - $this->setPosHorizontalRel(self::POSITION_HORIZONTAL_RELATIVE_CHAR); - $this->setPosVertical(self::POSITION_VERTICAL_TOP); - $this->setPosVerticalRel(self::POSITION_VERTICAL_RELATIVE_LINE); + $this->width = null; + $this->height = null; + $this->align = null; + $this->marginTop = null; + $this->marginLeft = null; + $this->setWrappingStyle(self::WRAPPING_STYLE_INLINE); + $this->setPositioning(self::POSITION_RELATIVE); + $this->setPosHorizontal(self::POSITION_HORIZONTAL_LEFT); + $this->setPosHorizontalRel(self::POSITION_HORIZONTAL_RELATIVE_CHAR); + $this->setPosVertical(self::POSITION_VERTICAL_TOP); + $this->setPosVerticalRel(self::POSITION_VERTICAL_RELATIVE_LINE); } /** @@ -146,17 +175,17 @@ public function __construct() */ public function getWidth() { - return $this->width; + return $this->width; } /** * Set width * - * @param int $pValue + * @param int $pValue */ public function setWidth($pValue = null) { - $this->width = $pValue; + $this->width = $pValue; } /** @@ -164,17 +193,17 @@ public function setWidth($pValue = null) */ public function getHeight() { - return $this->height; + return $this->height; } /** * Set height * - * @param int $pValue + * @param int $pValue */ public function setHeight($pValue = null) { - $this->height = $pValue; + $this->height = $pValue; } /** @@ -182,17 +211,17 @@ public function setHeight($pValue = null) */ public function getAlign() { - return $this->align; + return $this->align; } /** * Set alignment * - * @param string $pValue + * @param string $pValue */ public function setAlign($pValue = null) { - $this->align = $pValue; + $this->align = $pValue; } /** @@ -202,19 +231,19 @@ public function setAlign($pValue = null) */ public function getMarginTop() { - return $this->marginTop; + return $this->marginTop; } /** * Set Margin Top * - * @param int $pValue + * @param int $pValue * @return $this */ public function setMarginTop($pValue = null) { - $this->marginTop = $pValue; - return $this; + $this->marginTop = $pValue; + return $this; } /** @@ -224,25 +253,25 @@ public function setMarginTop($pValue = null) */ public function getMarginLeft() { - return $this->marginLeft; + return $this->marginLeft; } /** * Set Margin Left * - * @param int $pValue + * @param int $pValue * @return $this */ public function setMarginLeft($pValue = null) { - $this->marginLeft = $pValue; - return $this; + $this->marginLeft = $pValue; + return $this; } /** * Set wrapping style * - * @param string $wrappingStyle + * @param string $wrappingStyle * @throws \InvalidArgumentException * @return $this */ @@ -269,178 +298,176 @@ public function setWrappingStyle($wrappingStyle) */ public function getWrappingStyle() { - return $this->wrappingStyle; + return $this->wrappingStyle; } /** * Set positioning type * - * @param string $positioning + * @param string $positioning * @throws \InvalidArgumentException * @return $this */ - public function setPositioning($positioning) { - switch ($positioning) { - case self::POSITION_RELATIVE: - case self::POSITION_ABSOLUTE: - $this->positioning = $positioning; - break; - default: - throw new InvalidArgumentException('Positioning does not exists'); - break; - } - return $this; + switch ($positioning) { + case self::POSITION_RELATIVE: + case self::POSITION_ABSOLUTE: + $this->positioning = $positioning; + break; + default: + throw new InvalidArgumentException('Positioning does not exists'); + break; + } + return $this; } - + /** * Get positioning type - * + * * @return string */ public function getPositioning() { - return $this->positioning; + return $this->positioning; } /** * Set horizontal alignment * - * @param string $alignment + * @param string $alignment * @throws \InvalidArgumentException * @return $this */ public function setPosHorizontal($alignment) { - switch ($alignment) { - case self::POSITION_HORIZONTAL_LEFT: - case self::POSITION_HORIZONTAL_CENTER: - case self::POSITION_HORIZONTAL_RIGHT: - $this->posHorizontal = $alignment; - break; - default: - throw new InvalidArgumentException('Horizontal alignment does not exists'); - break; - } - return $this; + switch ($alignment) { + case self::POSITION_HORIZONTAL_LEFT: + case self::POSITION_HORIZONTAL_CENTER: + case self::POSITION_HORIZONTAL_RIGHT: + $this->posHorizontal = $alignment; + break; + default: + throw new InvalidArgumentException('Horizontal alignment does not exists'); + break; + } + return $this; } - + /** * Get horizontal alignment - * + * * @return string */ public function getPosHorizontal() { - return $this->posHorizontal; + return $this->posHorizontal; } /** * Set vertical alignment * - * @param string $alignment + * @param string $alignment * @throws \InvalidArgumentException * @return $this */ - public function setPosVertical($alignment) { - switch ($alignment) { - case self::POSITION_VERTICAL_TOP: - case self::POSITION_VERTICAL_CENTER: - case self::POSITION_VERTICAL_BOTTOM: - case self::POSITION_VERTICAL_INSIDE: - case self::POSITION_VERTICAL_OUTSIDE: - $this->posVertical = $alignment; - break; - default: - throw new InvalidArgumentException('Vertical alignment does not exists'); - break; - } - return $this; + switch ($alignment) { + case self::POSITION_VERTICAL_TOP: + case self::POSITION_VERTICAL_CENTER: + case self::POSITION_VERTICAL_BOTTOM: + case self::POSITION_VERTICAL_INSIDE: + case self::POSITION_VERTICAL_OUTSIDE: + $this->posVertical = $alignment; + break; + default: + throw new InvalidArgumentException('Vertical alignment does not exists'); + break; + } + return $this; } - + /** * Get vertical alignment - * + * * @return string */ public function getPosVertical() { - return $this->posVertical; + return $this->posVertical; } - + /** * Set horizontal relation * - * @param string $relto + * @param string $relto * @throws \InvalidArgumentException * @return $this */ public function setPosHorizontalRel($relto) { - switch ($relto) { - case self::POSITION_HORIZONTAL_RELATIVE_MARGIN: - case self::POSITION_HORIZONTAL_RELATIVE_PAGE: - case self::POSITION_HORIZONTAL_RELATIVE_COLUMN: - case self::POSITION_HORIZONTAL_RELATIVE_CHAR: - case self::POSITION_HORIZONTAL_RELATIVE_LMARGIN: - case self::POSITION_HORIZONTAL_RELATIVE_RMARGIN: - case self::POSITION_HORIZONTAL_RELATIVE_IMARGIN: - case self::POSITION_HORIZONTAL_RELATIVE_OMARGIN: - $this->posHorizontalRel = $relto; - break; - default: - throw new InvalidArgumentException('Horizontal relation does not exists'); - break; - } - return $this; + switch ($relto) { + case self::POSITION_HORIZONTAL_RELATIVE_MARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_PAGE: + case self::POSITION_HORIZONTAL_RELATIVE_COLUMN: + case self::POSITION_HORIZONTAL_RELATIVE_CHAR: + case self::POSITION_HORIZONTAL_RELATIVE_LMARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_RMARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_IMARGIN: + case self::POSITION_HORIZONTAL_RELATIVE_OMARGIN: + $this->posHorizontalRel = $relto; + break; + default: + throw new InvalidArgumentException('Horizontal relation does not exists'); + break; + } + return $this; } - + /** * Get horizontal relation - * + * * @return string */ public function getPosHorizontalRel() { - return $this->posHorizontalRel; + return $this->posHorizontalRel; } - + /** * Set vertical relation * - * @param string $relto + * @param string $relto * @throws \InvalidArgumentException * @return $this */ public function setPosVerticalRel($relto) { - switch ($relto) { - case self::POSITION_VERTICAL_RELATIVE_MARGIN: - case self::POSITION_VERTICAL_RELATIVE_PAGE: - case self::POSITION_VERTICAL_RELATIVE_LINE: - case self::POSITION_VERTICAL_RELATIVE_TMARGIN: - case self::POSITION_VERTICAL_RELATIVE_BMARGIN: - case self::POSITION_VERTICAL_RELATIVE_IMARGIN: - case self::POSITION_VERTICAL_RELATIVE_OMARGIN: - $this->posVerticalRel = $relto; - break; - default: - throw new InvalidArgumentException('Vertical relation does not exists'); - break; - } - return $this; + switch ($relto) { + case self::POSITION_VERTICAL_RELATIVE_MARGIN: + case self::POSITION_VERTICAL_RELATIVE_PAGE: + case self::POSITION_VERTICAL_RELATIVE_LINE: + case self::POSITION_VERTICAL_RELATIVE_TMARGIN: + case self::POSITION_VERTICAL_RELATIVE_BMARGIN: + case self::POSITION_VERTICAL_RELATIVE_IMARGIN: + case self::POSITION_VERTICAL_RELATIVE_OMARGIN: + $this->posVerticalRel = $relto; + break; + default: + throw new InvalidArgumentException('Vertical relation does not exists'); + break; + } + return $this; } - + /** * Get vertical relation - * + * * @return string */ public function getPosVerticalRel() { - return $this->posVerticalRel; + return $this->posVerticalRel; } } diff --git a/src/PhpWord/Writer/Word2007/Element/Image.php b/src/PhpWord/Writer/Word2007/Element/Image.php index 80b71121da..eb73536d16 100644 --- a/src/PhpWord/Writer/Word2007/Element/Image.php +++ b/src/PhpWord/Writer/Word2007/Element/Image.php @@ -59,21 +59,21 @@ private function writeImage() if (null !== $marginLeft) { $imgStyle .= 'margin-left:' . $marginLeft . 'px;'; } - $imgStyle.='position:absolute;mso-width-percent:0;mso-height-percent:0;mso-width-relative:margin;mso-height-relative:margin;'; - switch ($positioning) { - case ImageStyle::POSITION_RELATIVE: - $imgStyle.='mso-position-horizontal:'.$style->getPosHorizontal().';'; - $imgStyle.='mso-position-horizontal-relative:'.$style->getPosHorizontalRel().';'; - $imgStyle.='mso-position-vertical:'.$style->getPosVertical().';'; - $imgStyle.='mso-position-vertical-relative:'.$style->getPosVerticalRel().';'; - $imgStyle.='margin-left:0;margin-top:0;'; - break; - - case ImageStyle::POSITION_ABSOLUTE: - $imgStyle.='mso-position-horizontal-relative:page;'; - $imgStyle.='mso-position-vertical-relative:page;'; - break; - } + $imgStyle.='position:absolute;mso-width-percent:0;mso-height-percent:0;'; + $imgStyle.='mso-width-relative:margin;mso-height-relative:margin;'; + switch ($positioning) { + case ImageStyle::POSITION_RELATIVE: + $imgStyle.='mso-position-horizontal:'.$style->getPosHorizontal().';'; + $imgStyle.='mso-position-horizontal-relative:'.$style->getPosHorizontalRel().';'; + $imgStyle.='mso-position-vertical:'.$style->getPosVertical().';'; + $imgStyle.='mso-position-vertical-relative:'.$style->getPosVerticalRel().';'; + $imgStyle.='margin-left:0;margin-top:0;'; + break; + case ImageStyle::POSITION_ABSOLUTE: + $imgStyle.='mso-position-horizontal-relative:page;'; + $imgStyle.='mso-position-vertical-relative:page;'; + break; + } switch ($wrappingStyle) { case ImageStyle::WRAPPING_STYLE_BEHIND: From 1a544cb2fa3c20015892fc19f5f5bce9448f5324 Mon Sep 17 00:00:00 2001 From: Bas-Jan 't Jong Date: Sun, 4 May 2014 10:36:13 +0200 Subject: [PATCH 4/4] Fixed bug in header / footer, in which media elements were all assigned to the first header element. This resulted in a corrupted DOCX, when a media element was assigned to a second header in the same section. --- src/PhpWord/Element/AbstractContainer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index ea3450a5fa..b90f6d728a 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -412,6 +412,7 @@ private function checkElementDocPart() $docPart = $isCellTextrun ? $this->getDocPart() : $this->container; $docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId; $inHeaderFooter = ($docPart == 'header' || $docPart == 'footer'); + $docPartId = $inHeaderFooter ? $this->getDocPartId() : $docPartId; return $inHeaderFooter ? $docPart . $docPartId : $docPart; }