Skip to content

Commit fbce1c8

Browse files
committed
#244: Enable "image float left"
1 parent d764de0 commit fbce1c8

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
2727
- ODT Writer: Enable title element and custom document properties - @ivanlanin
2828
- ODT Reader: Ability to read standard and custom document properties - @ivanlanin
2929
- Word2007 Writer: Enable the missing custom document properties writer - @ivanlanin
30+
- Image: Enable "image float left" - @ivanlanin GH-244
3031

3132
### Bugfixes
3233

samples/Sample_13_Images.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
4141
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
4242
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
43+
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
44+
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
45+
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
4346
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.5),
4447
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1.55)
4548
)

src/PhpWord/Style/Image.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Image extends AbstractStyle
6161
const POSITION_RELATIVE_TO_PAGE = 'page';
6262
const POSITION_RELATIVE_TO_COLUMN = 'column'; // horizontal only
6363
const POSITION_RELATIVE_TO_CHAR = 'char'; // horizontal only
64+
const POSITION_RELATIVE_TO_TEXT = 'text'; // vertical only
6465
const POSITION_RELATIVE_TO_LINE = 'line'; // vertical only
6566
const POSITION_RELATIVE_TO_LMARGIN = 'left-margin-area'; // horizontal only
6667
const POSITION_RELATIVE_TO_RMARGIN = 'right-margin-area'; // horizontal only
@@ -103,14 +104,14 @@ class Image extends AbstractStyle
103104
*
104105
* @var int
105106
*/
106-
private $marginTop;
107+
private $marginTop = 0;
107108

108109
/**
109110
* Margin Left
110111
*
111112
* @var int
112113
*/
113-
private $marginLeft;
114+
private $marginLeft = 0;
114115

115116
/**
116117
* Wrapping style
@@ -247,9 +248,9 @@ public function getMarginTop()
247248
* @param int $value
248249
* @return self
249250
*/
250-
public function setMarginTop($value = null)
251+
public function setMarginTop($value = 0)
251252
{
252-
$this->marginTop = $value;
253+
$this->marginTop = $this->setIntVal($value, 0);
253254

254255
return $this;
255256
}
@@ -270,9 +271,9 @@ public function getMarginLeft()
270271
* @param int $value
271272
* @return self
272273
*/
273-
public function setMarginLeft($value = null)
274+
public function setMarginLeft($value = 0)
274275
{
275-
$this->marginLeft = $value;
276+
$this->marginLeft = $this->setIntVal($value, 0);
276277

277278
return $this;
278279
}
@@ -352,7 +353,7 @@ public function setPosHorizontal($alignment)
352353
{
353354
$enum = array(
354355
self::POSITION_HORIZONTAL_LEFT, self::POSITION_HORIZONTAL_CENTER,
355-
self::POSITION_HORIZONTAL_RIGHT,
356+
self::POSITION_HORIZONTAL_RIGHT, self::POSITION_ABSOLUTE
356357
);
357358
$this->posHorizontal = $this->setEnumVal($alignment, $enum, $this->posHorizontal);
358359

@@ -381,7 +382,7 @@ public function setPosVertical($alignment)
381382
$enum = array(
382383
self::POSITION_VERTICAL_TOP, self::POSITION_VERTICAL_CENTER,
383384
self::POSITION_VERTICAL_BOTTOM, self::POSITION_VERTICAL_INSIDE,
384-
self::POSITION_VERTICAL_OUTSIDE,
385+
self::POSITION_VERTICAL_OUTSIDE, self::POSITION_ABSOLUTE
385386
);
386387
$this->posVertical = $this->setEnumVal($alignment, $enum, $this->posVertical);
387388

@@ -439,7 +440,7 @@ public function setPosVerticalRel($relto)
439440
{
440441
$enum = array(
441442
self::POSITION_RELATIVE_TO_MARGIN, self::POSITION_RELATIVE_TO_PAGE,
442-
self::POSITION_RELATIVE_TO_LINE,
443+
self::POSITION_RELATIVE_TO_TEXT, self::POSITION_RELATIVE_TO_LINE,
443444
self::POSITION_RELATIVE_TO_TMARGIN, self::POSITION_RELATIVE_TO_BMARGIN,
444445
self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN,
445446
);

src/PhpWord/Writer/Word2007/Style/Image.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,11 @@ protected function writeStyle(ImageStyle $style)
6565
// Absolute/relative positioning
6666
$positioning = $style->getPositioning();
6767
$styleArray['position'] = $positioning;
68-
if ($positioning == ImageStyle::POSITION_ABSOLUTE) {
69-
$styleArray['mso-position-horizontal-relative'] = 'page';
70-
$styleArray['mso-position-vertical-relative'] = 'page';
71-
} elseif ($positioning == ImageStyle::POSITION_RELATIVE) {
68+
if ($positioning !== null) {
7269
$styleArray['mso-position-horizontal'] = $style->getPosHorizontal();
7370
$styleArray['mso-position-vertical'] = $style->getPosVertical();
7471
$styleArray['mso-position-horizontal-relative'] = $style->getPosHorizontalRel();
7572
$styleArray['mso-position-vertical-relative'] = $style->getPosVerticalRel();
76-
$styleArray['margin-left'] = 0;
77-
$styleArray['margin-top'] = 0;
7873
}
7974

8075
// Wrapping style

0 commit comments

Comments
 (0)