#244: Enable "image float left"

This commit is contained in:
Ivan Lanin 2014-05-21 23:53:08 +07:00
parent d764de018c
commit fbce1c8fc9
4 changed files with 15 additions and 15 deletions

View File

@ -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 Writer: Enable title element and custom document properties - @ivanlanin
- ODT Reader: Ability to read standard 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 - Word2007 Writer: Enable the missing custom document properties writer - @ivanlanin
- Image: Enable "image float left" - @ivanlanin GH-244
### Bugfixes ### Bugfixes

View File

@ -40,6 +40,9 @@ $section->addImage(
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3), 'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, '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), 'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.5),
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1.55) 'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1.55)
) )

View File

@ -61,6 +61,7 @@ class Image extends AbstractStyle
const POSITION_RELATIVE_TO_PAGE = 'page'; const POSITION_RELATIVE_TO_PAGE = 'page';
const POSITION_RELATIVE_TO_COLUMN = 'column'; // horizontal only const POSITION_RELATIVE_TO_COLUMN = 'column'; // horizontal only
const POSITION_RELATIVE_TO_CHAR = 'char'; // 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_LINE = 'line'; // vertical only
const POSITION_RELATIVE_TO_LMARGIN = 'left-margin-area'; // horizontal only const POSITION_RELATIVE_TO_LMARGIN = 'left-margin-area'; // horizontal only
const POSITION_RELATIVE_TO_RMARGIN = 'right-margin-area'; // horizontal only const POSITION_RELATIVE_TO_RMARGIN = 'right-margin-area'; // horizontal only
@ -103,14 +104,14 @@ class Image extends AbstractStyle
* *
* @var int * @var int
*/ */
private $marginTop; private $marginTop = 0;
/** /**
* Margin Left * Margin Left
* *
* @var int * @var int
*/ */
private $marginLeft; private $marginLeft = 0;
/** /**
* Wrapping style * Wrapping style
@ -247,9 +248,9 @@ class Image extends AbstractStyle
* @param int $value * @param int $value
* @return self * @return self
*/ */
public function setMarginTop($value = null) public function setMarginTop($value = 0)
{ {
$this->marginTop = $value; $this->marginTop = $this->setIntVal($value, 0);
return $this; return $this;
} }
@ -270,9 +271,9 @@ class Image extends AbstractStyle
* @param int $value * @param int $value
* @return self * @return self
*/ */
public function setMarginLeft($value = null) public function setMarginLeft($value = 0)
{ {
$this->marginLeft = $value; $this->marginLeft = $this->setIntVal($value, 0);
return $this; return $this;
} }
@ -352,7 +353,7 @@ class Image extends AbstractStyle
{ {
$enum = array( $enum = array(
self::POSITION_HORIZONTAL_LEFT, self::POSITION_HORIZONTAL_CENTER, 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); $this->posHorizontal = $this->setEnumVal($alignment, $enum, $this->posHorizontal);
@ -381,7 +382,7 @@ class Image extends AbstractStyle
$enum = array( $enum = array(
self::POSITION_VERTICAL_TOP, self::POSITION_VERTICAL_CENTER, self::POSITION_VERTICAL_TOP, self::POSITION_VERTICAL_CENTER,
self::POSITION_VERTICAL_BOTTOM, self::POSITION_VERTICAL_INSIDE, 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); $this->posVertical = $this->setEnumVal($alignment, $enum, $this->posVertical);
@ -439,7 +440,7 @@ class Image extends AbstractStyle
{ {
$enum = array( $enum = array(
self::POSITION_RELATIVE_TO_MARGIN, self::POSITION_RELATIVE_TO_PAGE, 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_TMARGIN, self::POSITION_RELATIVE_TO_BMARGIN,
self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN, self::POSITION_RELATIVE_TO_IMARGIN, self::POSITION_RELATIVE_TO_OMARGIN,
); );

View File

@ -65,16 +65,11 @@ class Image extends AbstractStyle
// Absolute/relative positioning // Absolute/relative positioning
$positioning = $style->getPositioning(); $positioning = $style->getPositioning();
$styleArray['position'] = $positioning; $styleArray['position'] = $positioning;
if ($positioning == ImageStyle::POSITION_ABSOLUTE) { if ($positioning !== null) {
$styleArray['mso-position-horizontal-relative'] = 'page';
$styleArray['mso-position-vertical-relative'] = 'page';
} elseif ($positioning == ImageStyle::POSITION_RELATIVE) {
$styleArray['mso-position-horizontal'] = $style->getPosHorizontal(); $styleArray['mso-position-horizontal'] = $style->getPosHorizontal();
$styleArray['mso-position-vertical'] = $style->getPosVertical(); $styleArray['mso-position-vertical'] = $style->getPosVertical();
$styleArray['mso-position-horizontal-relative'] = $style->getPosHorizontalRel(); $styleArray['mso-position-horizontal-relative'] = $style->getPosHorizontalRel();
$styleArray['mso-position-vertical-relative'] = $style->getPosVerticalRel(); $styleArray['mso-position-vertical-relative'] = $style->getPosVerticalRel();
$styleArray['margin-left'] = 0;
$styleArray['margin-top'] = 0;
} }
// Wrapping style // Wrapping style