This commit is contained in:
Roman Syroeshko 2014-03-22 10:08:04 +04:00
parent ab96c75b08
commit 667d0aaad1
85 changed files with 0 additions and 15760 deletions

View File

@ -1,234 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Template;
/** PHPWORD_BASE_PATH */
// @codeCoverageIgnoreStart
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
require PHPWORD_BASE_PATH . 'PhpWord/Autoloader.php';
PHPWord_Autoloader::Register();
}
// @codeCoverageIgnoreEnd
class PhpWord
{
const DEFAULT_FONT_COLOR = '000000'; // HEX
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
const DEFAULT_FONT_NAME = 'Arial';
/**
* Default font size, in points.
*
* OOXML defined font size values in halfpoints, i.e. twice of what PhpWord
* use, and the conversion will be conducted during XML writing.
*/
const DEFAULT_FONT_SIZE = 10;
/**
* @var PhpOffice\PhpWord\DocumentProperties
*/
private $_documentProperties;
/**
* @var string
*/
private $_defaultFontName;
/**
* @var int
*/
private $_defaultFontSize;
/**
* @var PhpOffice\PhpWord\Section[]
*/
private $_sections = array();
public function __construct()
{
$this->_documentProperties = new DocumentProperties();
$this->_defaultFontName = self::DEFAULT_FONT_NAME;
$this->_defaultFontSize = self::DEFAULT_FONT_SIZE;
}
/**
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function getDocumentProperties()
{
return $this->_documentProperties;
}
/**
* @param PhpOffice\PhpWord\DocumentProperties $documentProperties
* @return PhpOffice\PhpWord
*/
public function setDocumentProperties(DocumentProperties $documentProperties)
{
$this->_documentProperties = $documentProperties;
return $this;
}
/**
* @param PhpOffice\PhpWord\Section\Settings $settings
* @return PhpOffice\PhpWord\Section
*/
public function createSection($settings = null)
{
$section = new Section(\count($this->_sections) + 1, $settings);
$this->_sections[] = $section;
return $section;
}
/**
* @return string
*/
public function getDefaultFontName()
{
return $this->_defaultFontName;
}
/**
* @param string $fontName
*/
public function setDefaultFontName($fontName)
{
$this->_defaultFontName = $fontName;
}
/**
* @return string
*/
public function getDefaultFontSize()
{
return $this->_defaultFontSize;
}
/**
* @param int $fontSize
*/
public function setDefaultFontSize($fontSize)
{
$this->_defaultFontSize = $fontSize;
}
/**
* Set default paragraph style definition to styles.xml
*
* @param array $styles Paragraph style definition
*/
public function setDefaultParagraphStyle($styles)
{
Style::setDefaultParagraphStyle($styles);
}
/**
* Adds a paragraph style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addParagraphStyle($styleName, $styles)
{
Style::addParagraphStyle($styleName, $styles);
}
/**
* Adds a font style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addFontStyle($styleName, $styleFont, $styleParagraph = null)
{
Style::addFontStyle($styleName, $styleFont, $styleParagraph);
}
/**
* Adds a table style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
}
/**
* Adds a heading style definition to styles.xml
*
* @param $titleCount int
* @param $styles array
*/
public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
{
Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
}
/**
* Adds a hyperlink style to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addLinkStyle($styleName, $styles)
{
Style::addLinkStyle($styleName, $styles);
}
/**
* @return PhpOffice\PhpWord\Section[]
*/
public function getSections()
{
return $this->_sections;
}
/**
* @param string $filename Fully qualified filename.
* @return PhpOffice\PhpWord\Template
* @throws PhpOffice\PhpWord\Exceptions\Exception
*/
public function loadTemplate($filename)
{
if (\file_exists($filename)) {
return new Template($filename);
} else {
throw new Exception("Template file {$filename} not found.");
}
}
}

View File

@ -1,85 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', realpath(__DIR__ . '/../') . '/');
}
/**
* Class PHPWord_Autoloader
*
* TODO: remove legacy autoloader once everything is moved to namespaces
*/
class PHPWord_Autoloader
{
const PREFIX = 'PhpOffice\PhpWord';
/**
* Register the autoloader
*
* @return void
*/
public static function register()
{
spl_autoload_register(array('PHPWord_Autoloader', 'load')); // Legacy
spl_autoload_register(array(new self, 'autoload')); // PSR-4
}
/**
* Autoloader
*
* @param string $strObjectName
* @return mixed
*/
public static function load($strObjectName)
{
$strObjectFilePath = __DIR__ . '/../' . str_replace('_', '/', $strObjectName) . '.php';
if (file_exists($strObjectFilePath) && is_readable($strObjectFilePath)) {
require_once $strObjectFilePath;
return true;
}
return null;
}
/**
* Autoloader
*
* @param string
*/
public static function autoload($class)
{
$prefixLength = strlen(self::PREFIX);
if (0 === strncmp(self::PREFIX, $class, $prefixLength)) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
if (file_exists($file)) {
require_once $file;
}
}
}
}

View File

@ -1,606 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
class DocumentProperties
{
/** Constants */
const PROPERTY_TYPE_BOOLEAN = 'b';
const PROPERTY_TYPE_INTEGER = 'i';
const PROPERTY_TYPE_FLOAT = 'f';
const PROPERTY_TYPE_DATE = 'd';
const PROPERTY_TYPE_STRING = 's';
const PROPERTY_TYPE_UNKNOWN = 'u';
/**
* Creator
*
* @var string
*/
private $_creator;
/**
* LastModifiedBy
*
* @var string
*/
private $_lastModifiedBy;
/**
* Created
*
* @var datetime
*/
private $_created;
/**
* Modified
*
* @var datetime
*/
private $_modified;
/**
* Title
*
* @var string
*/
private $_title;
/**
* Description
*
* @var string
*/
private $_description;
/**
* Subject
*
* @var string
*/
private $_subject;
/**
* Keywords
*
* @var string
*/
private $_keywords;
/**
* Category
*
* @var string
*/
private $_category;
/**
* Company
*
* @var string
*/
private $_company;
/**
* Manager
*
* @var string
*/
private $_manager;
/**
* Custom Properties
*
* @var string
*/
private $_customProperties = array();
/**
* Create new DocumentProperties
*/
public function __construct()
{
$this->_creator = '';
$this->_lastModifiedBy = $this->_creator;
$this->_created = time();
$this->_modified = time();
$this->_title = '';
$this->_subject = '';
$this->_description = '';
$this->_keywords = '';
$this->_category = '';
$this->_company = '';
$this->_manager = '';
}
/**
* Get Creator
*
* @return string
*/
public function getCreator()
{
return $this->_creator;
}
/**
* Set Creator
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setCreator($pValue = '')
{
$this->_creator = $pValue;
return $this;
}
/**
* Get Last Modified By
*
* @return string
*/
public function getLastModifiedBy()
{
return $this->_lastModifiedBy;
}
/**
* Set Last Modified By
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setLastModifiedBy($pValue = '')
{
$this->_lastModifiedBy = $pValue;
return $this;
}
/**
* Get Created
*
* @return datetime
*/
public function getCreated()
{
return $this->_created;
}
/**
* Set Created
*
* @param datetime $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setCreated($pValue = null)
{
if (is_null($pValue)) {
$pValue = time();
}
$this->_created = $pValue;
return $this;
}
/**
* Get Modified
*
* @return datetime
*/
public function getModified()
{
return $this->_modified;
}
/**
* Set Modified
*
* @param datetime $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setModified($pValue = null)
{
if (is_null($pValue)) {
$pValue = time();
}
$this->_modified = $pValue;
return $this;
}
/**
* Get Title
*
* @return string
*/
public function getTitle()
{
return $this->_title;
}
/**
* Set Title
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setTitle($pValue = '')
{
$this->_title = $pValue;
return $this;
}
/**
* Get Description
*
* @return string
*/
public function getDescription()
{
return $this->_description;
}
/**
* Set Description
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setDescription($pValue = '')
{
$this->_description = $pValue;
return $this;
}
/**
* Get Subject
*
* @return string
*/
public function getSubject()
{
return $this->_subject;
}
/**
* Set Subject
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setSubject($pValue = '')
{
$this->_subject = $pValue;
return $this;
}
/**
* Get Keywords
*
* @return string
*/
public function getKeywords()
{
return $this->_keywords;
}
/**
* Set Keywords
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setKeywords($pValue = '')
{
$this->_keywords = $pValue;
return $this;
}
/**
* Get Category
*
* @return string
*/
public function getCategory()
{
return $this->_category;
}
/**
* Set Category
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setCategory($pValue = '')
{
$this->_category = $pValue;
return $this;
}
/**
* Get Company
*
* @return string
*/
public function getCompany()
{
return $this->_company;
}
/**
* Set Company
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setCompany($pValue = '')
{
$this->_company = $pValue;
return $this;
}
/**
* Get Manager
*
* @return string
*/
public function getManager()
{
return $this->_manager;
}
/**
* Set Manager
*
* @param string $pValue
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setManager($pValue = '')
{
$this->_manager = $pValue;
return $this;
}
/**
* Get a List of Custom Property Names
*
* @return array of string
*/
public function getCustomProperties()
{
return array_keys($this->_customProperties);
}
/**
* Check if a Custom Property is defined
*
* @param string $propertyName
* @return boolean
*/
public function isCustomPropertySet($propertyName)
{
return isset($this->_customProperties[$propertyName]);
}
/**
* Get a Custom Property Value
*
* @param string $propertyName
* @return string
*/
public function getCustomPropertyValue($propertyName)
{
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['value'];
}
}
/**
* Get a Custom Property Type
*
* @param string $propertyName
* @return string
*/
public function getCustomPropertyType($propertyName)
{
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['type'];
}
}
/**
* Set a Custom Property
*
* @param string $propertyName
* @param mixed $propertyValue
* @param string $propertyType
* 'i': Integer
* 'f': Floating Point
* 's': String
* 'd': Date/Time
* 'b': Boolean
* @return PhpOffice\PhpWord\DocumentProperties
*/
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
{
if (($propertyType === null) || (!in_array($propertyType, array(
self::PROPERTY_TYPE_INTEGER,
self::PROPERTY_TYPE_FLOAT,
self::PROPERTY_TYPE_STRING,
self::PROPERTY_TYPE_DATE,
self::PROPERTY_TYPE_BOOLEAN
)))) {
if ($propertyValue === null) {
$propertyType = self::PROPERTY_TYPE_STRING;
} elseif (is_float($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_FLOAT;
} elseif (is_int($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_INTEGER;
} elseif (is_bool($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_BOOLEAN;
} else {
$propertyType = self::PROPERTY_TYPE_STRING;
}
}
$this->_customProperties[$propertyName] = array(
'value' => $propertyValue,
'type' => $propertyType
);
return $this;
}
/**
* Convert document propery based on type
*
* @param mixed $propertyValue
* @param string $propertyType
* @return mixed
*/
public static function convertProperty($propertyValue, $propertyType)
{
switch ($propertyType) {
case 'empty': // Empty
return '';
break;
case 'null': // Null
return null;
break;
case 'i1': // 1-Byte Signed Integer
case 'i2': // 2-Byte Signed Integer
case 'i4': // 4-Byte Signed Integer
case 'i8': // 8-Byte Signed Integer
case 'int': // Integer
return (int) $propertyValue;
break;
case 'ui1': // 1-Byte Unsigned Integer
case 'ui2': // 2-Byte Unsigned Integer
case 'ui4': // 4-Byte Unsigned Integer
case 'ui8': // 8-Byte Unsigned Integer
case 'uint': // Unsigned Integer
return abs((int) $propertyValue);
break;
case 'r4': // 4-Byte Real Number
case 'r8': // 8-Byte Real Number
case 'decimal': // Decimal
return (float) $propertyValue;
break;
case 'lpstr': // LPSTR
case 'lpwstr': // LPWSTR
case 'bstr': // Basic String
return $propertyValue;
break;
case 'date': // Date and Time
case 'filetime': // File Time
return strtotime($propertyValue);
break;
case 'bool': // Boolean
return ($propertyValue == 'true') ? true : false;
break;
case 'cy': // Currency
case 'error': // Error Status Code
case 'vector': // Vector
case 'array': // Array
case 'blob': // Binary Blob
case 'oblob': // Binary Blob Object
case 'stream': // Binary Stream
case 'ostream': // Binary Stream Object
case 'storage': // Binary Storage
case 'ostorage': // Binary Storage Object
case 'vstream': // Binary Versioned Stream
case 'clsid': // Class ID
case 'cf': // Clipboard Data
return $propertyValue;
break;
}
return $propertyValue;
}
/**
* Convert document property type
*
* @param string $propertyType
* @return mixed
*/
public static function convertPropertyType($propertyType)
{
switch ($propertyType) {
case 'i1': // 1-Byte Signed Integer
case 'i2': // 2-Byte Signed Integer
case 'i4': // 4-Byte Signed Integer
case 'i8': // 8-Byte Signed Integer
case 'int': // Integer
case 'ui1': // 1-Byte Unsigned Integer
case 'ui2': // 2-Byte Unsigned Integer
case 'ui4': // 4-Byte Unsigned Integer
case 'ui8': // 8-Byte Unsigned Integer
case 'uint': // Unsigned Integer
return self::PROPERTY_TYPE_INTEGER;
break;
case 'r4': // 4-Byte Real Number
case 'r8': // 8-Byte Real Number
case 'decimal': // Decimal
return self::PROPERTY_TYPE_FLOAT;
break;
case 'empty': // Empty
case 'null': // Null
case 'lpstr': // LPSTR
case 'lpwstr': // LPWSTR
case 'bstr': // Basic String
return self::PROPERTY_TYPE_STRING;
break;
case 'date': // Date and Time
case 'filetime': // File Time
return self::PROPERTY_TYPE_DATE;
break;
case 'bool': // Boolean
return self::PROPERTY_TYPE_BOOLEAN;
break;
case 'cy': // Currency
case 'error': // Error Status Code
case 'vector': // Vector
case 'array': // Array
case 'blob': // Binary Blob
case 'oblob': // Binary Blob Object
case 'stream': // Binary Stream
case 'ostream': // Binary Stream Object
case 'storage': // Binary Storage
case 'ostorage': // Binary Storage Object
case 'vstream': // Binary Versioned Stream
case 'clsid': // Class ID
case 'cf': // Clipboard Data
return self::PROPERTY_TYPE_UNKNOWN;
break;
}
return self::PROPERTY_TYPE_UNKNOWN;
}
}

View File

@ -1,6 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Exceptions;
class Exception extends \Exception
{
}

View File

@ -1,13 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Exceptions;
/**
* InvalidImageException
*
* Exception used for when an image is not found
*
* @package PhpWord
*/
class InvalidImageException extends Exception
{
}

View File

@ -1,15 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Exceptions;
use InvalidArgumentException;
/**
* InvalidStyleException
*
* Exception used for when a style value is invalid
*
* @package PhpWord
*/
class InvalidStyleException extends InvalidArgumentException
{
}

View File

@ -1,13 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Exceptions;
/**
* UnsupportedImageTypeException
*
* Exception used for when an image type is unsupported
*
* @package PhpWord
*/
class UnsupportedImageTypeException extends Exception
{
}

View File

@ -1,124 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
class Footnote
{
/**
* Footnote Elements
*
* @var array
*/
private static $_footnoteCollection = array();
/**
* Footnote Link Elements
*
* @var array
*/
private static $_footnoteLink = array();
/**
* Add new Footnote Element
*
* @param string $linkSrc
* @param string $linkName
*
* @return mixed
*/
public static function addFootnoteElement(PhpOffice\PhpWord\Section\Footnote $footnote)
{
$refID = self::countFootnoteElements() + 2;
self::$_footnoteCollection[] = $footnote;
return $refID;
}
/**
* Get Footnote Elements
*
* @return array
*/
public static function getFootnoteElements()
{
return self::$_footnoteCollection;
}
/**
* Get Footnote Elements Count
*
* @return int
*/
public static function countFootnoteElements()
{
return count(self::$_footnoteCollection);
}
/**
* Add new Footnote Link Element
*
* @param string $src
* @param string $type
*
* @return mixed
*/
public static function addFootnoteLinkElement($linkSrc)
{
$rID = self::countFootnoteLinkElements() + 1;
$link = array();
$link['target'] = $linkSrc;
$link['rID'] = $rID;
$link['type'] = 'hyperlink';
self::$_footnoteLink[] = $link;
return $rID;
}
/**
* Get Footnote Link Elements
*
* @return array
*/
public static function getFootnoteLinkElements()
{
return self::$_footnoteLink;
}
/**
* Get Footnote Link Elements Count
*
* @return int
*/
public static function countFootnoteLinkElements()
{
return count(self::$_footnoteLink);
}
}

View File

@ -1,209 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
/**
* @codeCoverageIgnore Legacy from PHPExcel
*/
class HashTable
{
/**
* HashTable elements
*
* @var array
*/
public $_items = array();
/**
* HashTable key map
*
* @var array
*/
public $_keyMap = array();
/**
* @param PhpOffice\PhpWord\IComparable[] $pSource Optional source array to create HashTable from
* @throws Exception
*/
public function __construct($pSource = null)
{
if (!is_null($pSource)) {
$this->addFromSource($pSource);
}
}
/**
* Add HashTable items from source
*
* @param PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from
* @throws Exception
*/
public function addFromSource($pSource = null)
{
// Check if an array was passed
if ($pSource == null) {
return;
} elseif (!is_array($pSource)) {
throw new Exception('Invalid array parameter passed.');
}
foreach ($pSource as $item) {
$this->add($item);
}
}
/**
* Add HashTable item
*
* @param PhpOffice\PhpWord\IComparable $pSource Item to add
* @throws Exception
*/
public function add(IComparable $pSource = null)
{
// Determine hashcode
$hashCode = null;
$hashIndex = $pSource->getHashIndex();
if (is_null($hashIndex)) {
$hashCode = $pSource->getHashCode();
} elseif (isset ($this->_keyMap[$hashIndex])) {
$hashCode = $this->_keyMap[$hashIndex];
} else {
$hashCode = $pSource->getHashCode();
}
// Add value
if (!isset($this->_items[$hashCode])) {
$this->_items[$hashCode] = $pSource;
$index = count($this->_items) - 1;
$this->_keyMap[$index] = $hashCode;
$pSource->setHashIndex($index);
} else {
$pSource->setHashIndex($this->_items[$hashCode]->getHashIndex());
}
}
/**
* Remove HashTable item
*
* @param PhpOffice\PhpWord\IComparable $pSource Item to remove
* @throws Exception
*/
public function remove(IComparable $pSource = null)
{
if (isset($this->_items[$pSource->getHashCode()])) {
unset($this->_items[$pSource->getHashCode()]);
$deleteKey = -1;
foreach ($this->_keyMap as $key => $value) {
if ($deleteKey >= 0) {
$this->_keyMap[$key - 1] = $value;
}
if ($value == $pSource->getHashCode()) {
$deleteKey = $key;
}
}
unset($this->_keyMap[count($this->_keyMap) - 1]);
}
}
/**
* Clear HashTable
*
*/
public function clear()
{
$this->_items = array();
$this->_keyMap = array();
}
/**
* @return int
*/
public function count()
{
return count($this->_items);
}
/**
* @param string $pHashCode
* @return int Index
*/
public function getIndexForHashCode($pHashCode = '')
{
return array_search($pHashCode, $this->_keyMap);
}
/**
* @param int $pIndex
* @return PhpOffice\PhpWord\IComparable
*/
public function getByIndex($pIndex = 0)
{
if (isset($this->_keyMap[$pIndex])) {
return $this->getByHashCode($this->_keyMap[$pIndex]);
}
return null;
}
/**
* @param string $pHashCode
* @return PhpOffice\PhpWord\IComparable
*
*/
public function getByHashCode($pHashCode = '')
{
if (isset($this->_items[$pHashCode])) {
return $this->_items[$pHashCode];
}
return null;
}
/**
* @return PhpOffice\PhpWord\IComparable[]
*/
public function toArray()
{
return $this->_items;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/
public function __clone()
{
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (is_object($value)) {
$this->$key = clone $value;
}
}
}
}

View File

@ -1,80 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
abstract class IOFactory
{
/**
* @param PhpOffice\PhpWord $phpWord
* @param string $name
* @return PhpOffice\PhpWord\Writer\IWriter
* @throws PhpOffice\PhpWord\Exceptions\Exception
*/
public static function createWriter(PhpWord $phpWord, $name)
{
try {
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
return new $fqName($phpWord);
} catch (\Exception $ex) {
throw new Exception("Could not instantiate \"{$name}\" class.");
}
}
/**
* @param string $name
* @return PhpOffice\PhpWord\Reader\IReader
* @throws PhpOffice\PhpWord\Exceptions\Exception
*/
public static function createReader($name)
{
try {
$fqName = "PhpOffice\\PhpWord\\Reader\\{$name}";
return new $fqName();
} catch (\Exception $ex) {
throw new Exception("Could not instantiate \"{$name}\" class.");
}
}
/**
* Loads PhpWord from file
*
* @param string $filename The name of the file
* @param string $readerName
* @return PhpOffice\PhpWord
*/
public static function load($filename, $readerName = 'Word2007')
{
$reader = self::createReader($readerName);
return $reader->load($filename);
}
}

View File

@ -1,347 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Section\MemoryImage;
class Media
{
/**
* Section Media Elements
*
* @var array
*/
private static $_sectionMedia = array(
'images' => array(),
'embeddings' => array(),
'links' => array()
);
/**
* Header Media Elements
*
* @var array
*/
private static $_headerMedia = array();
/**
* Footer Media Elements
*
* @var array
*/
private static $_footerMedia = array();
/**
* ObjectID Counter
*
* @var int
*/
private static $_objectId = 1325353440;
/**
* Add new Section Media Element
*
* @param string $src
* @param string $type
* @param PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @return mixed
*/
public static function addSectionMediaElement($src, $type, MemoryImage $memoryImage = null)
{
$mediaId = md5($src);
$key = ($type === 'image') ? 'images' : 'embeddings';
if (!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
$cImg = self::countSectionMediaElements('images');
$cObj = self::countSectionMediaElements('embeddings');
$rID = self::countSectionMediaElements() + 7;
$media = array();
$folder = null;
$file = null;
if ($type === 'image') {
$cImg++;
//Detect if it's a memory image first by php ext and second by regex
$isMemImage = false;
if (stripos(strrev($src), strrev('.php')) === 0) {
$isMemImage = true;
}
if (!$isMemImage) {
$isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false);
}
$extension = '';
if ($isMemImage) {
$extension = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
} else {
$imageType = exif_imagetype($src);
if ($imageType === IMAGETYPE_JPEG) {
$extension = 'jpg';
} elseif ($imageType === IMAGETYPE_GIF) {
$extension = 'gif';
} elseif ($imageType === IMAGETYPE_PNG) {
$extension = 'png';
} elseif ($imageType === IMAGETYPE_BMP) {
$extension = 'bmp';
} elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) {
$extension = 'tif';
}
}
$folder = 'media';
$file = $type . $cImg . '.' . strtolower($extension);
} elseif ($type === 'oleObject') {
$cObj++;
$folder = 'embedding';
$file = $type . $cObj . '.bin';
}
$media['source'] = $src;
$media['target'] = "$folder/section_$file";
$media['type'] = $type;
$media['rID'] = $rID;
self::$_sectionMedia[$key][$mediaId] = $media;
if ($type === 'oleObject') {
return array($rID, ++self::$_objectId);
}
return $rID;
}
if ($type === 'oleObject') {
$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
return array($rID, ++self::$_objectId);
}
return self::$_sectionMedia[$key][$mediaId]['rID'];
}
/**
* Add new Section Link Element
*
* @param string $linkSrc
* @return mixed
*/
public static function addSectionLinkElement($linkSrc)
{
$rID = self::countSectionMediaElements() + 7;
$link = array();
$link['target'] = $linkSrc;
$link['rID'] = $rID;
$link['type'] = 'hyperlink';
self::$_sectionMedia['links'][] = $link;
return $rID;
}
/**
* Get Section Media Elements
*
* @param string $key
* @return array
*/
public static function getSectionMediaElements($key = null)
{
if (!is_null($key)) {
return self::$_sectionMedia[$key];
}
$arrImages = self::$_sectionMedia['images'];
$arrObjects = self::$_sectionMedia['embeddings'];
$arrLinks = self::$_sectionMedia['links'];
return array_merge($arrImages, $arrObjects, $arrLinks);
}
/**
* Get Section Media Elements Count
*
* @param string $key
* @return int
*/
public static function countSectionMediaElements($key = null)
{
if (!is_null($key)) {
return count(self::$_sectionMedia[$key]);
}
$cImages = count(self::$_sectionMedia['images']);
$cObjects = count(self::$_sectionMedia['embeddings']);
$cLinks = count(self::$_sectionMedia['links']);
return ($cImages + $cObjects + $cLinks);
}
/**
* Add new Header Media Element
*
* @param int $headerCount
* @param string $src
* @param PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @return int
*/
public static function addHeaderMediaElement($headerCount, $src, MemoryImage $memoryImage = null)
{
$mediaId = md5($src);
$key = 'header' . $headerCount;
if (!array_key_exists($key, self::$_headerMedia)) {
self::$_headerMedia[$key] = array();
}
if (!array_key_exists($mediaId, self::$_headerMedia[$key])) {
$cImg = self::countHeaderMediaElements($key);
$rID = $cImg + 1;
$cImg++;
$inf = pathinfo($src);
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
$media = array();
if ($isMemImage) {
$ext = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
} else {
$ext = $inf['extension'];
if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$ext = 'jpg';
}
}
$file = 'image' . $cImg . '.' . strtolower($ext);
$media['source'] = $src;
$media['target'] = 'media/' . $key . '_' . $file;
$media['type'] = 'image';
$media['rID'] = $rID;
self::$_headerMedia[$key][$mediaId] = $media;
return $rID;
}
return self::$_headerMedia[$key][$mediaId]['rID'];
}
/**
* Get Header Media Elements Count
*
* @param string $key
* @return int
*/
public static function countHeaderMediaElements($key)
{
return count(self::$_headerMedia[$key]);
}
/**
* Get Header Media Elements
*
* @return int
*/
public static function getHeaderMediaElements()
{
return self::$_headerMedia;
}
/**
* Add new Footer Media Element
*
* @param int $footerCount
* @param string $src
* @param PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @return int
*/
public static function addFooterMediaElement($footerCount, $src, MemoryImage $memoryImage = null)
{
$mediaId = md5($src);
$key = 'footer' . $footerCount;
if (!array_key_exists($key, self::$_footerMedia)) {
self::$_footerMedia[$key] = array();
}
if (!array_key_exists($mediaId, self::$_footerMedia[$key])) {
$cImg = self::countFooterMediaElements($key);
$rID = $cImg + 1;
$cImg++;
$inf = pathinfo($src);
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
$media = array();
if ($isMemImage) {
$ext = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
} else {
$ext = $inf['extension'];
if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$ext = 'jpg';
}
}
$file = 'image' . $cImg . '.' . strtolower($ext);
$media['source'] = $src;
$media['target'] = 'media/' . $key . '_' . $file;
$media['type'] = 'image';
$media['rID'] = $rID;
self::$_footerMedia[$key][$mediaId] = $media;
return $rID;
}
return self::$_footerMedia[$key][$mediaId]['rID'];
}
/**
* Get Footer Media Elements Count
*
* @param string $key
* @return int
*/
public static function countFooterMediaElements($key)
{
return count(self::$_footerMedia[$key]);
}
/**
* Get Footer Media Elements
*
* @return int
*/
public static function getFooterMediaElements()
{
return self::$_footerMedia;
}
}

View File

@ -1,110 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\Exceptions\Exception;
/**
* @codeCoverageIgnore Abstract class
*/
abstract class AbstractReader implements IReader
{
/**
* Read data only?
*
* @var bool
*/
protected $readDataOnly = true;
/**
* @var bool|resource
*/
protected $fileHandle = true;
/**
* Read data only?
*
* @return bool
*/
public function getReadDataOnly()
{
// return $this->readDataOnly;
return true;
}
/**
* Set read data only
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Reader\IReader
*/
public function setReadDataOnly($pValue = true)
{
$this->readDataOnly = $pValue;
return $this;
}
/**
* Open file for reading
*
* @param string $pFilename
* @return resource
* @throws Exception
*/
protected function openFile($pFilename)
{
// Check if file exists
if (!file_exists($pFilename) || !is_readable($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Open file
$this->fileHandle = fopen($pFilename, 'r');
if ($this->fileHandle === false) {
throw new Exception("Could not open file " . $pFilename . " for reading.");
}
}
/**
* Can the current IReader read the file?
*
* @param string $pFilename
* @return bool
*/
public function canRead($pFilename)
{
// Check if file exists
try {
$this->openFile($pFilename);
} catch (Exception $e) {
return false;
}
fclose($this->fileHandle);
return true;
}
}

View File

@ -1,46 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Reader;
interface IReader
{
/**
* Can the current IReader read the file?
*
* @param string $pFilename
* @return boolean
*/
public function canRead($pFilename);
/**
* Loads PhpWord from file
*
* @param string $pFilename
*/
public function load($pFilename);
}

View File

@ -1,453 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Shared\File;
/** PhpWord root directory */
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/../../');
require(PHPWORD_BASE_PATH . 'PhpWord/Autoloader.php');
}
class Word2007 extends AbstractReader implements IReader
{
/**
* Can the current IReader read the file?
*
* @param string $pFilename
* @return bool
* @throws PhpOffice\PhpWord\Exceptions\Exception
*/
public function canRead($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open {$pFilename} for reading! File does not exist.");
}
$return = false;
// Load file
$zip = new ZipArchive();
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
if ($rels !== false) {
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
if (basename($rel["Target"]) == 'document.xml') {
$return = true;
}
break;
}
}
}
$zip->close();
}
return $return;
}
/**
* @param ZipArchive $archive
* @param string $fileName
* @param bool $removeNamespace
* @return mixed
*/
public function getFromZipArchive($archive, $fileName = '', $removeNamespace = false)
{
// Root-relative paths
if (strpos($fileName, '//') !== false) {
$fileName = substr($fileName, strpos($fileName, '//') + 1);
}
$fileName = File::realpath($fileName);
// Apache POI fixes
$contents = $archive->getFromName($fileName);
if ($contents === false) {
$contents = $archive->getFromName(substr($fileName, 1));
}
// Remove namespaces from elements and attributes name
if ($removeNamespace) {
$contents = preg_replace('~(</?|\s)w:~is', '$1', $contents);
}
return $contents;
}
/**
* Loads PhpWord from file
*
* @param string $pFilename
* @return PhpOffice\PhpWord|null
*/
public function load($pFilename)
{
// Check if file exists and can be read
if (!$this->canRead($pFilename)) {
return null;
}
// Initialisations
$word = new PhpWord();
$zip = new ZipArchive();
$zip->open($pFilename);
// Read properties and documents
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
// Core properties
case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
$xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
$docProps = $word->getDocumentProperties();
$docProps->setCreator((string)self::arrayItem($xmlCore->xpath("dc:creator")));
$docProps->setLastModifiedBy((string)self::arrayItem($xmlCore->xpath("cp:lastModifiedBy")));
$docProps->setCreated(strtotime(self::arrayItem($xmlCore->xpath("dcterms:created"))));
$docProps->setModified(strtotime(self::arrayItem($xmlCore->xpath("dcterms:modified"))));
$docProps->setTitle((string)self::arrayItem($xmlCore->xpath("dc:title")));
$docProps->setDescription((string)self::arrayItem($xmlCore->xpath("dc:description")));
$docProps->setSubject((string)self::arrayItem($xmlCore->xpath("dc:subject")));
$docProps->setKeywords((string)self::arrayItem($xmlCore->xpath("cp:keywords")));
$docProps->setCategory((string)self::arrayItem($xmlCore->xpath("cp:category")));
}
break;
// Extended properties
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$docProps = $word->getDocumentProperties();
if (isset($xmlCore->Company)) {
$docProps->setCompany((string)$xmlCore->Company);
}
if (isset($xmlCore->Manager)) {
$docProps->setManager((string)$xmlCore->Manager);
}
}
break;
// Custom properties
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$docProps = $word->getDocumentProperties();
foreach ($xmlCore as $xmlProperty) {
$cellDataOfficeAttributes = $xmlProperty->attributes();
if (isset($cellDataOfficeAttributes['name'])) {
$propertyName = (string)$cellDataOfficeAttributes['name'];
$cellDataOfficeChildren = $xmlProperty->children("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
$attributeType = $cellDataOfficeChildren->getName();
$attributeValue = (string)$cellDataOfficeChildren->{$attributeType};
$attributeValue = DocumentProperties::convertProperty($attributeValue, $attributeType);
$attributeType = DocumentProperties::convertPropertyType($attributeType);
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
}
}
}
break;
// Document
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
$dir = dirname($rel["Target"]);
$archive = "$dir/_rels/" . basename($rel["Target"]) . ".rels";
$relsDoc = simplexml_load_string($this->getFromZipArchive($zip, $archive));
$relsDoc->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
$xpath = self::arrayItem(
$relsDoc->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")
);
$xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}", true));
if (is_object($xmlDoc)) {
$section = $word->createSection();
foreach ($xmlDoc->body->children() as $elm) {
$elmName = $elm->getName();
if ($elmName == 'p') { // Paragraph/section
// Create new section if section setting found
if ($elm->pPr->sectPr) {
$section->setSettings($this->loadSectionSettings($elm->pPr));
$section = $word->createSection();
continue;
}
// Has w:r? It's either text or textrun
if ($elm->r) {
// w:r = 1? It's a plain paragraph
if (count($elm->r) == 1) {
$section->addText(
$elm->r->t,
$this->loadFontStyle($elm->r)
);
// w:r more than 1? It's a textrun
} else {
$textRun = $section->createTextRun();
foreach ($elm->r as $r) {
$textRun->addText(
$r->t,
$this->loadFontStyle($r)
);
}
}
// No, it's a textbreak
} else {
$section->addTextBreak();
}
} elseif ($elmName == 'sectPr') {
// Last section setting
$section->setSettings($this->loadSectionSettings($xmlDoc->body));
}
}
}
break;
}
}
// Read styles
$docRels = simplexml_load_string($this->getFromZipArchive($zip, "word/_rels/document.xml.rels"));
foreach ($docRels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
$xmlStyle = simplexml_load_string($this->getFromZipArchive($zip, "word/{$rel['Target']}", true));
if (is_object($xmlStyle)) {
foreach ($xmlStyle->children() as $elm) {
if ($elm->getName() != 'style') {
continue;
}
$pStyle = null;
$fStyle = null;
$hasParagraphStyle = isset($elm->pPr);
$hasFontStyle = isset($elm->rPr);
$styleName = (string)$elm->name['val'];
if ($hasParagraphStyle) {
$pStyle = $this->loadParagraphStyle($elm);
if (!$hasFontStyle) {
$word->addParagraphStyle($styleName, $pStyle);
}
}
if ($hasFontStyle) {
$fStyle = $this->loadFontStyle($elm);
$word->addFontStyle($styleName, $fStyle, $pStyle);
}
}
}
break;
}
}
$zip->close();
return $word;
}
/**
* Load section settings from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @return array|string|null
*
* @todo Implement gutter
*/
private function loadSectionSettings($elm)
{
if ($xml = $elm->sectPr) {
$setting = array();
if ($xml->type) {
$setting['breakType'] = (string)$xml->type['val'];
}
if ($xml->pgSz) {
if (isset($xml->pgSz['w'])) {
$setting['pageSizeW'] = (int)$xml->pgSz['w'];
}
if (isset($xml->pgSz['h'])) {
$setting['pageSizeH'] = (int)$xml->pgSz['h'];
}
if (isset($xml->pgSz['orient'])) {
$setting['orientation'] = (string)$xml->pgSz['orient'];
}
}
if ($xml->pgMar) {
if (isset($xml->pgMar['top'])) {
$setting['topMargin'] = (int)$xml->pgMar['top'];
}
if (isset($xml->pgMar['left'])) {
$setting['leftMargin'] = (int)$xml->pgMar['left'];
}
if (isset($xml->pgMar['bottom'])) {
$setting['bottomMargin'] = (int)$xml->pgMar['bottom'];
}
if (isset($xml->pgMar['right'])) {
$setting['rightMargin'] = (int)$xml->pgMar['right'];
}
if (isset($xml->pgMar['header'])) {
$setting['headerHeight'] = (int)$xml->pgMar['header'];
}
if (isset($xml->pgMar['footer'])) {
$setting['footerHeight'] = (int)$xml->pgMar['footer'];
}
if (isset($xml->pgMar['gutter'])) {
// $setting['gutter'] = (int)$xml->pgMar['gutter'];
}
}
if ($xml->cols) {
if (isset($xml->cols['num'])) {
$setting['colsNum'] = (int)$xml->cols['num'];
}
if (isset($xml->cols['space'])) {
$setting['colsSpace'] = (int)$xml->cols['space'];
}
}
return $setting;
}
return null;
}
/**
* Load paragraph style from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @return array|string|null
*/
private function loadParagraphStyle($elm)
{
if ($xml = $elm->pPr) {
if ($xml->pStyle) {
return (string)$xml->pStyle['val'];
}
$style = array();
if ($xml->jc) {
$style['align'] = (string)$xml->jc['val'];
}
if ($xml->ind) {
if (isset($xml->ind->left)) {
$style['indent'] = (int)$xml->ind->left;
}
if (isset($xml->ind->hanging)) {
$style['hanging'] = (int)$xml->ind->hanging;
}
if (isset($xml->ind->line)) {
$style['spacing'] = (int)$xml->ind->line;
}
}
if ($xml->spacing) {
if (isset($xml->spacing['after'])) {
$style['spaceAfter'] = (int)$xml->spacing['after'];
}
if (isset($xml->spacing['before'])) {
$style['spaceBefore'] = (int)$xml->spacing['before'];
}
if (isset($xml->spacing['line'])) {
$style['spacing'] = (int)$xml->spacing['line'];
}
}
if ($xml->basedOn) {
$style['basedOn'] = (string)$xml->basedOn['val'];
}
if ($xml->next) {
$style['next'] = (string)$xml->next['val'];
}
if ($xml->widowControl) {
$style['widowControl'] = false;
}
if ($xml->keepNext) {
$style['keepNext'] = true;
}
if ($xml->keepLines) {
$style['keepLines'] = true;
}
if ($xml->pageBreakBefore) {
$style['pageBreakBefore'] = true;
}
return $style;
}
return null;
}
/**
* Load font style from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @return array|string|null
*/
private function loadFontStyle($elm)
{
if ($xml = $elm->rPr) {
if ($xml->rStyle) {
return (string)$xml->rStyle['val'];
}
$style = array();
if ($xml->rFonts) {
$style['name'] = (string)$xml->rFonts['ascii'];
}
if ($xml->sz) {
$style['size'] = (int)$xml->sz['val'] / 2;
}
if ($xml->color) {
$style['color'] = (string)$xml->color['val'];
}
if ($xml->b) {
$style['bold'] = true;
}
if ($xml->i) {
$style['italic'] = true;
}
if ($xml->u) {
$style['underline'] = (string)$xml->u['val'];
}
if ($xml->strike) {
$style['strikethrough'] = true;
}
if ($xml->highlight) {
$style['fgColor'] = (string)$xml->highlight['val'];
}
if ($xml->vertAlign) {
if ($xml->vertAlign['val'] == 'superscript') {
$style['superScript'] = true;
} else {
$style['subScript'] = true;
}
}
return $style;
}
return null;
}
/**
* @param array $array
* @param mixed $key
* @return mixed|null
*/
private static function arrayItem($array, $key = 0)
{
return (isset($array[$key]) ? $array[$key] : null);
}
}

View File

@ -1,453 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Section\Footer;
use PhpOffice\PhpWord\Section\Footnote;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Settings;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Shared\String;
class Section
{
/**
* Section count
*
* @var int
*/
private $_sectionCount;
/**
* Section settings
*
* @var PhpOffice\PhpWord\Section\Settings
*/
private $_settings;
/**
* Section Element Collection
*
* @var array
*/
private $_elementCollection = array();
/**
* Section Headers
*
* @var array
*/
private $_headers = array();
/**
* Section Footer
*
* @var PhpOffice\PhpWord\Section\Footer
*/
private $_footer = null;
/**
* Create a new Section
*
* @param int $sectionCount
* @param mixed $settings
*/
public function __construct($sectionCount, $settings = null)
{
$this->_sectionCount = $sectionCount;
$this->_settings = new Settings();
$this->setSettings($settings);
}
/**
* Set Section Settings
*
* @param array $settings
*/
public function setSettings($settings = null)
{
if (!is_null($settings) && is_array($settings)) {
foreach ($settings as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_settings->setSettingValue($key, $value);
}
}
}
/**
* Get Section Settings
*
* @return PhpOffice\PhpWord\Section\Settings
*/
public function getSettings()
{
return $this->_settings;
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add a Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
{
if (!String::IsUTF8($linkSrc)) {
$linkSrc = utf8_encode($linkSrc);
}
if (!is_null($linkName)) {
if (!String::IsUTF8($linkName)) {
$linkName = utf8_encode($linkName);
}
}
$link = new Link($linkSrc, $linkName, $styleFont, $styleParagraph);
$rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
}
/**
* Add a TextBreak Element
*
* @param int $count
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Add a PageBreak Element
*/
public function addPageBreak()
{
$this->_elementCollection[] = new PageBreak();
}
/**
* Add a Table Element
*
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new Table('section', $this->_sectionCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
/**
* Add a ListItem Element
*
* @param string $text
* @param int $depth
* @param mixed $styleFont
* @param mixed $styleList
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\ListItem
*/
public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$listItem = new ListItem($text, $depth, $styleFont, $styleList, $styleParagraph);
$this->_elementCollection[] = $listItem;
return $listItem;
}
/**
* Add a OLE-Object Element
*
* @param string $src
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Object
* @throws Exception
*/
public function addObject($src, $style = null)
{
$object = new Object($src, $style);
if (!is_null($object->getSource())) {
$inf = pathinfo($src);
$ext = $inf['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$iconSrc = PHPWORD_BASE_PATH . 'PhpWord/_staticDocParts/';
if (!file_exists($iconSrc . '_' . $ext . '.png')) {
$iconSrc = $iconSrc . '_default.png';
} else {
$iconSrc .= '_' . $ext . '.png';
}
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
$data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0];
$objectId = $data[1];
$object->setRelationId($rID);
$object->setObjectId($objectId);
$object->setImageRelationId($rIDimg);
$this->_elementCollection[] = $object;
return $object;
}
throw new Exception('Source does not exist or unsupported object type.');
}
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Image
* @throws Exception
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addSectionMediaElement($src, 'image');
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
}
throw new Exception('Source does not exist or unsupported image type.');
}
/**
* Add a by PHP created Image Element
*
* @param string $link
* @param mixed $style
* @return PhpOffice\PhpWord\Section\MemoryImage
* @throws Exception
*/
public function addMemoryImage($link, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
}
throw new Exception('Unsupported image type.');
}
/**
* Add a Table-of-Contents Element
*
* @param mixed $styleFont
* @param mixed $styleTOC
* @return PhpOffice\PhpWord\TOC
*/
public function addTOC($styleFont = null, $styleTOC = null)
{
$toc = new TOC($styleFont, $styleTOC);
$this->_elementCollection[] = $toc;
return $toc;
}
/**
* Add a Title Element
*
* @param string $text
* @param int $depth
* @return PhpOffice\PhpWord\Section\Title
*/
public function addTitle($text, $depth = 1)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$styles = Style::getStyles();
if (array_key_exists('Heading_' . $depth, $styles)) {
$style = 'Heading' . $depth;
} else {
$style = null;
}
$title = new Title($text, $depth, $style);
$data = TOC::addTitle($text, $depth);
$anchor = $data[0];
$bookmarkId = $data[1];
$title->setAnchor($anchor);
$title->setBookmarkId($bookmarkId);
$this->_elementCollection[] = $title;
return $title;
}
/**
* Create a new TextRun
*
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Get all Elements
*
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Create a new Header
*
* @return PhpOffice\PhpWord\Section\Header
*/
public function createHeader()
{
$header = new Header($this->_sectionCount);
$this->_headers[] = $header;
return $header;
}
/**
* Get Headers
*
* @return array
*/
public function getHeaders()
{
return $this->_headers;
}
/**
* Is there a header for this section that is for the first page only?
*
* If any of the Header instances have a type of Header::FIRST then this method returns true.
* False otherwise.
*
* @return Boolean
*/
public function hasDifferentFirstPage()
{
$value = array_filter($this->_headers, function (Header &$header) {
return $header->getType() == Header::FIRST;
});
return count($value) > 0;
}
/**
* Create a new Footer
*
* @return PhpOffice\PhpWord\Section\Footer
*/
public function createFooter()
{
$footer = new Footer($this->_sectionCount);
$this->_footer = $footer;
return $footer;
}
/**
* Get Footer
*
* @return PhpOffice\PhpWord\Section\Footer
*/
public function getFooter()
{
return $this->_footer;
}
/**
* Create a new Footnote Element
*
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Footnote
*/
public function createFootnote($styleParagraph = null)
{
$footnote = new Footnote($styleParagraph);
$refID = Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID);
$this->_elementCollection[] = $footnote;
return $footnote;
}
}

View File

@ -1,217 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
class Footer
{
/**
* Footer Count
*
* @var int
*/
private $_footerCount;
/**
* Footer Relation ID
*
* @var int
*/
private $_rId;
/**
* Footer Element Collection
*
* @var int
*/
private $_elementCollection = array();
/**
* Create a new Footer
*/
public function __construct($sectionCount)
{
$this->_footerCount = $sectionCount;
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new TextRun
*
* @return PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Add a Table Element
*
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new Table('footer', $this->_footerCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return Image
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addFooterMediaElement($this->_footerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Src does not exist or invalid image type.');
}
}
/**
* Add a by PHP created Image Element
*
* @param string $link
* @param mixed $style
* @return PhpOffice\PhpWord\Section\MemoryImage
*/
public function addMemoryImage($link, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
throw new Exception('Unsupported image type.');
}
}
/**
* Add a PreserveText Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
}
/**
* Get Footer Relation ID
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Footer Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get all Footer Elements
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Footer Count
*/
public function getFooterCount()
{
return $this->_footerCount;
}
}

View File

@ -1,130 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section\Footer;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class PreserveText
{
/**
* Text content
*
* @var string
*/
private $_text;
/**
* Text style
*
* @var PhpOffice\PhpWord\Style\Font
*/
private $_styleFont;
/**
* Paragraph style
*
* @var PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
/**
* Create a new Preserve Text Element
*
* @var string $text
* @var mixed $style
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{
// Set font style
if (is_array($styleFont)) {
$this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleFont->setStyleValue($key, $value);
}
} else {
$this->_styleFont = $styleFont;
}
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
$matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) {
$this->_text = $matches[0];
}
return $this;
}
/**
* Get Text style
*
* @return PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->_styleFont;
}
/**
* Get Paragraph style
*
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
/**
* Get Text content
*
* @return string
*/
public function getText()
{
return $this->_text;
}
}

View File

@ -1,151 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Paragraph;
class Footnote
{
/**
* Paragraph style
*
* @var PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
/**
* Footnote Reference ID
*
* @var string
*/
private $_refId;
/**
* Text collection
*
* @var array
*/
private $_elementCollection;
/**
* Create a new Footnote Element
*/
public function __construct($styleParagraph = null)
{
$this->_elementCollection = array();
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
}
/**
* Add a Text Element
*
* @var string $text
* @var mixed $styleFont
* @return PhpOffice\PhpWord\Section\Text
*/
public function addText($text = null, $styleFont = null)
{
$givenText = $text;
$text = new Text($givenText, $styleFont);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add a Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @return PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
$link = new Link($linkSrc, $linkName, $styleFont);
$rID = PhpOffice\PhpWord\Footnote::addFootnoteLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
}
/**
* Get Footnote content
*
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Paragraph style
*
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
/**
* Get Footnote Reference ID
*
* @return int
*/
public function getReferenceId()
{
return $this->_refId;
}
/**
* Set Footnote Reference ID
*
* @param int $refId
*/
public function setReferenceId($refId)
{
$this->_refId = $refId;
}
}

View File

@ -1,299 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
class Header
{
/**
* Header Count
*
* @var int
*/
private $_headerCount;
/**
* Header Relation ID
*
* @var int
*/
private $_rId;
/**
* Header type
*
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
private $_type = self::AUTO;
/**
* Even Numbered Pages Only
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
const EVEN = 'even';
/**
* Default Header or Footer
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
const AUTO = 'default'; // Did not use DEFAULT because it is a PHP keyword
/**
* First Page Only
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
const FIRST = 'first';
/**
* Header Element Collection
*
* @var int
*/
private $_elementCollection = array();
/**
* Create a new Header
*/
public function __construct($sectionCount)
{
$this->_headerCount = $sectionCount;
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new TextRun
*
* @return PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Add a Table Element
*
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new Table('header', $this->_headerCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Src does not exist or invalid image type.');
}
}
/**
* Add a by PHP created Image Element
*
* @param string $link
* @param mixed $style
* @return PhpOffice\PhpWord\Section\MemoryImage
*/
public function addMemoryImage($link, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
throw new Exception('Unsupported image type.');
}
}
/**
* Add a PreserveText Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
}
/**
* Add a Watermark Element
*
* @param string $src
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Image
*/
public function addWatermark($src, $style = null)
{
$image = new Image($src, $style, true);
if (!is_null($image->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Src does not exist or invalid image type.');
}
}
/**
* Get Header Relation ID
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Header Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get all Header Elements
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Header Count
*/
public function getHeaderCount()
{
return $this->_headerCount;
}
/**
* Get Header Type
*/
public function getType()
{
return $this->_type;
}
/**
* Reset back to default
*/
public function resetType()
{
return $this->_type = self::AUTO;
}
/**
* First page only header
*/
public function firstPage()
{
return $this->_type = self::FIRST;
}
/**
* Even numbered Pages only
*/
public function evenPage()
{
return $this->_type = self::EVEN;
}
}

View File

@ -1,177 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
class Image
{
/**
* Image Src
*
* @var string
*/
private $_src;
/**
* Image Style
*
* @var PhpOffice\PhpWord\Style\Image
*/
private $_style;
/**
* Image Relation ID
*
* @var string
*/
private $_rId;
/**
* Is Watermark
*
* @var bool
*/
private $_isWatermark;
/**
* Create a new Image
*
* @param string $src
* @param mixed $style
* @param bool $isWatermark
* @throws InvalidImageException|UnsupportedImageTypeException
*/
public function __construct($src, $style = null, $isWatermark = false)
{
$supportedImageTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM);
if (!file_exists($src)) {
throw new InvalidImageException;
}
if (!in_array(exif_imagetype($src), $supportedImageTypes)) {
throw new UnsupportedImageTypeException;
}
$this->_src = $src;
$this->_isWatermark = $isWatermark;
$this->_style = new PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
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]);
$this->_style->setHeight($imgData[1]);
}
}
/**
* Get Image style
*
* @return PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get Image Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Image Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get Image Source
*
* @return string
*/
public function getSource()
{
return $this->_src;
}
/**
* Get Image Media ID
*
* @return string
*/
public function getMediaId()
{
return md5($this->_src);
}
/**
* Get IsWatermark
*
* @return int
*/
public function getIsWatermark()
{
return $this->_isWatermark;
}
/**
* Set IsWatermark
*
* @param bool $pValue
*/
public function setIsWatermark($pValue)
{
$this->_isWatermark = $pValue;
}
}

View File

@ -1,174 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class Link
{
/**
* Link source
*
* @var string
*/
private $_linkSrc;
/**
* Link name
*
* @var string
*/
private $_linkName;
/**
* Link Relation ID
*
* @var string
*/
private $_rId;
/**
* Link style
*
* @var PhpOffice\PhpWord\Style\Font
*/
private $_styleFont;
/**
* Paragraph style
*
* @var PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
/**
* Create a new Link Element
*
* @var string $linkSrc
* @var string $linkName
* @var mixed $styleFont
* @var mixed $styleParagraph
*/
public function __construct($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
{
$this->_linkSrc = $linkSrc;
$this->_linkName = $linkName;
// Set font style
if (is_array($styleFont)) {
$this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleFont->setStyleValue($key, $value);
}
} else {
$this->_styleFont = $styleFont;
}
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
return $this;
}
/**
* Get Link Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Link Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get Link source
*
* @return string
*/
public function getLinkSrc()
{
return $this->_linkSrc;
}
/**
* Get Link name
*
* @return string
*/
public function getLinkName()
{
return $this->_linkName;
}
/**
* Get Text style
*
* @return PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->_styleFont;
}
/**
* Get Paragraph style
*
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
}

View File

@ -1,101 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
class ListItem
{
/**
* ListItem Style
*
* @var PhpOffice\PhpWord\Style\ListItem
*/
private $_style;
/**
* Textrun
*
* @var PhpOffice\PhpWord\Section\Text
*/
private $_textObject;
/**
* ListItem Depth
*
* @var int
*/
private $_depth;
/**
* Create a new ListItem
*
* @param string $text
* @param int $depth
* @param mixed $styleText
* @param mixed $styleList
*/
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
{
$this->_style = new PhpOffice\PhpWord\Style\ListItem();
$this->_textObject = new Text($text, $styleFont, $styleParagraph);
$this->_depth = $depth;
if (!is_null($styleList) && is_array($styleList)) {
foreach ($styleList as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
}
/**
* Get ListItem style
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get ListItem TextRun
*/
public function getTextObject()
{
return $this->_textObject;
}
/**
* Get ListItem depth
*/
public function getDepth()
{
return $this->_depth;
}
}

View File

@ -1,233 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Image;
class MemoryImage
{
/**
* Image Src
*
* @var string
*/
private $_src;
/**
* Image Style
*
* @var PhpOffice\PhpWord\Style\Image
*/
private $_style;
/**
* Image Relation ID
*
* @var string
*/
private $_rId;
/**
* Image Type
*
* @var string
*/
private $_imageType;
/**
* Image Create function
*
* @var string
*/
private $_imageCreateFunc;
/**
* Image function
*
* @var string
*/
private $_imageFunc;
/**
* Image function
*
* @var string
*/
private $_imageExtension;
/**
* Create a new Image
*
* @param string $src
* @param mixed $style
*/
public function __construct($src, $style = null)
{
$imgData = getimagesize($src);
$this->_imageType = $imgData['mime'];
$_supportedImageTypes = array('image/jpeg', 'image/gif', 'image/png');
if (in_array($this->_imageType, $_supportedImageTypes)) {
$this->_src = $src;
$this->_style = new Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
$this->_style->setWidth($imgData[0]);
$this->_style->setHeight($imgData[1]);
}
$this->_setFunctions();
}
}
/**
* Set Functions
*/
private function _setFunctions()
{
switch ($this->_imageType) {
case 'image/png':
$this->_imageCreateFunc = 'imagecreatefrompng';
$this->_imageFunc = 'imagepng';
$this->_imageExtension = 'png';
break;
case 'image/gif':
$this->_imageCreateFunc = 'imagecreatefromgif';
$this->_imageFunc = 'imagegif';
$this->_imageExtension = 'gif';
break;
case 'image/jpeg':
case 'image/jpg':
$this->_imageCreateFunc = 'imagecreatefromjpeg';
$this->_imageFunc = 'imagejpeg';
$this->_imageExtension = 'jpg';
break;
}
}
/**
* Get Image style
*
* @return PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get Image Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Image Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get Image Source
*
* @return string
*/
public function getSource()
{
return $this->_src;
}
/**
* Get Image Media ID
*
* @return string
*/
public function getMediaId()
{
return md5($this->_src);
}
/**
* Get Image Type
*
* @return string
*/
public function getImageType()
{
return $this->_imageType;
}
/**
* Get Image Create Function
*
* @return string
*/
public function getImageCreateFunction()
{
return $this->_imageCreateFunc;
}
/**
* Get Image Function
*
* @return string
*/
public function getImageFunction()
{
return $this->_imageFunc;
}
/**
* Get Image Extension
*
* @return string
*/
public function getImageExtension()
{
return $this->_imageExtension;
}
}

View File

@ -1,179 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Image;
class Object
{
/**
* Ole-Object Src
*
* @var string
*/
private $_src;
/**
* Image Style
*
* @var PhpOffice\PhpWord\Style\Image
*/
private $_style;
/**
* Object Relation ID
*
* @var int
*/
private $_rId;
/**
* Image Relation ID
*
* @var int
*/
private $_rIdImg;
/**
* Object ID
*
* @var int
*/
private $_objId;
/**
* Create a new Ole-Object Element
*
* @param string $src
* @param mixed $style
*/
public function __construct($src, $style = null)
{
$_supportedObjectTypes = array('xls', 'doc', 'ppt');
$inf = pathinfo($src);
if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
$this->_src = $src;
$this->_style = new Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
return $this;
} else {
return false;
}
}
/**
* Get Image style
*
* @return PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get Source
*
* @return string
*/
public function getSource()
{
return $this->_src;
}
/**
* Get Object Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Object Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get Image Relation ID
*
* @return int
*/
public function getImageRelationId()
{
return $this->_rIdImg;
}
/**
* Set Image Relation ID
*
* @param int $rId
*/
public function setImageRelationId($rId)
{
$this->_rIdImg = $rId;
}
/**
* Get Object ID
*
* @return int
*/
public function getObjectId()
{
return $this->_objId;
}
/**
* Set Object ID
*
* @param int $objId
*/
public function setObjectId($objId)
{
$this->_objId = $objId;
}
}

View File

@ -1,38 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
class PageBreak
{
/**
* Create a new PageBreak Element
*/
public function __construct()
{
}
}

View File

@ -1,728 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
class Settings
{
/**
* Default Page Size Width
*
* @var int
*/
private $_defaultPageSizeW = 11906;
/**
* Default Page Size Height
*
* @var int
*/
private $_defaultPageSizeH = 16838;
/**
* Page Orientation
*
* @var string
*/
private $_orientation;
/**
* Page Margin Top
*
* @var int
*/
private $_marginTop;
/**
* Page Margin Left
*
* @var int
*/
private $_marginLeft;
/**
* Page Margin Right
*
* @var int
*/
private $_marginRight;
/**
* Page Margin Bottom
*
* @var int
*/
private $_marginBottom;
/**
* Page Size Width
*
* @var int
*/
private $_pageSizeW;
/**
* Page Size Height
*
* @var int
*/
private $_pageSizeH;
/**
* Page Border Top Size
*
* @var int
*/
private $_borderTopSize;
/**
* Page Border Top Color
*
* @var int
*/
private $_borderTopColor;
/**
* Page Border Left Size
*
* @var int
*/
private $_borderLeftSize;
/**
* Page Border Left Color
*
* @var int
*/
private $_borderLeftColor;
/**
* Page Border Right Size
*
* @var int
*/
private $_borderRightSize;
/**
* Page Border Right Color
*
* @var int
*/
private $_borderRightColor;
/**
* Page Border Bottom Size
*
* @var int
*/
private $_borderBottomSize;
/**
* Page Border Bottom Color
*
* @var int
*/
private $_borderBottomColor;
/**
* Page Numbering Start
*
* @var int
*/
private $pageNumberingStart;
/**
* @var int
*/
private $headerHeight;
/**
* @var int
*/
private $footerHeight;
/**
* Section columns count
*
* @var int
*/
private $_colsNum;
/**
* Section spacing between columns
*
* @var int
*/
private $_colsSpace;
/**
* Section break type
*
* Options:
* - nextPage: Next page section break
* - nextColumn: Column section break
* - continuous: Continuous section break
* - evenPage: Even page section break
* - oddPage: Odd page section break
*
* @var string
*/
private $_breakType;
/**
* Create new Section Settings
*/
public function __construct()
{
$this->_orientation = null;
$this->_marginTop = 1418;
$this->_marginLeft = 1418;
$this->_marginRight = 1418;
$this->_marginBottom = 1134;
$this->_pageSizeW = $this->_defaultPageSizeW;
$this->_pageSizeH = $this->_defaultPageSizeH;
$this->_borderTopSize = null;
$this->_borderTopColor = null;
$this->_borderLeftSize = null;
$this->_borderLeftColor = null;
$this->_borderRightSize = null;
$this->_borderRightColor = null;
$this->_borderBottomSize = null;
$this->_borderBottomColor = null;
$this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches)
$this->footerHeight = 720;
$this->_colsNum = 1;
$this->_colsSpace = 720;
$this->_breakType = null;
}
/**
* Set Setting Value
*
* @param string $key
* @param string $value
*/
public function setSettingValue($key, $value)
{
if ($key == '_orientation' && $value == 'landscape') {
$this->setLandscape();
} elseif ($key == '_orientation' && is_null($value)) {
$this->setPortrait();
} elseif ($key == '_borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
$this->setBorderColor($value);
} else {
$this->$key = $value;
}
}
/**
* Get Margin Top
*
* @return int
*/
public function getMarginTop()
{
return $this->_marginTop;
}
/**
* Set Margin Top
*
* @param int $pValue
*/
public function setMarginTop($pValue = '')
{
$this->_marginTop = $pValue;
return $this;
}
/**
* Get Margin Left
*
* @return int
*/
public function getMarginLeft()
{
return $this->_marginLeft;
}
/**
* Set Margin Left
*
* @param int $pValue
*/
public function setMarginLeft($pValue = '')
{
$this->_marginLeft = $pValue;
return $this;
}
/**
* Get Margin Right
*
* @return int
*/
public function getMarginRight()
{
return $this->_marginRight;
}
/**
* Set Margin Right
*
* @param int $pValue
*/
public function setMarginRight($pValue = '')
{
$this->_marginRight = $pValue;
return $this;
}
/**
* Get Margin Bottom
*
* @return int
*/
public function getMarginBottom()
{
return $this->_marginBottom;
}
/**
* Set Margin Bottom
*
* @param int $pValue
*/
public function setMarginBottom($pValue = '')
{
$this->_marginBottom = $pValue;
return $this;
}
/**
* Set Landscape Orientation
*/
public function setLandscape()
{
$this->_orientation = 'landscape';
$this->_pageSizeW = $this->_defaultPageSizeH;
$this->_pageSizeH = $this->_defaultPageSizeW;
}
/**
* Set Portrait Orientation
*/
public function setPortrait()
{
$this->_orientation = null;
$this->_pageSizeW = $this->_defaultPageSizeW;
$this->_pageSizeH = $this->_defaultPageSizeH;
}
/**
* Get Page Size Width
*
* @return int
*/
public function getPageSizeW()
{
return $this->_pageSizeW;
}
/**
* Get Page Size Height
*
* @return int
*/
public function getPageSizeH()
{
return $this->_pageSizeH;
}
/**
* Get Page Orientation
*
* @return string
*/
public function getOrientation()
{
return $this->_orientation;
}
/**
* Set Border Size
*
* @param int $pValue
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
}
/**
* Get Border Size
*
* @return array
*/
public function getBorderSize()
{
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
return array($t, $l, $r, $b);
}
/**
* Set Border Color
*
* @param string $pValue
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
}
/**
* Get Border Color
*
* @return array
*/
public function getBorderColor()
{
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
return array($t, $l, $r, $b);
}
/**
* Set Border Top Size
*
* @param int $pValue
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
}
/**
* Get Border Top Size
*
* @return int
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
}
/**
* Set Border Top Color
*
* @param string $pValue
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
}
/**
* Get Border Top Color
*
* @return string
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
}
/**
* Set Border Left Size
*
* @param int $pValue
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
}
/**
* Get Border Left Size
*
* @return int
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
}
/**
* Set Border Left Color
*
* @param string $pValue
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
}
/**
* Get Border Left Color
*
* @return string
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
}
/**
* Set Border Right Size
*
* @param int $pValue
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
}
/**
* Get Border Right Size
*
* @return int
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
}
/**
* Set Border Right Color
*
* @param string $pValue
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
}
/**
* Get Border Right Color
*
* @return string
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
}
/**
* Set Border Bottom Size
*
* @param int $pValue
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
}
/**
* Get Border Bottom Size
*
* @return int
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
}
/**
* Set Border Bottom Color
*
* @param string $pValue
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
}
/**
* Get Border Bottom Color
*
* @return string
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}
/**
* @param null|int $pageNumberingStart
* @return $this
*/
public function setPageNumberingStart($pageNumberingStart = null)
{
$this->pageNumberingStart = $pageNumberingStart;
return $this;
}
/**
* @return null|int
*/
public function getPageNumberingStart()
{
return $this->pageNumberingStart;
}
/**
* Get Header Height
*
* @return int
*/
public function getHeaderHeight()
{
return $this->headerHeight;
}
/**
* Set Header Height
*
* @param int $pValue
*/
public function setHeaderHeight($pValue = '')
{
if (!is_numeric($pValue)) {
$pValue = 720;
}
$this->headerHeight = $pValue;
return $this;
}
/**
* Get Footer Height
*
* @return int
*/
public function getFooterHeight()
{
return $this->footerHeight;
}
/**
* Set Footer Height
*
* @param int $pValue
*/
public function setFooterHeight($pValue = '')
{
if (!is_numeric($pValue)) {
$pValue = 720;
}
$this->footerHeight = $pValue;
return $this;
}
/**
* Set Section Columns Count
*
* @param int $pValue
*/
public function setColsNum($pValue = '')
{
if (!is_numeric($pValue)) {
$pValue = 1;
}
$this->_colsNum = $pValue;
return $this;
}
/**
* Get Section Columns Count
*
* @return int
*/
public function getColsNum()
{
return $this->_colsNum;
}
/**
* Set Section Space Between Columns
*
* @param int $pValue
*/
public function setColsSpace($pValue = '')
{
if (!is_numeric($pValue)) {
$pValue = 720;
}
$this->_colsSpace = $pValue;
return $this;
}
/**
* Get Section Space Between Columns
*
* @return int
*/
public function getColsSpace()
{
return $this->_colsSpace;
}
/**
* Set Break Type
*
* @param string $pValue
*/
public function setBreakType($pValue = null)
{
$this->_breakType = $pValue;
return $this;
}
/**
* Get Break Type
*
* @return string
*/
public function getBreakType()
{
return $this->_breakType;
}
}

View File

@ -1,163 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Section\Table\Row;
class Table
{
/**
* Table style
*
* @var PhpOffice\PhpWord\Style\Table
*/
private $_style;
/**
* Table rows
*
* @var array
*/
private $_rows = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf = null;
/**
* Table holder count
*
* @var array
*/
private $_pCount;
/**
* Table width
*
* @var int
*/
private $_width = null;
/**
* Create a new table
*
* @param string $insideOf
* @param int $pCount
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
if (!is_null($style)) {
if (is_array($style)) {
$this->_style = new PhpOffice\PhpWord\Style\Table();
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
} else {
$this->_style = $style;
}
}
}
/**
* Add a row
*
* @param int $height
*/
public function addRow($height = null, $style = null)
{
$row = new Row($this->_insideOf, $this->_pCount, $height, $style);
$this->_rows[] = $row;
return $row;
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Table\Cell
*/
public function addCell($width = null, $style = null)
{
$i = count($this->_rows) - 1;
$cell = $this->_rows[$i]->addCell($width, $style);
return $cell;
}
/**
* Get all rows
*
* @return array
*/
public function getRows()
{
return $this->_rows;
}
/**
* Get table style
*
* @return PhpOffice\PhpWord\Style\Table
*/
public function getStyle()
{
return $this->_style;
}
/**
* Set table width
*
* @var int $width
*/
public function setWidth($width)
{
$this->_width = $width;
}
/**
* Get table width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}
}

View File

@ -1,350 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Shared\String;
class Cell
{
/**
* Cell Width
*
* @var int
*/
private $_width = null;
/**
* Cell Style
*
* @var PhpOffice\PhpWord\Style\Cell
*/
private $_style;
/**
* Cell Element Collection
*
* @var array
*/
private $_elementCollection = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf;
/**
* Section/Header/Footer count
*
* @var int
*/
private $_pCount;
/**
* Create a new Table Cell
*
* @param string $insideOf
* @param int $pCount
* @param int $width
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $width = null, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
$this->_width = $width;
$this->_style = new PhpOffice\PhpWord\Style\Cell();
if (!is_null($style)) {
if (is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
} else {
$this->_style = $style;
}
}
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add a Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $style = null)
{
if ($this->_insideOf == 'section') {
if (!String::IsUTF8($linkSrc)) {
$linkSrc = utf8_encode($linkSrc);
}
if (!is_null($linkName)) {
if (!String::IsUTF8($linkName)) {
$linkName = utf8_encode($linkName);
}
}
$link = new Link($linkSrc, $linkName, $style);
$rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
} else {
throw new Exception('Unsupported Link header / footer reference');
return false;
}
}
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Add a ListItem Element
*
* @param string $text
* @param int $depth
* @param mixed $styleText
* @param mixed $styleList
* @return PhpOffice\PhpWord\Section\ListItem
*/
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$listItem = new ListItem($text, $depth, $styleText, $styleList);
$this->_elementCollection[] = $listItem;
return $listItem;
}
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
if ($this->_insideOf == 'section') {
$rID = Media::addSectionMediaElement($src, 'image');
} elseif ($this->_insideOf == 'header') {
$rID = Media::addHeaderMediaElement($this->_pCount, $src);
} elseif ($this->_insideOf == 'footer') {
$rID = Media::addFooterMediaElement($this->_pCount, $src);
}
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Source does not exist or unsupported image type.');
}
}
/**
* Add a by PHP created Image Element
*
* @param string $link
* @param mixed $style
* @return PhpOffice\PhpWord\Section\MemoryImage
*/
public function addMemoryImage($link, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
if ($this->_insideOf == 'section') {
$rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
} elseif ($this->_insideOf == 'header') {
$rID = Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage);
} elseif ($this->_insideOf == 'footer') {
$rID = Media::addFooterMediaElement($this->_pCount, $link, $memoryImage);
}
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
throw new Exception('Unsupported image type.');
}
}
/**
* Add a OLE-Object Element
*
* @param string $src
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Object
*/
public function addObject($src, $style = null)
{
$object = new Object($src, $style);
if (!is_null($object->getSource())) {
$inf = pathinfo($src);
$ext = $inf['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$iconSrc = PHPWORD_BASE_PATH . 'PhpWord/_staticDocParts/';
if (!file_exists($iconSrc . '_' . $ext . '.png')) {
$iconSrc = $iconSrc . '_default.png';
} else {
$iconSrc .= '_' . $ext . '.png';
}
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
$data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0];
$objectId = $data[1];
$object->setRelationId($rID);
$object->setObjectId($objectId);
$object->setImageRelationId($rIDimg);
$this->_elementCollection[] = $object;
return $object;
} else {
throw new Exception('Source does not exist or unsupported object type.');
}
}
/**
* Add a PreserveText Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') {
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
} else {
throw new Exception('addPreserveText only supported in footer/header.');
}
}
/**
* Create a new TextRun
*
* @return PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Get all Elements
*
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Cell Style
*
* @return PhpOffice\PhpWord\Style\Cell
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get Cell width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}
}

View File

@ -1,139 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2013 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section\Table;
class Row
{
/**
* Row height
*
* @var int
*/
private $_height = null;
/**
* Row style
*
* @var PhpOffice\PhpWord\Style\Row
*/
private $_style;
/**
* Row cells
*
* @var array
*/
private $_cells = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf;
/**
* Section/Header/Footer count
*
* @var int
*/
private $_pCount;
/**
* Create a new table row
*
* @param string $insideOf
* @param int $pCount
* @param int $height
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $height = null, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
$this->_height = $height;
$this->_style = new PhpOffice\PhpWord\Style\Row();
if (!is_null($style)) {
if (is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
}
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return PhpOffice\PhpWord\Section\Table\Cell
*/
public function addCell($width = null, $style = null)
{
$cell = new Cell($this->_insideOf, $this->_pCount, $width, $style);
$this->_cells[] = $cell;
return $cell;
}
/**
* Get all cells
*
* @return array
*/
public function getCells()
{
return $this->_cells;
}
/**
* Get row style
*
* @return PhpOffice\PhpWord\Style\Row
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get row height
*
* @return int
*/
public function getHeight()
{
return $this->_height;
}
}

View File

@ -1,154 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class Text
{
/**
* Text content
*
* @var string
*/
private $text;
/**
* Text style
*
* @var PhpOffice\PhpWord\Style\Font
*/
private $fontStyle;
/**
* Paragraph style
*
* @var PhpOffice\PhpWord\Style\Paragraph
*/
private $paragraphStyle;
/**
* Create a new Text Element
*
* @param string $text
* @param null|array|PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
$this->setText($text);
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
$this->setFontStyle($fontStyle, $paragraphStyle);
}
/**
* Set Text style
*
* @param null|array|PhpOffice\PhpWord\Style\Font $style
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
if ($style instanceof Font) {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) {
$this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setArrayStyle($style);
} elseif (null === $style) {
$this->fontStyle = new Font('text', $paragraphStyle);
} else {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
}
return $this->fontStyle;
}
/**
* Get Text style
*
* @return PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Set Paragraph style
*
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $style
* @return null|PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle->setArrayStyle($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} elseif (null === $style) {
$this->paragraphStyle = new Paragraph;
} else {
$this->paragraphStyle = $style;
}
return $this->paragraphStyle;
}
/**
* Get Paragraph style
*
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* @param string $text
* @return $this
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
/**
* Get Text content
*
* @return string
*/
public function getText()
{
return $this->text;
}
}

View File

@ -1,122 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class TextBreak
{
/**
* Paragraph style
*
* @var PhpOffice\PhpWord\Style\Pagaraph
*/
private $paragraphStyle = null;
/**
* Text style
*
* @var PhpOffice\PhpWord\Style\Font
*/
private $fontStyle = null;
/**
* Create a new TextBreak Element
*/
public function __construct($fontStyle = null, $paragraphStyle = null)
{
if (!is_null($paragraphStyle)) {
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
}
if (!is_null($fontStyle)) {
$this->setFontStyle($fontStyle, $paragraphStyle);
}
}
/**
* Set Text style
*
* @param null|array|PhpOffice\PhpWord\Style\Font $style
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
if ($style instanceof Font) {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) {
$this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setArrayStyle($style);
} else {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
}
return $this->fontStyle;
}
/**
* Get Text style
*
* @return PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Set Paragraph style
*
* @param null|array|PhpOffice\PhpWord\Style\Paragraph $style
* @return null|PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle->setArrayStyle($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} else {
$this->paragraphStyle = $style;
}
return $this->paragraphStyle;
}
/**
* Get Paragraph style
*
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
}

View File

@ -1,184 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Paragraph;
class TextRun
{
/**
* Paragraph style
*
* @var PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
/**
* Text collection
*
* @var array
*/
private $_elementCollection;
/**
* Create a new TextRun Element
*/
public function __construct($styleParagraph = null)
{
$this->_elementCollection = array();
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
}
/**
* Add a Text Element
*
* @var string $text
* @var mixed $styleFont
* @return PhpOffice\PhpWord\Section\Text
*/
public function addText($text = null, $styleFont = null)
{
if (!String::IsUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add a Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @return PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
$linkSrc = utf8_encode($linkSrc);
if (!is_null($linkName)) {
$linkName = utf8_encode($linkName);
}
$link = new Link($linkSrc, $linkName, $styleFont);
$rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
}
/**
* Add a Image Element
*
* @param string $imageSrc
* @param mixed $styleFont
* @return PhpOffice\PhpWord\Section\Image
*/
public function addImage($imageSrc, $style = null)
{
$image = new Image($imageSrc, $style);
if (!is_null($image->getSource())) {
$rID = Media::addSectionMediaElement($imageSrc, 'image');
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Source does not exist or unsupported image type.');
}
}
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new Footnote Element
*
* @param string $text
* @return PhpOffice\PhpWord\Section\Footnote
*/
public function createFootnote($styleParagraph = null)
{
$footnote = new PhpOffice\PhpWord\Section\Footnote($styleParagraph);
$refID = PhpOffice\PhpWord\Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID);
$this->_elementCollection[] = $footnote;
return $footnote;
}
/**
* Get TextRun content
*
* @return string
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Paragraph style
*
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
}

View File

@ -1,145 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
class Title
{
/**
* Title Text content
*
* @var string
*/
private $_text;
/**
* Title depth
*
* @var int
*/
private $_depth;
/**
* Title anchor
*
* @var int
*/
private $_anchor;
/**
* Title Bookmark ID
*
* @var int
*/
private $_bookmarkId;
/**
* Title style
*
* @var string
*/
private $_style;
/**
* Create a new Title Element
*
* @var string $text
* @var int $depth
*/
public function __construct($text, $depth = 1, $style = null)
{
if (!is_null($style)) {
$this->_style = $style;
}
$this->_text = $text;
$this->_depth = $depth;
return $this;
}
/**
* Set Anchor
*
* @var int $anchor
*/
public function setAnchor($anchor)
{
$this->_anchor = $anchor;
}
/**
* Get Anchor
*
* @return int
*/
public function getAnchor()
{
return $this->_anchor;
}
/**
* Set Bookmark ID
*
* @var int $bookmarkId
*/
public function setBookmarkId($bookmarkId)
{
$this->_bookmarkId = $bookmarkId;
}
/**
* Get Anchor
*
* @return int
*/
public function getBookmarkId()
{
return $this->_bookmarkId;
}
/**
* Get Title Text content
*
* @return string
*/
public function getText()
{
return $this->_text;
}
/**
* Get Title style
*
* @return string
*/
public function getStyle()
{
return $this->_style;
}
}

View File

@ -1,63 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
class Settings
{
/**
* Compatibility option for XMLWriter
*
* @var boolean
*/
private static $_xmlWriterCompatibility = true;
/**
* Set the compatibility option used by the XMLWriter
*
* @param boolean $compatibility This sets the setIndent and setIndentString for better compatibility
* @return boolean Success or failure
*/
public static function setCompatibility($compatibility)
{
if (is_bool($compatibility)) {
self::$_xmlWriterCompatibility = $compatibility;
return true;
}
return false;
}
/**
* Return the compatibility option used by the XMLWriter
*
* @return boolean Compatibility
*/
public static function getCompatibility()
{
return self::$_xmlWriterCompatibility;
}
}

View File

@ -1,162 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
class Drawing
{
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int Value in EMU
*/
public static function pixelsToEMU($pValue = 0)
{
return round($pValue * 9525);
}
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int Value in pixels
*/
public static function EMUToPixels($pValue = 0)
{
if ($pValue != 0) {
return round($pValue / 9525);
} else {
return 0;
}
}
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return int Value in points
*/
public static function pixelsToPoints($pValue = 0)
{
return $pValue * 0.67777777;
}
/**
* Convert points width to pixels
*
* @param int $pValue Value in points
* @return int Value in pixels
*/
public static function pointsToPixels($pValue = 0)
{
if ($pValue != 0) {
return $pValue * 1.333333333;
} else {
return 0;
}
}
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int Angle
*/
public static function degreesToAngle($pValue = 0)
{
return (int)round($pValue * 60000);
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int Degrees
*/
public static function angleToDegrees($pValue = 0)
{
if ($pValue != 0) {
return round($pValue / 60000);
} else {
return 0;
}
}
/**
* Convert pixels to centimeters
*
* @param int $pValue Value in pixels
* @return int Value in centimeters
*/
public static function pixelsToCentimeters($pValue = 0)
{
return $pValue * 0.028;
}
/**
* Convert centimeters width to pixels
*
* @param int $pValue Value in centimeters
* @return int Value in pixels
*/
public static function centimetersToPixels($pValue = 0)
{
if ($pValue != 0) {
return $pValue / 0.028;
} else {
return 0;
}
}
/**
* Convert HTML hexadecimal to RGB
*
* @param str $pValue HTML Color in hexadecimal
* @return array Value in RGB
*/
public static function htmlToRGB($pValue)
{
if ($pValue[0] == '#') {
$pValue = substr($pValue, 1);
}
if (strlen($pValue) == 6) {
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]);
} elseif (strlen($pValue) == 3) {
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]);
} else {
return false;
}
$color_R = hexdec($color_R);
$color_G = hexdec($color_G);
$color_B = hexdec($color_B);
return array($color_R, $color_G, $color_B);
}
}

View File

@ -1,76 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
class File
{
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function file_exists($pFilename)
{
// Regular file_exists
return file_exists($pFilename);
}
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename)
{
// Returnvalue
$returnValue = '';
// Try using realpath()
$returnValue = realpath($pFilename);
// Found something?
if ($returnValue == '' || is_null($returnValue)) {
$pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
// Return
return $returnValue;
}
}

View File

@ -1,90 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
class Font
{
/**
* Calculate an (approximate) pixel size, based on a font points size
*
* @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels)
*/
public static function fontSizeToPixels($fontSizeInPoints = 12)
{
return ((16 / 12) * $fontSizeInPoints);
}
/**
* Calculate an (approximate) pixel size, based on inch size
*
* @param int $sizeInInch Font size (in inch)
* @return int Size (in pixels)
*/
public static function inchSizeToPixels($sizeInInch = 1)
{
return ($sizeInInch * 96);
}
/**
* Calculate an (approximate) pixel size, based on centimeter size
*
* @param int $sizeInCm Font size (in centimeters)
* @return int Size (in pixels)
*/
public static function centimeterSizeToPixels($sizeInCm = 1)
{
return ($sizeInCm * 37.795275591);
}
public static function centimeterSizeToTwips($sizeInCm = 1)
{
return ($sizeInCm * 565.217);
}
public static function inchSizeToTwips($sizeInInch = 1)
{
return self::centimeterSizeToTwips($sizeInInch * 2.54);
}
public static function pixelSizeToTwips($sizeInPixel = 1)
{
return self::centimeterSizeToTwips($sizeInPixel / 37.795275591);
}
/**
* Calculate twip based on point size, used mainly for paragraph spacing
*
* @param int|float $sizeInPoint Size in point
* @return int|float Size (in twips)
*/
public static function pointSizeToTwips($sizeInPoint = 1)
{
return ($sizeInPoint * 20);
}
}

View File

@ -1,109 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
class String
{
/**
* Control characters array
*
* @var string[]
*/
private static $_controlCharacters = array();
/**
* Build control characters array
*/
private static function _buildControlCharacters()
{
for ($i = 0; $i <= 19; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$_controlCharacters[$find] = $replace;
}
}
}
/**
* Convert from OpenXML escaped control character to PHP control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to unescape
* @return string
*/
public static function ControlCharacterOOXML2PHP($value = '')
{
if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
}
return str_replace(array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value);
}
/**
* Convert from PHP control character to OpenXML escaped control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to escape
* @return string
*/
public static function ControlCharacterPHP2OOXML($value = '')
{
if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
}
return str_replace(array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value);
}
/**
* Check if a string contains UTF-8 data
*
* @param string $value
* @return boolean
*/
public static function IsUTF8($value = '')
{
return $value === '' || preg_match('/^./su', $value) === 1;
}
}

View File

@ -1,155 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Settings;
if (!defined('DATE_W3C')) {
define('DATE_W3C', 'Y-m-d\TH:i:sP');
}
/**
* @method bool startElement(string $name)
* @method bool writeAttribute(string $name, string $value)
* @method bool endElement()
*/
class XMLWriter
{
/** Temporary storage method */
const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
/**
* Internal XMLWriter
*
* @var XMLWriter
*/
private $_xmlWriter;
/**
* Temporary filename
*
* @var string
*/
private $_tempFileName = '';
/**
* Create a new XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageFolder Temporary storage folder
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './')
{
// Create internal XMLWriter
$this->_xmlWriter = new XMLWriter();
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->_xmlWriter->openMemory();
} else {
// Create temporary filename
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
// Fallback to memory...
$this->_xmlWriter->openMemory();
}
}
// Set xml Compatibility
$compatibility = Settings::getCompatibility();
if ($compatibility) {
$this->_xmlWriter->setIndent(false);
$this->_xmlWriter->setIndentString('');
} else {
$this->_xmlWriter->setIndent(true);
$this->_xmlWriter->setIndentString(' ');
}
}
/**
* Destructor
*/
public function __destruct()
{
// Desctruct XMLWriter
unset($this->_xmlWriter);
// Unlink temporary files
if ($this->_tempFileName != '') {
@unlink($this->_tempFileName);
}
}
/**
* Get written data
*
* @return $data
*/
public function getData()
{
if ($this->_tempFileName == '') {
return $this->_xmlWriter->outputMemory(true);
} else {
$this->_xmlWriter->flush();
return file_get_contents($this->_tempFileName);
}
}
/**
* Catch function calls (and pass them to internal XMLWriter)
*
* @param unknown_type $function
* @param unknown_type $args
*/
public function __call($function, $args)
{
try {
@call_user_func_array(array($this->_xmlWriter, $function), $args);
} catch (Exception $ex) {
// Do nothing!
}
}
/**
* Fallback method for writeRaw, introduced in PHP 5.2
*
* @param string $text
* @return string
*/
public function writeRaw($text)
{
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
return $this->_xmlWriter->writeRaw($text);
}
return $this->text($text);
}
}

View File

@ -1,183 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
/**
* @codeCoverageIgnore Legacy from PHPExcel
*/
class ZipStreamWrapper
{
/**
* Internal ZipAcrhive
*
* @var ZipAcrhive
*/
private $_archive;
/**
* Filename in ZipAcrhive
*
* @var string
*/
private $_fileNameInArchive = '';
/**
* Position in file
*
* @var int
*/
private $_position = 0;
/**
* Data
*
* @var mixed
*/
private $_data = '';
/**
* Register wrapper
*/
public static function register()
{
@stream_wrapper_unregister("zip");
@stream_wrapper_register("zip", __CLASS__);
}
/**
* Open stream
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
// Check for mode
if ($mode{0} != 'r') {
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
}
// Parse URL
$url = @parse_url($path);
// Fix URL
if (!is_array($url)) {
$url['host'] = substr($path, strlen('zip://'));
$url['path'] = '';
}
if (strpos($url['host'], '#') !== false) {
if (!isset($url['fragment'])) {
$url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path'];
$url['host'] = substr($url['host'], 0, strpos($url['host'], '#'));
unset($url['path']);
}
} else {
$url['host'] = $url['host'] . $url['path'];
unset($url['path']);
}
// Open archive
$this->_archive = new ZipArchive();
$this->_archive->open($url['host']);
$this->_fileNameInArchive = $url['fragment'];
$this->_position = 0;
$this->_data = $this->_archive->getFromName($this->_fileNameInArchive);
return true;
}
/**
* Stat stream
*/
public function stream_stat()
{
return $this->_archive->statName($this->_fileNameInArchive);
}
/**
* Read stream
*/
public function stream_read($count)
{
$ret = substr($this->_data, $this->_position, $count);
$this->_position += strlen($ret);
return $ret;
}
/**
* Tell stream
*/
public function stream_tell()
{
return $this->_position;
}
/**
* EOF stream
*/
public function stream_eof()
{
return $this->_position >= strlen($this->_data);
}
/**
* Seek stream
*/
public function stream_seek($offset, $whence)
{
switch ($whence) {
case SEEK_SET:
if ($offset < strlen($this->_data) && $offset >= 0) {
$this->_position = $offset;
return true;
} else {
return false;
}
break;
case SEEK_CUR:
if ($offset >= 0) {
$this->_position += $offset;
return true;
} else {
return false;
}
break;
case SEEK_END:
if (strlen($this->_data) + $offset >= 0) {
$this->_position = strlen($this->_data) + $offset;
return true;
} else {
return false;
}
break;
default:
return false;
}
}
}

View File

@ -1,161 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
class Style
{
/**
* @var array
*/
private static $_styleElements = array();
/**
* @param string $styleName
* @param array $styles
*/
public static function addParagraphStyle($styleName, $styles)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new Paragraph();
foreach ($styles as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$style->setStyleValue($key, $value);
}
self::$_styleElements[$styleName] = $style;
}
}
/**
* @param string $styleName
* @param array $styleFont
* @param array $styleParagraph
*/
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$font = new Font('text', $styleParagraph);
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$font->setStyleValue($key, $value);
}
self::$_styleElements[$styleName] = $font;
}
}
/**
* @param string $styleName
* @param array $styles
*/
public static function addLinkStyle($styleName, $styles)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new Font('link');
foreach ($styles as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$style->setStyleValue($key, $value);
}
self::$_styleElements[$styleName] = $style;
}
}
/**
* @param string $styleName
* @param array $styles
*/
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new TableFull($styleTable, $styleFirstRow);
self::$_styleElements[$styleName] = $style;
}
}
/**
* @param string $styleName
* @param array $styleFont
* @param array $styleParagraph
*/
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
{
$styleName = 'Heading_' . $titleCount;
if (!array_key_exists($styleName, self::$_styleElements)) {
$font = new Font('title', $styleParagraph);
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$font->setStyleValue($key, $value);
}
self::$_styleElements[$styleName] = $font;
}
}
/**
* @param array $styles Paragraph style definition
*/
public static function setDefaultParagraphStyle($styles)
{
self::addParagraphStyle('Normal', $styles);
}
/**
* Get all styles
*
* @return PhpOffice\PhpWord\Style\Font[]
*/
public static function getStyles()
{
return self::$_styleElements;
}
/**
* @param string
*/
public static function getStyle($styleName)
{
if (array_key_exists($styleName, self::$_styleElements)) {
return self::$_styleElements[$styleName];
} else {
return null;
}
}
}

View File

@ -1,343 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
class Cell
{
const TEXT_DIR_BTLR = 'btLr';
const TEXT_DIR_TBRL = 'tbRl';
/**
* Vertical align (top, center, both, bottom)
*
* @var string
*/
private $_valign;
/**
* Text Direction
*
* @var string
*/
private $_textDirection;
/**
* Background-Color
*
* @var string
*/
private $_bgColor;
/**
* Border Top Size
*
* @var int
*/
private $_borderTopSize;
/**
* Border Top Color
*
* @var string
*/
private $_borderTopColor;
/**
* Border Left Size
*
* @var int
*/
private $_borderLeftSize;
/**
* Border Left Color
*
* @var string
*/
private $_borderLeftColor;
/**
* Border Right Size
*
* @var int
*/
private $_borderRightSize;
/**
* Border Right Color
*
* @var string
*/
private $_borderRightColor;
/**
* Border Bottom Size
*
* @var int
*/
private $_borderBottomSize;
/**
* Border Bottom Color
*
* @var string
*/
private $_borderBottomColor;
/**
* Border Default Color
*
* @var string
*/
private $_defaultBorderColor;
/**
* colspan
*
* @var integer
*/
private $_gridSpan = null;
/**
* rowspan (restart, continue)
*
* - restart: Start/restart merged region
* - continue: Continue merged region
*
* @var string
*/
private $_vMerge = null;
/**
* Create a new Cell Style
*/
public function __construct()
{
$this->_valign = null;
$this->_textDirection = null;
$this->_bgColor = null;
$this->_borderTopSize = null;
$this->_borderTopColor = null;
$this->_borderLeftSize = null;
$this->_borderLeftColor = null;
$this->_borderRightSize = null;
$this->_borderRightColor = null;
$this->_borderBottomSize = null;
$this->_borderBottomColor = null;
$this->_defaultBorderColor = '000000';
}
/**
* Set style value
*
* @var string $key
* @var mixed $value
*/
public function setStyleValue($key, $value)
{
if ($key == '_borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
$this->setBorderColor($value);
} else {
$this->$key = $value;
}
}
public function getVAlign()
{
return $this->_valign;
}
public function setVAlign($pValue = null)
{
$this->_valign = $pValue;
}
public function getTextDirection()
{
return $this->_textDirection;
}
public function setTextDirection($pValue = null)
{
$this->_textDirection = $pValue;
}
public function getBgColor()
{
return $this->_bgColor;
}
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
}
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
}
public function getBorderSize()
{
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
return array($t, $l, $r, $b);
}
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
}
public function getBorderColor()
{
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
return array($t, $l, $r, $b);
}
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
}
public function getBorderTopSize()
{
return $this->_borderTopSize;
}
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
}
public function getBorderTopColor()
{
return $this->_borderTopColor;
}
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
}
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
}
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
}
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
}
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
}
public function getBorderRightSize()
{
return $this->_borderRightSize;
}
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
}
public function getBorderRightColor()
{
return $this->_borderRightColor;
}
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
}
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
}
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
}
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}
public function getDefaultBorderColor()
{
return $this->_defaultBorderColor;
}
public function setGridSpan($pValue = null)
{
$this->_gridSpan = $pValue;
}
public function getGridSpan()
{
return $this->_gridSpan;
}
public function setVMerge($pValue = null)
{
$this->_vMerge = $pValue;
}
public function getVMerge()
{
return $this->_vMerge;
}
}

View File

@ -1,544 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
class Font
{
const UNDERLINE_NONE = 'none';
const UNDERLINE_DASH = 'dash';
const UNDERLINE_DASHHEAVY = 'dashHeavy';
const UNDERLINE_DASHLONG = 'dashLong';
const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy';
const UNDERLINE_DOUBLE = 'dbl';
const UNDERLINE_DOTHASH = 'dotDash';
const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy';
const UNDERLINE_DOTDOTDASH = 'dotDotDash';
const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy';
const UNDERLINE_DOTTED = 'dotted';
const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy';
const UNDERLINE_HEAVY = 'heavy';
const UNDERLINE_SINGLE = 'single';
const UNDERLINE_WAVY = 'wavy';
const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
const UNDERLINE_WORDS = 'words';
const FGCOLOR_YELLOW = 'yellow';
const FGCOLOR_LIGHTGREEN = 'green';
const FGCOLOR_CYAN = 'cyan';
const FGCOLOR_MAGENTA = 'magenta';
const FGCOLOR_BLUE = 'blue';
const FGCOLOR_RED = 'red';
const FGCOLOR_DARKBLUE = 'darkBlue';
const FGCOLOR_DARKCYAN = 'darkCyan';
const FGCOLOR_DARKGREEN = 'darkGreen';
const FGCOLOR_DARKMAGENTA = 'darkMagenta';
const FGCOLOR_DARKRED = 'darkRed';
const FGCOLOR_DARKYELLOW = 'darkYellow';
const FGCOLOR_DARKGRAY = 'darkGray';
const FGCOLOR_LIGHTGRAY = 'lightGray';
const FGCOLOR_BLACK = 'black';
/**
* Font style type
*
* @var string
*/
private $_type;
/**
* Paragraph Style
*
* @var PhpOffice\PhpWord\Style\Paragraph
*/
private $_paragraphStyle;
/**
* Font name
*
* @var int|float
*/
private $_name = PhpWord::DEFAULT_FONT_NAME;
/**
* Font size
*
* @var int|float
*/
private $_size = PhpWord::DEFAULT_FONT_SIZE;
/**
* Bold
*
* @var bool
*/
private $_bold = false;
/**
* Italics
*
* @var bool
*/
private $_italic = false;
/**
* Superscript
*
* @var bool
*/
private $_superScript = false;
/**
* Subscript
*
* @var bool
*/
private $_subScript = false;
/**
* Underline mode
*
* @var string
*/
private $_underline = self::UNDERLINE_NONE;
/**
* Strikethrough
*
* @var bool
*/
private $_strikethrough = false;
/**
* Font color
*
* @var string
*/
private $_color = PhpWord::DEFAULT_FONT_COLOR;
/**
* Foreground/highlight
*
* @var string
*/
private $_fgColor = null;
/**
* Text line height
*
* @var int
*/
private $lineHeight = 1.0;
/**
* Font Content Type
*
* @var string
*/
private $_hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
/**
* New font style
*
* @param string $type Type of font
* @param array $paragraphStyle Paragraph styles definition
*/
public function __construct($type = 'text', $paragraphStyle = null)
{
$this->_type = $type;
if ($paragraphStyle instanceof Paragraph) {
$this->_paragraphStyle = $paragraphStyle;
} elseif (is_array($paragraphStyle)) {
$this->_paragraphStyle = new Paragraph;
$this->_paragraphStyle->setArrayStyle($paragraphStyle);
} else {
$this->_paragraphStyle = $paragraphStyle;
}
}
/**
* @param array $style
* @return $this
*/
public function setArrayStyle(array $style = array())
{
foreach ($style as $key => $value) {
if ($key === 'line-height') {
$this->setLineHeight($value);
null;
} elseif (substr($key, 0, 1) !== '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
return $this;
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
$method = 'set' . substr($key, 1);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
/**
* Get font name
*
* @return bool
*/
public function getName()
{
return $this->_name;
}
/**
* Set font name
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setName($pValue = PhpWord::DEFAULT_FONT_NAME)
{
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_NAME;
}
$this->_name = $pValue;
return $this;
}
/**
* Get font size
*
* @return int|float
*/
public function getSize()
{
return $this->_size;
}
/**
* Set font size
*
* @param int|float $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setSize($pValue = PhpWord::DEFAULT_FONT_SIZE)
{
if (!is_numeric($pValue)) {
$pValue = PhpWord::DEFAULT_FONT_SIZE;
}
$this->_size = $pValue;
return $this;
}
/**
* Get bold
*
* @return bool
*/
public function getBold()
{
return $this->_bold;
}
/**
* Set bold
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setBold($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_bold = $pValue;
return $this;
}
/**
* Get italics
*
* @return bool
*/
public function getItalic()
{
return $this->_italic;
}
/**
* Set italics
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setItalic($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_italic = $pValue;
return $this;
}
/**
* Get superscript
*
* @return bool
*/
public function getSuperScript()
{
return $this->_superScript;
}
/**
* Set superscript
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setSuperScript($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_superScript = $pValue;
$this->_subScript = !$pValue;
return $this;
}
/**
* Get superscript
*
* @return bool
*/
public function getSubScript()
{
return $this->_subScript;
}
/**
* Set subscript
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setSubScript($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_subScript = $pValue;
$this->_superScript = !$pValue;
return $this;
}
/**
* Get underline
*
* @return string
*/
public function getUnderline()
{
return $this->_underline;
}
/**
* Set underline
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setUnderline($pValue = self::UNDERLINE_NONE)
{
if ($pValue == '') {
$pValue = self::UNDERLINE_NONE;
}
$this->_underline = $pValue;
return $this;
}
/**
* Get strikethrough
*
* @return bool
*/
public function getStrikethrough()
{
return $this->_strikethrough;
}
/**
* Set strikethrough
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setStrikethrough($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_strikethrough = $pValue;
return $this;
}
/**
* Get font color
*
* @return string
*/
public function getColor()
{
return $this->_color;
}
/**
* Set font color
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setColor($pValue = PhpWord::DEFAULT_FONT_COLOR)
{
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_COLOR;
}
$this->_color = $pValue;
return $this;
}
/**
* Get foreground/highlight color
*
* @return bool
*/
public function getFgColor()
{
return $this->_fgColor;
}
/**
* Set foreground/highlight color
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setFgColor($pValue = null)
{
$this->_fgColor = $pValue;
return $this;
}
/**
* Get style type
*
* @return string
*/
public function getStyleType()
{
return $this->_type;
}
/**
* Get paragraph style
*
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->_paragraphStyle;
}
/**
* Set the line height
*
* @param int|float|string $lineHeight
* @return $this
* @throws InvalidStyleException
*/
public function setLineHeight($lineHeight)
{
if (is_string($lineHeight)) {
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
}
if ((!is_integer($lineHeight) && !is_float($lineHeight)) || !$lineHeight) {
throw new InvalidStyleException('Line height must be a valid number');
}
$this->lineHeight = $lineHeight;
$this->getParagraphStyle()->setLineHeight($lineHeight);
return $this;
}
/**
* @return int|float
*/
public function getLineHeight()
{
return $this->lineHeight;
}
/**
* Get Font Content Type
*
* @return bool
*/
public function getHint()
{
return $this->_hint;
}
/**
* Set Font Content Type
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Font
*/
public function setHint($pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE)
{
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
}
$this->_hint = $pValue;
return $this;
}
}

View File

@ -1,175 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
class 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
*
* @var int
*/
private $_marginTop;
/**
* Margin Left
*
* @var int
*/
private $_marginLeft;
public function __construct()
{
$this->_width = null;
$this->_height = null;
$this->_align = null;
$this->_marginTop = null;
$this->_marginLeft = null;
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
}
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
public function getWidth()
{
return $this->_width;
}
public function setWidth($pValue = null)
{
$this->_width = $pValue;
}
public function getHeight()
{
return $this->_height;
}
public function setHeight($pValue = null)
{
$this->_height = $pValue;
}
public function getAlign()
{
return $this->_align;
}
public function setAlign($pValue = null)
{
$this->_align = $pValue;
}
/**
* Get Margin Top
*
* @return int
*/
public function getMarginTop()
{
return $this->_marginTop;
}
/**
* Set Margin Top
*
* @param int $pValue
* @return $this
*/
public function setMarginTop($pValue = null)
{
$this->_marginTop = $pValue;
return $this;
}
/**
* Get Margin Left
*
* @return int
*/
public function getMarginLeft()
{
return $this->_marginLeft;
}
/**
* 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;
}
}

View File

@ -1,80 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
class ListItem
{
const TYPE_NUMBER = 7;
const TYPE_NUMBER_NESTED = 8;
const TYPE_ALPHANUM = 9;
const TYPE_BULLET_FILLED = 3;
const TYPE_BULLET_EMPTY = 5;
const TYPE_SQUARE_FILLED = 1;
/**
* List Type
*/
private $_listType;
/**
* Create a new ListItem Style
*/
public function __construct()
{
$this->_listType = self::TYPE_BULLET_FILLED;
}
/**
* Set style value
*
* @param string $key
* @param string $value
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
/**
* Set List Type
*
* @param int $pValue
*/
public function setListType($pValue = self::TYPE_BULLET_FILLED)
{
$this->_listType = $pValue;
}
/**
* Get List Type
*/
public function getListType()
{
return $this->_listType;
}
}

View File

@ -1,508 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
class Paragraph
{
const LINE_HEIGHT = 240;
/**
* Text line height
*
* @var int
*/
private $lineHeight;
/**
* Paragraph alignment
*
* @var string
*/
private $_align;
/**
* Space before Paragraph
*
* @var int
*/
private $_spaceBefore;
/**
* Space after Paragraph
*
* @var int
*/
private $_spaceAfter;
/**
* Spacing between breaks
*
* @var int
*/
private $_spacing;
/**
* Set of Custom Tab Stops
*
* @var array
*/
private $_tabs;
/**
* Indent by how much
*
* @var int
*/
private $_indent;
/**
* Hanging by how much
*
* @var int
*/
private $_hanging;
/**
* Parent style
*
* @var string
*/
private $_basedOn = 'Normal';
/**
* Style for next paragraph
*
* @var string
*/
private $_next;
/**
* Allow first/last line to display on a separate page
*
* @var bool
*/
private $_widowControl = true;
/**
* Keep paragraph with next paragraph
*
* @var bool
*/
private $_keepNext = false;
/**
* Keep all lines on one page
*
* @var bool
*/
private $_keepLines = false;
/**
* Start paragraph on next page
*
* @var bool
*/
private $_pageBreakBefore = false;
/**
* @param array $style
* @return $this
*/
public function setArrayStyle(array $style = array())
{
foreach ($style as $key => $value) {
if ($key === 'line-height') {
null;
} elseif (substr($key, 0, 1) !== '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
return $this;
}
/**
* Set Style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
if ($key == '_indent' || $key == '_hanging') {
$value = $value * 720;
} elseif ($key == '_spacing') {
$value += 240; // because line height of 1 matches 240 twips
} elseif ($key === 'line-height') {
$this->setLineHeight($value);
return;
}
$this->$key = $value;
$method = 'set' . substr($key, 1);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
/**
* Get Paragraph Alignment
*
* @return string
*/
public function getAlign()
{
return $this->_align;
}
/**
* Set Paragraph Alignment
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setAlign($pValue = null)
{
if (strtolower($pValue) == 'justify') {
// justify becames both
$pValue = 'both';
}
$this->_align = $pValue;
return $this;
}
/**
* Get Space before Paragraph
*
* @return string
*/
public function getSpaceBefore()
{
return $this->_spaceBefore;
}
/**
* Set Space before Paragraph
*
* @param int $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setSpaceBefore($pValue = null)
{
$this->_spaceBefore = $pValue;
return $this;
}
/**
* Get Space after Paragraph
*
* @return string
*/
public function getSpaceAfter()
{
return $this->_spaceAfter;
}
/**
* Set Space after Paragraph
*
* @param int $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setSpaceAfter($pValue = null)
{
$this->_spaceAfter = $pValue;
return $this;
}
/**
* Get Spacing between breaks
*
* @return int
*/
public function getSpacing()
{
return $this->_spacing;
}
/**
* Set Spacing between breaks
*
* @param int $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setSpacing($pValue = null)
{
$this->_spacing = $pValue;
return $this;
}
/**
* Get indentation
*
* @return int
*/
public function getIndent()
{
return $this->_indent;
}
/**
* Set indentation
*
* @param int $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setIndent($pValue = null)
{
$this->_indent = $pValue;
return $this;
}
/**
* Get hanging
*
* @return int
*/
public function getHanging()
{
return $this->_hanging;
}
/**
* Set hanging
*
* @param int $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setHanging($pValue = null)
{
$this->_hanging = $pValue;
return $this;
}
/**
* Get tabs
*
* @return PhpOffice\PhpWord\Style\Tabs
*/
public function getTabs()
{
return $this->_tabs;
}
/*
* Set tabs
*
* @param array $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setTabs($pValue = null)
{
if (is_array($pValue)) {
$this->_tabs = new Tabs($pValue);
}
return $this;
}
/**
* Get parent style ID
*
* @return string
*/
public function getBasedOn()
{
return $this->_basedOn;
}
/**
* Set parent style ID
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setBasedOn($pValue = 'Normal')
{
$this->_basedOn = $pValue;
return $this;
}
/**
* Get style for next paragraph
*
* @return string
*/
public function getNext()
{
return $this->_next;
}
/**
* Set style for next paragraph
*
* @param string $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setNext($pValue = null)
{
$this->_next = $pValue;
return $this;
}
/**
* Get allow first/last line to display on a separate page setting
*
* @return bool
*/
public function getWidowControl()
{
return $this->_widowControl;
}
/**
* Set keep paragraph with next paragraph setting
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setWidowControl($pValue = true)
{
if (!is_bool($pValue)) {
$pValue = true;
}
$this->_widowControl = $pValue;
return $this;
}
/**
* Get keep paragraph with next paragraph setting
*
* @return bool
*/
public function getKeepNext()
{
return $this->_keepNext;
}
/**
* Set keep paragraph with next paragraph setting
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setKeepNext($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_keepNext = $pValue;
return $this;
}
/**
* Get keep all lines on one page setting
*
* @return bool
*/
public function getKeepLines()
{
return $this->_keepLines;
}
/**
* Set keep all lines on one page setting
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setKeepLines($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_keepLines = $pValue;
return $this;
}
/**
* Get start paragraph on next page setting
*
* @return bool
*/
public function getPageBreakBefore()
{
return $this->_pageBreakBefore;
}
/**
* Set start paragraph on next page setting
*
* @param bool $pValue
* @return PhpOffice\PhpWord\Style\Paragraph
*/
public function setPageBreakBefore($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_pageBreakBefore = $pValue;
return $this;
}
/**
* Set the line height
*
* @param int|float|string $lineHeight
* @return $this
* @throws InvalidStyleException
*/
public function setLineHeight($lineHeight)
{
if (is_string($lineHeight)) {
$lineHeight = floatval(preg_replace('/[^0-9\.\,]/', '', $lineHeight));
}
if ((!is_integer($lineHeight) && !is_float($lineHeight)) || !$lineHeight) {
throw new InvalidStyleException('Line height must be a valid number');
}
$this->lineHeight = $lineHeight;
$this->setSpacing($lineHeight * self::LINE_HEIGHT);
return $this;
}
/**
* @return int|float
*/
public function getLineHeight()
{
return $this->lineHeight;
}
}

View File

@ -1,88 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2013 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
class Row
{
/**
* Repeat table row on every new page
*
* @var bool
*/
private $_tblHeader = false;
/**
* Table row cannot break across pages
*
* @var bool
*/
private $_cantSplit = false;
/**
* Create a new row style
*/
public function __construct()
{
}
/**
* Set style value
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
public function setTblHeader($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_tblHeader = $pValue;
return $this;
}
public function getTblHeader()
{
return $this->_tblHeader;
}
public function setCantSplit($pValue = false)
{
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_cantSplit = $pValue;
return $this;
}
public function getCantSplit()
{
return $this->_cantSplit;
}
}

View File

@ -1,139 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
class TOC
{
const TABLEADER_DOT = 'dot';
const TABLEADER_UNDERSCORE = 'underscore';
const TABLEADER_LINE = 'hyphen';
const TABLEADER_NONE = '';
/**
* Tab Leader
*
* @var string
*/
private $_tabLeader;
/**
* Tab Position
*
* @var int
*/
private $_tabPos;
/**
* Indent
*
* @var int
*/
private $_indent;
/**
* Create a new TOC Style
*/
public function __construct()
{
$this->_tabPos = 9062;
$this->_tabLeader = self::TABLEADER_DOT;
$this->_indent = 200;
}
/**
* Get Tab Position
*
* @return int
*/
public function getTabPos()
{
return $this->_tabPos;
}
/**
* Set Tab Position
*
* @param int $pValue
*/
public function setTabPos($pValue)
{
$this->_tabPos = $pValue;
}
/**
* Get Tab Leader
*
* @return string
*/
public function getTabLeader()
{
return $this->_tabLeader;
}
/**
* Set Tab Leader
*
* @param string $pValue
*/
public function setTabLeader($pValue = self::TABLEADER_DOT)
{
$this->_tabLeader = $pValue;
}
/**
* Get Indent
*
* @return int
*/
public function getIndent()
{
return $this->_indent;
}
/**
* Set Indent
*
* @param string $pValue
*/
public function setIndent($pValue)
{
$this->_indent = $pValue;
}
/**
* Set style value
*
* @param string $key
* @param string $value
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
}

View File

@ -1,146 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Tab
{
/**
* Tab Stop Type
*
* @var string
*/
private $_val;
/**
* Tab Leader Character
*
* @var string
*/
private $_leader;
/**
* Tab Stop Position
*
* @var int
*/
private $_position;
/**
* Tab Stop Type
*
* @var array
* @link http://www.schemacentral.com/sc/ooxml/a-w_val-26.html Tab Stop Type
*/
private static $_possibleStopTypes = array(
'clear', // No Tab Stop
'left', // Left Tab Stop
'center', // Center Tab Stop
'right', // Right Tab Stop
'decimal', // Decimal Tab
'bar', // Bar Tab
'num' // List tab
);
/**
* Tab Leader Character
*
* @var array
* @link http://www.schemacentral.com/sc/ooxml/a-w_leader-1.html Tab Leader Character
*/
private static $_possibleLeaders = array(
'none', // No tab stop leader
'dot', // Dotted leader line
'hyphen', // Dashed tab stop leader line
'underscore', // Solid leader line
'heavy', // Heavy solid leader line
'middleDot' // Middle dot leader line
);
/**
* Create a new instance of Tab. Both $val and $leader
* must conform to the values put forth in the schema. If they do not
* they will be changed to default values.
*
* @param string $val Defaults to 'clear' if value is not possible.
* @param int $position Must be an integer; otherwise defaults to 0.
* @param string $leader Defaults to NULL if value is not possible.
*/
public function __construct($val = null, $position = 0, $leader = null)
{
// Default to clear if the stop type is not matched
$this->_val = (self::isStopType($val)) ? $val : 'clear';
// Default to 0 if the position is non-numeric
$this->_position = (is_numeric($position)) ? intval($position) : 0;
// Default to NULL if no tab leader
$this->_leader = (self::isLeaderType($leader)) ? $leader : null;
}
/**
* Creates the XML DOM for the instance of Tab.
*
* @param PhpOffice\PhpWord\Shared\XMLWriter &$xmlWriter
*/
public function toXml(XMLWriter &$xmlWriter = null)
{
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tab");
$xmlWriter->writeAttribute("w:val", $this->_val);
if (!is_null($this->_leader)) {
$xmlWriter->writeAttribute("w:leader", $this->_leader);
}
$xmlWriter->writeAttribute("w:pos", $this->_position);
$xmlWriter->endElement();
}
}
/**
* Test if attribute is a valid stop type.
*
* @param string $attribute
* @return bool True if it is; false otherwise.
*/
private static function isStopType($attribute)
{
return in_array($attribute, self::$_possibleStopTypes);
}
/**
* Test if attribute is a valid leader type.
*
* @param string $attribute
* @return bool True if it is; false otherwise.
*/
private static function isLeaderType($attribute)
{
return in_array($attribute, self::$_possibleLeaders);
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
class Table
{
private $_cellMarginTop;
private $_cellMarginLeft;
private $_cellMarginRight;
private $_cellMarginBottom;
public function __construct()
{
$this->_cellMarginTop = null;
$this->_cellMarginLeft = null;
$this->_cellMarginRight = null;
$this->_cellMarginBottom = null;
}
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
public function setCellMarginTop($pValue = null)
{
$this->_cellMarginTop = $pValue;
}
public function getCellMarginTop()
{
return $this->_cellMarginTop;
}
public function setCellMarginLeft($pValue = null)
{
$this->_cellMarginLeft = $pValue;
}
public function getCellMarginLeft()
{
return $this->_cellMarginLeft;
}
public function setCellMarginRight($pValue = null)
{
$this->_cellMarginRight = $pValue;
}
public function getCellMarginRight()
{
return $this->_cellMarginRight;
}
public function setCellMarginBottom($pValue = null)
{
$this->_cellMarginBottom = $pValue;
}
public function getCellMarginBottom()
{
return $this->_cellMarginBottom;
}
public function getCellMargin()
{
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom);
}
}

View File

@ -1,443 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
class TableFull
{
/**
* Style for first row
*
* @var PhpOffice\PhpWord\Style\TableFull
*/
private $_firstRow = null;
/**
* @var int
*/
private $_cellMarginTop = null;
/**
* @var int
*/
private $_cellMarginLeft = null;
/**
* @var int
*/
private $_cellMarginRight = null;
/**
* @var int
*/
private $_cellMarginBottom = null;
/**
* @var string
*/
private $_bgColor;
/**
* @var int
*/
private $_borderTopSize;
/**
* @var string
*/
private $_borderTopColor;
/**
* @var int
*/
private $_borderLeftSize;
/**
* @var string
*/
private $_borderLeftColor;
/**
* @var int
*/
private $_borderRightSize;
/**
* @var string
*/
private $_borderRightColor;
/**
* @var int
*/
private $_borderBottomSize;
/**
* @var string
*/
private $_borderBottomColor;
/**
* @var int
*/
private $_borderInsideHSize;
/**
* @var string
*/
private $_borderInsideHColor;
/**
* @var int
*/
private $_borderInsideVSize;
/**
* @var string
*/
private $_borderInsideVColor;
public function __construct($styleTable = null, $styleFirstRow = null)
{
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->_firstRow = clone $this;
unset($this->_firstRow->_firstRow);
unset($this->_firstRow->_cellMarginBottom);
unset($this->_firstRow->_cellMarginTop);
unset($this->_firstRow->_cellMarginLeft);
unset($this->_firstRow->_cellMarginRight);
unset($this->_firstRow->_borderInsideVColor);
unset($this->_firstRow->_borderInsideVSize);
unset($this->_firstRow->_borderInsideHColor);
unset($this->_firstRow->_borderInsideHSize);
foreach ($styleFirstRow as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_firstRow->setStyleValue($key, $value);
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
}
}
/**
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
if ($key == '_borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
$this->setBorderColor($value);
} elseif ($key == '_cellMargin') {
$this->setCellMargin($value);
} else {
$this->$key = $value;
}
}
/**
* Get First Row Style
*
* @return PhpOffice\PhpWord\Style\TableFull
*/
public function getFirstRow()
{
return $this->_firstRow;
}
/**
* Get Last Row Style
*
* @return PhpOffice\PhpWord\Style\TableFull
*/
public function getLastRow()
{
return $this->_lastRow;
}
public function getBgColor()
{
return $this->_bgColor;
}
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
}
/**
* Set TLRBVH Border Size
*
* @param int $pValue Border size in eighths of a point (1/8 point)
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
}
/**
* Get TLRBVH Border Size
*
* @return array
*/
public function getBorderSize()
{
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
$h = $this->getBorderInsideHSize();
$v = $this->getBorderInsideVSize();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set TLRBVH Border Color
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->_borderInsideHColor = $pValue;
$this->_borderInsideVColor = $pValue;
}
/**
* Get TLRB Border Color
*
* @return array
*/
public function getBorderColor()
{
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
$h = $this->getBorderInsideHColor();
$v = $this->getBorderInsideVColor();
return array($t, $l, $r, $b, $h, $v);
}
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
}
public function getBorderTopSize()
{
return $this->_borderTopSize;
}
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
}
public function getBorderTopColor()
{
return $this->_borderTopColor;
}
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
}
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
}
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
}
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
}
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
}
public function getBorderRightSize()
{
return $this->_borderRightSize;
}
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
}
public function getBorderRightColor()
{
return $this->_borderRightColor;
}
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
}
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
}
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
}
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}
public function setBorderInsideHColor($pValue = null)
{
$this->_borderInsideHColor = $pValue;
}
public function getBorderInsideHColor()
{
return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null;
}
public function setBorderInsideVColor($pValue = null)
{
$this->_borderInsideVColor = $pValue;
}
public function getBorderInsideVColor()
{
return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null;
}
public function setBorderInsideHSize($pValue = null)
{
$this->_borderInsideHSize = $pValue;
}
public function getBorderInsideHSize()
{
return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
}
public function setBorderInsideVSize($pValue = null)
{
$this->_borderInsideVSize = $pValue;
}
public function getBorderInsideVSize()
{
return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null;
}
public function setCellMarginTop($pValue = null)
{
$this->_cellMarginTop = $pValue;
}
public function getCellMarginTop()
{
return $this->_cellMarginTop;
}
public function setCellMarginLeft($pValue = null)
{
$this->_cellMarginLeft = $pValue;
}
public function getCellMarginLeft()
{
return $this->_cellMarginLeft;
}
public function setCellMarginRight($pValue = null)
{
$this->_cellMarginRight = $pValue;
}
public function getCellMarginRight()
{
return $this->_cellMarginRight;
}
public function setCellMarginBottom($pValue = null)
{
$this->_cellMarginBottom = $pValue;
}
public function getCellMarginBottom()
{
return $this->_cellMarginBottom;
}
/**
* Set TLRB cell margin
*
* @param int $pValue Margin in twips
*/
public function setCellMargin($pValue = null)
{
$this->_cellMarginTop = $pValue;
$this->_cellMarginLeft = $pValue;
$this->_cellMarginRight = $pValue;
$this->_cellMarginBottom = $pValue;
}
public function getCellMargin()
{
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom);
}
}

View File

@ -1,63 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Tabs
{
/**
* Tabs
*
* @var array
*/
private $_tabs;
/**
*
* @param array $tabs
*/
public function __construct(array $tabs)
{
$this->_tabs = $tabs;
}
/**
* @param PhpOffice\PhpWord\Shared\XMLWriter &$xmlWriter
*/
public function toXml(XMLWriter &$xmlWriter = null)
{
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tabs");
foreach ($this->_tabs as &$tab) {
$tab->toXml($xmlWriter);
}
$xmlWriter->endElement();
}
}
}

View File

@ -1,155 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font;
class TOC
{
/**
* Title Elements
*
* @var array
*/
private static $_titles = array();
/**
* TOC Style
*
* @var array
*/
private static $_styleTOC;
/**
* Font Style
*
* @var array
*/
private static $_styleFont;
/**
* Title Anchor
*
* @var array
*/
private static $_anchor = 252634154;
/**
* Title Bookmark
*
* @var array
*/
private static $_bookmarkId = 0;
/**
* Create a new Table-of-Contents Element
*
* @param array $styleFont
* @param array $styleTOC
*/
public function __construct($styleFont = null, $styleTOC = null)
{
self::$_styleTOC = new PhpOffice\PhpWord\Style\TOC();
if (!is_null($styleTOC) && is_array($styleTOC)) {
foreach ($styleTOC as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
self::$_styleTOC->setStyleValue($key, $value);
}
}
if (!is_null($styleFont)) {
if (is_array($styleFont)) {
self::$_styleFont = new Font();
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
self::$_styleFont->setStyleValue($key, $value);
}
} else {
self::$_styleFont = $styleFont;
}
}
}
/**
* Add a Title
*
* @return array
*/
public static function addTitle($text, $depth = 0)
{
$anchor = '_Toc' . ++self::$_anchor;
$bookmarkId = self::$_bookmarkId++;
$title = array();
$title['text'] = $text;
$title['depth'] = $depth;
$title['anchor'] = $anchor;
$title['bookmarkId'] = $bookmarkId;
self::$_titles[] = $title;
return array($anchor, $bookmarkId);
}
/**
* Get all titles
*
* @return array
*/
public static function getTitles()
{
return self::$_titles;
}
/**
* Get TOC Style
*
* @return PhpOffice\PhpWord\Style\TOC
*/
public static function getStyleTOC()
{
return self::$_styleTOC;
}
/**
* Get Font Style
*
* @return PhpOffice\PhpWord\Style\Font
*/
public static function getStyleFont()
{
return self::$_styleFont;
}
}

View File

@ -1,292 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Shared\String;
class Template
{
/**
* ZipArchive
*
* @var ZipArchive
*/
private $_objZip;
/**
* Temporary Filename
*
* @var string
*/
private $_tempFileName;
/**
* Document XML
*
* @var string
*/
private $_documentXML;
/**
* Create a new Template Object
*
* @param string $strFilename
* @throws Exception
*/
public function __construct($strFilename)
{
$this->_tempFileName = tempnam(sys_get_temp_dir(), '');
if ($this->_tempFileName === false) {
throw new Exception('Could not create temporary file with unique name in the default temporary directory.');
}
// Copy the source File to the temp File
if (!copy($strFilename, $this->_tempFileName)) {
throw new Exception("Could not copy the template from {$strFilename} to {$this->_tempFileName}.");
}
$this->_objZip = new ZipArchive();
$this->_objZip->open($this->_tempFileName);
$this->_documentXML = $this->_objZip->getFromName('word/document.xml');
}
/**
* Applies XSL style sheet to template's parts
*
* @param DOMDocument $xslDOMDocument
* @param array $xslOptions
* @param string $xslOptionsURI
* @throws Exception
*/
public function applyXslStyleSheet(&$xslDOMDocument, $xslOptions = array(), $xslOptionsURI = '')
{
$processor = new XSLTProcessor();
$processor->importStylesheet($xslDOMDocument);
if ($processor->setParameter($xslOptionsURI, $xslOptions) === false) {
throw new Exception('Could not set values for the given XSL style sheet parameters.');
}
$xmlDOMDocument = new DOMDocument();
if ($xmlDOMDocument->loadXML($this->_documentXML) === false) {
throw new Exception('Could not load XML from the given template.');
}
$xmlTransformed = $processor->transformToXml($xmlDOMDocument);
if ($xmlTransformed === false) {
throw new Exception('Could not transform the given XML document.');
}
$this->_documentXML = $xmlTransformed;
}
/**
* Set a Template value
*
* @param mixed $search
* @param mixed $replace
* @param integer $limit
*/
public function setValue($search, $replace, $limit = -1)
{
$pattern = '|\$\{([^\}]+)\}|U';
preg_match_all($pattern, $this->_documentXML, $matches);
foreach ($matches[0] as $value) {
$valueCleaned = preg_replace('/<[^>]+>/', '', $value);
$valueCleaned = preg_replace('/<\/[^>]+>/', '', $valueCleaned);
$this->_documentXML = str_replace($value, $valueCleaned, $this->_documentXML);
}
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${' . $search . '}';
}
if (!is_array($replace)) {
if (!String::IsUTF8($replace)) {
$replace = utf8_encode($replace);
}
$replace = htmlspecialchars($replace);
} else {
foreach ($replace as $key => $value) {
$replace[$key] = htmlspecialchars($value);
}
}
$regExpDelim = '/';
$escapedSearch = preg_quote($search, $regExpDelim);
$this->_documentXML = preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $this->_documentXML, $limit);
}
/**
* Returns array of all variables in template
*/
public function getVariables()
{
preg_match_all('/\$\{(.*?)}/i', $this->_documentXML, $matches);
return $matches[1];
}
/**
* Find the start position of the nearest table row before $offset
*
* @param int $offset
* @return int
* @throws Exception
*/
private function _findRowStart($offset)
{
$rowStart = strrpos($this->_documentXML, "<w:tr ", ((strlen($this->_documentXML) - $offset) * -1));
if (!$rowStart) {
$rowStart = strrpos($this->_documentXML, "<w:tr>", ((strlen($this->_documentXML) - $offset) * -1));
}
if (!$rowStart) {
throw new Exception("Can not find the start position of the row to clone.");
}
return $rowStart;
}
/**
* Find the end position of the nearest table row after $offset
*
* @param int $offset
* @return int
*/
private function _findRowEnd($offset)
{
$rowEnd = strpos($this->_documentXML, "</w:tr>", $offset) + 7;
return $rowEnd;
}
/**
* Get a slice of a string
*
* @param int $startPosition
* @param int $endPosition
* @return string
*/
private function _getSlice($startPosition, $endPosition = 0)
{
if (!$endPosition) {
$endPosition = strlen($this->_documentXML);
}
return substr($this->_documentXML, $startPosition, ($endPosition - $startPosition));
}
/**
* Clone a table row in a template document
*
* @param string $search
* @param int $numberOfClones
* @throws Exception
*/
public function cloneRow($search, $numberOfClones)
{
if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${' . $search . '}';
}
$tagPos = strpos($this->_documentXML, $search);
if (!$tagPos) {
throw new Exception("Can not clone row, template variable not found or variable contains markup.");
}
$rowStart = $this->_findRowStart($tagPos);
$rowEnd = $this->_findRowEnd($tagPos);
$xmlRow = $this->_getSlice($rowStart, $rowEnd);
// Check if there's a cell spanning multiple rows.
if (preg_match('#<w:vMerge w:val="restart"/>#', $xmlRow)) {
$extraRowStart = $rowEnd;
$extraRowEnd = $rowEnd;
while (true) {
$extraRowStart = $this->_findRowStart($extraRowEnd + 1);
$extraRowEnd = $this->_findRowEnd($extraRowEnd + 1);
// If extraRowEnd is lower then 7, there was no next row found.
if ($extraRowEnd < 7) {
break;
}
// If tmpXmlRow doesn't contain continue, this row is no longer part of the spanned row.
$tmpXmlRow = $this->_getSlice($extraRowStart, $extraRowEnd);
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) && !preg_match('#<w:vMerge w:val="continue" />#', $tmpXmlRow)) {
break;
}
// This row was a spanned row, update $rowEnd and search for the next row.
$rowEnd = $extraRowEnd;
}
$xmlRow = $this->_getSlice($rowStart, $rowEnd);
}
$result = $this->_getSlice(0, $rowStart);
for ($i = 1; $i <= $numberOfClones; $i++) {
$result .= preg_replace('/\$\{(.*?)\}/', '\${\\1#' . $i . '}', $xmlRow);
}
$result .= $this->_getSlice($rowEnd);
$this->_documentXML = $result;
}
/**
* Save Template
*
* @return string
* @throws Exception
*/
public function save()
{
$this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file
if ($this->_objZip->close() === false) {
throw new Exception('Could not close zip file.');
}
return $this->_tempFileName;
}
/**
* Save Template As...
*
* @param string $strFilename
*/
public function saveAs($strFilename)
{
$tempFilename = $this->save();
if (file_exists($strFilename)) {
unlink($strFilename);
}
rename($tempFilename, $strFilename);
}
}

View File

@ -1,39 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer;
interface IWriter
{
/**
* Save PhpWord to file
*
* @param string $pFileName
* @throws \Exception
*/
public function save($pFilename = null);
}

View File

@ -1,282 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\HashTable;
use PhpOffice\PhpWord\Writer\ODText\Content;
use PhpOffice\PhpWord\Writer\ODText\Manifest;
use PhpOffice\PhpWord\Writer\ODText\Meta;
use PhpOffice\PhpWord\Writer\ODText\Mimetype;
use PhpOffice\PhpWord\Writer\ODText\Styles;
class ODText implements IWriter
{
/**
* @var PhpOffice\PhpWord
*/
private $_document;
/**
* @var PhpOffice\PhpWord\Writer\ODText\WriterPart[]
*/
private $_writerParts;
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var PhpOffice\PhpWord\HashTable
*/
private $_drawingHashTable;
/**
* Use disk caching where possible?
*
* @var boolean
*/
private $_useDiskCaching = false;
/**
* @var string
*/
private $_diskCachingDirectory;
/**
* @param PhpOffice\PhpWord $phpWord
*/
public function __construct(PhpWord $phpWord = null)
{
// Assign PhpWord
$this->setPhpWord($phpWord);
// Set up disk caching location
$this->_diskCachingDirectory = './';
// Initialise writer parts
$this->_writerParts['content'] = new Content();
$this->_writerParts['manifest'] = new Manifest();
$this->_writerParts['meta'] = new Meta();
$this->_writerParts['mimetype'] = new Mimetype();
$this->_writerParts['styles'] = new Styles();
// Assign parent IWriter
foreach ($this->_writerParts as $writer) {
$writer->setParentWriter($this);
}
// Set HashTable variables
$this->_drawingHashTable = new HashTable();
}
/**
* Save PhpWord to file
*
* @param string $pFileName
* @throws \Exception
*/
public function save($pFilename = null)
{
if (!is_null($this->_document)) {
// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
$pFilename = @tempnam('./', 'phppttmp');
if ($pFilename == '') {
$pFilename = $originalFilename;
}
}
// Create drawing dictionary
// Create new ZIP file and open it for writing
$objZip = new ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
throw new \Exception("Could not open " . $pFilename . " for writing.");
}
}
// Add mimetype to ZIP file
//@todo Not in ZIPARCHIVE::CM_STORE mode
$objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype($this->_document));
// Add content.xml to ZIP file
$objZip->addFromString('content.xml', $this->getWriterPart('content')->writeContent($this->_document));
// Add meta.xml to ZIP file
$objZip->addFromString('meta.xml', $this->getWriterPart('meta')->writeMeta($this->_document));
// Add styles.xml to ZIP file
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document));
// Add META-INF/manifest.xml
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_document));
// Add media. Has not used yet. Legacy from PHPExcel.
// @codeCoverageIgnoreStart
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
$imageContents = null;
$imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath();
if (strpos($imagePath, 'zip://') !== false) {
$imagePath = substr($imagePath, 6);
$imagePathSplitted = explode('#', $imagePath);
$imageZip = new ZipArchive();
$imageZip->open($imagePathSplitted[0]);
$imageContents = $imageZip->getFromName($imagePathSplitted[1]);
$imageZip->close();
unset($imageZip);
} else {
$imageContents = file_get_contents($imagePath);
}
$objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
} elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
ob_start();
call_user_func(
$this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(),
$this->getDrawingHashTable()->getByIndex($i)->getImageResource()
);
$imageContents = ob_get_contents();
ob_end_clean();
$objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
}
}
// @codeCoverageIgnoreEnd
// Close file
if ($objZip->close() === false) {
throw new \Exception("Could not close zip file $pFilename.");
}
// If a temporary file was used, copy it to the correct file stream
if ($originalFilename != $pFilename) {
if (copy($pFilename, $originalFilename) === false) {
throw new \Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
}
@unlink($pFilename);
}
} else {
throw new \Exception("PhpWord object unassigned.");
}
}
/**
* @return PhpOffice\PhpWord
* @throws \Exception
*/
public function getPhpWord()
{
if (!is_null($this->_document)) {
return $this->_document;
} else {
throw new \Exception("No PhpWord assigned.");
}
}
/**
* @param PhpOffice\PhpWord $phpWord
* @return PhpOffice\PhpWord\Writer\ODText
*/
public function setPhpWord(PhpWord $phpWord = null)
{
$this->_document = $phpWord;
return $this;
}
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return PhpOffice\PhpWord\HashTable
*/
public function getDrawingHashTable()
{
return $this->_drawingHashTable;
}
/**
* @param string $pPartName Writer part name
* @return PhpOffice\PhpWord\Writer\ODText\WriterPart
*/
public function getWriterPart($pPartName = '')
{
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) {
return $this->_writerParts[strtolower($pPartName)];
} else {
return null;
}
}
/**
* Get use disk caching where possible?
*
* @return boolean
*/
public function getUseDiskCaching()
{
return $this->_useDiskCaching;
}
/**
* Set use disk caching where possible?
*
* @param boolean $pValue
* @param string $pDirectory Disk caching directory
* @throws \Exception Exception when directory does not exist
* @return PhpOffice\PhpWord\Writer\ODText
*/
public function setUseDiskCaching($pValue = false, $pDirectory = null)
{
$this->_useDiskCaching = $pValue;
if (!is_null($pDirectory)) {
if (is_dir($pDirectory)) {
$this->_diskCachingDirectory = $pDirectory;
} else {
throw new \Exception("Directory does not exist: $pDirectory");
}
}
return $this;
}
/**
* @return string
*/
public function getDiskCachingDirectory()
{
return $this->_diskCachingDirectory;
}
}

View File

@ -1,412 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TOC;
class Content extends WriterPart
{
/**
* Write content file to XML format
*
* @param PhpOffice\PhpWord $phpWord
* @return string XML Output
* @throws Exception
*/
public function writeContent(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8');
// office:document-content
$xmlWriter->startElement('office:document-content');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
$xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$xmlWriter->writeAttribute('office:version', '1.2');
// We firstly search all fonts used
$_sections = $phpWord->getSections();
$countSections = count($_sections);
if ($countSections > 0) {
$pSection = 0;
$numPStyles = 0;
$numFStyles = 0;
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
$pStyle = $element->getParagraphStyle();
if ($fStyle instanceof Font) {
$numFStyles++;
$arrStyle = array(
'color' => $fStyle->getColor(),
'name' => $fStyle->getName()
);
$phpWord->addFontStyle('T' . $numFStyles, $arrStyle);
$element->setFontStyle('T' . $numFStyles);
} elseif ($pStyle instanceof Paragraph) {
$numPStyles++;
$phpWord->addParagraphStyle('P' . $numPStyles, array());
$element->setParagraphStyle('P' . $numPStyles);
}
}
}
}
}
// office:font-face-decls
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
}
$xmlWriter->endElement();
$xmlWriter->startElement('office:automatic-styles');
$styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if (preg_match('#^T[0-9]+$#', $styleName) != 0
|| preg_match('#^P[0-9]+$#', $styleName) != 0
) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'text');
// style:text-properties
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('fo:color', '#' . $style->getColor());
$xmlWriter->writeAttribute('style:font-name', $style->getName());
$xmlWriter->writeAttribute('style:font-name-complex', $style->getName());
$xmlWriter->endElement();
$xmlWriter->endElement();
}
if ($style instanceof Paragraph) {
$numPStyles++;
// style:style
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'paragraph');
$xmlWriter->writeAttribute('style:parent-style-name', 'Standard');
$xmlWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('style:page-number', 'auto');
$xmlWriter->endElement();
$xmlWriter->endElement();
}
}
}
if ($numPStyles == 0) {
// style:style
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', 'P1');
$xmlWriter->writeAttribute('style:family', 'paragraph');
$xmlWriter->writeAttribute('style:parent-style-name', 'Standard');
$xmlWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('style:page-number', 'auto');
$xmlWriter->endElement();
$xmlWriter->endElement();
}
}
$xmlWriter->endElement();
// office:body
$xmlWriter->startElement('office:body');
// office:text
$xmlWriter->startElement('office:text');
// text:sequence-decls
$xmlWriter->startElement('text:sequence-decls');
// text:sequence-decl
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Illustration');
$xmlWriter->endElement();
// text:sequence-decl
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Table');
$xmlWriter->endElement();
// text:sequence-decl
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Text');
$xmlWriter->endElement();
// text:sequence-decl
$xmlWriter->startElement('text:sequence-decl');
$xmlWriter->writeAttribute('text:display-outline-level', 0);
$xmlWriter->writeAttribute('text:name', 'Drawing');
$xmlWriter->endElement();
$xmlWriter->endElement();
$_sections = $phpWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter);
} elseif ($element instanceof Link) {
$this->writeUnsupportedElement($xmlWriter, 'Link');
} elseif ($element instanceof Title) {
$this->writeUnsupportedElement($xmlWriter, 'Title');
} elseif ($element instanceof PageBreak) {
$this->writeUnsupportedElement($xmlWriter, 'Page Break');
} elseif ($element instanceof Table) {
$this->writeUnsupportedElement($xmlWriter, 'Table');
} elseif ($element instanceof ListItem) {
$this->writeUnsupportedElement($xmlWriter, 'List Item');
} elseif ($element instanceof Image ||
$element instanceof MemoryImage) {
$this->writeUnsupportedElement($xmlWriter, 'Image');
} elseif ($element instanceof Object) {
$this->writeUnsupportedElement($xmlWriter, 'Object');
} elseif ($element instanceof TOC) {
$this->writeUnsupportedElement($xmlWriter, 'TOC');
} else {
$this->writeUnsupportedElement($xmlWriter, 'Element');
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($xmlWriter, $section);
} else {
$this->_writeSection($xmlWriter, $section);
}
}
}
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
/**
* Write text
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\Text $text
* @param bool $withoutP
*/
protected function _writeText(XMLWriter $xmlWriter = null, Text $text, $withoutP = false)
{
$styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value
// $SfIsObject = ($styleFont instanceof Font) ? true : false;
$SfIsObject = false;
if ($SfIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared
die('PhpWord : $SfIsObject wouldn\'t be an object');
} else {
if (!$withoutP) {
$xmlWriter->startElement('text:p'); // text:p
}
if (empty($styleFont)) {
if (empty($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', 'P1');
} else {
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
$xmlWriter->writeRaw($text->getText());
} else {
if (empty($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', 'Standard');
} else {
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
// text:span
$xmlWriter->startElement('text:span');
$xmlWriter->writeAttribute('text:style-name', $styleFont);
$xmlWriter->writeRaw($text->getText());
$xmlWriter->endElement();
}
if (!$withoutP) {
$xmlWriter->endElement(); // text:p
}
}
}
/**
* Write TextRun section
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Section\TextRun $textrun
* @todo Enable all other section types
*/
protected function _writeTextRun(XMLWriter $xmlWriter = null, TextRun $textrun)
{
$elements = $textrun->getElements();
$xmlWriter->startElement('text:p');
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element, true);
}
}
}
$xmlWriter->endElement();
}
/**
* Write TextBreak
*/
protected function _writeTextBreak(XMLWriter $xmlWriter = null)
{
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard');
$xmlWriter->endElement();
}
// @codeCoverageIgnoreStart
private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
// @codeCoverageIgnoreEnd
/**
* Write unsupported element
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $element
*/
private function writeUnsupportedElement($xmlWriter, $element)
{
$xmlWriter->startElement('text:p');
$xmlWriter->writeRaw($element);
$xmlWriter->endElement();
}
}

View File

@ -1,132 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Shared\File;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Manifest extends WriterPart
{
/**
* Write Manifest file to XML format
*
* @param PhpOffice\PhpWord $phpWord
* @return string XML Output
* @throws Exception
*/
public function writeManifest(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8');
// manifest:manifest
$xmlWriter->startElement('manifest:manifest');
$xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
$xmlWriter->writeAttribute('manifest:version', '1.2');
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
$xmlWriter->writeAttribute('manifest:version', '1.2');
$xmlWriter->writeAttribute('manifest:full-path', '/');
$xmlWriter->endElement();
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'content.xml');
$xmlWriter->endElement();
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'meta.xml');
$xmlWriter->endElement();
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', 'text/xml');
$xmlWriter->writeAttribute('manifest:full-path', 'styles.xml');
$xmlWriter->endElement();
// Not used yet. Legacy from PHPExcel
// @codeCoverageIgnoreStart
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
$mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
$xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$xmlWriter->endElement();
} elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
$extension = explode('/', $extension);
$extension = $extension[1];
$mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
$xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$xmlWriter->endElement();
}
}
// @codeCoverageIgnoreEnd
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws Exception
*/
private function _getImageMimeType($pFile = '')
{
if (File::file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
}

View File

@ -1,96 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Meta extends WriterPart
{
/**
* Write Meta file to XML format
*
* @param PhpOffice\PhpWord $phpWord
* @return string XML Output
* @throws Exception
*/
public function writeMeta(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8');
// office:document-meta
$xmlWriter->startElement('office:document-meta');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('office:version', '1.2');
// office:meta
$xmlWriter->startElement('office:meta');
// dc:creator
$xmlWriter->writeElement('dc:creator', $phpWord->getDocumentProperties()->getLastModifiedBy());
// dc:date
$xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $phpWord->getDocumentProperties()->getModified()));
// dc:description
$xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription());
// dc:subject
$xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject());
// dc:title
$xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle());
// meta:creation-date
$xmlWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $phpWord->getDocumentProperties()->getCreated()));
// meta:initial-creator
$xmlWriter->writeElement('meta:initial-creator', $phpWord->getDocumentProperties()->getCreator());
// meta:keyword
$xmlWriter->writeElement('meta:keyword', $phpWord->getDocumentProperties()->getKeywords());
// @todo : Where these properties are written ?
// $phpWord->getDocumentProperties()->getCategory()
// $phpWord->getDocumentProperties()->getCompany()
$xmlWriter->endElement();
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
}

View File

@ -1,46 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord;
class Mimetype extends WriterPart
{
/**
* Write Mimetype to Text format
*
* @param PhpOffice\PhpWord $phpWord
* @return string Text Output
* @throws Exception
*/
public function writeMimetype(PhpWord $phpWord = null)
{
return 'application/vnd.oasis.opendocument.text';
}
}

View File

@ -1,273 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
class Styles extends WriterPart
{
/**
* Write Styles file to XML format
*
* @param PhpOffice\PhpWord $phpWord
* @return string XML Output
* @throws Exception
*/
public function writeStyles(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8');
// Styles:Styles
$xmlWriter->startElement('office:document-styles');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$xmlWriter->writeAttribute('office:version', '1.2');
// office:font-face-decls
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
}
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
// office:styles
$xmlWriter->startElement('office:styles');
// style:default-style
$xmlWriter->startElement('style:default-style');
$xmlWriter->writeAttribute('style:family', 'paragraph');
// style:paragraph-properties
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
$xmlWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
$xmlWriter->writeAttribute('style:punctuation-wrap', 'hanging');
$xmlWriter->writeAttribute('style:line-break', 'strict');
$xmlWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
$xmlWriter->writeAttribute('style:writing-mode', 'page');
$xmlWriter->endElement();
// style:text-properties
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('style:use-window-font-color', 'true');
$xmlWriter->writeAttribute('style:font-name', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('fo:font-size', PhpWord::DEFAULT_FONT_SIZE . 'pt');
$xmlWriter->writeAttribute('fo:language', 'fr');
$xmlWriter->writeAttribute('fo:country', 'FR');
$xmlWriter->writeAttribute('style:letter-kerning', 'true');
$xmlWriter->writeAttribute('style:font-name-asian', PhpWord::DEFAULT_FONT_NAME . '2');
$xmlWriter->writeAttribute('style:font-size-asian', PhpWord::DEFAULT_FONT_SIZE . 'pt');
$xmlWriter->writeAttribute('style:language-asian', 'zh');
$xmlWriter->writeAttribute('style:country-asian', 'CN');
$xmlWriter->writeAttribute('style:font-name-complex', PhpWord::DEFAULT_FONT_NAME . '2');
$xmlWriter->writeAttribute('style:font-size-complex', PhpWord::DEFAULT_FONT_SIZE . 'pt');
$xmlWriter->writeAttribute('style:language-complex', 'hi');
$xmlWriter->writeAttribute('style:country-complex', 'IN');
$xmlWriter->writeAttribute('fo:hyphenate', 'false');
$xmlWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
$xmlWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
$xmlWriter->endElement();
$xmlWriter->endElement();
// Write Style Definitions
$styles = Style::getStyles();
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if (preg_match('#^T[0-9]+$#', $styleName) == 0
&& preg_match('#^P[0-9]+$#', $styleName) == 0
) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
// style:style
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'text');
// style:text-properties
$xmlWriter->startElement('style:text-properties');
$xmlWriter->writeAttribute('fo:font-size', ($style->getSize()) . 'pt');
$xmlWriter->writeAttribute('style:font-size-asian', ($style->getSize()) . 'pt');
$xmlWriter->writeAttribute('style:font-size-complex', ($style->getSize()) . 'pt');
if ($style->getItalic()) {
$xmlWriter->writeAttribute('fo:font-style', 'italic');
$xmlWriter->writeAttribute('style:font-style-asian', 'italic');
$xmlWriter->writeAttribute('style:font-style-complex', 'italic');
}
if ($style->getBold()) {
$xmlWriter->writeAttribute('fo:font-weight', 'bold');
$xmlWriter->writeAttribute('style:font-weight-asian', 'bold');
}
$xmlWriter->endElement();
$xmlWriter->endElement();
} elseif ($style instanceof Paragraph) {
// PhpOffice\PhpWord\Style\Paragraph
// style:style
$xmlWriter->startElement('style:style');
$xmlWriter->writeAttribute('style:name', $styleName);
$xmlWriter->writeAttribute('style:family', 'paragraph');
//style:paragraph-properties
$xmlWriter->startElement('style:paragraph-properties');
$xmlWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)) . 'cm');
$xmlWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)) . 'cm');
$xmlWriter->writeAttribute('fo:text-align', $style->getAlign());
$xmlWriter->endElement();
$xmlWriter->endElement();
} elseif ($style instanceof TableFull) {
// PhpOffice\PhpWord\Style\TableFull
}
}
}
}
$xmlWriter->endElement();
// office:automatic-styles
$xmlWriter->startElement('office:automatic-styles');
// style:page-layout
$xmlWriter->startElement('style:page-layout');
$xmlWriter->writeAttribute('style:name', 'Mpm1');
// style:page-layout-properties
$xmlWriter->startElement('style:page-layout-properties');
$xmlWriter->writeAttribute('fo:page-width', "21.001cm");
$xmlWriter->writeAttribute('fo:page-height', '29.7cm');
$xmlWriter->writeAttribute('style:num-format', '1');
$xmlWriter->writeAttribute('style:print-orientation', 'portrait');
$xmlWriter->writeAttribute('fo:margin-top', '2.501cm');
$xmlWriter->writeAttribute('fo:margin-bottom', '2cm');
$xmlWriter->writeAttribute('fo:margin-left', '2.501cm');
$xmlWriter->writeAttribute('fo:margin-right', '2.501cm');
$xmlWriter->writeAttribute('style:writing-mode', 'lr-tb');
$xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
$xmlWriter->writeAttribute('style:layout-grid-lines', '25199');
$xmlWriter->writeAttribute('style:layout-grid-base-height', '0.423cm');
$xmlWriter->writeAttribute('style:layout-grid-ruby-height', '0cm');
$xmlWriter->writeAttribute('style:layout-grid-mode', 'none');
$xmlWriter->writeAttribute('style:layout-grid-ruby-below', 'false');
$xmlWriter->writeAttribute('style:layout-grid-print', 'false');
$xmlWriter->writeAttribute('style:layout-grid-display', 'false');
$xmlWriter->writeAttribute('style:layout-grid-base-width', '0.37cm');
$xmlWriter->writeAttribute('style:layout-grid-snap-to', 'true');
$xmlWriter->writeAttribute('style:footnote-max-height', '0cm');
//style:footnote-sep
$xmlWriter->startElement('style:footnote-sep');
$xmlWriter->writeAttribute('style:width', '0.018cm');
$xmlWriter->writeAttribute('style:line-style', 'solid');
$xmlWriter->writeAttribute('style:adjustment', 'left');
$xmlWriter->writeAttribute('style:rel-width', '25%');
$xmlWriter->writeAttribute('style:color', '#000000');
$xmlWriter->endElement();
$xmlWriter->endElement();
// style:header-style
$xmlWriter->startElement('style:header-style');
$xmlWriter->endElement();
// style:footer-style
$xmlWriter->startElement('style:footer-style');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
// office:master-styles
$xmlWriter->startElement('office:master-styles');
// style:master-page
$xmlWriter->startElement('style:master-page');
$xmlWriter->writeAttribute('style:name', 'Standard');
$xmlWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
}

View File

@ -1,66 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Writer\IWriter;
abstract class WriterPart
{
/**
* Parent IWriter object
*
* @var PhpOffice\PhpWord\Writer\IWriter
*/
private $_parentWriter;
/**
* Set parent IWriter object
*
* @param PhpOffice\PhpWord\Writer\IWriter $pWriter
* @throws Exception
*/
public function setParentWriter(IWriter $pWriter = null)
{
$this->_parentWriter = $pWriter;
}
/**
* Get parent IWriter object
*
* @return PhpOffice\PhpWord\Writer\IWriter
* @throws Exception
*/
public function getParentWriter()
{
if (!is_null($this->_parentWriter)) {
return $this->_parentWriter;
} else {
throw new Exception("No parent IWriter assigned.");
}
}
}

View File

@ -1,482 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\HashTable;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Shared\Drawing;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TOC;
class RTF implements IWriter
{
/**
* Private PhpWord
*
* @var PhpOffice\PhpWord
*/
private $_document;
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var PhpOffice\PhpWord\HashTable
*/
private $_drawingHashTable;
private $_colorTable;
private $_fontTable;
private $_lastParagraphStyle;
/**
* @param PhpOffice\PhpWord $phpWord
*/
public function __construct(PhpWord $phpWord = null)
{
// Assign PhpWord
$this->setPhpWord($phpWord);
// Set HashTable variables
$this->_drawingHashTable = new HashTable();
}
/**
* Save PhpWord to file
*
* @param string $pFileName
* @throws \Exception
*/
public function save($pFilename = null)
{
if (!is_null($this->_document)) {
// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
$pFilename = @tempnam('./', 'phppttmp');
if ($pFilename == '') {
$pFilename = $originalFilename;
}
}
$hFile = fopen($pFilename, 'w') or die("can't open file");
fwrite($hFile, $this->getData());
fclose($hFile);
// If a temporary file was used, copy it to the correct file stream
if ($originalFilename != $pFilename) {
if (copy($pFilename, $originalFilename) === false) {
throw new \Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
}
@unlink($pFilename);
}
} else {
throw new \Exception("PhpWord object unassigned.");
}
}
/**
* @return PhpOffice\PhpWord
* @throws \Exception
*/
public function getPhpWord()
{
if (!is_null($this->_document)) {
return $this->_document;
} else {
throw new \Exception("No PhpWord assigned.");
}
}
/**
* @param PhpOffice\PhpWord $phpWord
* @throws \Exception
* @return PhpOffice\PhpWord\Writer\RTF
*/
public function setPhpWord(PhpWord $phpWord = null)
{
$this->_document = $phpWord;
return $this;
}
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return PhpOffice\PhpWord\HashTable
*/
public function getDrawingHashTable()
{
return $this->_drawingHashTable;
}
private function getData()
{
// PhpWord object : $this->_document
$this->_fontTable = $this->getDataFont();
$this->_colorTable = $this->getDataColor();
$sRTFContent = '{\rtf1';
// Set the default character set
$sRTFContent .= '\ansi\ansicpg1252';
// Set the default font (the first one)
$sRTFContent .= '\deff0';
// Set the default tab size (720 twips)
$sRTFContent .= '\deftab720';
$sRTFContent .= PHP_EOL;
// Set the font tbl group
$sRTFContent .= '{\fonttbl';
foreach ($this->_fontTable as $idx => $font) {
$sRTFContent .= '{\f' . $idx . '\fnil\fcharset0 ' . $font . ';}';
}
$sRTFContent .= '}' . PHP_EOL;
// Set the color tbl group
$sRTFContent .= '{\colortbl ';
foreach ($this->_colorTable as $idx => $color) {
$arrColor = Drawing::htmlToRGB($color);
$sRTFContent .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . '';
}
$sRTFContent .= ';}' . PHP_EOL;
// Set the generator
$sRTFContent .= '{\*\generator PhpWord;}' . PHP_EOL;
// Set the view mode of the document
$sRTFContent .= '\viewkind4';
// Set the numberof bytes that follows a unicode character
$sRTFContent .= '\uc1';
// Resets to default paragraph properties.
$sRTFContent .= '\pard';
// No widow/orphan control
$sRTFContent .= '\nowidctlpar';
// Applies a language to a text run (1036 : French (France))
$sRTFContent .= '\lang1036';
// Point size (in half-points) above which to kern character pairs
$sRTFContent .= '\kerning1';
// Set the font size in half-points
$sRTFContent .= '\fs' . (PhpWord::DEFAULT_FONT_SIZE * 2);
$sRTFContent .= PHP_EOL;
// Body
$sRTFContent .= $this->getDataContent();
$sRTFContent .= '}';
return $sRTFContent;
}
private function getDataFont()
{
$phpWord = $this->_document;
$arrFonts = array();
// Default font : PhpWord::DEFAULT_FONT_NAME
$arrFonts[] = PhpWord::DEFAULT_FONT_NAME;
// PhpWord object : $this->_document
// Browse styles
$styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PhpOffice\PhpWord\Style\Font
if ($style instanceof Font) {
if (in_array($style->getName(), $arrFonts) == false) {
$arrFonts[] = $style->getName();
}
}
}
}
// Search all fonts used
$_sections = $phpWord->getSections();
$countSections = count($_sections);
if ($countSections > 0) {
$pSection = 0;
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
if ($fStyle instanceof Font) {
if (in_array($fStyle->getName(), $arrFonts) == false) {
$arrFonts[] = $fStyle->getName();
}
}
}
}
}
}
return $arrFonts;
}
private function getDataColor()
{
$phpWord = $this->_document;
$arrColors = array();
// PhpWord object : $this->_document
// Browse styles
$styles = Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// Font
if ($style instanceof Font) {
$color = $style->getColor();
$fgcolor = $style->getFgColor();
if (in_array($color, $arrColors) == false && $color != PhpWord::DEFAULT_FONT_COLOR && !empty($color)) {
$arrColors[] = $color;
}
if (in_array($fgcolor, $arrColors) == false && $fgcolor != PhpWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) {
$arrColors[] = $fgcolor;
}
}
}
}
// Search all fonts used
$_sections = $phpWord->getSections();
$countSections = count($_sections);
if ($countSections > 0) {
$pSection = 0;
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
if ($fStyle instanceof Font) {
if (in_array($fStyle->getColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getColor();
}
if (in_array($fStyle->getFgColor(), $arrColors) == false) {
$arrColors[] = $fStyle->getFgColor();
}
}
}
}
}
}
return $arrColors;
}
private function getDataContent()
{
$phpWord = $this->_document;
$sRTFBody = '';
$_sections = $phpWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$sRTFBody .= $this->getDataContentText($element);
} elseif ($element instanceof TextBreak) {
$sRTFBody .= $this->getDataContentTextBreak();
} elseif ($element instanceof TextRun) {
$sRTFBody .= $this->getDataContentTextRun($element);
} elseif ($element instanceof Link) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Link');
} elseif ($element instanceof Title) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Title');
} elseif ($element instanceof PageBreak) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Page Break');
} elseif ($element instanceof Table) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Table');
} elseif ($element instanceof ListItem) {
$sRTFBody .= $this->getDataContentUnsupportedElement('List Item');
} elseif ($element instanceof Image ||
$element instanceof MemoryImage) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Image');
} elseif ($element instanceof Object) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Object');
} elseif ($element instanceof TOC) {
$sRTFBody .= $this->getDataContentUnsupportedElement('TOC');
} else {
$sRTFBody .= $this->getDataContentUnsupportedElement('Other');
}
}
}
}
return $sRTFBody;
}
private function getDataContentText(Text $text, $withoutP = false)
{
$sRTFText = '';
$styleFont = $text->getFontStyle();
$SfIsObject = ($styleFont instanceof Font) ? true : false;
if (!$SfIsObject) {
$styleFont = Style::getStyle($styleFont);
}
$styleParagraph = $text->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
if (!$SpIsObject) {
$styleParagraph = Style::getStyle($styleParagraph);
}
if ($styleParagraph && !$withoutP) {
if ($this->_lastParagraphStyle != $text->getParagraphStyle()) {
$sRTFText .= '\pard\nowidctlpar';
if ($styleParagraph->getSpaceAfter() != null) {
$sRTFText .= '\sa' . $styleParagraph->getSpaceAfter();
}
if ($styleParagraph->getAlign() != null) {
if ($styleParagraph->getAlign() == 'center') {
$sRTFText .= '\qc';
}
}
$this->_lastParagraphStyle = $text->getParagraphStyle();
} else {
$this->_lastParagraphStyle = '';
}
} else {
$this->_lastParagraphStyle = '';
}
if ($styleFont instanceof Font) {
if ($styleFont->getColor() != null) {
$idxColor = array_search($styleFont->getColor(), $this->_colorTable);
if ($idxColor !== false) {
$sRTFText .= '\cf' . ($idxColor + 1);
}
} else {
$sRTFText .= '\cf0';
}
if ($styleFont->getName() != null) {
$idxFont = array_search($styleFont->getName(), $this->_fontTable);
if ($idxFont !== false) {
$sRTFText .= '\f' . $idxFont;
}
} else {
$sRTFText .= '\f0';
}
if ($styleFont->getBold()) {
$sRTFText .= '\b';
}
if ($styleFont->getBold()) {
$sRTFText .= '\i';
}
if ($styleFont->getSize()) {
$sRTFText .= '\fs' . ($styleFont->getSize() * 2);
}
}
if ($this->_lastParagraphStyle != '' || $styleFont) {
$sRTFText .= ' ';
}
$sRTFText .= $text->getText();
if ($styleFont instanceof Font) {
$sRTFText .= '\cf0';
$sRTFText .= '\f0';
if ($styleFont->getBold()) {
$sRTFText .= '\b0';
}
if ($styleFont->getItalic()) {
$sRTFText .= '\i0';
}
if ($styleFont->getSize()) {
$sRTFText .= '\fs' . (PhpWord::DEFAULT_FONT_SIZE * 2);
}
}
if (!$withoutP) {
$sRTFText .= '\par' . PHP_EOL;
}
return $sRTFText;
}
private function getDataContentTextRun(TextRun $textrun)
{
$sRTFText = '';
$elements = $textrun->getElements();
if (count($elements) > 0) {
$sRTFText .= '\pard\nowidctlpar' . PHP_EOL;
foreach ($elements as $element) {
if ($element instanceof Text) {
$sRTFText .= '{';
$sRTFText .= $this->getDataContentText($element, true);
$sRTFText .= '}' . PHP_EOL;
}
}
$sRTFText .= '\par' . PHP_EOL;
}
return $sRTFText;
}
private function getDataContentTextBreak()
{
$this->_lastParagraphStyle = '';
return '\par' . PHP_EOL;
}
/**
* Write unsupported element
*
* @param string $element
*/
private function getDataContentUnsupportedElement($element)
{
$sRTFText = '';
$sRTFText .= '\pard\nowidctlpar' . PHP_EOL;
$sRTFText .= "{$element}";
$sRTFText .= '\par' . PHP_EOL;
return $sRTFText;
}
}

View File

@ -1,301 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Footnote;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Writer\Word2007\ContentTypes;
use PhpOffice\PhpWord\Writer\Word2007\DocProps;
use PhpOffice\PhpWord\Writer\Word2007\Document;
use PhpOffice\PhpWord\Writer\Word2007\DocumentRels;
use PhpOffice\PhpWord\Writer\Word2007\Footer;
use PhpOffice\PhpWord\Writer\Word2007\Footnotes;
use PhpOffice\PhpWord\Writer\Word2007\FootnotesRels;
use PhpOffice\PhpWord\Writer\Word2007\Header;
use PhpOffice\PhpWord\Writer\Word2007\Rels;
use PhpOffice\PhpWord\Writer\Word2007\Styles;
class Word2007 implements IWriter
{
private $_document;
private $_writerParts;
private $_diskCachingDirectory;
private $_useDiskCaching = false;
private $_imageTypes = array();
private $_objectTypes = array();
public function __construct(PhpWord $phpWord = null)
{
$this->_document = $phpWord;
$this->_diskCachingDirectory = './';
$this->_writerParts['contenttypes'] = new ContentTypes();
$this->_writerParts['rels'] = new Rels();
$this->_writerParts['docprops'] = new DocProps();
$this->_writerParts['documentrels'] = new DocumentRels();
$this->_writerParts['document'] = new Document();
$this->_writerParts['styles'] = new Styles();
$this->_writerParts['header'] = new Header();
$this->_writerParts['footer'] = new Footer();
$this->_writerParts['footnotes'] = new Footnotes();
$this->_writerParts['footnotesrels'] = new FootnotesRels();
foreach ($this->_writerParts as $writer) {
$writer->setParentWriter($this);
}
}
public function save($pFilename = null)
{
if (!is_null($this->_document)) {
// If $pFilename is php://output or php://stdout, make it a temporary file...
$originalFilename = $pFilename;
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
$pFilename = @tempnam('./', 'phppttmp');
if ($pFilename == '') {
$pFilename = $originalFilename;
}
}
// Create new ZIP file and open it for writing
$objZip = new ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
}
}
$sectionElements = array();
$_secElements = Media::getSectionMediaElements();
foreach ($_secElements as $element) { // loop through section media elements
if ($element['type'] != 'hyperlink') {
$this->_addFileToPackage($objZip, $element);
}
$sectionElements[] = $element;
}
$_hdrElements = Media::getHeaderMediaElements();
foreach ($_hdrElements as $_headerFile => $_hdrMedia) { // loop through headers
if (count($_hdrMedia) > 0) {
$objZip->addFromString('word/_rels/' . $_headerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_hdrMedia));
foreach ($_hdrMedia as $element) { // loop through header media elements
$this->_addFileToPackage($objZip, $element);
}
}
}
$_ftrElements = Media::getFooterMediaElements();
foreach ($_ftrElements as $_footerFile => $_ftrMedia) { // loop through footers
if (count($_ftrMedia) > 0) {
$objZip->addFromString('word/_rels/' . $_footerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_ftrMedia));
foreach ($_ftrMedia as $element) { // loop through footers media elements
$this->_addFileToPackage($objZip, $element);
}
}
}
$footnoteLinks = array();
$_footnoteElements = Footnote::getFootnoteLinkElements();
// loop through footnote link elements
foreach ($_footnoteElements as $element) {
$footnoteLinks[] = $element;
}
$_cHdrs = 0;
$_cFtrs = 0;
$rID = Media::countSectionMediaElements() + 6;
$_sections = $this->_document->getSections();
$footers = array();
foreach ($_sections as $section) {
$_headers = $section->getHeaders();
foreach ($_headers as $index => &$_header) {
$_cHdrs++;
$_header->setRelationId(++$rID);
$_headerFile = 'header' . $_cHdrs . '.xml';
$sectionElements[] = array('target' => $_headerFile, 'type' => 'header', 'rID' => $rID);
$objZip->addFromString('word/' . $_headerFile, $this->getWriterPart('header')->writeHeader($_header));
}
$_footer = $section->getFooter();
$footers[++$_cFtrs] = $_footer;
if (!is_null($_footer)) {
$_footer->setRelationId(++$rID);
$_footerCount = $_footer->getFooterCount();
$_footerFile = 'footer' . $_footerCount . '.xml';
$sectionElements[] = array('target' => $_footerFile, 'type' => 'footer', 'rID' => $rID);
$objZip->addFromString('word/' . $_footerFile, $this->getWriterPart('footer')->writeFooter($_footer));
}
}
if (Footnote::countFootnoteElements() > 0) {
$_allFootnotesCollection = Footnote::getFootnoteElements();
$_footnoteFile = 'footnotes.xml';
$sectionElements[] = array('target'=>$_footnoteFile, 'type'=>'footnotes', 'rID'=>++$rID);
$objZip->addFromString('word/'.$_footnoteFile, $this->getWriterPart('footnotes')->writeFootnotes($_allFootnotesCollection));
if (count($footnoteLinks) > 0) {
$objZip->addFromString('word/_rels/footnotes.xml.rels', $this->getWriterPart('footnotesrels')->writeFootnotesRels($footnoteLinks));
}
}
// build docx file
// Write dynamic files
$objZip->addFromString(
'[Content_Types].xml',
$this->getWriterPart('contenttypes')->writeContentTypes(
$this->_imageTypes,
$this->_objectTypes,
$_cHdrs,
$footers
)
);
$objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->_document));
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docprops')->writeDocPropsApp($this->_document));
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('docprops')->writeDocPropsCore($this->_document));
$objZip->addFromString('word/document.xml', $this->getWriterPart('document')->writeDocument($this->_document));
$objZip->addFromString('word/_rels/document.xml.rels', $this->getWriterPart('documentrels')->writeDocumentRels($sectionElements));
$objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document));
// Write static files
$objZip->addFile(PHPWORD_BASE_PATH . 'PhpWord/_staticDocParts/numbering.xml', 'word/numbering.xml');
$objZip->addFile(PHPWORD_BASE_PATH . 'PhpWord/_staticDocParts/settings.xml', 'word/settings.xml');
$objZip->addFile(PHPWORD_BASE_PATH . 'PhpWord/_staticDocParts/theme1.xml', 'word/theme/theme1.xml');
$objZip->addFile(PHPWORD_BASE_PATH . 'PhpWord/_staticDocParts/webSettings.xml', 'word/webSettings.xml');
$objZip->addFile(PHPWORD_BASE_PATH . 'PhpWord/_staticDocParts/fontTable.xml', 'word/fontTable.xml');
// Close file
if ($objZip->close() === false) {
throw new Exception("Could not close zip file $pFilename.");
}
// If a temporary file was used, copy it to the correct file stream
if ($originalFilename != $pFilename) {
if (copy($pFilename, $originalFilename) === false) {
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
}
@unlink($pFilename);
}
} else {
throw new Exception("PhpWord object unassigned.");
}
}
/**
* @param string $src
*/
private function checkContentTypes($src)
{
$extension = null;
if (stripos(strrev($src), strrev('.php')) === 0) {
$extension = 'php';
} else {
$imageType = exif_imagetype($src);
if ($imageType === IMAGETYPE_JPEG) {
$extension = 'jpg';
} elseif ($imageType === IMAGETYPE_GIF) {
$extension = 'gif';
} elseif ($imageType === IMAGETYPE_PNG) {
$extension = 'png';
} elseif ($imageType === IMAGETYPE_BMP) {
$extension = 'bmp';
} elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) {
$extension = 'tif';
}
}
if (isset($extension)) {
$imageData = getimagesize($src);
$imageType = image_type_to_mime_type($imageData[2]);
$imageExtension = str_replace('.', '', image_type_to_extension($imageData[2]));
if ($imageExtension === 'jpeg') {
$imageExtension = 'jpg';
}
if (!in_array($imageType, $this->_imageTypes)) {
$this->_imageTypes[$imageExtension] = $imageType;
}
} else {
if (!in_array($extension, $this->_objectTypes)) {
$this->_objectTypes[] = $extension;
}
}
}
public function getWriterPart($pPartName = '')
{
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) {
return $this->_writerParts[strtolower($pPartName)];
} else {
return null;
}
}
public function getUseDiskCaching()
{
return $this->_useDiskCaching;
}
public function setUseDiskCaching($pValue = false, $pDirectory = null)
{
$this->_useDiskCaching = $pValue;
if (!is_null($pDirectory)) {
if (is_dir($pDirectory)) {
$this->_diskCachingDirectory = $pDirectory;
} else {
throw new Exception("Directory does not exist: $pDirectory");
}
}
return $this;
}
private function _addFileToPackage($objZip, $element)
{
if (isset($element['isMemImage']) && $element['isMemImage']) {
$image = call_user_func($element['createfunction'], $element['source']);
ob_start();
call_user_func($element['imagefunction'], $image);
$imageContents = ob_get_contents();
ob_end_clean();
$objZip->addFromString('word/' . $element['target'], $imageContents);
imagedestroy($image);
$this->checkContentTypes($element['source']);
} else {
$objZip->addFile($element['source'], 'word/' . $element['target']);
$this->checkContentTypes($element['source']);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,228 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Shared\File;
use PhpOffice\PhpWord\Shared\XMLWriter;
class ContentTypes extends WriterPart
{
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Types
$xmlWriter->startElement('Types');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
// Rels
$this->_writeDefaultContentType(
$xmlWriter,
'rels',
'application/vnd.openxmlformats-package.relationships+xml'
);
// XML
$this->_writeDefaultContentType(
$xmlWriter,
'xml',
'application/xml'
);
// Add media content-types
foreach ($_imageTypes as $key => $value) {
$this->_writeDefaultContentType($xmlWriter, $key, $value);
}
// Add embedding content-types
if (count($_objectTypes) > 0) {
$this->_writeDefaultContentType(
$xmlWriter,
'bin',
'application/vnd.openxmlformats-officedocument.oleObject'
);
}
// DocProps
$this->_writeOverrideContentType(
$xmlWriter,
'/docProps/app.xml',
'application/vnd.openxmlformats-officedocument.extended-properties+xml'
);
$this->_writeOverrideContentType(
$xmlWriter,
'/docProps/core.xml',
'application/vnd.openxmlformats-package.core-properties+xml'
);
// Document
$this->_writeOverrideContentType(
$xmlWriter,
'/word/document.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
);
// Styles
$this->_writeOverrideContentType(
$xmlWriter,
'/word/styles.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
);
// Numbering
$this->_writeOverrideContentType(
$xmlWriter,
'/word/numbering.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
);
// Settings
$this->_writeOverrideContentType(
$xmlWriter,
'/word/settings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
);
// Theme1
$this->_writeOverrideContentType(
$xmlWriter,
'/word/theme/theme1.xml',
'application/vnd.openxmlformats-officedocument.theme+xml'
);
// WebSettings
$this->_writeOverrideContentType(
$xmlWriter,
'/word/webSettings.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
);
// Font Table
$this->_writeOverrideContentType(
$xmlWriter,
'/word/fontTable.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
);
// Footnotes
$this->_writeOverrideContentType(
$xmlWriter,
'/word/footnotes.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
);
for ($i = 1; $i <= $_cHdrs; $i++) {
$this->_writeOverrideContentType(
$xmlWriter,
'/word/header' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
);
}
for ($i = 1; $i <= count($footers); $i++) {
if (!is_null($footers[$i])) {
$this->_writeOverrideContentType(
$xmlWriter,
'/word/footer' . $i . '.xml',
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
);
}
}
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws Exception
*/
private function _getImageMimeType($pFile = '')
{
if (File::file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
/**
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* @param string $pPartname Part name
* @param string $pContentType Content type
* @throws Exception
*/
private function _writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{
if ($pPartname != '' && $pContentType != '') {
// Write content type
$xmlWriter->startElement('Default');
$xmlWriter->writeAttribute('Extension', $pPartname);
$xmlWriter->writeAttribute('ContentType', $pContentType);
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
/**
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $pPartname Part name
* @param string $pContentType Content type
* @throws Exception
*/
private function _writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
{
if ($pPartname != '' && $pContentType != '') {
// Write content type
$xmlWriter->startElement('Override');
$xmlWriter->writeAttribute('PartName', $pPartname);
$xmlWriter->writeAttribute('ContentType', $pContentType);
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -1,186 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
class DocProps extends WriterPart
{
public function writeDocPropsApp(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Properties
$xmlWriter->startElement('Properties');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
$xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
// Application
$xmlWriter->writeElement('Application', 'Microsoft Office Word');
// ScaleCrop
$xmlWriter->writeElement('ScaleCrop', 'false');
// HeadingPairs
$xmlWriter->startElement('HeadingPairs');
// Vector
$xmlWriter->startElement('vt:vector');
$xmlWriter->writeAttribute('size', '4');
$xmlWriter->writeAttribute('baseType', 'variant');
// Variant
$xmlWriter->startElement('vt:variant');
$xmlWriter->writeElement('vt:lpstr', 'Theme');
$xmlWriter->endElement();
// Variant
$xmlWriter->startElement('vt:variant');
$xmlWriter->writeElement('vt:i4', '1');
$xmlWriter->endElement();
// Variant
$xmlWriter->startElement('vt:variant');
$xmlWriter->writeElement('vt:lpstr', 'Slide Titles');
$xmlWriter->endElement();
// Variant
$xmlWriter->startElement('vt:variant');
$xmlWriter->writeElement('vt:i4', '1');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
// TitlesOfParts
$xmlWriter->startElement('TitlesOfParts');
// Vector
$xmlWriter->startElement('vt:vector');
$xmlWriter->writeAttribute('size', '1');
$xmlWriter->writeAttribute('baseType', 'lpstr');
$xmlWriter->writeElement('vt:lpstr', 'Office Theme');
$xmlWriter->endElement();
$xmlWriter->endElement();
// Company
$xmlWriter->writeElement('Company', $phpWord->getDocumentProperties()->getCompany());
// LinksUpToDate
$xmlWriter->writeElement('LinksUpToDate', 'false');
// SharedDoc
$xmlWriter->writeElement('SharedDoc', 'false');
// HyperlinksChanged
$xmlWriter->writeElement('HyperlinksChanged', 'false');
// AppVersion
$xmlWriter->writeElement('AppVersion', '12.0000');
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
public function writeDocPropsCore(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// cp:coreProperties
$xmlWriter->startElement('cp:coreProperties');
$xmlWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
$xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
// dc:creator
$xmlWriter->writeElement('dc:creator', $phpWord->getDocumentProperties()->getCreator());
// cp:lastModifiedBy
$xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocumentProperties()->getLastModifiedBy());
// dcterms:created
$xmlWriter->startElement('dcterms:created');
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$xmlWriter->writeRaw(date(DATE_W3C, $phpWord->getDocumentProperties()->getCreated()));
$xmlWriter->endElement();
// dcterms:modified
$xmlWriter->startElement('dcterms:modified');
$xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$xmlWriter->writeRaw(date(DATE_W3C, $phpWord->getDocumentProperties()->getModified()));
$xmlWriter->endElement();
// dc:title
$xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle());
// dc:description
$xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription());
// dc:subject
$xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject());
// cp:keywords
$xmlWriter->writeElement('cp:keywords', $phpWord->getDocumentProperties()->getKeywords());
// cp:category
$xmlWriter->writeElement('cp:category', $phpWord->getDocumentProperties()->getCategory());
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
}

View File

@ -1,506 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Section\Footnote;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\TOC;
class Document extends Base
{
public function writeDocument(PhpWord $phpWord = null)
{
// Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// w:document
$xmlWriter->startElement('w:document');
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$xmlWriter->startElement('w:body');
$_sections = $phpWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof Link) {
$this->_writeLink($xmlWriter, $element);
} elseif ($element instanceof Title) {
$this->_writeTitle($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof PageBreak) {
$this->_writePageBreak($xmlWriter);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof ListItem) {
$this->_writeListItem($xmlWriter, $element);
} elseif ($element instanceof Image ||
$element instanceof MemoryImage
) {
$this->_writeImage($xmlWriter, $element);
} elseif ($element instanceof Object) {
$this->_writeObject($xmlWriter, $element);
} elseif ($element instanceof TOC) {
$this->_writeTOC($xmlWriter);
} elseif ($element instanceof Footnote) {
$this->_writeFootnoteReference($xmlWriter, $element);
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($xmlWriter, $section);
} else {
$this->_writeSection($xmlWriter, $section);
}
}
}
$xmlWriter->endElement(); // End w:body
$xmlWriter->endElement(); // End w:document
// Return
return $xmlWriter->getData();
}
private function _writeSection(XMLWriter $xmlWriter = null, Section $section)
{
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr');
$this->_writeEndSection($xmlWriter, $section, 3);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section)
{
$settings = $section->getSettings();
$_headers = $section->getHeaders();
$_footer = $section->getFooter();
$pgSzW = $settings->getPageSizeW();
$pgSzH = $settings->getPageSizeH();
$orientation = $settings->getOrientation();
$marginTop = $settings->getMarginTop();
$marginLeft = $settings->getMarginLeft();
$marginRight = $settings->getMarginRight();
$marginBottom = $settings->getMarginBottom();
$headerHeight = $settings->getHeaderHeight();
$footerHeight = $settings->getFooterHeight();
$borders = $settings->getBorderSize();
$colsNum = $settings->getColsNum();
$colsSpace = $settings->getColsSpace();
$breakType = $settings->getBreakType();
$xmlWriter->startElement('w:sectPr');
foreach ($_headers as &$_header) {
$rId = $_header->getRelationId();
$xmlWriter->startElement('w:headerReference');
$xmlWriter->writeAttribute('w:type', $_header->getType());
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->endElement();
}
if ($section->hasDifferentFirstPage()) {
$xmlWriter->startElement('w:titlePg');
$xmlWriter->endElement();
}
if (!is_null($breakType)) {
$xmlWriter->startElement('w:type');
$xmlWriter->writeAttribute('w:val', $breakType);
$xmlWriter->endElement();
}
if (!is_null($_footer)) {
$rId = $_footer->getRelationId();
$xmlWriter->startElement('w:footerReference');
$xmlWriter->writeAttribute('w:type', 'default');
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:pgSz');
$xmlWriter->writeAttribute('w:w', $pgSzW);
$xmlWriter->writeAttribute('w:h', $pgSzH);
if (!is_null($orientation) && strtolower($orientation) != 'portrait') {
$xmlWriter->writeAttribute('w:orient', $orientation);
}
$xmlWriter->endElement();
$xmlWriter->startElement('w:pgMar');
$xmlWriter->writeAttribute('w:top', $marginTop);
$xmlWriter->writeAttribute('w:right', $marginRight);
$xmlWriter->writeAttribute('w:bottom', $marginBottom);
$xmlWriter->writeAttribute('w:left', $marginLeft);
$xmlWriter->writeAttribute('w:header', $headerHeight);
$xmlWriter->writeAttribute('w:footer', $footerHeight);
$xmlWriter->writeAttribute('w:gutter', '0');
$xmlWriter->endElement();
if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
$borderColor = $settings->getBorderColor();
$xmlWriter->startElement('w:pgBorders');
$xmlWriter->writeAttribute('w:offsetFrom', 'page');
if (!is_null($borders[0])) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $borders[0]);
$xmlWriter->writeAttribute('w:space', '24');
$xmlWriter->writeAttribute('w:color', $borderColor[0]);
$xmlWriter->endElement();
}
if (!is_null($borders[1])) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $borders[1]);
$xmlWriter->writeAttribute('w:space', '24');
$xmlWriter->writeAttribute('w:color', $borderColor[1]);
$xmlWriter->endElement();
}
if (!is_null($borders[2])) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $borders[2]);
$xmlWriter->writeAttribute('w:space', '24');
$xmlWriter->writeAttribute('w:color', $borderColor[2]);
$xmlWriter->endElement();
}
if (!is_null($borders[3])) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $borders[3]);
$xmlWriter->writeAttribute('w:space', '24');
$xmlWriter->writeAttribute('w:color', $borderColor[3]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
// Page numbering
if (null !== $settings->getPageNumberingStart()) {
$xmlWriter->startElement('w:pgNumType');
$xmlWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart());
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:cols');
$xmlWriter->writeAttribute('w:num', $colsNum);
$xmlWriter->writeAttribute('w:space', $colsSpace);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
private function _writePageBreak(XMLWriter $xmlWriter = null)
{
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:br');
$xmlWriter->writeAttribute('w:type', 'page');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
public function _writeListItem(XMLWriter $xmlWriter = null, ListItem $listItem)
{
$textObject = $listItem->getTextObject();
$text = $textObject->getText();
$styleParagraph = $textObject->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
$depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType();
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr');
if ($SpIsObject) {
$this->_writeParagraphStyle($xmlWriter, $styleParagraph, true);
} elseif (!$SpIsObject && !is_null($styleParagraph)) {
$xmlWriter->startElement('w:pStyle');
$xmlWriter->writeAttribute('w:val', $styleParagraph);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:numPr');
$xmlWriter->startElement('w:ilvl');
$xmlWriter->writeAttribute('w:val', $depth);
$xmlWriter->endElement();
$xmlWriter->startElement('w:numId');
$xmlWriter->writeAttribute('w:val', $listType);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
$this->_writeText($xmlWriter, $textObject, true);
$xmlWriter->endElement();
}
protected function _writeObject(XMLWriter $xmlWriter = null, Object $object)
{
$rIdObject = $object->getRelationId();
$rIdImage = $object->getImageRelationId();
$shapeId = md5($rIdObject . '_' . $rIdImage);
$objectId = $object->getObjectId();
$style = $object->getStyle();
$width = $style->getWidth();
$height = $style->getHeight();
$align = $style->getAlign();
$xmlWriter->startElement('w:p');
if (!is_null($align)) {
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:jc');
$xmlWriter->writeAttribute('w:val', $align);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:object');
$xmlWriter->writeAttribute('w:dxaOrig', '249');
$xmlWriter->writeAttribute('w:dyaOrig', '160');
$xmlWriter->startElement('v:shape');
$xmlWriter->writeAttribute('id', $shapeId);
$xmlWriter->writeAttribute('type', '#_x0000_t75');
$xmlWriter->writeAttribute('style', 'width:104px;height:67px');
$xmlWriter->writeAttribute('o:ole', '');
$xmlWriter->startElement('v:imagedata');
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage);
$xmlWriter->writeAttribute('o:title', '');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('o:OLEObject');
$xmlWriter->writeAttribute('Type', 'Embed');
$xmlWriter->writeAttribute('ProgID', 'Package');
$xmlWriter->writeAttribute('ShapeID', $shapeId);
$xmlWriter->writeAttribute('DrawAspect', 'Icon');
$xmlWriter->writeAttribute('ObjectID', '_' . $objectId);
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
}
private function _writeTOC(XMLWriter $xmlWriter = null)
{
$titles = TOC::getTitles();
$styleFont = TOC::getStyleFont();
$styleTOC = TOC::getStyleTOC();
$fIndent = $styleTOC->getIndent();
$tabLeader = $styleTOC->getTabLeader();
$tabPos = $styleTOC->getTabPos();
$isObject = ($styleFont instanceof Font) ? true : false;
for ($i = 0; $i < count($titles); $i++) {
$title = $titles[$i];
$indent = ($title['depth'] - 1) * $fIndent;
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:pPr');
if ($isObject && !is_null($styleFont->getParagraphStyle())) {
$this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
}
if ($indent > 0) {
$xmlWriter->startElement('w:ind');
$xmlWriter->writeAttribute('w:left', $indent);
$xmlWriter->endElement();
}
if (!empty($styleFont) && !$isObject) {
$xmlWriter->startElement('w:pPr');
$xmlWriter->startElement('w:pStyle');
$xmlWriter->writeAttribute('w:val', $styleFont);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:tabs');
$xmlWriter->startElement('w:tab');
$xmlWriter->writeAttribute('w:val', 'right');
if (!empty($tabLeader)) {
$xmlWriter->writeAttribute('w:leader', $tabLeader);
}
$xmlWriter->writeAttribute('w:pos', $tabPos);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:pPr
if ($i == 0) {
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:fldChar');
$xmlWriter->writeAttribute('w:fldCharType', 'begin');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:instrText');
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->writeRaw('TOC \o "1-9" \h \z \u');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:fldChar');
$xmlWriter->writeAttribute('w:fldCharType', 'separate');
$xmlWriter->endElement();
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:hyperlink');
$xmlWriter->writeAttribute('w:anchor', $title['anchor']);
$xmlWriter->writeAttribute('w:history', '1');
$xmlWriter->startElement('w:r');
if ($isObject) {
$this->_writeTextStyle($xmlWriter, $styleFont);
}
$xmlWriter->startElement('w:t');
$xmlWriter->writeRaw($title['text']);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('w:r');
$xmlWriter->writeElement('w:tab', null);
$xmlWriter->endElement();
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:fldChar');
$xmlWriter->writeAttribute('w:fldCharType', 'begin');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:instrText');
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:fldChar');
$xmlWriter->writeAttribute('w:fldCharType', 'end');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:hyperlink
$xmlWriter->endElement(); // w:p
}
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:fldChar');
$xmlWriter->writeAttribute('w:fldCharType', 'end');
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
}

View File

@ -1,182 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Shared\XMLWriter;
class DocumentRels extends WriterPart
{
public function writeDocumentRels($_relsCollection)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$xmlWriter->startElement('Relationships');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationship word/document.xml
$this->_writeRelationship(
$xmlWriter,
1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
'styles.xml'
);
// Relationship word/numbering.xml
$this->_writeRelationship(
$xmlWriter,
2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
'numbering.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$xmlWriter,
3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
'settings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$xmlWriter,
4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
'theme/theme1.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$xmlWriter,
5,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
'webSettings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$xmlWriter,
6,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
'fontTable.xml'
);
// Relationships to Images / Embeddings / Headers / Footers
foreach ($_relsCollection as $relation) {
$relationType = $relation['type'];
$relationName = $relation['target'];
$relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship(
$xmlWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName,
$targetMode
);
}
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
public function writeHeaderFooterRels($_relsCollection)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$xmlWriter->startElement('Relationships');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationships to Images / Embeddings / Headers / Footers
foreach ($_relsCollection as $relation) {
$relationType = $relation['type'];
$relationName = $relation['target'];
$relationId = $relation['rID'];
$this->_writeRelationship(
$xmlWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName
);
}
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -1,90 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Footer extends Base
{
public function writeFooter(PhpOffice\PhpWord\Section\Footer $footer)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:ftr');
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$_elements = $footer->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof Image ||
$element instanceof MemoryImage
) {
$this->_writeImage($xmlWriter, $element);
} elseif ($element instanceof PreserveText) {
$this->_writePreserveText($xmlWriter, $element);
}
}
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
}

View File

@ -1,87 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Section\Footnote;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Footnotes extends Base
{
public function writeFootnotes($allFootnotesCollection)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:footnotes');
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// write separator and continuation separator
$xmlWriter->startElement('w:footnote');
$xmlWriter->writeAttribute('w:id', 0);
$xmlWriter->writeAttribute('w:type', 'separator');
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:separator');
$xmlWriter->endElement(); // w:separator
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
$xmlWriter->endElement(); // w:footnote
$xmlWriter->startElement('w:footnote');
$xmlWriter->writeAttribute('w:id', 1);
$xmlWriter->writeAttribute('w:type', 'continuationSeparator');
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:continuationSeparator');
$xmlWriter->endElement(); // w:continuationSeparator
$xmlWriter->endElement(); // w:r
$xmlWriter->endElement(); // w:p
$xmlWriter->endElement(); // w:footnote
foreach ($allFootnotesCollection as $footnote) {
if ($footnote instanceof Footnote) {
$this->_writeFootnote($xmlWriter, $footnote);
}
}
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
}

View File

@ -1,89 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Shared\XMLWriter;
class FootnotesRels extends WriterPart
{
public function writeFootnotesRels($_relsCollection)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$xmlWriter->startElement('Relationships');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationships to Links
foreach ($_relsCollection as $relation) {
$relationType = $relation['type'];
$relationName = $relation['target'];
$relationId = $relation['rID'];
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
$this->_writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
}
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Header extends Base
{
public function writeHeader(PhpOffice\PhpWord\Section\Header $header)
{
// Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:hdr');
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$_elements = $header->getElements();
foreach ($_elements as $element) {
if ($element instanceof Text) {
$this->_writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
$this->_writeTextRun($xmlWriter, $element);
} elseif ($element instanceof TextBreak) {
$this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof Image ||
$element instanceof MemoryImage
) {
if (!$element->getIsWatermark()) {
$this->_writeImage($xmlWriter, $element);
} else {
$this->_writeWatermark($xmlWriter, $element);
}
} elseif ($element instanceof PreserveText) {
$this->_writePreserveText($xmlWriter, $element);
}
}
$xmlWriter->endElement();
// Return
return $xmlWriter->getData();
}
}

View File

@ -1,115 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
class Rels extends WriterPart
{
public function writeRelationships(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$xmlWriter->startElement('Relationships');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
$relationId = 1;
// Relationship word/document.xml
$this->_writeRelationship(
$xmlWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
'word/document.xml'
);
// Relationship docProps/core.xml
$this->_writeRelationship(
$xmlWriter,
++$relationId,
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
'docProps/core.xml'
);
// Relationship docProps/app.xml
$this->_writeRelationship(
$xmlWriter,
++$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
'docProps/app.xml'
);
$xmlWriter->endElement();
return $xmlWriter->getData();
}
/**
* Write Override content type
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $pId Relationship ID. rId will be prepended!
* @param string $pType Relationship type
* @param string $pTarget Relationship target
* @param string $pTargetMode Relationship target mode
* @throws Exception
*/
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$xmlWriter->startElement('Relationship');
$xmlWriter->writeAttribute('Id', $pId);
$xmlWriter->writeAttribute('Type', $pType);
$xmlWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
}
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}

View File

@ -1,399 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
class Styles extends Base
{
private $_document;
public function writeStyles(PhpWord $phpWord = null)
{
// Create XML writer
$xmlWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
}
$this->_document = $phpWord;
// XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:styles');
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// Write DocDefaults
$this->_writeDocDefaults($xmlWriter);
// Write Style Definitions
$styles = Style::getStyles();
// Write normal paragraph style
$normalStyle = null;
if (array_key_exists('Normal', $styles)) {
$normalStyle = $styles['Normal'];
}
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'paragraph');
$xmlWriter->writeAttribute('w:default', '1');
$xmlWriter->writeAttribute('w:styleId', 'Normal');
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement();
if (!is_null($normalStyle)) {
$this->_writeParagraphStyle($xmlWriter, $normalStyle);
}
$xmlWriter->endElement();
// Write other styles
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if ($styleName == 'Normal') {
continue;
}
if ($style instanceof Font) {
$paragraphStyle = $style->getParagraphStyle();
$styleType = $style->getStyleType();
$type = ($styleType == 'title') ? 'paragraph' : 'character';
if (!is_null($paragraphStyle)) {
$type = 'paragraph';
}
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', $type);
if ($styleType == 'title') {
$arrStyle = explode('_', $styleName);
$styleId = 'Heading' . $arrStyle[1];
$styleName = 'heading ' . $arrStyle[1];
$styleLink = 'Heading' . $arrStyle[1] . 'Char';
$xmlWriter->writeAttribute('w:styleId', $styleId);
$xmlWriter->startElement('w:link');
$xmlWriter->writeAttribute('w:val', $styleLink);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', $styleName);
$xmlWriter->endElement();
if (!is_null($paragraphStyle)) {
// Point parent style to Normal
$xmlWriter->startElement('w:basedOn');
$xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement();
$this->_writeParagraphStyle($xmlWriter, $paragraphStyle);
}
$this->_writeTextStyle($xmlWriter, $style);
$xmlWriter->endElement();
} elseif ($style instanceof Paragraph) {
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'paragraph');
$xmlWriter->writeAttribute('w:customStyle', '1');
$xmlWriter->writeAttribute('w:styleId', $styleName);
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', $styleName);
$xmlWriter->endElement();
// Parent style
$basedOn = $style->getBasedOn();
if (!is_null($basedOn)) {
$xmlWriter->startElement('w:basedOn');
$xmlWriter->writeAttribute('w:val', $basedOn);
$xmlWriter->endElement();
}
// Next paragraph style
$next = $style->getNext();
if (!is_null($next)) {
$xmlWriter->startElement('w:next');
$xmlWriter->writeAttribute('w:val', $next);
$xmlWriter->endElement();
}
$this->_writeParagraphStyle($xmlWriter, $style);
$xmlWriter->endElement();
} elseif ($style instanceof TableFull) {
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'table');
$xmlWriter->writeAttribute('w:customStyle', '1');
$xmlWriter->writeAttribute('w:styleId', $styleName);
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', $styleName);
$xmlWriter->endElement();
$xmlWriter->startElement('w:uiPriority');
$xmlWriter->writeAttribute('w:val', '99');
$xmlWriter->endElement();
$this->_writeFullTableStyle($xmlWriter, $style);
$xmlWriter->endElement();
}
}
}
$xmlWriter->endElement(); // w:styles
// Return
return $xmlWriter->getData();
}
private function _writeFullTableStyle(XMLWriter $xmlWriter = null, TableFull $style)
{
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$cellMargin = $style->getCellMargin();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$bInsH = (!is_null($brdSz[4])) ? true : false;
$bInsV = (!is_null($brdSz[5])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
$mTop = (!is_null($cellMargin[0])) ? true : false;
$mLeft = (!is_null($cellMargin[1])) ? true : false;
$mRight = (!is_null($cellMargin[2])) ? true : false;
$mBottom = (!is_null($cellMargin[3])) ? true : false;
$margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
$xmlWriter->startElement('w:tblPr');
if ($margins) {
$xmlWriter->startElement('w:tblCellMar');
if ($mTop) {
echo $margins[0];
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:w', $cellMargin[0]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:w', $cellMargin[1]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:w', $cellMargin[2]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:w', $cellMargin[3]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
if ($borders) {
$xmlWriter->startElement('w:tblBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
if ($bInsH) {
$xmlWriter->startElement('w:insideH');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[4]);
$xmlWriter->writeAttribute('w:color', $brdCol[4]);
$xmlWriter->endElement();
}
if ($bInsV) {
$xmlWriter->startElement('w:insideV');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[5]);
$xmlWriter->writeAttribute('w:color', $brdCol[5]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
$xmlWriter->endElement();
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:tcPr');
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
// First Row
$firstRow = $style->getFirstRow();
if (!is_null($firstRow)) {
$this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow);
}
}
private function _writeRowStyle(XMLWriter $xmlWriter = null, $type, TableFull $style)
{
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
$xmlWriter->startElement('w:tblStylePr');
$xmlWriter->writeAttribute('w:type', $type);
$xmlWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:tcBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
private function _writeDocDefaults(XMLWriter $xmlWriter = null)
{
$fontName = $this->_document->getDefaultFontName();
$fontSize = $this->_document->getDefaultFontSize();
$xmlWriter->startElement('w:docDefaults');
$xmlWriter->startElement('w:rPrDefault');
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:rFonts');
$xmlWriter->writeAttribute('w:ascii', $fontName);
$xmlWriter->writeAttribute('w:hAnsi', $fontName);
$xmlWriter->writeAttribute('w:eastAsia', $fontName);
$xmlWriter->writeAttribute('w:cs', $fontName);
$xmlWriter->endElement();
$xmlWriter->startElement('w:sz');
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
$xmlWriter->endElement();
$xmlWriter->startElement('w:szCs');
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
}

View File

@ -1,49 +0,0 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PhpWord
* @package PhpWord
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Writer\IWriter;
abstract class WriterPart
{
private $_parentWriter;
public function setParentWriter(IWriter $pWriter = null)
{
$this->_parentWriter = $pWriter;
}
public function getParentWriter()
{
if (!is_null($this->_parentWriter)) {
return $this->_parentWriter;
} else {
throw new Exception("No parent IWriter assigned.");
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:fonts xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:font w:name="Times New Roman"><w:panose1 w:val="02020603050405020304"/><w:charset w:val="00"/><w:family w:val="roman"/><w:pitch w:val="variable"/><w:sig w:usb0="E0002AFF" w:usb1="C0007841" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/></w:font><w:font w:name="Courier New"><w:panose1 w:val="02070309020205020404"/><w:charset w:val="00"/><w:family w:val="modern"/><w:pitch w:val="fixed"/><w:sig w:usb0="E0002AFF" w:usb1="C0007843" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/></w:font><w:font w:name="Wingdings"><w:panose1 w:val="05000000000000000000"/><w:charset w:val="02"/><w:family w:val="auto"/><w:pitch w:val="variable"/><w:sig w:usb0="00000000" w:usb1="10000000" w:usb2="00000000" w:usb3="00000000" w:csb0="80000000" w:csb1="00000000"/></w:font><w:font w:name="Symbol"><w:panose1 w:val="05050102010706020507"/><w:charset w:val="02"/><w:family w:val="roman"/><w:pitch w:val="variable"/><w:sig w:usb0="00000000" w:usb1="10000000" w:usb2="00000000" w:usb3="00000000" w:csb0="80000000" w:csb1="00000000"/></w:font><w:font w:name="Arial"><w:panose1 w:val="020B0604020202020204"/><w:charset w:val="00"/><w:family w:val="swiss"/><w:pitch w:val="variable"/><w:sig w:usb0="E0002AFF" w:usb1="C0007843" w:usb2="00000009" w:usb3="00000000" w:csb0="000001FF" w:csb1="00000000"/></w:font><w:font w:name="Cambria"><w:panose1 w:val="02040503050406030204"/><w:charset w:val="00"/><w:family w:val="roman"/><w:pitch w:val="variable"/><w:sig w:usb0="A00002EF" w:usb1="4000004B" w:usb2="00000000" w:usb3="00000000" w:csb0="0000019F" w:csb1="00000000"/></w:font><w:font w:name="Calibri"><w:panose1 w:val="020F0502020204030204"/><w:charset w:val="00"/><w:family w:val="swiss"/><w:pitch w:val="variable"/><w:sig w:usb0="E10002FF" w:usb1="4000ACFF" w:usb2="00000009" w:usb3="00000000" w:csb0="0000019F" w:csb1="00000000"/></w:font></w:fonts>

File diff suppressed because one or more lines are too long

View File

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<w:settings xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main">
<w:zoom w:percent="100" />
<w:embedSystemFonts />
<w:defaultTabStop w:val="708" />
<w:hyphenationZone w:val="425" />
<w:doNotHyphenateCaps />
<w:characterSpacingControl w:val="doNotCompress" />
<w:doNotValidateAgainstSchema />
<w:doNotDemarcateInvalidXml />
<w:compat>
<w:useNormalStyleForList />
<w:doNotUseIndentAsNumberingTabStop />
<w:useAltKinsokuLineBreakRules />
<w:allowSpaceOfSameStyleInTable />
<w:doNotSuppressIndentation />
<w:doNotAutofitConstrainedTables />
<w:autofitToFirstFixedWidthCell />
<w:underlineTabInNumList />
<w:displayHangulFixedWidth />
<w:splitPgBreakAndParaMark />
<w:doNotVertAlignCellWithSp />
<w:doNotBreakConstrainedForcedTable />
<w:doNotVertAlignInTxbx />
<w:useAnsiKerningPairs />
<w:cachedColBalance />
</w:compat>
<m:mathPr>
<m:mathFont m:val="Cambria Math" />
<m:brkBin m:val="before" />
<m:brkBinSub m:val="--" />
<m:smallFrac m:val="off" />
<m:dispDef />
<m:lMargin m:val="0" />
<m:rMargin m:val="0" />
<m:defJc m:val="centerGroup" />
<m:wrapIndent m:val="1440" />
<m:intLim m:val="subSup" />
<m:naryLim m:val="undOvr" />
</m:mathPr>
<w:uiCompat97To2003 />
<w:themeFontLang w:val="de-DE" />
<w:clrSchemeMapping w:bg1="light1" w:t1="dark1" w:bg2="light2" w:t2="dark2" w:accent1="accent1" w:accent2="accent2" w:accent3="accent3" w:accent4="accent4" w:accent5="accent5" w:accent6="accent6" w:hyperlink="hyperlink" w:followedHyperlink="followedHyperlink" />
<w:doNotIncludeSubdocsInStats />
<w:doNotAutoCompressPictures />
<w:decimalSymbol w:val="," />
<w:listSeparator w:val=";" />
</w:settings>

File diff suppressed because one or more lines are too long

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:webSettings xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:optimizeForBrowser/></w:webSettings>

0
src/Exceptions/Exception.php Normal file → Executable file
View File