diff --git a/src/PHPWord/Autoloader.php b/src/PHPWord/Autoloader.php index 86ad651d..dc48ef91 100644 --- a/src/PHPWord/Autoloader.php +++ b/src/PHPWord/Autoloader.php @@ -27,23 +27,35 @@ class PHPWord_Autoloader { - public static function Register() + /** + * Register the autoloader + * + * @return void + */ + public static function register() { - return spl_autoload_register(array('PHPWord_Autoloader', 'Load')); + spl_autoload_register(array('PHPWord_Autoloader', 'load')); } - public static function Load($strObjectName) + /** + * Autoloader + * + * @param string $strObjectName + * @return mixed + */ + public static function load($strObjectName) { if ((class_exists($strObjectName)) || (strpos($strObjectName, 'PHPWord') === false)) { - return false; + return null; } $strObjectFilePath = PHPWORD_BASE_PATH . str_replace('_', '/', $strObjectName) . '.php'; if ((file_exists($strObjectFilePath) === false) || (is_readable($strObjectFilePath) === false)) { - return false; + return null; } - require($strObjectFilePath); + require_once $strObjectFilePath; + return true; } -} +} \ No newline at end of file diff --git a/src/PHPWord/Section/Image.php b/src/PHPWord/Section/Image.php index 68ac3065..3df4f9e8 100644 --- a/src/PHPWord/Section/Image.php +++ b/src/PHPWord/Section/Image.php @@ -92,6 +92,10 @@ class PHPWord_Section_Image } } + if (isset($style['wrappingStyle'])) { + $this->_style->setWrappingStyle($style['wrappingStyle']); + } + if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) { $imgData = getimagesize($this->_src); $this->_style->setWidth($imgData[0]); @@ -173,5 +177,4 @@ class PHPWord_Section_Image { $this->_isWatermark = $pValue; } -} - +} \ No newline at end of file diff --git a/src/PHPWord/Shared/XMLWriter.php b/src/PHPWord/Shared/XMLWriter.php index 5f699cdc..7d62b82a 100644 --- a/src/PHPWord/Shared/XMLWriter.php +++ b/src/PHPWord/Shared/XMLWriter.php @@ -30,7 +30,16 @@ if (!defined('DATE_W3C')) { define('DATE_W3C', 'Y-m-d\TH:i:sP'); } - +/** + * Class PHPWord_Shared_XMLWriter + * + * @category PHPWord + * @package PHPWord_Section + * @copyright Copyright (c) 2011 PHPWord + * @method bool startElement(string $name) + * @method bool writeAttribute(string $name, string $value) + * @method bool endElement() + */ class PHPWord_Shared_XMLWriter { /** Temporary storage method */ @@ -145,4 +154,4 @@ class PHPWord_Shared_XMLWriter return $this->text($text); } -} +} \ No newline at end of file diff --git a/src/PHPWord/Style/Image.php b/src/PHPWord/Style/Image.php index 1c93674f..556d53f3 100644 --- a/src/PHPWord/Style/Image.php +++ b/src/PHPWord/Style/Image.php @@ -35,10 +35,16 @@ */ class PHPWord_Style_Image { + const WRAPPING_STYLE_INLINE = 'inline'; + const WRAPPING_STYLE_SQUARE = 'square'; + const WRAPPING_STYLE_TIGHT = 'tight'; + const WRAPPING_STYLE_BEHIND = 'behind'; + const WRAPPING_STYLE_INFRONT = 'infront'; private $_width; private $_height; private $_align; + private $wrappingStyle; /** * Margin Top @@ -61,6 +67,7 @@ class PHPWord_Style_Image $this->_align = null; $this->_marginTop = null; $this->_marginLeft = null; + $this->setWrappingStyle(self::WRAPPING_STYLE_INLINE); } public function setStyleValue($key, $value) @@ -112,6 +119,7 @@ class PHPWord_Style_Image * Set Margin Top * * @param int $pValue + * @return $this */ public function setMarginTop($pValue = null) { @@ -133,10 +141,41 @@ class PHPWord_Style_Image * Set Margin Left * * @param int $pValue + * @return $this */ public function setMarginLeft($pValue = null) { $this->_marginLeft = $pValue; return $this; } -} + + /** + * @param string $wrappingStyle + * @throws InvalidArgumentException + * @return $this + */ + public function setWrappingStyle($wrappingStyle) + { + switch ($wrappingStyle) { + case self::WRAPPING_STYLE_BEHIND: + case self::WRAPPING_STYLE_INFRONT: + case self::WRAPPING_STYLE_INLINE: + case self::WRAPPING_STYLE_SQUARE: + case self::WRAPPING_STYLE_TIGHT: + $this->wrappingStyle = $wrappingStyle; + break; + default: + throw new InvalidArgumentException('Wrapping style does not exists'); + break; + } + return $this; + } + + /** + * @return string + */ + public function getWrappingStyle() + { + return $this->wrappingStyle; + } +} \ No newline at end of file diff --git a/src/PHPWord/Writer/Word2007/Base.php b/src/PHPWord/Writer/Word2007/Base.php index b55dcb2c..ae39e1bd 100644 --- a/src/PHPWord/Writer/Word2007/Base.php +++ b/src/PHPWord/Writer/Word2007/Base.php @@ -608,7 +608,11 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart } } - protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, $image) + /** + * @param \PHPWord_Shared_XMLWriter $objWriter + * @param \PHPWord_Section_Image $image + */ + protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Image $image) { $rId = $image->getRelationId(); @@ -616,6 +620,9 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $width = $style->getWidth(); $height = $style->getHeight(); $align = $style->getAlign(); + $marginTop = $style->getMarginTop(); + $marginLeft = $style->getMarginLeft(); + $wrappingStyle = $style->getWrappingStyle(); $objWriter->startElement('w:p'); @@ -633,7 +640,37 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->startElement('v:shape'); $objWriter->writeAttribute('type', '#_x0000_t75'); - $objWriter->writeAttribute('style', 'width:' . $width . 'px;height:' . $height . 'px'); + + $imgStyle = ''; + if (null !== $width) { + $imgStyle .= 'width:' . $width . 'px;'; + } + if (null !== $height) { + $imgStyle .= 'height:' . $height . 'px;'; + } + if (null !== $marginTop) { + $imgStyle .= 'margin-top:' . $marginTop . 'in;'; + } + if (null !== $marginLeft) { + $imgStyle .= 'margin-left:' . $marginLeft . 'in;'; + } + + switch ($wrappingStyle) { + case PHPWord_Style_Image::WRAPPING_STYLE_BEHIND: + $imgStyle .= 'position:absolute;z-index:-251658752;'; + break; + case PHPWord_Style_Image::WRAPPING_STYLE_SQUARE: + $imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; + break; + case PHPWord_Style_Image::WRAPPING_STYLE_TIGHT: + $imgStyle .= 'position:absolute;z-index:251659264;mso-wrap-edited:f;mso-position-horizontal:absolute;mso-position-vertical:absolute'; + break; + case PHPWord_Style_Image::WRAPPING_STYLE_INFRONT: + $imgStyle .= 'position:absolute;zz-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; + break; + } + + $objWriter->writeAttribute('style', $imgStyle); $objWriter->startElement('v:imagedata'); $objWriter->writeAttribute('r:id', 'rId' . $rId); @@ -733,4 +770,4 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart $objWriter->endElement(); } -} +} \ No newline at end of file