Skip to content

Commit

Permalink
PHPOffice#244: Enable "image float left"
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanlanin committed May 21, 2014
1 parent d764de0 commit fbce1c8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
- ODT Writer: Enable title element and custom document properties - @ivanlanin
- ODT Reader: Ability to read standard and custom document properties - @ivanlanin
- Word2007 Writer: Enable the missing custom document properties writer - @ivanlanin
- Image: Enable "image float left" - @ivanlanin GH-244

### Bugfixes

Expand Down
3 changes: 3 additions & 0 deletions samples/Sample_13_Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.5),
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1.55)
)
Expand Down
19 changes: 10 additions & 9 deletions src/PhpWord/Style/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Image extends AbstractStyle
const POSITION_RELATIVE_TO_PAGE = 'page';
const POSITION_RELATIVE_TO_COLUMN = 'column'; // horizontal only
const POSITION_RELATIVE_TO_CHAR = 'char'; // horizontal only
const POSITION_RELATIVE_TO_TEXT = 'text'; // vertical only
const POSITION_RELATIVE_TO_LINE = 'line'; // vertical only
const POSITION_RELATIVE_TO_LMARGIN = 'left-margin-area'; // horizontal only
const POSITION_RELATIVE_TO_RMARGIN = 'right-margin-area'; // horizontal only
Expand Down Expand Up @@ -103,14 +104,14 @@ class Image extends AbstractStyle
*
* @var int
*/
private $marginTop;
private $marginTop = 0;

/**
* Margin Left
*
* @var int
*/
private $marginLeft;
private $marginLeft = 0;

/**
* Wrapping style
Expand Down Expand Up @@ -247,9 +248,9 @@ public function getMarginTop()
* @param int $value
* @return self
*/
public function setMarginTop($value = null)
public function setMarginTop($value = 0)
{
$this->marginTop = $value;
$this->marginTop = $this->setIntVal($value, 0);

return $this;
}
Expand All @@ -270,9 +271,9 @@ public function getMarginLeft()
* @param int $value
* @return self
*/
public function setMarginLeft($value = null)
public function setMarginLeft($value = 0)
{
$this->marginLeft = $value;
$this->marginLeft = $this->setIntVal($value, 0);

return $this;
}
Expand Down Expand Up @@ -352,7 +353,7 @@ public function setPosHorizontal($alignment)
{
$enum = array(
self::POSITION_HORIZONTAL_LEFT, self::POSITION_HORIZONTAL_CENTER,
self::POSITION_HORIZONTAL_RIGHT,
self::POSITION_HORIZONTAL_RIGHT, self::POSITION_ABSOLUTE
);
$this->posHorizontal = $this->setEnumVal($alignment, $enum, $this->posHorizontal);

Expand Down Expand Up @@ -381,7 +382,7 @@ public function setPosVertical($alignment)
$enum = array(
self::POSITION_VERTICAL_TOP, self::POSITION_VERTICAL_CENTER,
self::POSITION_VERTICAL_BOTTOM, self::POSITION_VERTICAL_INSIDE,
self::POSITION_VERTICAL_OUTSIDE,
self::POSITION_VERTICAL_OUTSIDE, self::POSITION_ABSOLUTE
);
$this->posVertical = $this->setEnumVal($alignment, $enum, $this->posVertical);

Expand Down Expand Up @@ -439,7 +440,7 @@ public function setPosVerticalRel($relto)
{
$enum = array(
self::POSITION_RELATIVE_TO_MARGIN, self::POSITION_RELATIVE_TO_PAGE,
self::POSITION_RELATIVE_TO_LINE,
self::POSITION_RELATIVE_TO_TEXT, self::POSITION_RELATIVE_TO_LINE,
self::POSITION_RELATIVE_TO_TMARGIN, self::POSITION_RELATIVE_TO_BMARGIN,
self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN,
);
Expand Down
7 changes: 1 addition & 6 deletions src/PhpWord/Writer/Word2007/Style/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,11 @@ protected function writeStyle(ImageStyle $style)
// Absolute/relative positioning
$positioning = $style->getPositioning();
$styleArray['position'] = $positioning;
if ($positioning == ImageStyle::POSITION_ABSOLUTE) {
$styleArray['mso-position-horizontal-relative'] = 'page';
$styleArray['mso-position-vertical-relative'] = 'page';
} elseif ($positioning == ImageStyle::POSITION_RELATIVE) {
if ($positioning !== null) {
$styleArray['mso-position-horizontal'] = $style->getPosHorizontal();
$styleArray['mso-position-vertical'] = $style->getPosVertical();
$styleArray['mso-position-horizontal-relative'] = $style->getPosHorizontalRel();
$styleArray['mso-position-vertical-relative'] = $style->getPosVerticalRel();
$styleArray['margin-left'] = 0;
$styleArray['margin-top'] = 0;
}

// Wrapping style
Expand Down

0 comments on commit fbce1c8

Please sign in to comment.