Formatted PHP code toward PSR-2 compliance

This commit is contained in:
Gabriel Bull 2013-12-11 14:45:44 -05:00
parent 3f7ed20a28
commit b6c33c8931
60 changed files with 9868 additions and 9362 deletions

View File

@ -26,7 +26,7 @@
*/ */
/** PHPWORD_BASE_PATH */ /** PHPWORD_BASE_PATH */
if(!defined('PHPWORD_BASE_PATH')) { if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/'); define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php'; require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php';
PHPWord_Autoloader::Register(); PHPWord_Autoloader::Register();
@ -40,191 +40,207 @@ if(!defined('PHPWORD_BASE_PATH')) {
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord { class PHPWord
{
/**
* Document properties
*
* @var PHPWord_DocumentProperties
*/
private $_properties;
/**
* Default Font Name
*
* @var string
*/
private $_defaultFontName;
/**
* Default Font Size
*
* @var int
*/
private $_defaultFontSize;
/**
* Collection of section elements
*
* @var array
*/
private $_sectionCollection = array();
/**
/** * Document properties
* Create a new PHPWord Document *
*/ * @var PHPWord_DocumentProperties
public function __construct() { */
$this->_properties = new PHPWord_DocumentProperties(); private $_properties;
$this->_defaultFontName = 'Arial';
$this->_defaultFontSize = 20; /**
} * Default Font Name
*
* @var string
*/
private $_defaultFontName;
/**
* Default Font Size
*
* @var int
*/
private $_defaultFontSize;
/**
* Collection of section elements
*
* @var array
*/
private $_sectionCollection = array();
/**
* Create a new PHPWord Document
*/
public function __construct()
{
$this->_properties = new PHPWord_DocumentProperties();
$this->_defaultFontName = 'Arial';
$this->_defaultFontSize = 20;
}
/**
* Get properties
* @return PHPWord_DocumentProperties
*/
public function getProperties()
{
return $this->_properties;
}
/**
* Set properties
*
* @param PHPWord_DocumentProperties $value
* @return PHPWord
*/
public function setProperties(PHPWord_DocumentProperties $value)
{
$this->_properties = $value;
return $this;
}
/**
* Create a new Section
*
* @param PHPWord_Section_Settings $settings
* @return PHPWord_Section
*/
public function createSection($settings = null)
{
$sectionCount = $this->_countSections() + 1;
$section = new PHPWord_Section($sectionCount, $settings);
$this->_sectionCollection[] = $section;
return $section;
}
/**
* Get default Font name
* @return string
*/
public function getDefaultFontName()
{
return $this->_defaultFontName;
}
/**
* Set default Font name
* @param string $pValue
*/
public function setDefaultFontName($pValue)
{
$this->_defaultFontName = $pValue;
}
/**
* Get default Font size
* @return string
*/
public function getDefaultFontSize()
{
return $this->_defaultFontSize;
}
/**
* Set default Font size
* @param int $pValue
*/
public function setDefaultFontSize($pValue)
{
$pValue = $pValue * 2;
$this->_defaultFontSize = $pValue;
}
/**
* Adds a paragraph style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addParagraphStyle($styleName, $styles)
{
PHPWord_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)
{
PHPWord_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)
{
PHPWord_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)
{
PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
}
/**
* Adds a hyperlink style to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addLinkStyle($styleName, $styles)
{
PHPWord_Style::addLinkStyle($styleName, $styles);
}
/**
* Get sections
* @return PHPWord_Section[]
*/
public function getSections()
{
return $this->_sectionCollection;
}
/**
* Get section count
* @return int
*/
private function _countSections()
{
return count($this->_sectionCollection);
}
/**
* Get properties
* @return PHPWord_DocumentProperties
*/
public function getProperties() {
return $this->_properties;
}
/**
* Set properties
*
* @param PHPWord_DocumentProperties $value
* @return PHPWord
*/
public function setProperties(PHPWord_DocumentProperties $value) {
$this->_properties = $value;
return $this;
}
/**
* Create a new Section
*
* @param PHPWord_Section_Settings $settings
* @return PHPWord_Section
*/
public function createSection($settings = null) {
$sectionCount = $this->_countSections() + 1;
$section = new PHPWord_Section($sectionCount, $settings);
$this->_sectionCollection[] = $section;
return $section;
}
/**
* Get default Font name
* @return string
*/
public function getDefaultFontName() {
return $this->_defaultFontName;
}
/**
* Set default Font name
* @param string $pValue
*/
public function setDefaultFontName($pValue) {
$this->_defaultFontName = $pValue;
}
/**
* Get default Font size
* @return string
*/
public function getDefaultFontSize() {
return $this->_defaultFontSize;
}
/**
* Set default Font size
* @param int $pValue
*/
public function setDefaultFontSize($pValue) {
$pValue = $pValue * 2;
$this->_defaultFontSize = $pValue;
}
/**
* Adds a paragraph style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addParagraphStyle($styleName, $styles) {
PHPWord_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) {
PHPWord_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) {
PHPWord_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) {
PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
}
/**
* Adds a hyperlink style to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addLinkStyle($styleName, $styles) {
PHPWord_Style::addLinkStyle($styleName, $styles);
}
/**
* Get sections
* @return PHPWord_Section[]
*/
public function getSections() {
return $this->_sectionCollection;
}
/**
* Get section count
* @return int
*/
private function _countSections() {
return count($this->_sectionCollection);
}
/** /**
* Load a Template File * Load a Template File
* *
* @param string $strFilename * @param string $strFilename
* @return PHPWord_Template * @return PHPWord_Template
*/ */
public function loadTemplate($strFilename) { public function loadTemplate($strFilename)
if(file_exists($strFilename)) { {
if (file_exists($strFilename)) {
$template = new PHPWord_Template($strFilename); $template = new PHPWord_Template($strFilename);
return $template; return $template;
} else { } else {
trigger_error('Template file '.$strFilename.' not found.', E_ERROR); trigger_error('Template file ' . $strFilename . ' not found.', E_ERROR);
} }
} }
} }
?>

View File

@ -27,22 +27,23 @@
class PHPWord_Autoloader class PHPWord_Autoloader
{ {
public static function Register() { public static function Register()
return spl_autoload_register(array('PHPWord_Autoloader', 'Load')); {
} return spl_autoload_register(array('PHPWord_Autoloader', 'Load'));
}
public static function Load($strObjectName) { public static function Load($strObjectName)
if((class_exists($strObjectName)) || (strpos($strObjectName, 'PHPWord') === false)) { {
return false; if ((class_exists($strObjectName)) || (strpos($strObjectName, 'PHPWord') === false)) {
} return false;
}
$strObjectFilePath = PHPWORD_BASE_PATH . str_replace('_', '/', $strObjectName) . '.php'; $strObjectFilePath = PHPWORD_BASE_PATH . str_replace('_', '/', $strObjectName) . '.php';
if((file_exists($strObjectFilePath) === false) || (is_readable($strObjectFilePath) === false)) { if ((file_exists($strObjectFilePath) === false) || (is_readable($strObjectFilePath) === false)) {
return false; return false;
} }
require($strObjectFilePath); require($strObjectFilePath);
} }
} }
?>

View File

@ -33,298 +33,319 @@
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 2009 - 2011 PHPWord (http://www.codeplex.com/PHPWord) * @copyright Copyright (c) 2009 - 2011 PHPWord (http://www.codeplex.com/PHPWord)
*/ */
class PHPWord_DocumentProperties { class PHPWord_DocumentProperties
{
/** /**
* Creator * Creator
* *
* @var string * @var string
*/ */
private $_creator; 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;
/** /**
* Create new PHPWord_DocumentProperties * LastModifiedBy
*/ *
public function __construct() { * @var string
$this->_creator = ''; */
$this->_lastModifiedBy = $this->_creator; private $_lastModifiedBy;
$this->_created = time();
$this->_modified = time();
$this->_title = '';
$this->_subject = '';
$this->_description = '';
$this->_keywords = '';
$this->_category = '';
$this->_company = '';
}
/** /**
* Get Creator * Created
* *
* @return string * @var datetime
*/ */
public function getCreator() { private $_created;
return $this->_creator;
} /**
* Modified
/** *
* Set Creator * @var datetime
* */
* @param string $pValue private $_modified;
* @return PHPWord_DocumentProperties
*/ /**
public function setCreator($pValue = '') { * Title
$this->_creator = $pValue; *
return $this; * @var string
} */
private $_title;
/**
* Get Last Modified By /**
* * Description
* @return string *
*/ * @var string
public function getLastModifiedBy() { */
return $this->_lastModifiedBy; private $_description;
}
/**
/** * Subject
* Set Last Modified By *
* * @var string
* @param string $pValue */
* @return PHPWord_DocumentProperties private $_subject;
*/
public function setLastModifiedBy($pValue = '') { /**
$this->_lastModifiedBy = $pValue; * Keywords
return $this; *
} * @var string
*/
/** private $_keywords;
* Get Created
* /**
* @return datetime * Category
*/ *
public function getCreated() { * @var string
return $this->_created; */
} private $_category;
/** /**
* Set Created * Company
* *
* @param datetime $pValue * @var string
* @return PHPWord_DocumentProperties */
*/ private $_company;
public function setCreated($pValue = null) {
if (is_null($pValue)) { /**
$pValue = time(); * Create new PHPWord_DocumentProperties
} */
$this->_created = $pValue; public function __construct()
return $this; {
} $this->_creator = '';
$this->_lastModifiedBy = $this->_creator;
/** $this->_created = time();
* Get Modified $this->_modified = time();
* $this->_title = '';
* @return datetime $this->_subject = '';
*/ $this->_description = '';
public function getModified() { $this->_keywords = '';
return $this->_modified; $this->_category = '';
} $this->_company = '';
}
/**
* Set Modified /**
* * Get Creator
* @param datetime $pValue *
* @return PHPWord_DocumentProperties * @return string
*/ */
public function setModified($pValue = null) { public function getCreator()
if (is_null($pValue)) { {
$pValue = time(); return $this->_creator;
} }
$this->_modified = $pValue;
return $this; /**
} * Set Creator
*
/** * @param string $pValue
* Get Title * @return PHPWord_DocumentProperties
* */
* @return string public function setCreator($pValue = '')
*/ {
public function getTitle() { $this->_creator = $pValue;
return $this->_title; return $this;
} }
/** /**
* Set Title * Get Last Modified By
* *
* @param string $pValue * @return string
* @return PHPWord_DocumentProperties */
*/ public function getLastModifiedBy()
public function setTitle($pValue = '') { {
$this->_title = $pValue; return $this->_lastModifiedBy;
return $this; }
}
/**
/** * Set Last Modified By
* Get Description *
* * @param string $pValue
* @return string * @return PHPWord_DocumentProperties
*/ */
public function getDescription() { public function setLastModifiedBy($pValue = '')
return $this->_description; {
} $this->_lastModifiedBy = $pValue;
return $this;
/** }
* Set Description
* /**
* @param string $pValue * Get Created
* @return PHPWord_DocumentProperties *
*/ * @return datetime
public function setDescription($pValue = '') { */
$this->_description = $pValue; public function getCreated()
return $this; {
} return $this->_created;
}
/**
* Get Subject /**
* * Set Created
* @return string *
*/ * @param datetime $pValue
public function getSubject() { * @return PHPWord_DocumentProperties
return $this->_subject; */
} public function setCreated($pValue = null)
{
/** if (is_null($pValue)) {
* Set Subject $pValue = time();
* }
* @param string $pValue $this->_created = $pValue;
* @return PHPWord_DocumentProperties return $this;
*/ }
public function setSubject($pValue = '') {
$this->_subject = $pValue; /**
return $this; * Get Modified
} *
* @return datetime
/** */
* Get Keywords public function getModified()
* {
* @return string return $this->_modified;
*/ }
public function getKeywords() {
return $this->_keywords; /**
} * Set Modified
*
/** * @param datetime $pValue
* Set Keywords * @return PHPWord_DocumentProperties
* */
* @param string $pValue public function setModified($pValue = null)
* @return PHPWord_DocumentProperties {
*/ if (is_null($pValue)) {
public function setKeywords($pValue = '') { $pValue = time();
$this->_keywords = $pValue; }
return $this; $this->_modified = $pValue;
} return $this;
}
/**
* Get Category /**
* * Get Title
* @return string *
*/ * @return string
public function getCategory() { */
return $this->_category; public function getTitle()
} {
return $this->_title;
/** }
* Set Category
* /**
* @param string $pValue * Set Title
* @return PHPWord_DocumentProperties *
*/ * @param string $pValue
public function setCategory($pValue = '') { * @return PHPWord_DocumentProperties
$this->_category = $pValue; */
return $this; public function setTitle($pValue = '')
} {
$this->_title = $pValue;
/** return $this;
* Get Company }
*
* @return string /**
*/ * Get Description
public function getCompany() { *
return $this->_company; * @return string
} */
public function getDescription()
/** {
* Set Company return $this->_description;
* }
* @param string $pValue
* @return PHPWord_DocumentProperties /**
*/ * Set Description
public function setCompany($pValue = '') { *
$this->_company = $pValue; * @param string $pValue
return $this; * @return 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 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 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 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 PHPWord_DocumentProperties
*/
public function setCompany($pValue = '')
{
$this->_company = $pValue;
return $this;
}
}

View File

@ -52,25 +52,26 @@ class PHPWord_HashTable
/** /**
* Create a new PHPWord_HashTable * Create a new PHPWord_HashTable
* *
* @param PHPWord_IComparable[] $pSource Optional source array to create HashTable from * @param PHPWord_IComparable[] $pSource Optional source array to create HashTable from
* @throws Exception * @throws Exception
*/ */
public function __construct($pSource = null) public function __construct($pSource = null)
{ {
if (!is_null($pSource)) { if (!is_null($pSource)) {
// Create HashTable // Create HashTable
$this->addFromSource($pSource); $this->addFromSource($pSource);
} }
} }
/** /**
* Add HashTable items from source * Add HashTable items from source
* *
* @param PHPWord_IComparable[] $pSource Source array to create HashTable from * @param PHPWord_IComparable[] $pSource Source array to create HashTable from
* @throws Exception * @throws Exception
*/ */
public function addFromSource($pSource = null) { public function addFromSource($pSource = null)
// Check if an array was passed {
// Check if an array was passed
if ($pSource == null) { if ($pSource == null) {
return; return;
} else if (!is_array($pSource)) { } else if (!is_array($pSource)) {
@ -85,63 +86,66 @@ class PHPWord_HashTable
/** /**
* Add HashTable item * Add HashTable item
* *
* @param PHPWord_IComparable $pSource Item to add * @param PHPWord_IComparable $pSource Item to add
* @throws Exception * @throws Exception
*/ */
public function add(PHPWord_IComparable $pSource = null) { public function add(PHPWord_IComparable $pSource = null)
// Determine hashcode {
$hashCode = null; // Determine hashcode
$hashIndex = $pSource->getHashIndex(); $hashCode = null;
if ( is_null ( $hashIndex ) ) { $hashIndex = $pSource->getHashIndex();
$hashCode = $pSource->getHashCode(); if (is_null($hashIndex)) {
} else if ( isset ( $this->_keyMap[$hashIndex] ) ) { $hashCode = $pSource->getHashCode();
$hashCode = $this->_keyMap[$hashIndex]; } else if (isset ($this->_keyMap[$hashIndex])) {
} else { $hashCode = $this->_keyMap[$hashIndex];
$hashCode = $pSource->getHashCode(); } else {
} $hashCode = $pSource->getHashCode();
}
// Add value // Add value
if (!isset($this->_items[ $hashCode ])) { if (!isset($this->_items[$hashCode])) {
$this->_items[ $hashCode ] = $pSource; $this->_items[$hashCode] = $pSource;
$index = count($this->_items) - 1; $index = count($this->_items) - 1;
$this->_keyMap[ $index ] = $hashCode; $this->_keyMap[$index] = $hashCode;
$pSource->setHashIndex( $index ); $pSource->setHashIndex($index);
} else { } else {
$pSource->setHashIndex( $this->_items[ $hashCode ]->getHashIndex() ); $pSource->setHashIndex($this->_items[$hashCode]->getHashIndex());
} }
} }
/** /**
* Remove HashTable item * Remove HashTable item
* *
* @param PHPWord_IComparable $pSource Item to remove * @param PHPWord_IComparable $pSource Item to remove
* @throws Exception * @throws Exception
*/ */
public function remove(PHPWord_IComparable $pSource = null) { public function remove(PHPWord_IComparable $pSource = null)
if (isset($this->_items[ $pSource->getHashCode() ])) { {
unset($this->_items[ $pSource->getHashCode() ]); if (isset($this->_items[$pSource->getHashCode()])) {
unset($this->_items[$pSource->getHashCode()]);
$deleteKey = -1; $deleteKey = -1;
foreach ($this->_keyMap as $key => $value) { foreach ($this->_keyMap as $key => $value) {
if ($deleteKey >= 0) { if ($deleteKey >= 0) {
$this->_keyMap[$key - 1] = $value; $this->_keyMap[$key - 1] = $value;
} }
if ($value == $pSource->getHashCode()) { if ($value == $pSource->getHashCode()) {
$deleteKey = $key; $deleteKey = $key;
} }
} }
unset($this->_keyMap[ count($this->_keyMap) - 1 ]); unset($this->_keyMap[count($this->_keyMap) - 1]);
} }
} }
/** /**
* Clear HashTable * Clear HashTable
* *
*/ */
public function clear() { public function clear()
$this->_items = array(); {
$this->_keyMap = array(); $this->_items = array();
$this->_keyMap = array();
} }
/** /**
@ -149,48 +153,52 @@ class PHPWord_HashTable
* *
* @return int * @return int
*/ */
public function count() { public function count()
return count($this->_items); {
return count($this->_items);
} }
/** /**
* Get index for hash code * Get index for hash code
* *
* @param string $pHashCode * @param string $pHashCode
* @return int Index * @return int Index
*/ */
public function getIndexForHashCode($pHashCode = '') { public function getIndexForHashCode($pHashCode = '')
return array_search($pHashCode, $this->_keyMap); {
return array_search($pHashCode, $this->_keyMap);
} }
/** /**
* Get by index * Get by index
* *
* @param int $pIndex * @param int $pIndex
* @return PHPWord_IComparable * @return PHPWord_IComparable
* *
*/ */
public function getByIndex($pIndex = 0) { public function getByIndex($pIndex = 0)
if (isset($this->_keyMap[$pIndex])) { {
return $this->getByHashCode( $this->_keyMap[$pIndex] ); if (isset($this->_keyMap[$pIndex])) {
} return $this->getByHashCode($this->_keyMap[$pIndex]);
}
return null; return null;
} }
/** /**
* Get by hashcode * Get by hashcode
* *
* @param string $pHashCode * @param string $pHashCode
* @return PHPWord_IComparable * @return PHPWord_IComparable
* *
*/ */
public function getByHashCode($pHashCode = '') { public function getByHashCode($pHashCode = '')
if (isset($this->_items[$pHashCode])) { {
return $this->_items[$pHashCode]; if (isset($this->_items[$pHashCode])) {
} return $this->_items[$pHashCode];
}
return null; return null;
} }
/** /**
@ -198,19 +206,21 @@ class PHPWord_HashTable
* *
* @return PHPWord_IComparable[] * @return PHPWord_IComparable[]
*/ */
public function toArray() { public function toArray()
return $this->_items; {
return $this->_items;
} }
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone()
$vars = get_object_vars($this); {
foreach ($vars as $key => $value) { $vars = get_object_vars($this);
if (is_object($value)) { foreach ($vars as $key => $value) {
$this->$key = clone $value; if (is_object($value)) {
} $this->$key = clone $value;
} }
} }
}
} }

View File

@ -33,88 +33,94 @@
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_IOFactory { class PHPWord_IOFactory
{
/**
* Search locations /**
* * Search locations
* @var array *
*/ * @var array
private static $_searchLocations = array( */
array('type' => 'IWriter', 'path' => 'PHPWord/Writer/{0}.php', 'class' => 'PHPWord_Writer_{0}') private static $_searchLocations = array(
); array('type' => 'IWriter', 'path' => 'PHPWord/Writer/{0}.php', 'class' => 'PHPWord_Writer_{0}')
);
/**
* Autoresolve classes /**
* * Autoresolve classes
* @var array *
*/ * @var array
private static $_autoResolveClasses = array( */
'Serialized' private static $_autoResolveClasses = array(
); 'Serialized'
);
/**
* Private constructor for PHPWord_IOFactory /**
*/ * Private constructor for PHPWord_IOFactory
private function __construct() { } */
private function __construct()
/** {
* Get search locations }
*
* @return array /**
*/ * Get search locations
public static function getSearchLocations() { *
return self::$_searchLocations; * @return array
} */
public static function getSearchLocations()
/** {
* Set search locations return self::$_searchLocations;
* }
* @param array $value
* @throws Exception /**
*/ * Set search locations
public static function setSearchLocations($value) { *
if (is_array($value)) { * @param array $value
self::$_searchLocations = $value; * @throws Exception
} else { */
throw new Exception('Invalid parameter passed.'); public static function setSearchLocations($value)
} {
} if (is_array($value)) {
self::$_searchLocations = $value;
/** } else {
* Add search location throw new Exception('Invalid parameter passed.');
* }
* @param string $type Example: IWriter }
* @param string $location Example: PHPWord/Writer/{0}.php
* @param string $classname Example: PHPWord_Writer_{0} /**
*/ * Add search location
public static function addSearchLocation($type = '', $location = '', $classname = '') { *
self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname ); * @param string $type Example: IWriter
} * @param string $location Example: PHPWord/Writer/{0}.php
* @param string $classname Example: PHPWord_Writer_{0}
/** */
* Create PHPWord_Writer_IWriter public static function addSearchLocation($type = '', $location = '', $classname = '')
* {
* @param PHPWord $PHPWord self::$_searchLocations[] = array('type' => $type, 'path' => $location, 'class' => $classname);
* @param string $writerType Example: Word2007 }
* @return PHPWord_Writer_IWriter
*/ /**
public static function createWriter(PHPWord $PHPWord, $writerType = '') { * Create PHPWord_Writer_IWriter
$searchType = 'IWriter'; *
* @param PHPWord $PHPWord
foreach (self::$_searchLocations as $searchLocation) { * @param string $writerType Example: Word2007
if ($searchLocation['type'] == $searchType) { * @return PHPWord_Writer_IWriter
$className = str_replace('{0}', $writerType, $searchLocation['class']); */
$classFile = str_replace('{0}', $writerType, $searchLocation['path']); public static function createWriter(PHPWord $PHPWord, $writerType = '')
{
$instance = new $className($PHPWord); $searchType = 'IWriter';
if(!is_null($instance)) {
return $instance; foreach (self::$_searchLocations as $searchLocation) {
} if ($searchLocation['type'] == $searchType) {
} $className = str_replace('{0}', $writerType, $searchLocation['class']);
} $classFile = str_replace('{0}', $writerType, $searchLocation['path']);
throw new Exception("No $searchType found for type $writerType"); $instance = new $className($PHPWord);
} if (!is_null($instance)) {
return $instance;
}
}
}
throw new Exception("No $searchType found for type $writerType");
}
} }
?>

View File

@ -33,296 +33,307 @@
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Media { class PHPWord_Media
{
/**
* Section Media Elements /**
* * Section Media Elements
* @var array *
*/ * @var array
private static $_sectionMedia = array('images'=>array(), */
'embeddings'=>array(), private static $_sectionMedia = array('images' => array(),
'links'=>array()); 'embeddings' => array(),
'links' => array());
/**
* Header Media Elements /**
* * Header Media Elements
* @var array *
*/ * @var array
private static $_headerMedia = array(); */
private static $_headerMedia = array();
/**
* Footer Media Elements /**
* * Footer Media Elements
* @var array *
*/ * @var array
private static $_footerMedia = array(); */
private static $_footerMedia = array();
/**
* ObjectID Counter /**
* * ObjectID Counter
* @var int *
*/ * @var int
private static $_objectId = 1325353440; */
private static $_objectId = 1325353440;
/**
* Add new Section Media Element /**
* * Add new Section Media Element
* @param string $src *
* @param string $type * @param string $src
* * @param string $type
* @return mixed *
*/ * @return mixed
public static function addSectionMediaElement($src, $type, PHPWord_Section_MemoryImage $memoryImage = null) { */
$mediaId = md5($src); public static function addSectionMediaElement($src, $type, PHPWord_Section_MemoryImage $memoryImage = null)
$key = ($type == 'image') ? 'images' : 'embeddings'; {
$mediaId = md5($src);
if(!array_key_exists($mediaId, self::$_sectionMedia[$key])) { $key = ($type == 'image') ? 'images' : 'embeddings';
$cImg = self::countSectionMediaElements('images');
$cObj = self::countSectionMediaElements('embeddings'); if (!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
$rID = self::countSectionMediaElements() + 7; $cImg = self::countSectionMediaElements('images');
$cObj = self::countSectionMediaElements('embeddings');
$media = array(); $rID = self::countSectionMediaElements() + 7;
if($type == 'image') { $media = array();
$cImg++;
$inf = pathinfo($src); if ($type == 'image') {
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php' && $type == 'image') ? true : false; $cImg++;
$inf = pathinfo($src);
if($isMemImage) { $isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php' && $type == 'image') ? true : false;
$ext = $memoryImage->getImageExtension();
$media['isMemImage'] = true; if ($isMemImage) {
$media['createfunction'] = $memoryImage->getImageCreateFunction(); $ext = $memoryImage->getImageExtension();
$media['imagefunction'] = $memoryImage->getImageFunction(); $media['isMemImage'] = true;
} else { $media['createfunction'] = $memoryImage->getImageCreateFunction();
$ext = $inf['extension']; $media['imagefunction'] = $memoryImage->getImageFunction();
if($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg } else {
$ext = 'jpg'; $ext = $inf['extension'];
} if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
} $ext = 'jpg';
}
$folder = 'media'; }
$file = $type.$cImg.'.'.strtolower($ext);
} elseif($type == 'oleObject') { $folder = 'media';
$cObj++; $file = $type . $cImg . '.' . strtolower($ext);
$folder = 'embedding'; } elseif ($type == 'oleObject') {
$file = $type.$cObj.'.bin'; $cObj++;
} $folder = 'embedding';
$file = $type . $cObj . '.bin';
$media['source'] = $src; }
$media['target'] = "$folder/section_$file";
$media['type'] = $type; $media['source'] = $src;
$media['rID'] = $rID; $media['target'] = "$folder/section_$file";
$media['type'] = $type;
self::$_sectionMedia[$key][$mediaId] = $media; $media['rID'] = $rID;
if($type == 'oleObject') { self::$_sectionMedia[$key][$mediaId] = $media;
return array($rID, ++self::$_objectId);
} else { if ($type == 'oleObject') {
return $rID; return array($rID, ++self::$_objectId);
} } else {
} else { return $rID;
if($type == 'oleObject') { }
$rID = self::$_sectionMedia[$key][$mediaId]['rID']; } else {
return array($rID, ++self::$_objectId); if ($type == 'oleObject') {
} else { $rID = self::$_sectionMedia[$key][$mediaId]['rID'];
return self::$_sectionMedia[$key][$mediaId]['rID']; return array($rID, ++self::$_objectId);
} } else {
} return self::$_sectionMedia[$key][$mediaId]['rID'];
} }
}
/** }
* Add new Section Link Element
* /**
* @param string $linkSrc * Add new Section Link Element
* @param string $linkName *
* * @param string $linkSrc
* @return mixed * @param string $linkName
*/ *
public static function addSectionLinkElement($linkSrc) { * @return mixed
$rID = self::countSectionMediaElements() + 7; */
public static function addSectionLinkElement($linkSrc)
$link = array(); {
$link['target'] = $linkSrc; $rID = self::countSectionMediaElements() + 7;
$link['rID'] = $rID;
$link['type'] = 'hyperlink'; $link = array();
$link['target'] = $linkSrc;
self::$_sectionMedia['links'][] = $link; $link['rID'] = $rID;
$link['type'] = 'hyperlink';
return $rID;
} self::$_sectionMedia['links'][] = $link;
/** return $rID;
* Get Section Media Elements }
*
* @param string $key /**
* @return array * Get Section Media Elements
*/ *
public static function getSectionMediaElements($key = null) { * @param string $key
if(!is_null($key)) { * @return array
return self::$_sectionMedia[$key]; */
} else { public static function getSectionMediaElements($key = null)
$arrImages = self::$_sectionMedia['images']; {
$arrObjects = self::$_sectionMedia['embeddings']; if (!is_null($key)) {
$arrLinks = self::$_sectionMedia['links']; return self::$_sectionMedia[$key];
return array_merge($arrImages, $arrObjects, $arrLinks); } else {
} $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 /**
*/ * Get Section Media Elements Count
public static function countSectionMediaElements($key = null) { *
if(!is_null($key)) { * @param string $key
return count(self::$_sectionMedia[$key]); * @return int
} else { */
$cImages = count(self::$_sectionMedia['images']); public static function countSectionMediaElements($key = null)
$cObjects = count(self::$_sectionMedia['embeddings']); {
$cLinks = count(self::$_sectionMedia['links']); if (!is_null($key)) {
return ($cImages + $cObjects + $cLinks); return count(self::$_sectionMedia[$key]);
} } else {
} $cImages = count(self::$_sectionMedia['images']);
$cObjects = count(self::$_sectionMedia['embeddings']);
/** $cLinks = count(self::$_sectionMedia['links']);
* Add new Header Media Element return ($cImages + $cObjects + $cLinks);
* }
* @param int $headerCount }
* @param string $src
* @return int /**
*/ * Add new Header Media Element
public static function addHeaderMediaElement($headerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null) { *
$mediaId = md5($src); * @param int $headerCount
$key = 'header'.$headerCount; * @param string $src
* @return int
if(!array_key_exists($key, self::$_headerMedia)) { */
self::$_headerMedia[$key] = array(); public static function addHeaderMediaElement($headerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null)
} {
$mediaId = md5($src);
if(!array_key_exists($mediaId, self::$_headerMedia[$key])) { $key = 'header' . $headerCount;
$cImg = self::countHeaderMediaElements($key);
$rID = $cImg + 1; if (!array_key_exists($key, self::$_headerMedia)) {
self::$_headerMedia[$key] = array();
$cImg++; }
$inf = pathinfo($src);
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false; if (!array_key_exists($mediaId, self::$_headerMedia[$key])) {
$cImg = self::countHeaderMediaElements($key);
$media = array(); $rID = $cImg + 1;
if($isMemImage) {
$ext = $memoryImage->getImageExtension(); $cImg++;
$media['isMemImage'] = true; $inf = pathinfo($src);
$media['createfunction'] = $memoryImage->getImageCreateFunction(); $isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
$media['imagefunction'] = $memoryImage->getImageFunction();
} else { $media = array();
$ext = $inf['extension']; if ($isMemImage) {
if($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg $ext = $memoryImage->getImageExtension();
$ext = 'jpg'; $media['isMemImage'] = true;
} $media['createfunction'] = $memoryImage->getImageCreateFunction();
} $media['imagefunction'] = $memoryImage->getImageFunction();
$file = 'image'.$cImg.'.'.strtolower($ext); } else {
$ext = $inf['extension'];
$media['source'] = $src; if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$media['target'] = 'media/'.$key.'_'.$file; $ext = 'jpg';
$media['type'] = 'image'; }
$media['rID'] = $rID; }
$file = 'image' . $cImg . '.' . strtolower($ext);
self::$_headerMedia[$key][$mediaId] = $media;
$media['source'] = $src;
return $rID; $media['target'] = 'media/' . $key . '_' . $file;
} else { $media['type'] = 'image';
return self::$_headerMedia[$key][$mediaId]['rID']; $media['rID'] = $rID;
}
} self::$_headerMedia[$key][$mediaId] = $media;
/** return $rID;
* Get Header Media Elements Count } else {
* return self::$_headerMedia[$key][$mediaId]['rID'];
* @param string $key }
* @return int }
*/
public static function countHeaderMediaElements($key) { /**
return count(self::$_headerMedia[$key]); * Get Header Media Elements Count
} *
* @param string $key
/** * @return int
* Get Header Media Elements */
* public static function countHeaderMediaElements($key)
* @return int {
*/ return count(self::$_headerMedia[$key]);
public static function getHeaderMediaElements() { }
return self::$_headerMedia;
} /**
* Get Header Media Elements
/** *
* Add new Footer Media Element * @return int
* */
* @param int $footerCount public static function getHeaderMediaElements()
* @param string $src {
* @return int return self::$_headerMedia;
*/ }
public static function addFooterMediaElement($footerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null) {
$mediaId = md5($src); /**
$key = 'footer'.$footerCount; * Add new Footer Media Element
*
if(!array_key_exists($key, self::$_footerMedia)) { * @param int $footerCount
self::$_footerMedia[$key] = array(); * @param string $src
} * @return int
*/
if(!array_key_exists($mediaId, self::$_footerMedia[$key])) { public static function addFooterMediaElement($footerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null)
$cImg = self::countFooterMediaElements($key); {
$rID = $cImg + 1; $mediaId = md5($src);
$key = 'footer' . $footerCount;
$cImg++;
$inf = pathinfo($src); if (!array_key_exists($key, self::$_footerMedia)) {
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false; self::$_footerMedia[$key] = array();
}
$media = array();
if($isMemImage) { if (!array_key_exists($mediaId, self::$_footerMedia[$key])) {
$ext = $memoryImage->getImageExtension(); $cImg = self::countFooterMediaElements($key);
$media['isMemImage'] = true; $rID = $cImg + 1;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction(); $cImg++;
} else { $inf = pathinfo($src);
$ext = $inf['extension']; $isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
if($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$ext = 'jpg'; $media = array();
} if ($isMemImage) {
} $ext = $memoryImage->getImageExtension();
$file = 'image'.$cImg.'.'.strtolower($ext); $media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['source'] = $src; $media['imagefunction'] = $memoryImage->getImageFunction();
$media['target'] = 'media/'.$key.'_'.$file; } else {
$media['type'] = 'image'; $ext = $inf['extension'];
$media['rID'] = $rID; if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$ext = 'jpg';
self::$_footerMedia[$key][$mediaId] = $media; }
}
return $rID; $file = 'image' . $cImg . '.' . strtolower($ext);
} else {
return self::$_footerMedia[$key][$mediaId]['rID']; $media['source'] = $src;
} $media['target'] = 'media/' . $key . '_' . $file;
} $media['type'] = 'image';
$media['rID'] = $rID;
/**
* Get Footer Media Elements Count self::$_footerMedia[$key][$mediaId] = $media;
*
* @param string $key return $rID;
* @return int } else {
*/ return self::$_footerMedia[$key][$mediaId]['rID'];
public static function countFooterMediaElements($key) { }
return count(self::$_footerMedia[$key]); }
}
/**
/** * Get Footer Media Elements Count
* Get Footer Media Elements *
* * @param string $key
* @return int * @return int
*/ */
public static function getFooterMediaElements() { public static function countFooterMediaElements($key)
return self::$_footerMedia; {
} return count(self::$_footerMedia[$key]);
}
/**
* Get Footer Media Elements
*
* @return int
*/
public static function getFooterMediaElements()
{
return self::$_footerMedia;
}
} }
?>

View File

@ -33,339 +33,358 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section { class PHPWord_Section
{
/**
* Section count /**
* * Section count
* @var int *
*/ * @var int
private $_sectionCount; */
private $_sectionCount;
/**
* Section settings /**
* * Section settings
* @var PHPWord_Section_Settings *
*/ * @var PHPWord_Section_Settings
private $_settings; */
private $_settings;
/**
* Section Element Collection /**
* * Section Element Collection
* @var array *
*/ * @var array
private $_elementCollection = array(); */
private $_elementCollection = array();
/**
* Section Header /**
* * Section Header
* @var PHPWord_Section_Header *
*/ * @var PHPWord_Section_Header
private $_header = null; */
private $_header = null;
/**
* Section Footer /**
* * Section Footer
* @var PHPWord_Section_Footer *
*/ * @var PHPWord_Section_Footer
private $_footer = null; */
private $_footer = null;
/**
* Create a new Section /**
* * Create a new Section
* @param int $sectionCount *
* @param mixed $settings * @param int $sectionCount
*/ * @param mixed $settings
public function __construct($sectionCount, $settings = null) { */
$this->_sectionCount = $sectionCount; public function __construct($sectionCount, $settings = null)
$this->_settings = new PHPWord_Section_Settings(); {
$this->_sectionCount = $sectionCount;
if(!is_null($settings) && is_array($settings)) { $this->_settings = new PHPWord_Section_Settings();
foreach($settings as $key => $value) {
if(substr($key, 0, 1) != '_') { if (!is_null($settings) && is_array($settings)) {
$key = '_'.$key; foreach ($settings as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_settings->setSettingValue($key, $value); $key = '_' . $key;
} }
} $this->_settings->setSettingValue($key, $value);
} }
}
/** }
* Get Section Settings
* /**
* @return PHPWord_Section_Settings * Get Section Settings
*/ *
public function getSettings() { * @return PHPWord_Section_Settings
return $this->_settings; */
} public function getSettings()
{
/** return $this->_settings;
* Add a Text Element }
*
* @param string $text /**
* @param mixed $styleFont * Add a Text Element
* @param mixed $styleParagraph *
* @return PHPWord_Section_Text * @param string $text
*/ * @param mixed $styleFont
public function addText($text, $styleFont = null, $styleParagraph = null) { * @param mixed $styleParagraph
$givenText = utf8_encode($text); * @return PHPWord_Section_Text
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); */
$this->_elementCollection[] = $text; public function addText($text, $styleFont = null, $styleParagraph = null)
return $text; {
} $givenText = utf8_encode($text);
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph);
/** $this->_elementCollection[] = $text;
* Add a Link Element return $text;
* }
* @param string $linkSrc
* @param string $linkName /**
* @param mixed $styleFont * Add a Link Element
* @param mixed $styleParagraph *
* @return PHPWord_Section_Link * @param string $linkSrc
*/ * @param string $linkName
public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null) { * @param mixed $styleFont
$linkSrc = utf8_encode($linkSrc); * @param mixed $styleParagraph
if(!is_null($linkName)) { * @return PHPWord_Section_Link
$linkName = utf8_encode($linkName); */
} public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
{
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont, $styleParagraph); $linkSrc = utf8_encode($linkSrc);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc); if (!is_null($linkName)) {
$link->setRelationId($rID); $linkName = utf8_encode($linkName);
}
$this->_elementCollection[] = $link;
return $link; $link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont, $styleParagraph);
} $rID = PHPWord_Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
/**
* Add a TextBreak Element $this->_elementCollection[] = $link;
* return $link;
* @param int $count }
*/
public function addTextBreak($count = 1) { /**
for($i=1; $i<=$count; $i++) { * Add a TextBreak Element
$this->_elementCollection[] = new PHPWord_Section_TextBreak(); *
} * @param int $count
} */
public function addTextBreak($count = 1)
/** {
* Add a PageBreak Element for ($i = 1; $i <= $count; $i++) {
*/ $this->_elementCollection[] = new PHPWord_Section_TextBreak();
public function addPageBreak() { }
$this->_elementCollection[] = new PHPWord_Section_PageBreak(); }
}
/**
/** * Add a PageBreak Element
* Add a Table Element */
* public function addPageBreak()
* @param mixed $style {
* @return PHPWord_Section_Table $this->_elementCollection[] = new PHPWord_Section_PageBreak();
*/ }
public function addTable($style = null) {
$table = new PHPWord_Section_Table('section', $this->_sectionCount, $style); /**
$this->_elementCollection[] = $table; * Add a Table Element
return $table; *
} * @param mixed $style
* @return PHPWord_Section_Table
/** */
* Add a ListItem Element public function addTable($style = null)
* {
* @param string $text $table = new PHPWord_Section_Table('section', $this->_sectionCount, $style);
* @param int $depth $this->_elementCollection[] = $table;
* @param mixed $styleFont return $table;
}
/**
* Add a ListItem Element
*
* @param string $text
* @param int $depth
* @param mixed $styleFont
* @param mixed $styleList * @param mixed $styleList
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_ListItem * @return PHPWord_Section_ListItem
*/ */
public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null) { public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
$text = utf8_encode($text); {
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleFont, $styleList, $styleParagraph); $text = utf8_encode($text);
$this->_elementCollection[] = $listItem; $listItem = new PHPWord_Section_ListItem($text, $depth, $styleFont, $styleList, $styleParagraph);
return $listItem; $this->_elementCollection[] = $listItem;
} return $listItem;
}
/**
* Add a OLE-Object Element /**
* * Add a OLE-Object Element
* @param string $src *
* @param mixed $style * @param string $src
* @return PHPWord_Section_Object * @param mixed $style
*/ * @return PHPWord_Section_Object
public function addObject($src, $style = null) { */
$object = new PHPWord_Section_Object($src, $style); public function addObject($src, $style = null)
{
if(!is_null($object->getSource())) { $object = new PHPWord_Section_Object($src, $style);
$inf = pathinfo($src);
$ext = $inf['extension']; if (!is_null($object->getSource())) {
if(strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') { $inf = pathinfo($src);
$ext = substr($ext, 0, -1); $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'; $iconSrc = PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/';
} else { if (!file_exists($iconSrc . '_' . $ext . '.png')) {
$iconSrc .= '_'.$ext.'.png'; $iconSrc = $iconSrc . '_default.png';
} } else {
$iconSrc .= '_' . $ext . '.png';
$rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image'); }
$data = PHPWord_Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0]; $rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image');
$objectId = $data[1]; $data = PHPWord_Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0];
$object->setRelationId($rID); $objectId = $data[1];
$object->setObjectId($objectId);
$object->setImageRelationId($rIDimg); $object->setRelationId($rID);
$object->setObjectId($objectId);
$this->_elementCollection[] = $object; $object->setImageRelationId($rIDimg);
return $object;
} else { $this->_elementCollection[] = $object;
trigger_error('Source does not exist or unsupported object type.'); return $object;
} } else {
} trigger_error('Source does not exist or unsupported object type.');
}
/** }
* Add a Image Element
* /**
* @param string $src * Add a Image Element
* @param mixed $style *
* @return PHPWord_Section_Image * @param string $src
*/ * @param mixed $style
public function addImage($src, $style = null) { * @return PHPWord_Section_Image
$image = new PHPWord_Section_Image($src, $style); */
public function addImage($src, $style = null)
if(!is_null($image->getSource())) { {
$rID = PHPWord_Media::addSectionMediaElement($src, 'image'); $image = new PHPWord_Section_Image($src, $style);
$image->setRelationId($rID);
if (!is_null($image->getSource())) {
$this->_elementCollection[] = $image; $rID = PHPWord_Media::addSectionMediaElement($src, 'image');
return $image; $image->setRelationId($rID);
} else {
trigger_error('Source does not exist or unsupported image type.'); $this->_elementCollection[] = $image;
} return $image;
} } else {
trigger_error('Source does not exist or unsupported image type.');
/** }
* Add a by PHP created Image Element }
*
* @param string $link /**
* @param mixed $style * Add a by PHP created Image Element
* @return PHPWord_Section_MemoryImage *
*/ * @param string $link
public function addMemoryImage($link, $style = null) { * @param mixed $style
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); * @return PHPWord_Section_MemoryImage
if(!is_null($memoryImage->getSource())) { */
$rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage); public function addMemoryImage($link, $style = null)
$memoryImage->setRelationId($rID); {
$memoryImage = new PHPWord_Section_MemoryImage($link, $style);
$this->_elementCollection[] = $memoryImage; if (!is_null($memoryImage->getSource())) {
return $memoryImage; $rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage);
} else { $memoryImage->setRelationId($rID);
trigger_error('Unsupported image type.');
} $this->_elementCollection[] = $memoryImage;
} return $memoryImage;
} else {
/** trigger_error('Unsupported image type.');
* Add a Table-of-Contents Element }
* }
* @param mixed $styleFont
* @param mixed $styleTOC /**
* @return PHPWord_TOC * Add a Table-of-Contents Element
*/ *
public function addTOC($styleFont = null, $styleTOC = null) { * @param mixed $styleFont
$toc = new PHPWord_TOC($styleFont, $styleTOC); * @param mixed $styleTOC
$this->_elementCollection[] = $toc; * @return PHPWord_TOC
return $toc; */
} public function addTOC($styleFont = null, $styleTOC = null)
{
/** $toc = new PHPWord_TOC($styleFont, $styleTOC);
* Add a Title Element $this->_elementCollection[] = $toc;
* return $toc;
* @param string $text }
* @param int $depth
* @return PHPWord_Section_Title /**
*/ * Add a Title Element
public function addTitle($text, $depth = 1) { *
$text = utf8_encode($text); * @param string $text
$styles = PHPWord_Style::getStyles(); * @param int $depth
if(array_key_exists('Heading_'.$depth, $styles)) { * @return PHPWord_Section_Title
$style = 'Heading'.$depth; */
} else { public function addTitle($text, $depth = 1)
$style = null; {
} $text = utf8_encode($text);
$styles = PHPWord_Style::getStyles();
$title = new PHPWord_Section_Title($text, $depth, $style); if (array_key_exists('Heading_' . $depth, $styles)) {
$style = 'Heading' . $depth;
$data = PHPWord_TOC::addTitle($text, $depth); } else {
$anchor = $data[0]; $style = null;
$bookmarkId = $data[1]; }
$title->setAnchor($anchor); $title = new PHPWord_Section_Title($text, $depth, $style);
$title->setBookmarkId($bookmarkId);
$data = PHPWord_TOC::addTitle($text, $depth);
$this->_elementCollection[] = $title; $anchor = $data[0];
return $title; $bookmarkId = $data[1];
}
$title->setAnchor($anchor);
/** $title->setBookmarkId($bookmarkId);
* Create a new TextRun
* $this->_elementCollection[] = $title;
* @return PHPWord_Section_TextRun return $title;
*/ }
public function createTextRun($styleParagraph = null) {
$textRun = new PHPWord_Section_TextRun($styleParagraph); /**
$this->_elementCollection[] = $textRun; * Create a new TextRun
return $textRun; *
} * @return PHPWord_Section_TextRun
*/
/** public function createTextRun($styleParagraph = null)
* Get all Elements {
* $textRun = new PHPWord_Section_TextRun($styleParagraph);
* @return array $this->_elementCollection[] = $textRun;
*/ return $textRun;
public function getElements() { }
return $this->_elementCollection;
} /**
* Get all Elements
/** *
* Create a new Header * @return array
* */
* @return PHPWord_Section_Header public function getElements()
*/ {
public function createHeader() { return $this->_elementCollection;
$header = new PHPWord_Section_Header($this->_sectionCount); }
$this->_header = $header;
return $header; /**
} * Create a new Header
*
/** * @return PHPWord_Section_Header
* Get Header */
* public function createHeader()
* @return PHPWord_Section_Header {
*/ $header = new PHPWord_Section_Header($this->_sectionCount);
public function getHeader() { $this->_header = $header;
return $this->_header; return $header;
} }
/** /**
* Create a new Footer * Get Header
* *
* @return PHPWord_Section_Footer * @return PHPWord_Section_Header
*/ */
public function createFooter() { public function getHeader()
$footer = new PHPWord_Section_Footer($this->_sectionCount); {
$this->_footer = $footer; return $this->_header;
return $footer; }
}
/**
/** * Create a new Footer
* Get Footer *
* * @return PHPWord_Section_Footer
* @return PHPWord_Section_Footer */
*/ public function createFooter()
public function getFooter() { {
return $this->_footer; $footer = new PHPWord_Section_Footer($this->_sectionCount);
} $this->_footer = $footer;
return $footer;
}
/**
* Get Footer
*
* @return PHPWord_Section_Footer
*/
public function getFooter()
{
return $this->_footer;
}
} }
?>

View File

@ -33,169 +33,181 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Footer { class PHPWord_Section_Footer
{
/**
* Footer Count /**
* * Footer Count
* @var int *
*/ * @var int
private $_footerCount; */
private $_footerCount;
/**
* Footer Relation ID /**
* * Footer Relation ID
* @var int *
*/ * @var int
private $_rId; */
private $_rId;
/**
* Footer Element Collection /**
* * Footer Element Collection
* @var int *
*/ * @var int
private $_elementCollection = array(); */
private $_elementCollection = array();
/**
* Create a new Footer /**
*/ * Create a new Footer
public function __construct($sectionCount) { */
$this->_footerCount = $sectionCount; public function __construct($sectionCount)
} {
$this->_footerCount = $sectionCount;
/** }
* Add a Text Element
* /**
* @param string $text * Add a Text Element
* @param mixed $styleFont *
* @param mixed $styleParagraph * @param string $text
* @return PHPWord_Section_Text * @param mixed $styleFont
*/ * @param mixed $styleParagraph
public function addText($text, $styleFont = null, $styleParagraph = null) { * @return PHPWord_Section_Text
$givenText = utf8_encode($text); */
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); public function addText($text, $styleFont = null, $styleParagraph = null)
$this->_elementCollection[] = $text; {
return $text; $givenText = utf8_encode($text);
} $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
/** return $text;
* Add a TextBreak Element }
*
* @param int $count /**
*/ * Add a TextBreak Element
public function addTextBreak($count = 1) { *
for($i=1; $i<=$count; $i++) { * @param int $count
$this->_elementCollection[] = new PHPWord_Section_TextBreak(); */
} public function addTextBreak($count = 1)
} {
for ($i = 1; $i <= $count; $i++) {
/** $this->_elementCollection[] = new PHPWord_Section_TextBreak();
* Create a new TextRun }
* }
* @return PHPWord_Section_TextRun
*/ /**
public function createTextRun($styleParagraph = null) { * Create a new TextRun
$textRun = new PHPWord_Section_TextRun($styleParagraph); *
$this->_elementCollection[] = $textRun; * @return PHPWord_Section_TextRun
return $textRun; */
} public function createTextRun($styleParagraph = null)
{
/** $textRun = new PHPWord_Section_TextRun($styleParagraph);
* Add a Table Element $this->_elementCollection[] = $textRun;
* return $textRun;
* @param mixed $style }
* @return PHPWord_Section_Table
*/ /**
public function addTable($style = null) { * Add a Table Element
$table = new PHPWord_Section_Table('footer', $this->_footerCount, $style); *
$this->_elementCollection[] = $table; * @param mixed $style
return $table; * @return PHPWord_Section_Table
} */
public function addTable($style = null)
/** {
* Add a Image Element $table = new PHPWord_Section_Table('footer', $this->_footerCount, $style);
* $this->_elementCollection[] = $table;
* @param string $src return $table;
* @param mixed $style }
* @return PHPWord_Section_Image
*/ /**
public function addImage($src, $style = null) { * Add a Image Element
$image = new PHPWord_Section_Image($src, $style); *
* @param string $src
if(!is_null($image->getSource())) { * @param mixed $style
$rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $src); * @return PHPWord_Section_Image
$image->setRelationId($rID); */
public function addImage($src, $style = null)
$this->_elementCollection[] = $image; {
return $image; $image = new PHPWord_Section_Image($src, $style);
} else {
trigger_error('Src does not exist or invalid image type.', E_ERROR); if (!is_null($image->getSource())) {
} $rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $src);
} $image->setRelationId($rID);
/** $this->_elementCollection[] = $image;
* Add a by PHP created Image Element return $image;
* } else {
* @param string $link trigger_error('Src does not exist or invalid image type.', E_ERROR);
* @param mixed $style }
* @return PHPWord_Section_MemoryImage }
*/
public function addMemoryImage($link, $style = null) { /**
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); * Add a by PHP created Image Element
if(!is_null($memoryImage->getSource())) { *
$rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage); * @param string $link
$memoryImage->setRelationId($rID); * @param mixed $style
* @return PHPWord_Section_MemoryImage
$this->_elementCollection[] = $memoryImage; */
return $memoryImage; public function addMemoryImage($link, $style = null)
} else { {
trigger_error('Unsupported image type.'); $memoryImage = new PHPWord_Section_MemoryImage($link, $style);
} if (!is_null($memoryImage->getSource())) {
} $rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
/**
* Add a PreserveText Element $this->_elementCollection[] = $memoryImage;
* return $memoryImage;
* @param string $text } else {
* @param mixed $styleFont trigger_error('Unsupported image type.');
* @param mixed $styleParagraph }
* @return PHPWord_Section_Footer_PreserveText }
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { /**
$text = utf8_encode($text); * Add a PreserveText Element
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); *
$this->_elementCollection[] = $ptext; * @param string $text
return $ptext; * @param mixed $styleFont
} * @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText
/** */
* Get Footer Relation ID public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
*/ {
public function getRelationId() { $text = utf8_encode($text);
return $this->_rId; $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
} $this->_elementCollection[] = $ptext;
return $ptext;
/** }
* Set Footer Relation ID
* /**
* @param int $rId * Get Footer Relation ID
*/ */
public function setRelationId($rId) { public function getRelationId()
$this->_rId = $rId; {
} return $this->_rId;
}
/**
* Get all Footer Elements /**
*/ * Set Footer Relation ID
public function getElements() { *
return $this->_elementCollection; * @param int $rId
} */
public function setRelationId($rId)
/** {
* Get Footer Count $this->_rId = $rId;
*/ }
public function getFooterCount() {
return $this->_footerCount; /**
} * Get all Footer Elements
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Footer Count
*/
public function getFooterCount()
{
return $this->_footerCount;
}
} }
?>

View File

@ -33,96 +33,100 @@
* @package PHPWord_Section_Footer * @package PHPWord_Section_Footer
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Footer_PreserveText { class PHPWord_Section_Footer_PreserveText
{
/**
* Text content /**
* * Text content
* @var string *
*/ * @var string
private $_text; */
private $_text;
/**
* Text style /**
* * Text style
* @var PHPWord_Style_Font *
*/ * @var PHPWord_Style_Font
private $_styleFont; */
private $_styleFont;
/**
* Paragraph style /**
* * Paragraph style
* @var PHPWord_Style_Font *
*/ * @var PHPWord_Style_Font
private $_styleParagraph; */
private $_styleParagraph;
/**
* Create a new Preserve Text Element /**
* * Create a new Preserve Text Element
* @var string $text *
* @var mixed $style * @var string $text
*/ * @var mixed $style
public function __construct($text = null, $styleFont = null, $styleParagraph = null) { */
// Set font style public function __construct($text = null, $styleFont = null, $styleParagraph = null)
if(is_array($styleFont)) { {
$this->_styleFont = new PHPWord_Style_Font('text'); // Set font style
if (is_array($styleFont)) {
foreach($styleFont as $key => $value) { $this->_styleFont = new PHPWord_Style_Font('text');
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($styleFont as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_styleFont->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { $this->_styleFont->setStyleValue($key, $value);
$this->_styleFont = $styleFont; }
} } else {
$this->_styleFont = $styleFont;
// Set paragraph style }
if(is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); // Set paragraph style
if (is_array($styleParagraph)) {
foreach($styleParagraph as $key => $value) { $this->_styleParagraph = new PHPWord_Style_Paragraph();
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($styleParagraph as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_styleParagraph->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { $this->_styleParagraph->setStyleValue($key, $value);
$this->_styleParagraph = $styleParagraph; }
} } else {
$this->_styleParagraph = $styleParagraph;
$pattern = '/({.*?})/'; }
$this->_text = preg_split($pattern, $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$pattern = '/({.*?})/';
return $this; $this->_text = preg_split($pattern, $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
}
return $this;
/** }
* Get Text style
* /**
* @return PHPWord_Style_Font * Get Text style
*/ *
public function getFontStyle() { * @return PHPWord_Style_Font
return $this->_styleFont; */
} public function getFontStyle()
{
/** return $this->_styleFont;
* Get Paragraph style }
*
* @return PHPWord_Style_Paragraph /**
*/ * Get Paragraph style
public function getParagraphStyle() { *
return $this->_styleParagraph; * @return PHPWord_Style_Paragraph
} */
public function getParagraphStyle()
/** {
* Get Text content return $this->_styleParagraph;
* }
* @return string
*/ /**
public function getText() { * Get Text content
return $this->_text; *
} * @return string
*/
public function getText()
{
return $this->_text;
}
} }
?>

View File

@ -33,190 +33,203 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Header { class PHPWord_Section_Header
{
/**
* Header Count /**
* * Header Count
* @var int *
*/ * @var int
private $_headerCount; */
private $_headerCount;
/**
* Header Relation ID /**
* * Header Relation ID
* @var int *
*/ * @var int
private $_rId; */
private $_rId;
/**
* Header Element Collection /**
* * Header Element Collection
* @var int *
*/ * @var int
private $_elementCollection = array(); */
private $_elementCollection = array();
/**
* Create a new Header /**
*/ * Create a new Header
public function __construct($sectionCount) { */
$this->_headerCount = $sectionCount; public function __construct($sectionCount)
} {
$this->_headerCount = $sectionCount;
/** }
* Add a Text Element
* /**
* @param string $text * Add a Text Element
* @param mixed $styleFont *
* @param mixed $styleParagraph * @param string $text
* @return PHPWord_Section_Text * @param mixed $styleFont
*/ * @param mixed $styleParagraph
public function addText($text, $styleFont = null, $styleParagraph = null) { * @return PHPWord_Section_Text
$givenText = utf8_encode($text); */
$text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); public function addText($text, $styleFont = null, $styleParagraph = null)
$this->_elementCollection[] = $text; {
return $text; $givenText = utf8_encode($text);
} $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
/** return $text;
* Add a TextBreak Element }
*
* @param int $count /**
*/ * Add a TextBreak Element
public function addTextBreak($count = 1) { *
for($i=1; $i<=$count; $i++) { * @param int $count
$this->_elementCollection[] = new PHPWord_Section_TextBreak(); */
} public function addTextBreak($count = 1)
} {
for ($i = 1; $i <= $count; $i++) {
/** $this->_elementCollection[] = new PHPWord_Section_TextBreak();
* Create a new TextRun }
* }
* @return PHPWord_Section_TextRun
*/ /**
public function createTextRun($styleParagraph = null) { * Create a new TextRun
$textRun = new PHPWord_Section_TextRun($styleParagraph); *
$this->_elementCollection[] = $textRun; * @return PHPWord_Section_TextRun
return $textRun; */
} public function createTextRun($styleParagraph = null)
{
/** $textRun = new PHPWord_Section_TextRun($styleParagraph);
* Add a Table Element $this->_elementCollection[] = $textRun;
* return $textRun;
* @param mixed $style }
* @return PHPWord_Section_Table
*/ /**
public function addTable($style = null) { * Add a Table Element
$table = new PHPWord_Section_Table('header', $this->_headerCount, $style); *
$this->_elementCollection[] = $table; * @param mixed $style
return $table; * @return PHPWord_Section_Table
} */
public function addTable($style = null)
/** {
* Add a Image Element $table = new PHPWord_Section_Table('header', $this->_headerCount, $style);
* $this->_elementCollection[] = $table;
* @param string $src return $table;
* @param mixed $style }
* @return PHPWord_Section_Image
*/ /**
public function addImage($src, $style = null) { * Add a Image Element
$image = new PHPWord_Section_Image($src, $style); *
* @param string $src
if(!is_null($image->getSource())) { * @param mixed $style
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src); * @return PHPWord_Section_Image
$image->setRelationId($rID); */
public function addImage($src, $style = null)
$this->_elementCollection[] = $image; {
return $image; $image = new PHPWord_Section_Image($src, $style);
} else {
trigger_error('Src does not exist or invalid image type.', E_ERROR); if (!is_null($image->getSource())) {
} $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
} $image->setRelationId($rID);
/** $this->_elementCollection[] = $image;
* Add a by PHP created Image Element return $image;
* } else {
* @param string $link trigger_error('Src does not exist or invalid image type.', E_ERROR);
* @param mixed $style }
* @return PHPWord_Section_MemoryImage }
*/
public function addMemoryImage($link, $style = null) { /**
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); * Add a by PHP created Image Element
if(!is_null($memoryImage->getSource())) { *
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage); * @param string $link
$memoryImage->setRelationId($rID); * @param mixed $style
* @return PHPWord_Section_MemoryImage
$this->_elementCollection[] = $memoryImage; */
return $memoryImage; public function addMemoryImage($link, $style = null)
} else { {
trigger_error('Unsupported image type.'); $memoryImage = new PHPWord_Section_MemoryImage($link, $style);
} if (!is_null($memoryImage->getSource())) {
} $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
/**
* Add a PreserveText Element $this->_elementCollection[] = $memoryImage;
* return $memoryImage;
* @param string $text } else {
* @param mixed $styleFont trigger_error('Unsupported image type.');
* @param mixed $styleParagraph }
* @return PHPWord_Section_Footer_PreserveText }
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { /**
$text = utf8_encode($text); * Add a PreserveText Element
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); *
$this->_elementCollection[] = $ptext; * @param string $text
return $ptext; * @param mixed $styleFont
} * @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText
/** */
* Add a Watermark Element public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
* {
* @param string $src $text = utf8_encode($text);
* @param mixed $style $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
* @return PHPWord_Section_Image $this->_elementCollection[] = $ptext;
*/ return $ptext;
public function addWatermark($src, $style = null) { }
$image = new PHPWord_Section_Image($src, $style, true);
/**
if(!is_null($image->getSource())) { * Add a Watermark Element
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src); *
$image->setRelationId($rID); * @param string $src
* @param mixed $style
$this->_elementCollection[] = $image; * @return PHPWord_Section_Image
return $image; */
} else { public function addWatermark($src, $style = null)
trigger_error('Src does not exist or invalid image type.', E_ERROR); {
} $image = new PHPWord_Section_Image($src, $style, true);
}
if (!is_null($image->getSource())) {
/** $rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
* Get Header Relation ID $image->setRelationId($rID);
*/
public function getRelationId() { $this->_elementCollection[] = $image;
return $this->_rId; return $image;
} } else {
trigger_error('Src does not exist or invalid image type.', E_ERROR);
/** }
* Set Header Relation ID }
*
* @param int $rId /**
*/ * Get Header Relation ID
public function setRelationId($rId) { */
$this->_rId = $rId; public function getRelationId()
} {
return $this->_rId;
/** }
* Get all Header Elements
*/ /**
public function getElements() { * Set Header Relation ID
return $this->_elementCollection; *
} * @param int $rId
*/
/** public function setRelationId($rId)
* Get Header Count {
*/ $this->_rId = $rId;
public function getHeaderCount() { }
return $this->_headerCount;
} /**
* Get all Header Elements
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Header Count
*/
public function getHeaderCount()
{
return $this->_headerCount;
}
} }
?>

View File

@ -33,136 +33,145 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Image { class PHPWord_Section_Image
{
/**
* Image Src /**
* * Image Src
* @var string *
*/ * @var string
private $_src; */
private $_src;
/**
* Image Style /**
* * Image Style
* @var PHPWord_Style_Image *
*/ * @var PHPWord_Style_Image
private $_style; */
private $_style;
/**
* Image Relation ID /**
* * Image Relation ID
* @var string *
*/ * @var string
private $_rId; */
private $_rId;
/**
* Is Watermark /**
* * Is Watermark
* @var bool *
*/ * @var bool
private $_isWatermark; */
private $_isWatermark;
/**
* Create a new Image /**
* * Create a new Image
* @param string $src *
* @param mixed style * @param string $src
*/ * @param mixed style
public function __construct($src, $style = null, $isWatermark = false) { */
$_supportedImageTypes = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff'); public function __construct($src, $style = null, $isWatermark = false)
{
$inf = pathinfo($src); $_supportedImageTypes = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff');
$ext = strtolower($inf['extension']);
$inf = pathinfo($src);
if(file_exists($src) && in_array($ext, $_supportedImageTypes)) { $ext = strtolower($inf['extension']);
$this->_src = $src;
$this->_isWatermark = $isWatermark; if (file_exists($src) && in_array($ext, $_supportedImageTypes)) {
$this->_style = new PHPWord_Style_Image(); $this->_src = $src;
$this->_isWatermark = $isWatermark;
if(!is_null($style) && is_array($style)) { $this->_style = new PHPWord_Style_Image();
foreach($style as $key => $value) {
if(substr($key, 0, 1) != '_') { if (!is_null($style) && is_array($style)) {
$key = '_'.$key; foreach ($style as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_style->setStyleValue($key, $value); $key = '_' . $key;
} }
} $this->_style->setStyleValue($key, $value);
}
if($this->_style->getWidth() == null && $this->_style->getHeight() == null) { }
$imgData = getimagesize($this->_src);
$this->_style->setWidth($imgData[0]); if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
$this->_style->setHeight($imgData[1]); $imgData = getimagesize($this->_src);
} $this->_style->setWidth($imgData[0]);
$this->_style->setHeight($imgData[1]);
return $this; }
} else {
return false; return $this;
} } else {
} return false;
}
/** }
* Get Image style
* /**
* @return PHPWord_Style_Image * Get Image style
*/ *
public function getStyle() { * @return PHPWord_Style_Image
return $this->_style; */
} public function getStyle()
{
/** return $this->_style;
* Get Image Relation ID }
*
* @return int /**
*/ * Get Image Relation ID
public function getRelationId() { *
return $this->_rId; * @return int
} */
public function getRelationId()
/** {
* Set Image Relation ID return $this->_rId;
* }
* @param int $rId
*/ /**
public function setRelationId($rId) { * Set Image Relation ID
$this->_rId = $rId; *
} * @param int $rId
*/
/** public function setRelationId($rId)
* Get Image Source {
* $this->_rId = $rId;
* @return string }
*/
public function getSource() { /**
return $this->_src; * Get Image Source
} *
* @return string
/** */
* Get Image Media ID public function getSource()
* {
* @return string return $this->_src;
*/ }
public function getMediaId() {
return md5($this->_src); /**
} * Get Image Media ID
*
/** * @return string
* Get IsWatermark */
* public function getMediaId()
* @return int {
*/ return md5($this->_src);
public function getIsWatermark() { }
return $this->_isWatermark;
} /**
* Get IsWatermark
/** *
* Set IsWatermark * @return int
* */
* @param bool $pValue public function getIsWatermark()
*/ {
public function setIsWatermark($pValue) { return $this->_isWatermark;
$this->_isWatermark = $pValue; }
}
/**
* Set IsWatermark
*
* @param bool $pValue
*/
public function setIsWatermark($pValue)
{
$this->_isWatermark = $pValue;
}
} }
?>

View File

@ -33,139 +33,146 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Link { class PHPWord_Section_Link
{
/**
* Link source /**
* * Link source
* @var string *
*/ * @var string
private $_linkSrc; */
private $_linkSrc;
/**
* Link name /**
* * Link name
* @var string *
*/ * @var string
private $_linkName; */
private $_linkName;
/**
* Link Relation ID /**
* * Link Relation ID
* @var string *
*/ * @var string
private $_rId; */
private $_rId;
/**
* Link style /**
* * Link style
* @var PHPWord_Style_Font *
*/ * @var PHPWord_Style_Font
private $_styleFont; */
private $_styleFont;
/**
* Paragraph style /**
* * Paragraph style
* @var PHPWord_Style_Font *
*/ * @var PHPWord_Style_Font
private $_styleParagraph; */
private $_styleParagraph;
/**
* Create a new Link Element /**
* * Create a new Link Element
* @var string $linkSrc *
* @var string $linkName * @var string $linkSrc
* @var mixed $styleFont * @var string $linkName
* @var mixed $styleParagraph * @var mixed $styleFont
*/ * @var mixed $styleParagraph
public function __construct($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null) { */
$this->_linkSrc = $linkSrc; public function __construct($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
$this->_linkName = $linkName; {
$this->_linkSrc = $linkSrc;
// Set font style $this->_linkName = $linkName;
if(is_array($styleFont)) {
$this->_styleFont = new PHPWord_Style_Font('text'); // Set font style
if (is_array($styleFont)) {
foreach($styleFont as $key => $value) { $this->_styleFont = new PHPWord_Style_Font('text');
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($styleFont as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_styleFont->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { $this->_styleFont->setStyleValue($key, $value);
$this->_styleFont = $styleFont; }
} } else {
$this->_styleFont = $styleFont;
// Set paragraph style }
if(is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); // Set paragraph style
if (is_array($styleParagraph)) {
foreach($styleParagraph as $key => $value) { $this->_styleParagraph = new PHPWord_Style_Paragraph();
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($styleParagraph as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_styleParagraph->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { $this->_styleParagraph->setStyleValue($key, $value);
$this->_styleParagraph = $styleParagraph; }
} } else {
$this->_styleParagraph = $styleParagraph;
return $this; }
}
return $this;
/** }
* Get Link Relation ID
* /**
* @return int * Get Link Relation ID
*/ *
public function getRelationId() { * @return int
return $this->_rId; */
} public function getRelationId()
{
/** return $this->_rId;
* Set Link Relation ID }
*
* @param int $rId /**
*/ * Set Link Relation ID
public function setRelationId($rId) { *
$this->_rId = $rId; * @param int $rId
} */
public function setRelationId($rId)
/** {
* Get Link source $this->_rId = $rId;
* }
* @return string
*/ /**
public function getLinkSrc() { * Get Link source
return $this->_linkSrc; *
} * @return string
*/
/** public function getLinkSrc()
* Get Link name {
* return $this->_linkSrc;
* @return string }
*/
public function getLinkName() { /**
return $this->_linkName; * Get Link name
} *
* @return string
/** */
* Get Text style public function getLinkName()
* {
* @return PHPWord_Style_Font return $this->_linkName;
*/ }
public function getFontStyle() {
return $this->_styleFont; /**
} * Get Text style
*
/** * @return PHPWord_Style_Font
* Get Paragraph style */
* public function getFontStyle()
* @return PHPWord_Style_Paragraph {
*/ return $this->_styleFont;
public function getParagraphStyle() { }
return $this->_styleParagraph;
} /**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
} }
?>

View File

@ -33,72 +33,76 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_ListItem { class PHPWord_Section_ListItem
{
/**
* ListItem Style /**
* * ListItem Style
* @var PHPWord_Style_ListItem *
*/ * @var PHPWord_Style_ListItem
private $_style; */
private $_style;
/**
* Textrun /**
* * Textrun
* @var PHPWord_Section_Text *
*/ * @var PHPWord_Section_Text
private $_textObject; */
private $_textObject;
/**
* ListItem Depth /**
* * ListItem Depth
* @var int *
*/ * @var int
private $_depth; */
private $_depth;
/**
* Create a new ListItem /**
* * Create a new ListItem
* @param string $text *
* @param int $depth * @param string $text
* @param mixed $styleText * @param int $depth
* @param mixed $styleList * @param mixed $styleText
*/ * @param mixed $styleList
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null) { */
$this->_style = new PHPWord_Style_ListItem(); public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
$this->_textObject = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); {
$this->_depth = $depth; $this->_style = new PHPWord_Style_ListItem();
$this->_textObject = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
if(!is_null($styleList) && is_array($styleList)) { $this->_depth = $depth;
foreach($styleList as $key => $value) {
if(substr($key, 0, 1) != '_') { if (!is_null($styleList) && is_array($styleList)) {
$key = '_'.$key; foreach ($styleList as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_style->setStyleValue($key, $value); $key = '_' . $key;
} }
} $this->_style->setStyleValue($key, $value);
} }
}
/** }
* Get ListItem style
*/ /**
public function getStyle() { * Get ListItem style
return $this->_style; */
} public function getStyle()
{
/** return $this->_style;
* Get ListItem TextRun }
*/
public function getTextObject() { /**
return $this->_textObject; * Get ListItem TextRun
} */
public function getTextObject()
/** {
* Get ListItem depth return $this->_textObject;
*/ }
public function getDepth() {
return $this->_depth; /**
} * Get ListItem depth
*/
public function getDepth()
{
return $this->_depth;
}
} }
?>

View File

@ -33,199 +33,211 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_MemoryImage { class PHPWord_Section_MemoryImage
{
/**
* Image Src /**
* * Image Src
* @var string *
*/ * @var string
private $_src; */
private $_src;
/**
* Image Style /**
* * Image Style
* @var PHPWord_Style_Image *
*/ * @var PHPWord_Style_Image
private $_style; */
private $_style;
/**
* Image Relation ID /**
* * Image Relation ID
* @var string *
*/ * @var string
private $_rId; */
private $_rId;
/**
* Image Type /**
* * Image Type
* @var string *
*/ * @var string
private $_imageType; */
private $_imageType;
/**
* Image Create function /**
* * Image Create function
* @var string *
*/ * @var string
private $_imageCreateFunc; */
private $_imageCreateFunc;
/**
* Image function /**
* * Image function
* @var string *
*/ * @var string
private $_imageFunc; */
private $_imageFunc;
/**
* Image function /**
* * Image function
* @var string *
*/ * @var string
private $_imageExtension; */
private $_imageExtension;
/**
* Create a new Image /**
* * Create a new Image
* @param string $src *
* @param mixed style * @param string $src
*/ * @param mixed style
public function __construct($src, $style = null) { */
$imgData = getimagesize($src); public function __construct($src, $style = null)
$this->_imageType = $imgData['mime']; {
$imgData = getimagesize($src);
$_supportedImageTypes = array('image/jpeg', 'image/gif', 'image/png'); $this->_imageType = $imgData['mime'];
if(in_array($this->_imageType, $_supportedImageTypes)) { $_supportedImageTypes = array('image/jpeg', 'image/gif', 'image/png');
$this->_src = $src;
$this->_style = new PHPWord_Style_Image(); if (in_array($this->_imageType, $_supportedImageTypes)) {
$this->_src = $src;
if(!is_null($style) && is_array($style)) { $this->_style = new PHPWord_Style_Image();
foreach($style as $key => $value) {
if(substr($key, 0, 1) != '_') { if (!is_null($style) && is_array($style)) {
$key = '_'.$key; foreach ($style as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_style->setStyleValue($key, $value); $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]); if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
} $this->_style->setWidth($imgData[0]);
$this->_style->setHeight($imgData[1]);
$this->_setFunctions(); }
return $this; $this->_setFunctions();
} else {
return false; return $this;
} } else {
} return false;
}
/** }
* Set Functions
*/ /**
private function _setFunctions() { * Set Functions
switch($this->_imageType) { */
case 'image/png': private function _setFunctions()
$this->_imageCreateFunc = 'imagecreatefrompng'; {
$this->_imageFunc = 'imagepng'; switch ($this->_imageType) {
$this->_imageExtension = 'png'; case 'image/png':
break; $this->_imageCreateFunc = 'imagecreatefrompng';
case 'image/gif': $this->_imageFunc = 'imagepng';
$this->_imageCreateFunc = 'imagecreatefromgif'; $this->_imageExtension = 'png';
$this->_imageFunc = 'imagegif'; break;
$this->_imageExtension = 'gif'; case 'image/gif':
break; $this->_imageCreateFunc = 'imagecreatefromgif';
case 'image/jpeg': case 'image/jpg': $this->_imageFunc = 'imagegif';
$this->_imageCreateFunc = 'imagecreatefromjpeg'; $this->_imageExtension = 'gif';
$this->_imageFunc = 'imagejpeg'; break;
$this->_imageExtension = 'jpg'; case 'image/jpeg':
break; case 'image/jpg':
} $this->_imageCreateFunc = 'imagecreatefromjpeg';
} $this->_imageFunc = 'imagejpeg';
$this->_imageExtension = 'jpg';
break;
/** }
* Get Image style }
*
* @return PHPWord_Style_Image
*/ /**
public function getStyle() { * Get Image style
return $this->_style; *
} * @return PHPWord_Style_Image
*/
/** public function getStyle()
* Get Image Relation ID {
* return $this->_style;
* @return int }
*/
public function getRelationId() { /**
return $this->_rId; * Get Image Relation ID
} *
* @return int
/** */
* Set Image Relation ID public function getRelationId()
* {
* @param int $rId return $this->_rId;
*/ }
public function setRelationId($rId) {
$this->_rId = $rId; /**
} * Set Image Relation ID
*
/** * @param int $rId
* Get Image Source */
* public function setRelationId($rId)
* @return string {
*/ $this->_rId = $rId;
public function getSource() { }
return $this->_src;
} /**
* Get Image Source
/** *
* Get Image Media ID * @return string
* */
* @return string public function getSource()
*/ {
public function getMediaId() { return $this->_src;
return md5($this->_src); }
}
/**
/** * Get Image Media ID
* Get Image Type *
* * @return string
* @return string */
*/ public function getMediaId()
public function getImageType() { {
return $this->_imageType; return md5($this->_src);
} }
/** /**
* Get Image Create Function * Get Image Type
* *
* @return string * @return string
*/ */
public function getImageCreateFunction() { public function getImageType()
return $this->_imageCreateFunc; {
} return $this->_imageType;
}
/**
* Get Image Function /**
* * Get Image Create Function
* @return string *
*/ * @return string
public function getImageFunction() { */
return $this->_imageFunc; public function getImageCreateFunction()
} {
return $this->_imageCreateFunc;
/** }
* Get Image Extension
* /**
* @return string * Get Image Function
*/ *
public function getImageExtension() { * @return string
return $this->_imageExtension; */
} public function getImageFunction()
{
return $this->_imageFunc;
}
/**
* Get Image Extension
*
* @return string
*/
public function getImageExtension()
{
return $this->_imageExtension;
}
} }
?>

View File

@ -33,143 +33,152 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Object { class PHPWord_Section_Object
{
/**
* Ole-Object Src /**
* * Ole-Object Src
* @var string *
*/ * @var string
private $_src; */
private $_src;
/**
* Image Style /**
* * Image Style
* @var PHPWord_Style_Image *
*/ * @var PHPWord_Style_Image
private $_style; */
private $_style;
/**
* Object Relation ID /**
* * Object Relation ID
* @var int *
*/ * @var int
private $_rId; */
private $_rId;
/**
* Image Relation ID /**
* * Image Relation ID
* @var int *
*/ * @var int
private $_rIdImg; */
private $_rIdImg;
/**
* Object ID /**
* * Object ID
* @var int *
*/ * @var int
private $_objId; */
private $_objId;
/**
* Create a new Ole-Object Element /**
* * Create a new Ole-Object Element
* @param string $src *
* @param mixed $style * @param string $src
*/ * @param mixed $style
public function __construct($src, $style = null) { */
$_supportedObjectTypes = array('xls', 'doc', 'ppt'); public function __construct($src, $style = null)
$inf = pathinfo($src); {
$_supportedObjectTypes = array('xls', 'doc', 'ppt');
if(file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) { $inf = pathinfo($src);
$this->_src = $src;
$this->_style = new PHPWord_Style_Image(); if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
$this->_src = $src;
if(!is_null($style) && is_array($style)) { $this->_style = new PHPWord_Style_Image();
foreach($style as $key => $value) {
if(substr($key, 0, 1) != '_') { if (!is_null($style) && is_array($style)) {
$key = '_'.$key; foreach ($style as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_style->setStyleValue($key, $value); $key = '_' . $key;
} }
} $this->_style->setStyleValue($key, $value);
}
return $this; }
} else {
return false; return $this;
} } else {
} return false;
}
/** }
* Get Image style
* /**
* @return PHPWord_Style_Image * Get Image style
*/ *
public function getStyle() { * @return PHPWord_Style_Image
return $this->_style; */
} public function getStyle()
{
/** return $this->_style;
* Get Source }
*
* @return string /**
*/ * Get Source
public function getSource() { *
return $this->_src; * @return string
} */
public function getSource()
/** {
* Get Object Relation ID return $this->_src;
* }
* @return int
*/ /**
public function getRelationId() { * Get Object Relation ID
return $this->_rId; *
} * @return int
*/
/** public function getRelationId()
* Set Object Relation ID {
* return $this->_rId;
* @param int $rId }
*/
public function setRelationId($rId) { /**
$this->_rId = $rId; * Set Object Relation ID
} *
* @param int $rId
/** */
* Get Image Relation ID public function setRelationId($rId)
* {
* @return int $this->_rId = $rId;
*/ }
public function getImageRelationId() {
return $this->_rIdImg; /**
} * Get Image Relation ID
*
/** * @return int
* Set Image Relation ID */
* public function getImageRelationId()
* @param int $rId {
*/ return $this->_rIdImg;
public function setImageRelationId($rId) { }
$this->_rIdImg = $rId;
} /**
* Set Image Relation ID
/** *
* Get Object ID * @param int $rId
* */
* @return int public function setImageRelationId($rId)
*/ {
public function getObjectId() { $this->_rIdImg = $rId;
return $this->_objId; }
}
/**
/** * Get Object ID
* Set Object ID *
* * @return int
* @param int $objId */
*/ public function getObjectId()
public function setObjectId($objId) { {
$this->_objId = $objId; return $this->_objId;
} }
/**
* Set Object ID
*
* @param int $objId
*/
public function setObjectId($objId)
{
$this->_objId = $objId;
}
} }
?>

View File

@ -33,13 +33,14 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_PageBreak { class PHPWord_Section_PageBreak
{
/** /**
* Create a new PageBreak Element * Create a new PageBreak Element
*/ */
public function __construct() { public function __construct()
// nothing {
} // nothing
}
} }
?>

View File

@ -33,483 +33,518 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Settings { class PHPWord_Section_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 * Default Page Size Width
* *
* @var int * @var int
*/ */
private $_borderTopSize; private $_defaultPageSizeW = 11906;
/** /**
* Page Border Top Color * Default Page Size Height
* *
* @var int * @var int
*/ */
private $_borderTopColor; private $_defaultPageSizeH = 16838;
/** /**
* Page Border Left Size * Page Orientation
* *
* @var int * @var string
*/ */
private $_borderLeftSize; private $_orientation;
/** /**
* Page Border Left Color * Page Margin Top
* *
* @var int * @var int
*/ */
private $_borderLeftColor; private $_marginTop;
/** /**
* Page Border Right Size * Page Margin Left
* *
* @var int * @var int
*/ */
private $_borderRightSize; private $_marginLeft;
/** /**
* Page Border Right Color * Page Margin Right
* *
* @var int * @var int
*/ */
private $_borderRightColor; private $_marginRight;
/** /**
* Page Border Bottom Size * Page Margin Bottom
* *
* @var int * @var int
*/ */
private $_borderBottomSize; private $_marginBottom;
/** /**
* Page Border Bottom Color * Page Size Width
* *
* @var int * @var int
*/ */
private $_borderBottomColor; private $_pageSizeW;
/**
* 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;
}
/**
* 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 * Page Size Height
* *
* @param int $pValue * @var int
*/ */
public function setMarginTop($pValue = '') { private $_pageSizeH;
$this->_marginTop = $pValue;
return $this;
}
/** /**
* Get Margin Left * Page Border Top Size
* *
* @return int * @var int
*/ */
public function getMarginLeft() { private $_borderTopSize;
return $this->_marginLeft;
}
/** /**
* Set Margin Left * Page Border Top Color
* *
* @param int $pValue * @var int
*/ */
public function setMarginLeft($pValue = '') { private $_borderTopColor;
$this->_marginLeft = $pValue;
return $this;
}
/** /**
* Get Margin Right * Page Border Left Size
* *
* @return int * @var int
*/ */
public function getMarginRight() { private $_borderLeftSize;
return $this->_marginRight;
}
/** /**
* Set Margin Right * Page Border Left Color
* *
* @param int $pValue * @var int
*/ */
public function setMarginRight($pValue = '') { private $_borderLeftColor;
$this->_marginRight = $pValue;
return $this;
}
/** /**
* Get Margin Bottom * Page Border Right Size
* *
* @return int * @var int
*/ */
public function getMarginBottom() { private $_borderRightSize;
return $this->_marginBottom;
}
/** /**
* Set Margin Bottom * Page Border Right Color
* *
* @param int $pValue * @var int
*/ */
public function setMarginBottom($pValue = '') { private $_borderRightColor;
$this->_marginBottom = $pValue;
return $this; /**
} * Page Border Bottom Size
*
/** * @var int
* Set Landscape Orientation */
*/ private $_borderBottomSize;
public function setLandscape() {
$this->_orientation = 'landscape'; /**
$this->_pageSizeW = $this->_defaultPageSizeH; * Page Border Bottom Color
$this->_pageSizeH = $this->_defaultPageSizeW; *
} * @var int
*/
/** private $_borderBottomColor;
* Set Portrait Orientation
*/ /**
public function setPortrait() { * Create new Section Settings
$this->_orientation = null; */
$this->_pageSizeW = $this->_defaultPageSizeW; public function __construct()
$this->_pageSizeH = $this->_defaultPageSizeH; {
} $this->_orientation = null;
$this->_marginTop = 1418;
/** $this->_marginLeft = 1418;
* Get Page Size Width $this->_marginRight = 1418;
* $this->_marginBottom = 1134;
* @return int $this->_pageSizeW = $this->_defaultPageSizeW;
*/ $this->_pageSizeH = $this->_defaultPageSizeH;
public function getPageSizeW() { $this->_borderTopSize = null;
return $this->_pageSizeW; $this->_borderTopColor = null;
} $this->_borderLeftSize = null;
$this->_borderLeftColor = null;
/** $this->_borderRightSize = null;
* Get Page Size Height $this->_borderRightColor = null;
* $this->_borderBottomSize = null;
* @return int $this->_borderBottomColor = null;
*/ }
public function getPageSizeH() {
return $this->_pageSizeH; /**
} * Set Setting Value
*
/** * @param string $key
* Get Page Orientation * @param string $value
* */
* @return string public function setSettingValue($key, $value)
*/ {
public function getOrientation() { if ($key == '_orientation' && $value == 'landscape') {
return $this->_orientation; $this->setLandscape();
} } elseif ($key == '_orientation' && is_null($value)) {
$this->setPortrait();
/** } elseif ($key == '_borderSize') {
* Set Border Size $this->setBorderSize($value);
* } elseif ($key == '_borderColor') {
* @param int $pValue $this->setBorderColor($value);
*/ } else {
public function setBorderSize($pValue = null) { $this->$key = $value;
$this->_borderTopSize = $pValue; }
$this->_borderLeftSize = $pValue; }
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue; /**
} * Get Margin Top
*
/** * @return int
* Get Border Size */
* public function getMarginTop()
* @return array {
*/ return $this->_marginTop;
public function getBorderSize() { }
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize(); /**
$r = $this->getBorderRightSize(); * Set Margin Top
$b = $this->getBorderBottomSize(); *
* @param int $pValue
return array($t, $l, $r, $b); */
} public function setMarginTop($pValue = '')
{
/** $this->_marginTop = $pValue;
* Set Border Color return $this;
* }
* @param string $pValue
*/ /**
public function setBorderColor($pValue = null) { * Get Margin Left
$this->_borderTopColor = $pValue; *
$this->_borderLeftColor = $pValue; * @return int
$this->_borderRightColor = $pValue; */
$this->_borderBottomColor = $pValue; public function getMarginLeft()
} {
return $this->_marginLeft;
/** }
* Get Border Color
* /**
* @return array * Set Margin Left
*/ *
public function getBorderColor() { * @param int $pValue
$t = $this->getBorderTopColor(); */
$l = $this->getBorderLeftColor(); public function setMarginLeft($pValue = '')
$r = $this->getBorderRightColor(); {
$b = $this->getBorderBottomColor(); $this->_marginLeft = $pValue;
return $this;
return array($t, $l, $r, $b); }
}
/**
/** * Get Margin Right
* Set Border Top Size *
* * @return int
* @param int $pValue */
*/ public function getMarginRight()
public function setBorderTopSize($pValue = null) { {
$this->_borderTopSize = $pValue; return $this->_marginRight;
} }
/** /**
* Get Border Top Size * Set Margin Right
* *
* @return int * @param int $pValue
*/ */
public function getBorderTopSize() { public function setMarginRight($pValue = '')
return $this->_borderTopSize; {
} $this->_marginRight = $pValue;
return $this;
/** }
* Set Border Top Color
* /**
* @param string $pValue * Get Margin Bottom
*/ *
public function setBorderTopColor($pValue = null) { * @return int
$this->_borderTopColor = $pValue; */
} public function getMarginBottom()
{
/** return $this->_marginBottom;
* Get Border Top Color }
*
* @return string /**
*/ * Set Margin Bottom
public function getBorderTopColor() { *
return $this->_borderTopColor; * @param int $pValue
} */
public function setMarginBottom($pValue = '')
/** {
* Set Border Left Size $this->_marginBottom = $pValue;
* return $this;
* @param int $pValue }
*/
public function setBorderLeftSize($pValue = null) { /**
$this->_borderLeftSize = $pValue; * Set Landscape Orientation
} */
public function setLandscape()
/** {
* Get Border Left Size $this->_orientation = 'landscape';
* $this->_pageSizeW = $this->_defaultPageSizeH;
* @return int $this->_pageSizeH = $this->_defaultPageSizeW;
*/ }
public function getBorderLeftSize() {
return $this->_borderLeftSize; /**
} * Set Portrait Orientation
*/
/** public function setPortrait()
* Set Border Left Color {
* $this->_orientation = null;
* @param string $pValue $this->_pageSizeW = $this->_defaultPageSizeW;
*/ $this->_pageSizeH = $this->_defaultPageSizeH;
public function setBorderLeftColor($pValue = null) { }
$this->_borderLeftColor = $pValue;
} /**
* Get Page Size Width
/** *
* Get Border Left Color * @return int
* */
* @return string public function getPageSizeW()
*/ {
public function getBorderLeftColor() { return $this->_pageSizeW;
return $this->_borderLeftColor; }
}
/**
/** * Get Page Size Height
* Set Border Right Size *
* * @return int
* @param int $pValue */
*/ public function getPageSizeH()
public function setBorderRightSize($pValue = null) { {
$this->_borderRightSize = $pValue; return $this->_pageSizeH;
} }
/** /**
* Get Border Right Size * Get Page Orientation
* *
* @return int * @return string
*/ */
public function getBorderRightSize() { public function getOrientation()
return $this->_borderRightSize; {
} return $this->_orientation;
}
/**
* Set Border Right Color /**
* * Set Border Size
* @param string $pValue *
*/ * @param int $pValue
public function setBorderRightColor($pValue = null) { */
$this->_borderRightColor = $pValue; public function setBorderSize($pValue = null)
} {
$this->_borderTopSize = $pValue;
/** $this->_borderLeftSize = $pValue;
* Get Border Right Color $this->_borderRightSize = $pValue;
* $this->_borderBottomSize = $pValue;
* @return string }
*/
public function getBorderRightColor() { /**
return $this->_borderRightColor; * Get Border Size
} *
* @return array
/** */
* Set Border Bottom Size public function getBorderSize()
* {
* @param int $pValue $t = $this->getBorderTopSize();
*/ $l = $this->getBorderLeftSize();
public function setBorderBottomSize($pValue = null) { $r = $this->getBorderRightSize();
$this->_borderBottomSize = $pValue; $b = $this->getBorderBottomSize();
}
return array($t, $l, $r, $b);
/** }
* Get Border Bottom Size
* /**
* @return int * Set Border Color
*/ *
public function getBorderBottomSize() { * @param string $pValue
return $this->_borderBottomSize; */
} public function setBorderColor($pValue = null)
{
/** $this->_borderTopColor = $pValue;
* Set Border Bottom Color $this->_borderLeftColor = $pValue;
* $this->_borderRightColor = $pValue;
* @param string $pValue $this->_borderBottomColor = $pValue;
*/ }
public function setBorderBottomColor($pValue = null) {
$this->_borderBottomColor = $pValue; /**
} * Get Border Color
*
/** * @return array
* Get Border Bottom Color */
* public function getBorderColor()
* @return string {
*/ $t = $this->getBorderTopColor();
public function getBorderBottomColor() { $l = $this->getBorderLeftColor();
return $this->_borderBottomColor; $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;
}
} }
?>

View File

@ -33,120 +33,126 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Table { class PHPWord_Section_Table
{
/**
* Table style /**
* * Table style
* @var PHPWord_Style_Table *
*/ * @var PHPWord_Style_Table
private $_style; */
private $_style;
/**
* Table rows /**
* * Table rows
* @var array *
*/ * @var array
private $_rows = array(); */
private $_rows = array();
/**
* Row heights /**
* * Row heights
* @var array *
*/ * @var array
private $_rowHeights = array(); */
private $_rowHeights = array();
/**
* Table holder /**
* * Table holder
* @var string *
*/ * @var string
private $_insideOf = null; */
private $_insideOf = null;
/**
* Table holder count /**
* * Table holder count
* @var array *
*/ * @var array
private $_pCount; */
private $_pCount;
/**
* Create a new table /**
* * Create a new table
* @param string $insideOf *
* @param int $pCount * @param string $insideOf
* @param mixed $style * @param int $pCount
*/ * @param mixed $style
public function __construct($insideOf, $pCount, $style = null) { */
$this->_insideOf = $insideOf; public function __construct($insideOf, $pCount, $style = null)
$this->_pCount = $pCount; {
$this->_insideOf = $insideOf;
if(!is_null($style)) { $this->_pCount = $pCount;
if(is_array($style)) {
$this->_style = new PHPWord_Style_Table(); if (!is_null($style)) {
if (is_array($style)) {
foreach($style as $key => $value) { $this->_style = new PHPWord_Style_Table();
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($style as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_style->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { $this->_style->setStyleValue($key, $value);
$this->_style = $style; }
} } else {
} $this->_style = $style;
} }
}
/** }
* Add a row
* /**
* @param int $height * Add a row
*/ *
public function addRow($height = null) { * @param int $height
$this->_rows[] = array(); */
$this->_rowHeights[] = $height; public function addRow($height = null)
} {
$this->_rows[] = array();
/** $this->_rowHeights[] = $height;
* Add a cell }
*
* @param int $width /**
* @param mixed $style * Add a cell
* @return PHPWord_Section_Table_Cell *
*/ * @param int $width
public function addCell($width, $style = null) { * @param mixed $style
$cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style); * @return PHPWord_Section_Table_Cell
$i = count($this->_rows) - 1; */
$this->_rows[$i][] = $cell; public function addCell($width, $style = null)
return $cell; {
} $cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style);
$i = count($this->_rows) - 1;
/** $this->_rows[$i][] = $cell;
* Get all rows return $cell;
* }
* @return array
*/ /**
public function getRows() { * Get all rows
return $this->_rows; *
} * @return array
*/
/** public function getRows()
* Get all row heights {
* return $this->_rows;
* @return array }
*/
public function getRowHeights() { /**
return $this->_rowHeights; * Get all row heights
} *
* @return array
/** */
* Get table style public function getRowHeights()
* {
* @return PHPWord_Style_Table return $this->_rowHeights;
*/ }
public function getStyle() {
return $this->_style; /**
} * Get table style
*
* @return PHPWord_Style_Table
*/
public function getStyle()
{
return $this->_style;
}
} }
?>

View File

@ -33,287 +33,300 @@
* @package PHPWord_Section_Table * @package PHPWord_Section_Table
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Table_Cell { class PHPWord_Section_Table_Cell
{
/**
* Cell Width /**
* * Cell Width
* @var int *
*/ * @var int
private $_width = null; */
private $_width = null;
/**
* Cell Style /**
* * Cell Style
* @var PHPWord_Style_Cell *
*/ * @var PHPWord_Style_Cell
private $_style; */
private $_style;
/**
* Cell Element Collection /**
* * Cell Element Collection
* @var array *
*/ * @var array
private $_elementCollection = array(); */
private $_elementCollection = array();
/**
* Table holder /**
* * Table holder
* @var string *
*/ * @var string
private $_insideOf; */
private $_insideOf;
/**
* Section/Header/Footer count /**
* * Section/Header/Footer count
* @var int *
*/ * @var int
private $_pCount; */
private $_pCount;
/**
* Create a new Table Cell /**
* * Create a new Table Cell
* @param string $insideOf *
* @param int $pCount * @param string $insideOf
* @param int $width * @param int $pCount
* @param mixed $style * @param int $width
*/ * @param mixed $style
public function __construct($insideOf, $pCount, $width = null, $style = null) { */
$this->_insideOf = $insideOf; public function __construct($insideOf, $pCount, $width = null, $style = null)
$this->_pCount = $pCount; {
$this->_width = $width; $this->_insideOf = $insideOf;
$this->_pCount = $pCount;
if(!is_null($style)) { $this->_width = $width;
if(is_array($style)) {
$this->_style = new PHPWord_Style_Cell(); if (!is_null($style)) {
if (is_array($style)) {
foreach($style as $key => $value) { $this->_style = new PHPWord_Style_Cell();
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($style as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_style->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { $this->_style->setStyleValue($key, $value);
$this->_style = $style; }
} } else {
} $this->_style = $style;
} }
}
/** }
* Add a Text Element
* /**
* @param string $text * Add a Text Element
* @param mixed $style *
* @return PHPWord_Section_Text * @param string $text
*/ * @param mixed $style
public function addText($text, $styleFont = null, $styleParagraph = null) { * @return PHPWord_Section_Text
$text = utf8_encode($text); */
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); public function addText($text, $styleFont = null, $styleParagraph = null)
$this->_elementCollection[] = $text; {
return $text; $text = utf8_encode($text);
} $text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
/** return $text;
* Add a Link Element }
*
* @param string $linkSrc /**
* @param string $linkName * Add a Link Element
* @param mixed $style *
* @return PHPWord_Section_Link * @param string $linkSrc
*/ * @param string $linkName
public function addLink($linkSrc, $linkName = null, $style = null) { * @param mixed $style
if($this->_insideOf == 'section') { * @return PHPWord_Section_Link
$linkSrc = utf8_encode($linkSrc); */
if(!is_null($linkName)) { public function addLink($linkSrc, $linkName = null, $style = null)
$linkName = utf8_encode($linkName); {
} if ($this->_insideOf == 'section') {
$linkSrc = utf8_encode($linkSrc);
$link = new PHPWord_Section_Link($linkSrc, $linkName, $style); if (!is_null($linkName)) {
$rID = PHPWord_Media::addSectionLinkElement($linkSrc); $linkName = utf8_encode($linkName);
$link->setRelationId($rID); }
$this->_elementCollection[] = $link; $link = new PHPWord_Section_Link($linkSrc, $linkName, $style);
return $link; $rID = PHPWord_Media::addSectionLinkElement($linkSrc);
} else { $link->setRelationId($rID);
trigger_error('Unsupported Link header / footer reference');
return false; $this->_elementCollection[] = $link;
} return $link;
} } else {
trigger_error('Unsupported Link header / footer reference');
/** return false;
* Add a TextBreak Element }
* }
* @param int $count
*/ /**
public function addTextBreak() { * Add a TextBreak Element
$this->_elementCollection[] = new PHPWord_Section_TextBreak(); *
} * @param int $count
*/
/** public function addTextBreak()
* Add a ListItem Element {
* $this->_elementCollection[] = new PHPWord_Section_TextBreak();
* @param string $text }
* @param int $depth
* @param mixed $styleText /**
* @param mixed $styleList * Add a ListItem Element
* @return PHPWord_Section_ListItem *
*/ * @param string $text
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) { * @param int $depth
$text = utf8_encode($text); * @param mixed $styleText
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList); * @param mixed $styleList
$this->_elementCollection[] = $listItem; * @return PHPWord_Section_ListItem
return $listItem; */
} public function addListItem($text, $depth = 0, $styleText = null, $styleList = null)
{
/** $text = utf8_encode($text);
* Add a Image Element $listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList);
* $this->_elementCollection[] = $listItem;
* @param string $src return $listItem;
* @param mixed $style }
* @return PHPWord_Section_Image
*/ /**
public function addImage($src, $style = null) { * Add a Image Element
$image = new PHPWord_Section_Image($src, $style); *
* @param string $src
if(!is_null($image->getSource())) { * @param mixed $style
if($this->_insideOf == 'section') { * @return PHPWord_Section_Image
$rID = PHPWord_Media::addSectionMediaElement($src, 'image'); */
} elseif($this->_insideOf == 'header') { public function addImage($src, $style = null)
$rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $src); {
} elseif($this->_insideOf == 'footer') { $image = new PHPWord_Section_Image($src, $style);
$rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $src);
} if (!is_null($image->getSource())) {
$image->setRelationId($rID); if ($this->_insideOf == 'section') {
$rID = PHPWord_Media::addSectionMediaElement($src, 'image');
$this->_elementCollection[] = $image; } elseif ($this->_insideOf == 'header') {
return $image; $rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $src);
} else { } elseif ($this->_insideOf == 'footer') {
trigger_error('Source does not exist or unsupported image type.'); $rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $src);
} }
} $image->setRelationId($rID);
/** $this->_elementCollection[] = $image;
* Add a by PHP created Image Element return $image;
* } else {
* @param string $link trigger_error('Source does not exist or unsupported image type.');
* @param mixed $style }
* @return PHPWord_Section_MemoryImage }
*/
public function addMemoryImage($link, $style = null) { /**
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); * Add a by PHP created Image Element
if(!is_null($memoryImage->getSource())) { *
if($this->_insideOf == 'section') { * @param string $link
$rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage); * @param mixed $style
} elseif($this->_insideOf == 'header') { * @return PHPWord_Section_MemoryImage
$rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage); */
} elseif($this->_insideOf == 'footer') { public function addMemoryImage($link, $style = null)
$rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $link, $memoryImage); {
} $memoryImage = new PHPWord_Section_MemoryImage($link, $style);
$memoryImage->setRelationId($rID); if (!is_null($memoryImage->getSource())) {
if ($this->_insideOf == 'section') {
$this->_elementCollection[] = $memoryImage; $rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage);
return $memoryImage; } elseif ($this->_insideOf == 'header') {
} else { $rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage);
trigger_error('Unsupported image type.'); } elseif ($this->_insideOf == 'footer') {
} $rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $link, $memoryImage);
} }
$memoryImage->setRelationId($rID);
/**
* Add a OLE-Object Element $this->_elementCollection[] = $memoryImage;
* return $memoryImage;
* @param string $src } else {
* @param mixed $style trigger_error('Unsupported image type.');
* @return PHPWord_Section_Object }
*/ }
public function addObject($src, $style = null) {
$object = new PHPWord_Section_Object($src, $style); /**
* Add a OLE-Object Element
if(!is_null($object->getSource())) { *
$inf = pathinfo($src); * @param string $src
$ext = $inf['extension']; * @param mixed $style
if(strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') { * @return PHPWord_Section_Object
$ext = substr($ext, 0, -1); */
} public function addObject($src, $style = null)
{
$iconSrc = PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/'; $object = new PHPWord_Section_Object($src, $style);
if(!file_exists($iconSrc.'_'.$ext.'.png')) {
$iconSrc = $iconSrc.'_default.png'; if (!is_null($object->getSource())) {
} else { $inf = pathinfo($src);
$iconSrc .= '_'.$ext.'.png'; $ext = $inf['extension'];
} if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
$rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image'); }
$data = PHPWord_Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0]; $iconSrc = PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/';
$objectId = $data[1]; if (!file_exists($iconSrc . '_' . $ext . '.png')) {
$iconSrc = $iconSrc . '_default.png';
$object->setRelationId($rID); } else {
$object->setObjectId($objectId); $iconSrc .= '_' . $ext . '.png';
$object->setImageRelationId($rIDimg); }
$this->_elementCollection[] = $object; $rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image');
return $object; $data = PHPWord_Media::addSectionMediaElement($src, 'oleObject');
} else { $rID = $data[0];
trigger_error('Source does not exist or unsupported object type.'); $objectId = $data[1];
}
} $object->setRelationId($rID);
$object->setObjectId($objectId);
/** $object->setImageRelationId($rIDimg);
* Add a PreserveText Element
* $this->_elementCollection[] = $object;
* @param string $text return $object;
* @param mixed $styleFont } else {
* @param mixed $styleParagraph trigger_error('Source does not exist or unsupported object type.');
* @return PHPWord_Section_Footer_PreserveText }
*/ }
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) {
if($this->_insideOf == 'footer' || $this->_insideOf == 'header') { /**
$text = utf8_encode($text); * Add a PreserveText Element
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); *
$this->_elementCollection[] = $ptext; * @param string $text
return $ptext; * @param mixed $styleFont
} else { * @param mixed $styleParagraph
trigger_error('addPreserveText only supported in footer/header.'); * @return PHPWord_Section_Footer_PreserveText
} */
} public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
/** if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') {
* Create a new TextRun $text = utf8_encode($text);
* $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
* @return PHPWord_Section_TextRun $this->_elementCollection[] = $ptext;
*/ return $ptext;
public function createTextRun($styleParagraph = null) { } else {
$textRun = new PHPWord_Section_TextRun($styleParagraph); trigger_error('addPreserveText only supported in footer/header.');
$this->_elementCollection[] = $textRun; }
return $textRun; }
}
/**
/** * Create a new TextRun
* Get all Elements *
* * @return PHPWord_Section_TextRun
* @return array */
*/ public function createTextRun($styleParagraph = null)
public function getElements() { {
return $this->_elementCollection; $textRun = new PHPWord_Section_TextRun($styleParagraph);
} $this->_elementCollection[] = $textRun;
return $textRun;
/** }
* Get Cell Style
* /**
* @return PHPWord_Style_Cell * Get all Elements
*/ *
public function getStyle() { * @return array
return $this->_style; */
} public function getElements()
{
/** return $this->_elementCollection;
* Get Cell width }
*
* @return int /**
*/ * Get Cell Style
public function getWidth() { *
return $this->_width; * @return PHPWord_Style_Cell
} */
} public function getStyle()
?> {
return $this->_style;
}
/**
* Get Cell width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}
}

View File

@ -33,113 +33,119 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Text { class PHPWord_Section_Text
{
/**
* Text content /**
* * Text content
* @var string *
*/ * @var string
private $_text; */
private $_text;
/**
* Text style /**
* * Text style
* @var PHPWord_Style_Font *
*/ * @var PHPWord_Style_Font
private $_styleFont; */
private $_styleFont;
/**
* Paragraph style /**
* * Paragraph style
* @var PHPWord_Style_Font *
*/ * @var PHPWord_Style_Font
private $_styleParagraph; */
private $_styleParagraph;
/**
* Create a new Text Element /**
* * Create a new Text Element
* @var string $text *
* @var mixed $style * @var string $text
*/ * @var mixed $style
public function __construct($text = null, $styleFont = null, $styleParagraph = null) { */
// Set font style public function __construct($text = null, $styleFont = null, $styleParagraph = null)
$this->setFontStyle($styleFont); {
// Set font style
// Set paragraph style $this->setFontStyle($styleFont);
$this->setParagraphStyle($styleParagraph);
// Set paragraph style
$this->_text = $text; $this->setParagraphStyle($styleParagraph);
return $this; $this->_text = $text;
}
return $this;
/** }
* Get Text style
* /**
* @return PHPWord_Style_Font * Get Text style
*/ *
public function getFontStyle() { * @return PHPWord_Style_Font
return $this->_styleFont; */
} public function getFontStyle()
{
/** return $this->_styleFont;
* Set Text style }
*
* @return PHPWord_Style_Font /**
*/ * Set Text style
public function setFontStyle($styleFont) { *
if(is_array($styleFont)) { * @return PHPWord_Style_Font
$this->_styleFont = new PHPWord_Style_Font('text'); */
public function setFontStyle($styleFont)
foreach($styleFont as $key => $value) { {
if(substr($key, 0, 1) != '_') { if (is_array($styleFont)) {
$key = '_'.$key; $this->_styleFont = new PHPWord_Style_Font('text');
}
$this->_styleFont->setStyleValue($key, $value); foreach ($styleFont as $key => $value) {
} if (substr($key, 0, 1) != '_') {
} else { $key = '_' . $key;
$this->_styleFont = $styleFont; }
} $this->_styleFont->setStyleValue($key, $value);
} }
} else {
/** $this->_styleFont = $styleFont;
* Get Paragraph style }
* }
* @return PHPWord_Style_Paragraph
*/ /**
public function getParagraphStyle() { * Get Paragraph style
return $this->_styleParagraph; *
} * @return PHPWord_Style_Paragraph
*/
/** public function getParagraphStyle()
* Set Paragraph style {
* return $this->_styleParagraph;
* @return PHPWord_Style_Paragraph }
*/
public function setParagraphStyle($styleParagraph) { /**
if(is_array($styleParagraph)) { * Set Paragraph style
$this->_styleParagraph = new PHPWord_Style_Paragraph(); *
* @return PHPWord_Style_Paragraph
foreach($styleParagraph as $key => $value) { */
if(substr($key, 0, 1) != '_') { public function setParagraphStyle($styleParagraph)
$key = '_'.$key; {
} if (is_array($styleParagraph)) {
$this->_styleParagraph->setStyleValue($key, $value); $this->_styleParagraph = new PHPWord_Style_Paragraph();
}
} else { foreach ($styleParagraph as $key => $value) {
$this->_styleParagraph = $styleParagraph; if (substr($key, 0, 1) != '_') {
} $key = '_' . $key;
} }
$this->_styleParagraph->setStyleValue($key, $value);
/** }
* Get Text content } else {
* $this->_styleParagraph = $styleParagraph;
* @return string }
*/ }
public function getText() {
return $this->_text; /**
} * Get Text content
*
* @return string
*/
public function getText()
{
return $this->_text;
}
} }
?>

View File

@ -33,13 +33,14 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_TextBreak { class PHPWord_Section_TextBreak
{
/**
* Create a new TextBreak Element /**
*/ * Create a new TextBreak Element
public function __construct() { */
// nothing public function __construct()
} {
// nothing
}
} }
?>

View File

@ -33,97 +33,102 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_TextRun { class PHPWord_Section_TextRun
{
/**
* Paragraph style /**
* * Paragraph style
* @var PHPWord_Style_Font *
*/ * @var PHPWord_Style_Font
private $_styleParagraph; */
private $_styleParagraph;
/**
* Text collection /**
* * Text collection
* @var array *
*/ * @var array
private $_elementCollection; */
private $_elementCollection;
/**
* Create a new TextRun Element /**
*/ * Create a new TextRun Element
public function __construct($styleParagraph = null) { */
$this->_elementCollection = array(); public function __construct($styleParagraph = null)
{
// Set paragraph style $this->_elementCollection = array();
if(is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); // Set paragraph style
if (is_array($styleParagraph)) {
foreach($styleParagraph as $key => $value) { $this->_styleParagraph = new PHPWord_Style_Paragraph();
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($styleParagraph as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$this->_styleParagraph->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { $this->_styleParagraph->setStyleValue($key, $value);
$this->_styleParagraph = $styleParagraph; }
} } else {
} $this->_styleParagraph = $styleParagraph;
}
}
/**
* Add a Text Element
* /**
* @var string $text * Add a Text Element
* @var mixed $styleFont *
* @return PHPWord_Section_Text * @var string $text
*/ * @var mixed $styleFont
public function addText($text = null, $styleFont = null) { * @return PHPWord_Section_Text
$givenText = utf8_encode($text); */
$text = new PHPWord_Section_Text($givenText, $styleFont); public function addText($text = null, $styleFont = null)
$this->_elementCollection[] = $text; {
return $text; $givenText = utf8_encode($text);
} $text = new PHPWord_Section_Text($givenText, $styleFont);
$this->_elementCollection[] = $text;
/** return $text;
* Add a Link Element }
*
* @param string $linkSrc /**
* @param string $linkName * Add a Link Element
* @param mixed $styleFont *
* @return PHPWord_Section_Link * @param string $linkSrc
*/ * @param string $linkName
public function addLink($linkSrc, $linkName = null, $styleFont = null) { * @param mixed $styleFont
$linkSrc = utf8_encode($linkSrc); * @return PHPWord_Section_Link
if(!is_null($linkName)) { */
$linkName = utf8_encode($linkName); public function addLink($linkSrc, $linkName = null, $styleFont = null)
} {
$linkSrc = utf8_encode($linkSrc);
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont); if (!is_null($linkName)) {
$rID = PHPWord_Media::addSectionLinkElement($linkSrc); $linkName = utf8_encode($linkName);
$link->setRelationId($rID); }
$this->_elementCollection[] = $link; $link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont);
return $link; $rID = PHPWord_Media::addSectionLinkElement($linkSrc);
} $link->setRelationId($rID);
/** $this->_elementCollection[] = $link;
* Get TextRun content return $link;
* }
* @return string
*/ /**
public function getElements() { * Get TextRun content
return $this->_elementCollection; *
} * @return string
*/
/** public function getElements()
* Get Paragraph style {
* return $this->_elementCollection;
* @return PHPWord_Style_Paragraph }
*/
public function getParagraphStyle() { /**
return $this->_styleParagraph; * Get Paragraph style
} *
* @return PHPWord_Style_Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
} }
?>

View File

@ -33,113 +33,120 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Section_Title { class PHPWord_Section_Title
{
/**
* Title Text content /**
* * Title Text content
* @var string *
*/ * @var string
private $_text; */
private $_text;
/**
* Title depth /**
* * Title depth
* @var int *
*/ * @var int
private $_depth; */
private $_depth;
/**
* Title anchor /**
* * Title anchor
* @var int *
*/ * @var int
private $_anchor; */
private $_anchor;
/**
* Title Bookmark ID /**
* * Title Bookmark ID
* @var int *
*/ * @var int
private $_bookmarkId; */
private $_bookmarkId;
/**
* Title style /**
* * Title style
* @var string *
*/ * @var string
private $_style; */
private $_style;
/**
* Create a new Title Element /**
* * Create a new Title Element
* @var string $text *
* @var int $depth * @var string $text
*/ * @var int $depth
public function __construct($text, $depth = 1, $style = null) { */
if(!is_null($style)) { public function __construct($text, $depth = 1, $style = null)
$this->_style = $style; {
} if (!is_null($style)) {
$this->_style = $style;
$this->_text = $text; }
$this->_depth = $depth;
$this->_text = $text;
return $this; $this->_depth = $depth;
}
return $this;
/** }
* Set Anchor
* /**
* @var int $anchor * Set Anchor
*/ *
public function setAnchor($anchor) { * @var int $anchor
$this->_anchor = $anchor; */
} public function setAnchor($anchor)
{
/** $this->_anchor = $anchor;
* Get Anchor }
*
* @return int /**
*/ * Get Anchor
public function getAnchor() { *
return $this->_anchor; * @return int
} */
public function getAnchor()
/** {
* Set Bookmark ID return $this->_anchor;
* }
* @var int $bookmarkId
*/ /**
public function setBookmarkId($bookmarkId) { * Set Bookmark ID
$this->_bookmarkId = $bookmarkId; *
} * @var int $bookmarkId
*/
/** public function setBookmarkId($bookmarkId)
* Get Anchor {
* $this->_bookmarkId = $bookmarkId;
* @return int }
*/
public function getBookmarkId() { /**
return $this->_bookmarkId; * Get Anchor
} *
* @return int
/** */
* Get Title Text content public function getBookmarkId()
* {
* @return string return $this->_bookmarkId;
*/ }
public function getText() {
return $this->_text; /**
} * Get Title Text content
*
/** * @return string
* Get Title style */
* public function getText()
* @return string {
*/ return $this->_text;
public function getStyle() { }
return $this->_style;
} /**
* Get Title style
*
* @return string
*/
public function getStyle()
{
return $this->_style;
}
} }
?>

View File

@ -28,127 +28,134 @@
class PHPWord_Shared_Drawing class PHPWord_Shared_Drawing
{ {
/** /**
* Convert pixels to EMU * Convert pixels to EMU
* *
* @param int $pValue Value in pixels * @param int $pValue Value in pixels
* @return int Value in EMU * @return int Value in EMU
*/ */
public static function pixelsToEMU($pValue = 0) { public static function pixelsToEMU($pValue = 0)
return round($pValue * 9525); {
} 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 * Convert EMU to pixels
* *
* @param int $pValue Degrees * @param int $pValue Value in EMU
* @return int Angle * @return int Value in pixels
*/ */
public static function degreesToAngle($pValue = 0) { public static function EMUToPixels($pValue = 0)
return (int)round($pValue * 60000); {
} if ($pValue != 0) {
return round($pValue / 9525);
/** } else {
* Convert angle to degrees return 0;
* }
* @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 * Convert pixels to points
* *
* @param int $pValue Value in pixels * @param int $pValue Value in pixels
* @return int Value in centimeters * @return int Value in points
*/ */
public static function pixelsToCentimeters($pValue = 0) { public static function pixelsToPoints($pValue = 0)
return $pValue * 0.028; {
} return $pValue * 0.67777777;
}
/**
* Convert centimeters width to pixels /**
* * Convert points width to pixels
* @param int $pValue Value in centimeters *
* @return int Value in pixels * @param int $pValue Value in points
*/ * @return int Value in pixels
public static function centimetersToPixels($pValue = 0) { */
if ($pValue != 0) { public static function pointsToPixels($pValue = 0)
return $pValue * 0.028; {
} else { if ($pValue != 0) {
return 0; return $pValue * 1.333333333;
} } else {
} return 0;
}
/** }
* Convert HTML hexadecimal to RGB
* /**
* @param str $pValue HTML Color in hexadecimal * Convert degrees to angle
* @return array Value in RGB *
*/ * @param int $pValue Degrees
public static function htmlToRGB($pValue) { * @return int Angle
if ($pValue[0] == '#'){ */
$pValue = substr($pValue, 1); public static function degreesToAngle($pValue = 0)
} {
return (int)round($pValue * 60000);
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){ * Convert angle to degrees
list($color_R, $color_G, $color_B) = array($pValue[0].$pValue[0],$pValue[1].$pValue[1],$pValue[2].$pValue[2]); *
} * @param int $pValue Angle
else{ * @return int Degrees
return false; */
} public static function angleToDegrees($pValue = 0)
{
$color_R = hexdec($color_R); if ($pValue != 0) {
$color_G = hexdec($color_G); return round($pValue / 60000);
$color_B = hexdec($color_B); } else {
return 0;
return array($color_R, $color_G, $color_B); }
} }
/**
* 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

@ -28,64 +28,66 @@
class PHPWord_Shared_File class PHPWord_Shared_File
{ {
/** /**
* Verify if a file exists * Verify if a file exists
* *
* @param string $pFilename Filename * @param string $pFilename Filename
* @return bool * @return bool
*/ */
public static function file_exists($pFilename) { public static function file_exists($pFilename)
// Sick construction, but it seems that {
// file_exists returns strange values when // Sick construction, but it seems that
// doing the original file_exists on ZIP archives... // file_exists returns strange values when
if ( strtolower(substr($pFilename, 0, 3)) == 'zip' ) { // doing the original file_exists on ZIP archives...
// Open ZIP file and verify if the file exists if (strtolower(substr($pFilename, 0, 3)) == 'zip') {
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6); // Open ZIP file and verify if the file exists
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1); $zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
$zip = new ZipArchive(); $zip = new ZipArchive();
if ($zip->open($zipFile) === true) { if ($zip->open($zipFile) === true) {
$returnValue = ($zip->getFromName($archiveFile) !== false); $returnValue = ($zip->getFromName($archiveFile) !== false);
$zip->close(); $zip->close();
return $returnValue; return $returnValue;
} else { } else {
return false; return false;
} }
} else { } else {
// Regular file_exists // Regular file_exists
return file_exists($pFilename); return file_exists($pFilename);
} }
} }
/** /**
* Returns canonicalized absolute pathname, also for ZIP archives * Returns canonicalized absolute pathname, also for ZIP archives
* *
* @param string $pFilename * @param string $pFilename
* @return string * @return string
*/ */
public static function realpath($pFilename) { public static function realpath($pFilename)
// Returnvalue {
$returnValue = ''; // Returnvalue
$returnValue = '';
// Try using realpath() // Try using realpath()
$returnValue = realpath($pFilename); $returnValue = realpath($pFilename);
// Found something? // Found something?
if ($returnValue == '' || is_null($returnValue)) { if ($returnValue == '' || is_null($returnValue)) {
$pathArray = split('/' , $pFilename); $pathArray = split('/', $pFilename);
while(in_array('..', $pathArray) && $pathArray[0] != '..') { while (in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) { for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) { if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i]); unset($pathArray[$i]);
unset($pathArray[$i - 1]); unset($pathArray[$i - 1]);
break; break;
} }
} }
} }
$returnValue = implode('/', $pathArray); $returnValue = implode('/', $pathArray);
} }
// Return // Return
return $returnValue; return $returnValue;
} }
} }

View File

@ -28,45 +28,51 @@
class PHPWord_Shared_Font class PHPWord_Shared_Font
{ {
/** /**
* Calculate an (approximate) pixel size, based on a font points size * Calculate an (approximate) pixel size, based on a font points size
* *
* @param int $fontSizeInPoints Font size (in points) * @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels) * @return int Font size (in pixels)
*/ */
public static function fontSizeToPixels($fontSizeInPoints = 12) { public static function fontSizeToPixels($fontSizeInPoints = 12)
return ((16 / 12) * $fontSizeInPoints); {
} return ((16 / 12) * $fontSizeInPoints);
}
/**
* Calculate an (approximate) pixel size, based on inch size /**
* * Calculate an (approximate) pixel size, based on inch size
* @param int $sizeInInch Font size (in inch) *
* @return int Size (in pixels) * @param int $sizeInInch Font size (in inch)
*/ * @return int Size (in pixels)
public static function inchSizeToPixels($sizeInInch = 1) { */
return ($sizeInInch * 96); 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) * Calculate an (approximate) pixel size, based on centimeter size
* @return int Size (in pixels) *
*/ * @param int $sizeInCm Font size (in centimeters)
public static function centimeterSizeToPixels($sizeInCm = 1) { * @return int Size (in pixels)
return ($sizeInCm * 37.795275591); */
} public static function centimeterSizeToPixels($sizeInCm = 1)
{
public static function centimeterSizeToTwips($sizeInCm = 1) { return ($sizeInCm * 37.795275591);
return ($sizeInCm * 565.217); }
}
public static function centimeterSizeToTwips($sizeInCm = 1)
public static function inchSizeToTwips($sizeInInch = 1) { {
return self::centimeterSizeToTwips($sizeInInch * 2.54); return ($sizeInCm * 565.217);
} }
public static function pixelSizeToTwips($sizeInPixel = 1) { public static function inchSizeToTwips($sizeInInch = 1)
return self::centimeterSizeToTwips($sizeInPixel / 37.795275591); {
} return self::centimeterSizeToTwips($sizeInInch * 2.54);
}
public static function pixelSizeToTwips($sizeInPixel = 1)
{
return self::centimeterSizeToTwips($sizeInPixel / 37.795275591);
}
} }

View File

@ -28,236 +28,241 @@
class PHPWord_Shared_String class PHPWord_Shared_String
{ {
/** /**
* Control characters array * Control characters array
* *
* @var string[] * @var string[]
*/ */
private static $_controlCharacters = array(); private static $_controlCharacters = array();
/** /**
* Is mbstring extension avalable? * Is mbstring extension avalable?
* *
* @var boolean * @var boolean
*/ */
private static $_isMbstringEnabled; private static $_isMbstringEnabled;
/** /**
* Is iconv extension avalable? * Is iconv extension avalable?
* *
* @var boolean * @var boolean
*/ */
private static $_isIconvEnabled; private static $_isIconvEnabled;
/** /**
* Build control characters array * Build control characters array
*/ */
private static function _buildControlCharacters() { private static function _buildControlCharacters()
for ($i = 0; $i <= 19; ++$i) { {
if ($i != 9 && $i != 10 && $i != 13) { for ($i = 0; $i <= 19; ++$i) {
$find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_'; if ($i != 9 && $i != 10 && $i != 13) {
$replace = chr($i); $find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
self::$_controlCharacters[$find] = $replace; $replace = chr($i);
} self::$_controlCharacters[$find] = $replace;
} }
} }
}
/** /**
* Get whether mbstring extension is available * Get whether mbstring extension is available
* *
* @return boolean * @return boolean
*/ */
public static function getIsMbstringEnabled() public static function getIsMbstringEnabled()
{ {
if (isset(self::$_isMbstringEnabled)) { if (isset(self::$_isMbstringEnabled)) {
return self::$_isMbstringEnabled; return self::$_isMbstringEnabled;
} }
self::$_isMbstringEnabled = function_exists('mb_convert_encoding') ? self::$_isMbstringEnabled = function_exists('mb_convert_encoding') ?
true : false; true : false;
return self::$_isMbstringEnabled; return self::$_isMbstringEnabled;
} }
/** /**
* Get whether iconv extension is available * Get whether iconv extension is available
* *
* @return boolean * @return boolean
*/ */
public static function getIsIconvEnabled() public static function getIsIconvEnabled()
{ {
if (isset(self::$_isIconvEnabled)) { if (isset(self::$_isIconvEnabled)) {
return self::$_isIconvEnabled; return self::$_isIconvEnabled;
} }
self::$_isIconvEnabled = function_exists('iconv') ? self::$_isIconvEnabled = function_exists('iconv') ?
true : false; true : false;
return self::$_isIconvEnabled; return self::$_isIconvEnabled;
} }
/** /**
* Convert from OpenXML escaped control character to PHP control character * Convert from OpenXML escaped control character to PHP control character
* *
* Excel 2007 team: * Excel 2007 team:
* ---------------- * ----------------
* That's correct, control characters are stored directly in the shared-strings table. * 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: * 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... * _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>) * 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. * element or in the shared string <t> element.
* *
* @param string $value Value to unescape * @param string $value Value to unescape
* @return string * @return string
*/ */
public static function ControlCharacterOOXML2PHP($value = '') { public static function ControlCharacterOOXML2PHP($value = '')
if(empty(self::$_controlCharacters)) { {
self::_buildControlCharacters(); if (empty(self::$_controlCharacters)) {
} self::_buildControlCharacters();
}
return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value ); return str_replace(array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value);
} }
/** /**
* Convert from PHP control character to OpenXML escaped control character * Convert from PHP control character to OpenXML escaped control character
* *
* Excel 2007 team: * Excel 2007 team:
* ---------------- * ----------------
* That's correct, control characters are stored directly in the shared-strings table. * 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: * 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... * _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>) * 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. * element or in the shared string <t> element.
* *
* @param string $value Value to escape * @param string $value Value to escape
* @return string * @return string
*/ */
public static function ControlCharacterPHP2OOXML($value = '') { public static function ControlCharacterPHP2OOXML($value = '')
if(empty(self::$_controlCharacters)) { {
self::_buildControlCharacters(); if (empty(self::$_controlCharacters)) {
} self::_buildControlCharacters();
}
return str_replace( array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value ); return str_replace(array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value);
} }
/** /**
* Check if a string contains UTF8 data * Check if a string contains UTF8 data
* *
* @param string $value * @param string $value
* @return boolean * @return boolean
*/ */
public static function IsUTF8($value = '') { public static function IsUTF8($value = '')
return utf8_encode(utf8_decode($value)) === $value; {
} return utf8_encode(utf8_decode($value)) === $value;
}
/** /**
* Formats a numeric value as a string for output in various output writers * Formats a numeric value as a string for output in various output writers
* *
* @param mixed $value * @param mixed $value
* @return string * @return string
*/ */
public static function FormatNumber($value) { public static function FormatNumber($value)
return number_format($value, 2, '.', ''); {
} return number_format($value, 2, '.', '');
}
/** /**
* Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length) * Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length)
* Writes the string using uncompressed notation, no rich text, no Asian phonetics * Writes the string using uncompressed notation, no rich text, no Asian phonetics
* If mbstring extension is not available, ASCII is assumed, and compressed notation is used * If mbstring extension is not available, ASCII is assumed, and compressed notation is used
* although this will give wrong results for non-ASCII strings * although this will give wrong results for non-ASCII strings
* see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3 * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3
* *
* @param string $value UTF-8 encoded string * @param string $value UTF-8 encoded string
* @return string * @return string
*/ */
public static function UTF8toBIFF8UnicodeShort($value) public static function UTF8toBIFF8UnicodeShort($value)
{ {
// character count // character count
$ln = self::CountCharacters($value, 'UTF-8'); $ln = self::CountCharacters($value, 'UTF-8');
// option flags // option flags
$opt = (self::getIsMbstringEnabled() || self::getIsIconvEnabled()) ? $opt = (self::getIsMbstringEnabled() || self::getIsIconvEnabled()) ?
0x0001 : 0x0000; 0x0001 : 0x0000;
// characters // characters
$chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8'); $chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
$data = pack('CC', $ln, $opt) . $chars; $data = pack('CC', $ln, $opt) . $chars;
return $data; return $data;
} }
/** /**
* Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length) * Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length)
* Writes the string using uncompressed notation, no rich text, no Asian phonetics * Writes the string using uncompressed notation, no rich text, no Asian phonetics
* If mbstring extension is not available, ASCII is assumed, and compressed notation is used * If mbstring extension is not available, ASCII is assumed, and compressed notation is used
* although this will give wrong results for non-ASCII strings * although this will give wrong results for non-ASCII strings
* see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3 * see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3
* *
* @param string $value UTF-8 encoded string * @param string $value UTF-8 encoded string
* @return string * @return string
*/ */
public static function UTF8toBIFF8UnicodeLong($value) public static function UTF8toBIFF8UnicodeLong($value)
{ {
// character count // character count
$ln = self::CountCharacters($value, 'UTF-8'); $ln = self::CountCharacters($value, 'UTF-8');
// option flags // option flags
$opt = (self::getIsMbstringEnabled() || self::getIsIconvEnabled()) ? $opt = (self::getIsMbstringEnabled() || self::getIsIconvEnabled()) ?
0x0001 : 0x0000; 0x0001 : 0x0000;
// characters // characters
$chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8'); $chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
$data = pack('vC', $ln, $opt) . $chars; $data = pack('vC', $ln, $opt) . $chars;
return $data; return $data;
} }
/** /**
* Convert string from one encoding to another. First try mbstring, then iconv, or no convertion * Convert string from one encoding to another. First try mbstring, then iconv, or no convertion
* *
* @param string $value * @param string $value
* @param string $to Encoding to convert to, e.g. 'UTF-8' * @param string $to Encoding to convert to, e.g. 'UTF-8'
* @param string $from Encoding to convert from, e.g. 'UTF-16LE' * @param string $from Encoding to convert from, e.g. 'UTF-16LE'
* @return string * @return string
*/ */
public static function ConvertEncoding($value, $to, $from) public static function ConvertEncoding($value, $to, $from)
{ {
if (self::getIsMbstringEnabled()) { if (self::getIsMbstringEnabled()) {
$value = mb_convert_encoding($value, $to, $from); $value = mb_convert_encoding($value, $to, $from);
return $value; return $value;
} }
if (self::getIsIconvEnabled()) { if (self::getIsIconvEnabled()) {
$value = iconv($from, $to, $value); $value = iconv($from, $to, $value);
return $value; return $value;
} }
// else, no conversion // else, no conversion
return $value; return $value;
} }
/**
* Get character count. First try mbstring, then iconv, finally strlen
*
* @param string $value
* @param string $enc Encoding
* @return int Character count
*/
public static function CountCharacters($value, $enc = 'UTF-8')
{
if (self::getIsMbstringEnabled()) {
$count = mb_strlen($value, $enc);
return $count;
}
if (self::getIsIconvEnabled()) { /**
$count = iconv_strlen($value, $enc); * Get character count. First try mbstring, then iconv, finally strlen
return $count; *
} * @param string $value
* @param string $enc Encoding
* @return int Character count
*/
public static function CountCharacters($value, $enc = 'UTF-8')
{
if (self::getIsMbstringEnabled()) {
$count = mb_strlen($value, $enc);
return $count;
}
// else strlen if (self::getIsIconvEnabled()) {
$count = strlen($value); $count = iconv_strlen($value, $enc);
return $count; return $count;
} }
// else strlen
$count = strlen($value);
return $count;
}
} }

View File

@ -26,118 +26,123 @@
*/ */
if(!defined('DATE_W3C')) { if (!defined('DATE_W3C')) {
define('DATE_W3C', 'Y-m-d\TH:i:sP'); define('DATE_W3C', 'Y-m-d\TH:i:sP');
} }
class PHPWord_Shared_XMLWriter { class PHPWord_Shared_XMLWriter
/** Temporary storage method */ {
const STORAGE_MEMORY = 1; /** Temporary storage method */
const STORAGE_DISK = 2; const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
/** /**
* Internal XMLWriter * Internal XMLWriter
* *
* @var XMLWriter * @var XMLWriter
*/ */
private $_xmlWriter; private $_xmlWriter;
/** /**
* Temporary filename * Temporary filename
* *
* @var string * @var string
*/ */
private $_tempFileName = ''; private $_tempFileName = '';
/** /**
* Create a new PHPPowerPoint_Shared_XMLWriter instance * Create a new PHPPowerPoint_Shared_XMLWriter instance
* *
* @param int $pTemporaryStorage Temporary storage location * @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageFolder Temporary storage folder * @param string $pTemporaryStorageFolder Temporary storage folder
*/ */
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') { public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './')
// Create internal XMLWriter {
$this->_xmlWriter = new XMLWriter(); // Create internal XMLWriter
$this->_xmlWriter = new XMLWriter();
// Open temporary storage // Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) { if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->_xmlWriter->openMemory(); $this->_xmlWriter->openMemory();
} else { } else {
// Create temporary filename // Create temporary filename
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml'); $this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage // Open storage
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) { if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
// Fallback to memory... // Fallback to memory...
$this->_xmlWriter->openMemory(); $this->_xmlWriter->openMemory();
} }
} }
// Set default values // Set default values
// proposed to be false in production version // proposed to be false in production version
$this->_xmlWriter->setIndent(true); $this->_xmlWriter->setIndent(true);
//$this->_xmlWriter->setIndent(false); //$this->_xmlWriter->setIndent(false);
// Set indent
// proposed to be '' in production version
$this->_xmlWriter->setIndentString(' ');
//$this->_xmlWriter->setIndentString('');
}
/** // Set indent
* Destructor // proposed to be '' in production version
*/ $this->_xmlWriter->setIndentString(' ');
public function __destruct() { //$this->_xmlWriter->setIndentString('');
// Desctruct XMLWriter }
unset($this->_xmlWriter);
// Unlink temporary files /**
if ($this->_tempFileName != '') { * Destructor
@unlink($this->_tempFileName); */
} public function __destruct()
} {
// Desctruct XMLWriter
unset($this->_xmlWriter);
/** // Unlink temporary files
* Get written data if ($this->_tempFileName != '') {
* @unlink($this->_tempFileName);
* @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) * Get written data
* *
* @param unknown_type $function * @return $data
* @param unknown_type $args */
*/ public function getData()
public function __call($function, $args) { {
try { if ($this->_tempFileName == '') {
@call_user_func_array(array($this->_xmlWriter, $function), $args); return $this->_xmlWriter->outputMemory(true);
} catch (Exception $ex) { } else {
// Do nothing! $this->_xmlWriter->flush();
} return file_get_contents($this->_tempFileName);
} }
}
/** /**
* Fallback method for writeRaw, introduced in PHP 5.2 * Catch function calls (and pass them to internal XMLWriter)
* *
* @param string $text * @param unknown_type $function
* @return string * @param unknown_type $args
*/ */
public function writeRaw($text) public function __call($function, $args)
{ {
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) { try {
return $this->_xmlWriter->writeRaw($text); @call_user_func_array(array($this->_xmlWriter, $function), $args);
} } catch (Exception $ex) {
// Do nothing!
}
}
return $this->text($text); /**
} * 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

@ -30,147 +30,154 @@
PHPWord_Shared_ZipStreamWrapper::register(); PHPWord_Shared_ZipStreamWrapper::register();
class PHPWord_Shared_ZipStreamWrapper { class PHPWord_Shared_ZipStreamWrapper
/** {
* Internal ZipAcrhive /**
* * Internal ZipAcrhive
* @var ZipAcrhive *
*/ * @var ZipAcrhive
private $_archive; */
private $_archive;
/** /**
* Filename in ZipAcrhive * Filename in ZipAcrhive
* *
* @var string * @var string
*/ */
private $_fileNameInArchive = ''; private $_fileNameInArchive = '';
/** /**
* Position in file * Position in file
* *
* @var int * @var int
*/ */
private $_position = 0; private $_position = 0;
/** /**
* Data * Data
* *
* @var mixed * @var mixed
*/ */
private $_data = ''; private $_data = '';
/** /**
* Register wrapper * Register wrapper
*/ */
public static function register() { public static function register()
@stream_wrapper_unregister("zip"); {
@stream_wrapper_register("zip", __CLASS__); @stream_wrapper_unregister("zip");
} @stream_wrapper_register("zip", __CLASS__);
}
/** /**
* Open stream * Open stream
*/ */
public function stream_open($path, $mode, $options, &$opened_path) { public function stream_open($path, $mode, $options, &$opened_path)
// Check for mode {
if ($mode{0} != 'r') { // Check for mode
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.'); if ($mode{0} != 'r') {
} throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
}
// Parse URL // Parse URL
$url = @parse_url($path); $url = @parse_url($path);
// Fix URL // Fix URL
if (!is_array($url)) { if (!is_array($url)) {
$url['host'] = substr($path, strlen('zip://')); $url['host'] = substr($path, strlen('zip://'));
$url['path'] = ''; $url['path'] = '';
} }
if (strpos($url['host'], '#') !== false) { if (strpos($url['host'], '#') !== false) {
if (!isset($url['fragment'])) { if (!isset($url['fragment'])) {
$url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path']; $url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path'];
$url['host'] = substr($url['host'], 0, strpos($url['host'], '#')); $url['host'] = substr($url['host'], 0, strpos($url['host'], '#'));
unset($url['path']); unset($url['path']);
} }
} else { } else {
$url['host'] = $url['host'] . $url['path']; $url['host'] = $url['host'] . $url['path'];
unset($url['path']); unset($url['path']);
} }
// Open archive // Open archive
$this->_archive = new ZipArchive(); $this->_archive = new ZipArchive();
$this->_archive->open($url['host']); $this->_archive->open($url['host']);
$this->_fileNameInArchive = $url['fragment']; $this->_fileNameInArchive = $url['fragment'];
$this->_position = 0; $this->_position = 0;
$this->_data = $this->_archive->getFromName( $this->_fileNameInArchive ); $this->_data = $this->_archive->getFromName($this->_fileNameInArchive);
return true; return true;
} }
/** /**
* Stat stream * Stat stream
*/ */
public function stream_stat() { public function stream_stat()
return $this->_archive->statName( $this->_fileNameInArchive ); {
} return $this->_archive->statName($this->_fileNameInArchive);
}
/** /**
* Read stream * Read stream
*/ */
function stream_read($count) { function stream_read($count)
$ret = substr($this->_data, $this->_position, $count); {
$this->_position += strlen($ret); $ret = substr($this->_data, $this->_position, $count);
return $ret; $this->_position += strlen($ret);
} return $ret;
}
/** /**
* Tell stream * Tell stream
*/ */
public function stream_tell() { public function stream_tell()
return $this->_position; {
} return $this->_position;
}
/** /**
* EOF stream * EOF stream
*/ */
public function stream_eof() { public function stream_eof()
return $this->_position >= strlen($this->_data); {
} return $this->_position >= strlen($this->_data);
}
/** /**
* Seek stream * Seek stream
*/ */
public function stream_seek($offset, $whence) { public function stream_seek($offset, $whence)
switch ($whence) { {
case SEEK_SET: switch ($whence) {
if ($offset < strlen($this->_data) && $offset >= 0) { case SEEK_SET:
$this->_position = $offset; if ($offset < strlen($this->_data) && $offset >= 0) {
return true; $this->_position = $offset;
} else { return true;
return false; } else {
} return false;
break; }
break;
case SEEK_CUR: case SEEK_CUR:
if ($offset >= 0) { if ($offset >= 0) {
$this->_position += $offset; $this->_position += $offset;
return true; return true;
} else { } else {
return false; return false;
} }
break; break;
case SEEK_END: case SEEK_END:
if (strlen($this->_data) + $offset >= 0) { if (strlen($this->_data) + $offset >= 0) {
$this->_position = strlen($this->_data) + $offset; $this->_position = strlen($this->_data) + $offset;
return true; return true;
} else { } else {
return false; return false;
} }
break; break;
default: default:
return false; return false;
} }
} }
} }
?>

View File

@ -33,133 +33,141 @@
* @package PHPWord_Style * @package PHPWord_Style
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style { class PHPWord_Style
{
/**
* Style Elements /**
* * Style Elements
* @var array *
*/ * @var array
private static $_styleElements = array(); */
private static $_styleElements = array();
/**
* Add a paragraph style /**
* * Add a paragraph style
* @param string $styleName *
* @param array $styles * @param string $styleName
*/ * @param array $styles
public static function addParagraphStyle($styleName, $styles) { */
if(!array_key_exists($styleName, self::$_styleElements)) { public static function addParagraphStyle($styleName, $styles)
$style = new PHPWord_Style_Paragraph(); {
foreach($styles as $key => $value) { if (!array_key_exists($styleName, self::$_styleElements)) {
if(substr($key, 0, 1) != '_') { $style = new PHPWord_Style_Paragraph();
$key = '_'.$key; foreach ($styles as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$style->setStyleValue($key, $value); $key = '_' . $key;
} }
$style->setStyleValue($key, $value);
self::$_styleElements[$styleName] = $style; }
}
} self::$_styleElements[$styleName] = $style;
}
/** }
* Add a font style
* /**
* @param string $styleName * Add a font style
* @param array $styleFont *
* @param array $styleParagraph * @param string $styleName
*/ * @param array $styleFont
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null) { * @param array $styleParagraph
if(!array_key_exists($styleName, self::$_styleElements)) { */
$font = new PHPWord_Style_Font('text', $styleParagraph); public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
foreach($styleFont as $key => $value) { {
if(substr($key, 0, 1) != '_') { if (!array_key_exists($styleName, self::$_styleElements)) {
$key = '_'.$key; $font = new PHPWord_Style_Font('text', $styleParagraph);
} foreach ($styleFont as $key => $value) {
$font->setStyleValue($key, $value); if (substr($key, 0, 1) != '_') {
} $key = '_' . $key;
self::$_styleElements[$styleName] = $font; }
} $font->setStyleValue($key, $value);
} }
self::$_styleElements[$styleName] = $font;
/** }
* Add a link style }
*
* @param string $styleName /**
* @param array $styles * Add a link style
*/ *
public static function addLinkStyle($styleName, $styles) { * @param string $styleName
if(!array_key_exists($styleName, self::$_styleElements)) { * @param array $styles
$style = new PHPWord_Style_Font('link'); */
foreach($styles as $key => $value) { public static function addLinkStyle($styleName, $styles)
if(substr($key, 0, 1) != '_') { {
$key = '_'.$key; if (!array_key_exists($styleName, self::$_styleElements)) {
} $style = new PHPWord_Style_Font('link');
$style->setStyleValue($key, $value); foreach ($styles as $key => $value) {
} if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
self::$_styleElements[$styleName] = $style; }
} $style->setStyleValue($key, $value);
} }
/** self::$_styleElements[$styleName] = $style;
* Add a table style }
* }
* @param string $styleName
* @param array $styles /**
*/ * Add a table style
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null, $styleLastRow = null) { *
if(!array_key_exists($styleName, self::$_styleElements)) { * @param string $styleName
$style = new PHPWord_Style_TableFull($styleTable, $styleFirstRow, $styleLastRow); * @param array $styles
*/
self::$_styleElements[$styleName] = $style; public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null, $styleLastRow = null)
} {
} if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new PHPWord_Style_TableFull($styleTable, $styleFirstRow, $styleLastRow);
/**
* Add a title style self::$_styleElements[$styleName] = $style;
* }
* @param string $styleName }
* @param array $styleFont
* @param array $styleParagraph /**
*/ * Add a title style
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null) { *
$styleName = 'Heading_'.$titleCount; * @param string $styleName
if(!array_key_exists($styleName, self::$_styleElements)) { * @param array $styleFont
$font = new PHPWord_Style_Font('title', $styleParagraph); * @param array $styleParagraph
foreach($styleFont as $key => $value) { */
if(substr($key, 0, 1) != '_') { public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
$key = '_'.$key; {
} $styleName = 'Heading_' . $titleCount;
$font->setStyleValue($key, $value); if (!array_key_exists($styleName, self::$_styleElements)) {
} $font = new PHPWord_Style_Font('title', $styleParagraph);
foreach ($styleFont as $key => $value) {
self::$_styleElements[$styleName] = $font; if (substr($key, 0, 1) != '_') {
} $key = '_' . $key;
} }
$font->setStyleValue($key, $value);
/** }
* Get all styles
* self::$_styleElements[$styleName] = $font;
* @return PHPWord_Style_Font[] }
*/ }
public static function getStyles() {
return self::$_styleElements; /**
} * Get all styles
*
/** * @return PHPWord_Style_Font[]
* Get style */
* public static function getStyles()
* @param string {
* @return PHPWord_Style return self::$_styleElements;
*/ }
public static function getStyle($styleName) {
if(array_key_exists($styleName, self::$_styleElements)){ /**
return self::$_styleElements[$styleName]; * Get style
} else { *
return null; * @param string
} * @return PHPWord_Style
} */
public static function getStyle($styleName)
{
if (array_key_exists($styleName, self::$_styleElements)) {
return self::$_styleElements[$styleName];
} else {
return null;
}
}
} }
?>

View File

@ -33,259 +33,289 @@
* @package PHPWord_Style * @package PHPWord_Style
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style_Cell { class PHPWord_Style_Cell
{
const TEXT_DIR_BTLR = 'btLr';
const TEXT_DIR_TBRL = 'tbRl';
/**
* Vertical align
*
* @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;
/**
* 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) { const TEXT_DIR_BTLR = 'btLr';
$this->_bgColor = $pValue; const TEXT_DIR_TBRL = 'tbRl';
}
public function setHeight($pValue = null) { /**
$this->_height = $pValue; * Vertical align
} *
* @var string
public function setBorderSize($pValue = null) { */
$this->_borderTopSize = $pValue; private $_valign;
$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) { * Text Direction
$this->_borderLeftSize = $pValue; *
} * @var string
*/
public function getBorderLeftSize() { private $_textDirection;
return $this->_borderLeftSize;
} /**
* Background-Color
public function setBorderLeftColor($pValue = null) { *
$this->_borderLeftColor = $pValue; * @var string
} */
private $_bgColor;
public function getBorderLeftColor() {
return $this->_borderLeftColor; /**
} * Border Top Size
*
* @var int
public function setBorderRightSize($pValue = null) { */
$this->_borderRightSize = $pValue; private $_borderTopSize;
}
/**
public function getBorderRightSize() { * Border Top Color
return $this->_borderRightSize; *
} * @var string
*/
public function setBorderRightColor($pValue = null) { private $_borderTopColor;
$this->_borderRightColor = $pValue;
} /**
* Border Left Size
public function getBorderRightColor() { *
return $this->_borderRightColor; * @var int
} */
private $_borderLeftSize;
public function setBorderBottomSize($pValue = null) { /**
$this->_borderBottomSize = $pValue; * Border Left Color
} *
* @var string
public function getBorderBottomSize() { */
return $this->_borderBottomSize; private $_borderLeftColor;
}
/**
public function setBorderBottomColor($pValue = null) { * Border Right Size
$this->_borderBottomColor = $pValue; *
} * @var int
*/
public function getBorderBottomColor() { private $_borderRightSize;
return $this->_borderBottomColor;
} /**
* Border Right Color
public function getDefaultBorderColor() { *
return $this->_defaultBorderColor; * @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;
/**
* 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 setHeight($pValue = null)
{
$this->_height = $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;
}
} }
?>

View File

@ -33,229 +33,253 @@
* @package PHPWord_Style * @package PHPWord_Style
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style_Font { class PHPWord_Style_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 PHPWord_Style_Paragraph
*/
private $_paragraphStyle;
private $_size;
private $_name;
private $_bold;
private $_italic;
private $_superScript;
private $_subScript;
private $_underline;
private $_strikethrough;
private $_color;
private $_fgColor;
public function __construct($type = 'text', $styleParagraph = null) { const UNDERLINE_NONE = 'none';
$this->_type = $type; const UNDERLINE_DASH = 'dash';
$this->_name = 'Arial'; const UNDERLINE_DASHHEAVY = 'dashHeavy';
$this->_size = 20; const UNDERLINE_DASHLONG = 'dashLong';
$this->_bold = false; const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy';
$this->_italic = false; const UNDERLINE_DOUBLE = 'dbl';
$this->_superScript = false; const UNDERLINE_DOTHASH = 'dotDash';
$this->_subScript = false; const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy';
$this->_underline = PHPWord_Style_Font::UNDERLINE_NONE; const UNDERLINE_DOTDOTDASH = 'dotDotDash';
$this->_strikethrough = false; const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy';
$this->_color = '000000'; const UNDERLINE_DOTTED = 'dotted';
$this->_fgColor = null; const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy';
const UNDERLINE_HEAVY = 'heavy';
if(!is_null($styleParagraph)) { const UNDERLINE_SINGLE = 'single';
$paragraph = new PHPWord_Style_Paragraph(); const UNDERLINE_WAVY = 'wavy';
foreach($styleParagraph as $key => $value) { const UNDERLINE_WAVYDOUBLE = 'wavyDbl';
if(substr($key, 0, 1) != '_') { const UNDERLINE_WAVYHEAVY = 'wavyHeavy';
$key = '_'.$key; const UNDERLINE_WORDS = 'words';
}
$paragraph->setStyleValue($key, $value);
}
$this->_paragraphStyle = $paragraph;
} else {
$this->_paragraphStyle = null;
}
}
public function getName() { const FGCOLOR_YELLOW = 'yellow';
return $this->_name; const FGCOLOR_LIGHTGREEN = 'green';
} const FGCOLOR_CYAN = 'cyan';
const FGCOLOR_MAGENTA = 'magenta';
public function setStyleValue($key, $value) { const FGCOLOR_BLUE = 'blue';
if($key == '_size') { const FGCOLOR_RED = 'red';
$value *= 2; const FGCOLOR_DARKBLUE = 'darkBlue';
} const FGCOLOR_DARKCYAN = 'darkCyan';
$this->$key = $value; const FGCOLOR_DARKGREEN = 'darkGreen';
} const FGCOLOR_DARKMAGENTA = 'darkMagenta';
const FGCOLOR_DARKRED = 'darkRed';
public function setName($pValue = 'Arial') { const FGCOLOR_DARKYELLOW = 'darkYellow';
if($pValue == '') { const FGCOLOR_DARKGRAY = 'darkGray';
$pValue = 'Arial'; const FGCOLOR_LIGHTGRAY = 'lightGray';
} const FGCOLOR_BLACK = 'black';
$this->_name = $pValue;
return $this;
}
public function getSize() { /**
return $this->_size; * Font style type
} *
* @var string
*/
private $_type;
public function setSize($pValue = 20) { /**
if($pValue == '') { * Paragraph Style
$pValue = 20; *
} * @var PHPWord_Style_Paragraph
$this->_size = ($pValue*2); */
return $this; private $_paragraphStyle;
}
public function getBold() { private $_size;
return $this->_bold; private $_name;
} private $_bold;
private $_italic;
private $_superScript;
private $_subScript;
private $_underline;
private $_strikethrough;
private $_color;
private $_fgColor;
public function setBold($pValue = false) { public function __construct($type = 'text', $styleParagraph = null)
if($pValue == '') { {
$pValue = false; $this->_type = $type;
} $this->_name = 'Arial';
$this->_bold = $pValue; $this->_size = 20;
return $this; $this->_bold = false;
} $this->_italic = false;
$this->_superScript = false;
$this->_subScript = false;
$this->_underline = PHPWord_Style_Font::UNDERLINE_NONE;
$this->_strikethrough = false;
$this->_color = '000000';
$this->_fgColor = null;
public function getItalic() { if (!is_null($styleParagraph)) {
return $this->_italic; $paragraph = new PHPWord_Style_Paragraph();
} foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$paragraph->setStyleValue($key, $value);
}
$this->_paragraphStyle = $paragraph;
} else {
$this->_paragraphStyle = null;
}
}
public function setItalic($pValue = false) { public function getName()
if($pValue == '') { {
$pValue = false; return $this->_name;
} }
$this->_italic = $pValue;
return $this;
}
public function getSuperScript() { public function setStyleValue($key, $value)
return $this->_superScript; {
} if ($key == '_size') {
$value *= 2;
}
$this->$key = $value;
}
public function setSuperScript($pValue = false) { public function setName($pValue = 'Arial')
if($pValue == '') { {
$pValue = false; if ($pValue == '') {
} $pValue = 'Arial';
$this->_superScript = $pValue; }
$this->_subScript = !$pValue; $this->_name = $pValue;
return $this; return $this;
} }
public function getSubScript() { public function getSize()
return $this->_subScript; {
} return $this->_size;
}
public function setSubScript($pValue = false) { public function setSize($pValue = 20)
if($pValue == '') { {
$pValue = false; if ($pValue == '') {
} $pValue = 20;
$this->_subScript = $pValue; }
$this->_superScript = !$pValue; $this->_size = ($pValue * 2);
return $this; return $this;
} }
public function getUnderline() { public function getBold()
return $this->_underline; {
} return $this->_bold;
}
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE) { public function setBold($pValue = false)
if ($pValue == '') { {
$pValue = PHPWord_Style_Font::UNDERLINE_NONE; if ($pValue == '') {
} $pValue = false;
$this->_underline = $pValue; }
return $this; $this->_bold = $pValue;
} return $this;
}
public function getStrikethrough() { public function getItalic()
return $this->_strikethrough; {
} return $this->_italic;
}
public function setStrikethrough($pValue = false) { public function setItalic($pValue = false)
if($pValue == '') { {
$pValue = false; if ($pValue == '') {
} $pValue = false;
$this->_strikethrough = $pValue; }
return $this; $this->_italic = $pValue;
} return $this;
}
public function getColor() {
return $this->_color;
}
public function setColor($pValue = '000000') { public function getSuperScript()
$this->_color = $pValue; {
return $this; return $this->_superScript;
} }
public function getFgColor() { public function setSuperScript($pValue = false)
return $this->_fgColor; {
} if ($pValue == '') {
$pValue = false;
}
$this->_superScript = $pValue;
$this->_subScript = !$pValue;
return $this;
}
public function setFgColor($pValue = null) { public function getSubScript()
$this->_fgColor = $pValue; {
return $this; return $this->_subScript;
} }
public function getStyleType() { public function setSubScript($pValue = false)
return $this->_type; {
} if ($pValue == '') {
$pValue = false;
/** }
* Get Paragraph style $this->_subScript = $pValue;
* $this->_superScript = !$pValue;
* @return PHPWord_Style_Paragraph return $this;
*/ }
public function getParagraphStyle() {
return $this->_paragraphStyle; public function getUnderline()
} {
return $this->_underline;
}
public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE)
{
if ($pValue == '') {
$pValue = PHPWord_Style_Font::UNDERLINE_NONE;
}
$this->_underline = $pValue;
return $this;
}
public function getStrikethrough()
{
return $this->_strikethrough;
}
public function setStrikethrough($pValue = false)
{
if ($pValue == '') {
$pValue = false;
}
$this->_strikethrough = $pValue;
return $this;
}
public function getColor()
{
return $this->_color;
}
public function setColor($pValue = '000000')
{
$this->_color = $pValue;
return $this;
}
public function getFgColor()
{
return $this->_fgColor;
}
public function setFgColor($pValue = null)
{
$this->_fgColor = $pValue;
return $this;
}
public function getStyleType()
{
return $this->_type;
}
/**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
*/
public function getParagraphStyle()
{
return $this->_paragraphStyle;
}
} }
?>

View File

@ -33,98 +33,110 @@
* @package PHPWord_Section * @package PHPWord_Section
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style_Image { class PHPWord_Style_Image
{
private $_width;
private $_height;
private $_align;
/**
* 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;
}
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;
}
/** private $_width;
* Set Margin Top private $_height;
* private $_align;
* @param int $pValue
*/
public function setMarginTop($pValue = null) {
$this->_marginTop = $pValue;
return $this;
}
/** /**
* Get Margin Left * Margin Top
* *
* @return int * @var int
*/ */
public function getMarginLeft() { private $_marginTop;
return $this->_marginLeft;
}
/** /**
* Set Margin Left * Margin Left
* *
* @param int $pValue * @var int
*/ */
public function setMarginLeft($pValue = null) { private $_marginLeft;
$this->_marginLeft = $pValue;
return $this; public function __construct()
} {
$this->_width = null;
$this->_height = null;
$this->_align = null;
$this->_marginTop = null;
$this->_marginLeft = null;
}
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
*/
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
*/
public function setMarginLeft($pValue = null)
{
$this->_marginLeft = $pValue;
return $this;
}
} }
?>

View File

@ -33,51 +33,55 @@
* @package PHPWord_Style * @package PHPWord_Style
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style_ListItem { class PHPWord_Style_ListItem
{
const TYPE_NUMBER = 7;
const TYPE_NUMBER_NESTED = 8; const TYPE_NUMBER = 7;
const TYPE_ALPHANUM = 9; const TYPE_NUMBER_NESTED = 8;
const TYPE_BULLET_FILLED = 3; const TYPE_ALPHANUM = 9;
const TYPE_BULLET_EMPTY = 5; const TYPE_BULLET_FILLED = 3;
const TYPE_SQUARE_FILLED = 1; const TYPE_BULLET_EMPTY = 5;
const TYPE_SQUARE_FILLED = 1;
/**
* List Type /**
*/ * List Type
private $_listType; */
private $_listType;
/**
* Create a new ListItem Style /**
*/ * Create a new ListItem Style
public function __construct() { */
$this->_listType = PHPWord_Style_ListItem::TYPE_BULLET_FILLED; public function __construct()
} {
$this->_listType = PHPWord_Style_ListItem::TYPE_BULLET_FILLED;
/** }
* Set style value
* /**
* @param string $key * Set style value
* @param string $value *
*/ * @param string $key
public function setStyleValue($key, $value) { * @param string $value
$this->$key = $value; */
} public function setStyleValue($key, $value)
{
/** $this->$key = $value;
* Set List Type }
*
* @param int $pValue /**
*/ * Set List Type
public function setListType($pValue = PHPWord_Style_ListItem::TYPE_BULLET_FILLED) { *
$this->_listType = $pValue; * @param int $pValue
} */
public function setListType($pValue = PHPWord_Style_ListItem::TYPE_BULLET_FILLED)
/** {
* Get List Type $this->_listType = $pValue;
*/ }
public function getListType() {
return $this->_listType; /**
} * Get List Type
*/
public function getListType()
{
return $this->_listType;
}
} }
?>

View File

@ -33,174 +33,186 @@
* @package PHPWord_Style * @package PHPWord_Style
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style_Paragraph { class PHPWord_Style_Paragraph
{
/**
* Paragraph alignment /**
* * Paragraph alignment
* @var string *
*/ * @var string
private $_align; */
private $_align;
/**
* Space before Paragraph /**
* * Space before Paragraph
* @var int *
*/ * @var int
private $_spaceBefore; */
private $_spaceBefore;
/**
* Space after Paragraph /**
* * Space after Paragraph
* @var int *
*/ * @var int
private $_spaceAfter; */
private $_spaceAfter;
/**
* Spacing between breaks /**
* * Spacing between breaks
* @var int *
*/ * @var int
private $_spacing; */
private $_spacing;
/**
* Indent by how much /**
* * Indent by how much
* @var int *
*/ * @var int
private $_indent; */
private $_indent;
/**
* New Paragraph Style /**
*/ * New Paragraph Style
public function __construct() { */
$this->_align = null; public function __construct()
$this->_spaceBefore = null; {
$this->_spaceAfter = null; $this->_align = null;
$this->_spacing = null; $this->_spaceBefore = null;
$this->_indent = null; $this->_spaceAfter = null;
} $this->_spacing = null;
$this->_indent = null;
/** }
* Set Style value
* /**
* @param string $key * Set Style value
* @param mixed $value *
*/ * @param string $key
public function setStyleValue($key, $value) { * @param mixed $value
if($key == '_spacing') { */
$value += 240; // because line height of 1 matches 240 twips public function setStyleValue($key, $value)
} {
if($key == '_indent') { if ($key == '_spacing') {
$value += 240; // because line height of 1 matches 240 twips
}
if ($key == '_indent') {
$value = (int)$value * 720; // 720 twips per indent $value = (int)$value * 720; // 720 twips per indent
} }
$this->$key = $value; $this->$key = $value;
} }
/** /**
* Get Paragraph Alignment * Get Paragraph Alignment
* *
* @return string * @return string
*/ */
public function getAlign() { public function getAlign()
return $this->_align; {
} return $this->_align;
}
/** /**
* Set Paragraph Alignment * Set Paragraph Alignment
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_Style_Paragraph * @return PHPWord_Style_Paragraph
*/ */
public function setAlign($pValue = null) { public function setAlign($pValue = null)
if(strtolower($pValue) == 'justify') { {
// justify becames both if (strtolower($pValue) == 'justify') {
$pValue = 'both'; // justify becames both
} $pValue = 'both';
$this->_align = $pValue; }
return $this; $this->_align = $pValue;
} return $this;
}
/** /**
* Get Space before Paragraph * Get Space before Paragraph
* *
* @return string * @return string
*/ */
public function getSpaceBefore() { public function getSpaceBefore()
return $this->_spaceBefore; {
} return $this->_spaceBefore;
}
/** /**
* Set Space before Paragraph * Set Space before Paragraph
* *
* @param int $pValue * @param int $pValue
* @return PHPWord_Style_Paragraph * @return PHPWord_Style_Paragraph
*/ */
public function setSpaceBefore($pValue = null) { public function setSpaceBefore($pValue = null)
$this->_spaceBefore = $pValue; {
return $this; $this->_spaceBefore = $pValue;
} return $this;
}
/** /**
* Get Space after Paragraph * Get Space after Paragraph
* *
* @return string * @return string
*/ */
public function getSpaceAfter() { public function getSpaceAfter()
return $this->_spaceAfter; {
} return $this->_spaceAfter;
}
/** /**
* Set Space after Paragraph * Set Space after Paragraph
* *
* @param int $pValue * @param int $pValue
* @return PHPWord_Style_Paragraph * @return PHPWord_Style_Paragraph
*/ */
public function setSpaceAfter($pValue = null) { public function setSpaceAfter($pValue = null)
$this->_spaceAfter = $pValue; {
return $this; $this->_spaceAfter = $pValue;
} return $this;
}
/** /**
* Get Spacing between breaks * Get Spacing between breaks
* *
* @return int * @return int
*/ */
public function getSpacing() { public function getSpacing()
return $this->_spacing; {
} return $this->_spacing;
}
/** /**
* Set Spacing between breaks * Set Spacing between breaks
* *
* @param int $pValue * @param int $pValue
* @return PHPWord_Style_Paragraph * @return PHPWord_Style_Paragraph
*/ */
public function setSpacing($pValue = null) { public function setSpacing($pValue = null)
$this->_spacing = $pValue; {
return $this; $this->_spacing = $pValue;
} return $this;
}
/** /**
* Get indentation * Get indentation
* *
* @return int * @return int
*/ */
public function getIndent() { public function getIndent()
return $this->_indent; {
} return $this->_indent;
}
/** /**
* Set indentation * Set indentation
* *
* @param int $pValue * @param int $pValue
* @return PHPWord_Style_Paragraph * @return PHPWord_Style_Paragraph
*/ */
public function setIndent($pValue = null) { public function setIndent($pValue = null)
$this->_indent = $pValue; {
return $this; $this->_indent = $pValue;
} return $this;
}
} }
?>

View File

@ -33,106 +33,114 @@
* @package PHPWord_Style * @package PHPWord_Style
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style_TOC { class PHPWord_Style_TOC
{
const TABLEADER_DOT = 'dot';
const TABLEADER_UNDERSCORE = 'underscore'; const TABLEADER_DOT = 'dot';
const TABLEADER_LINE = 'hyphen'; const TABLEADER_UNDERSCORE = 'underscore';
const TABLEADER_NONE = ''; const TABLEADER_LINE = 'hyphen';
const TABLEADER_NONE = '';
/**
* Tab Leader /**
* * Tab Leader
* @var string *
*/ * @var string
private $_tabLeader; */
private $_tabLeader;
/**
* Tab Position /**
* * Tab Position
* @var int *
*/ * @var int
private $_tabPos; */
private $_tabPos;
/**
* Indent /**
* * Indent
* @var int *
*/ * @var int
private $_indent; */
private $_indent;
/**
* Create a new TOC Style /**
*/ * Create a new TOC Style
public function __construct() { */
$this->_tabPos = 9062; public function __construct()
$this->_tabLeader = PHPWord_Style_TOC::TABLEADER_DOT; {
$this->_indent = 200; $this->_tabPos = 9062;
} $this->_tabLeader = PHPWord_Style_TOC::TABLEADER_DOT;
$this->_indent = 200;
/** }
* Get Tab Position
* /**
* @return int * Get Tab Position
*/ *
public function getTabPos() { * @return int
return $this->_tabPos; */
} public function getTabPos()
{
/** return $this->_tabPos;
* Set Tab Position }
*
* @param int $pValue /**
*/ * Set Tab Position
public function setTabPos($pValue) { *
$this->_tabLeader = $pValue; * @param int $pValue
} */
public function setTabPos($pValue)
/** {
* Get Tab Leader $this->_tabLeader = $pValue;
* }
* @return string
*/ /**
public function getTabLeader() { * Get Tab Leader
return $this->_tabLeader; *
} * @return string
*/
/** public function getTabLeader()
* Set Tab Leader {
* return $this->_tabLeader;
* @param string $pValue }
*/
public function setTabLeader($pValue = PHPWord_Style_TOC::TABLEADER_DOT) { /**
$this->_tabLeader = $pValue; * Set Tab Leader
} *
* @param string $pValue
/** */
* Get Indent public function setTabLeader($pValue = PHPWord_Style_TOC::TABLEADER_DOT)
* {
* @return int $this->_tabLeader = $pValue;
*/ }
public function getIndent() {
return $this->_indent; /**
} * Get Indent
*
/** * @return int
* Set Indent */
* public function getIndent()
* @param string $pValue {
*/ return $this->_indent;
public function setIndent($pValue) { }
$this->_indent = $pValue;
} /**
* Set Indent
/** *
* Set style value * @param string $pValue
* */
* @param string $key public function setIndent($pValue)
* @param string $value {
*/ $this->_indent = $pValue;
public function setStyleValue($key, $value) { }
$this->$key = $value;
} /**
* Set style value
*
* @param string $key
* @param string $value
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
} }
?>

View File

@ -26,58 +26,69 @@
*/ */
class PHPWord_Style_Table { class PHPWord_Style_Table
{
private $_cellMarginTop;
private $_cellMarginLeft; private $_cellMarginTop;
private $_cellMarginRight; private $_cellMarginLeft;
private $_cellMarginBottom; private $_cellMarginRight;
private $_cellMarginBottom;
public function __construct() {
$this->_cellMarginTop = null; public function __construct()
$this->_cellMarginLeft = null; {
$this->_cellMarginRight = null; $this->_cellMarginTop = null;
$this->_cellMarginBottom = null; $this->_cellMarginLeft = null;
} $this->_cellMarginRight = null;
$this->_cellMarginBottom = null;
public function setStyleValue($key, $value) { }
$this->$key = $value;
} public function setStyleValue($key, $value)
{
public function setCellMarginTop($pValue = null) { $this->$key = $value;
$this->_cellMarginTop = $pValue; }
}
public function setCellMarginTop($pValue = null)
public function getCellMarginTop() { {
return $this->_cellMarginTop; $this->_cellMarginTop = $pValue;
} }
public function setCellMarginLeft($pValue = null) { public function getCellMarginTop()
$this->_cellMarginLeft = $pValue; {
} return $this->_cellMarginTop;
}
public function getCellMarginLeft() {
return $this->_cellMarginLeft; public function setCellMarginLeft($pValue = null)
} {
$this->_cellMarginLeft = $pValue;
public function setCellMarginRight($pValue = null) { }
$this->_cellMarginRight = $pValue;
} public function getCellMarginLeft()
{
public function getCellMarginRight() { return $this->_cellMarginLeft;
return $this->_cellMarginRight; }
}
public function setCellMarginRight($pValue = null)
public function setCellMarginBottom($pValue = null) { {
$this->_cellMarginBottom = $pValue; $this->_cellMarginRight = $pValue;
} }
public function getCellMarginBottom() { public function getCellMarginRight()
return $this->_cellMarginBottom; {
} return $this->_cellMarginRight;
}
public function getCellMargin() {
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom); 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

@ -33,410 +33,454 @@
* @package PHPWord_Style * @package PHPWord_Style
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_Style_TableFull { class PHPWord_Style_TableFull
{
/**
* Style for first row
*
* @var PHPWord_Style_Table
*/
private $_firstRow = null;
/**
* Cell Margin Top
*
* @var int
*/
private $_cellMarginTop = null;
/**
* Cell Margin Left
*
* @var int
*/
private $_cellMarginLeft = null;
/**
* Cell Margin Right
*
* @var int
*/
private $_cellMarginRight = null;
/**
* Cell Margin Bottom
*
* @var int
*/
private $_cellMarginBottom = null;
/**
* 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 InsideH Size
*
* @var int
*/
private $_borderInsideHSize;
/**
* Border InsideH Color
*
* @var string
*/
private $_borderInsideHColor;
/**
* Border InsideV Size
*
* @var int
*/
private $_borderInsideVSize;
/**
* Border InsideV Color
*
* @var string
*/
private $_borderInsideVColor;
/**
* Create a new TableFull Font
*/
public function __construct($styleTable = null, $styleFirstRow = null, $styleLastRow = 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);
}
}
}
/**
* Set style 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 PHPWord_Style_TableFull
*/
public function getFirstRow() {
return $this->_firstRow;
}
/**
* Get Last Row Style
*
* @return PHPWord_Style_TableFull
*/
public function getLastRow() {
return $this->_lastRow;
}
public function getBgColor() {
return $this->_bgColor;
}
public function setBgColor($pValue = null) { /**
$this->_bgColor = $pValue; * Style for first row
} *
* @var PHPWord_Style_Table
*/
private $_firstRow = null;
/** /**
* Set TLRBVH Border Size * Cell Margin Top
* *
* @param int $pValue * @var int
*/ */
public function setBorderSize($pValue = null) { private $_cellMarginTop = 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; * Cell Margin Left
} *
* @var int
public function getBorderLeftSize() { */
return $this->_borderLeftSize; private $_cellMarginLeft = null;
}
/**
public function setBorderLeftColor($pValue = null) { * Cell Margin Right
$this->_borderLeftColor = $pValue; *
} * @var int
*/
public function getBorderLeftColor() { private $_cellMarginRight = null;
return $this->_borderLeftColor;
} /**
* Cell Margin Bottom
public function setBorderRightSize($pValue = null) { *
$this->_borderRightSize = $pValue; * @var int
} */
private $_cellMarginBottom = null;
public function getBorderRightSize() {
return $this->_borderRightSize; /**
} * Background-Color
*
public function setBorderRightColor($pValue = null) { * @var string
$this->_borderRightColor = $pValue; */
} private $_bgColor;
public function getBorderRightColor() { /**
return $this->_borderRightColor; * Border Top Size
} *
* @var int
public function setBorderBottomSize($pValue = null) { */
$this->_borderBottomSize = $pValue; private $_borderTopSize;
}
/**
public function getBorderBottomSize() { * Border Top Color
return $this->_borderBottomSize; *
} * @var string
*/
public function setBorderBottomColor($pValue = null) { private $_borderTopColor;
$this->_borderBottomColor = $pValue;
} /**
* Border Left Size
public function getBorderBottomColor() { *
return $this->_borderBottomColor; * @var int
} */
private $_borderLeftSize;
public function setBorderInsideHColor($pValue = null) {
$this->_borderInsideHColor = $pValue; /**
} * Border Left Color
*
public function getBorderInsideHColor() { * @var string
return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null; */
} private $_borderLeftColor;
public function setBorderInsideVColor($pValue = null) { /**
$this->_borderInsideVColor = $pValue; * Border Right Size
} *
* @var int
public function getBorderInsideVColor() { */
return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null; private $_borderRightSize;
}
/**
public function setBorderInsideHSize($pValue = null) { * Border Right Color
$this->_borderInsideHSize = $pValue; *
} * @var string
*/
public function getBorderInsideHSize() { private $_borderRightColor;
return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
} /**
* Border Bottom Size
public function setBorderInsideVSize($pValue = null) { *
$this->_borderInsideVSize = $pValue; * @var int
} */
private $_borderBottomSize;
public function getBorderInsideVSize() {
return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null; /**
} * Border Bottom Color
*
public function setCellMarginTop($pValue = null) { * @var string
$this->_cellMarginTop = $pValue; */
} private $_borderBottomColor;
public function getCellMarginTop() { /**
return $this->_cellMarginTop; * Border InsideH Size
} *
* @var int
public function setCellMarginLeft($pValue = null) { */
$this->_cellMarginLeft = $pValue; private $_borderInsideHSize;
}
/**
public function getCellMarginLeft() { * Border InsideH Color
return $this->_cellMarginLeft; *
} * @var string
*/
public function setCellMarginRight($pValue = null) { private $_borderInsideHColor;
$this->_cellMarginRight = $pValue;
} /**
* Border InsideV Size
public function getCellMarginRight() { *
return $this->_cellMarginRight; * @var int
} */
private $_borderInsideVSize;
public function setCellMarginBottom($pValue = null) {
$this->_cellMarginBottom = $pValue; /**
} * Border InsideV Color
*
public function getCellMarginBottom() { * @var string
return $this->_cellMarginBottom; */
} private $_borderInsideVColor;
public function setCellMargin($pValue = null) {
$this->_cellMarginTop = $pValue; /**
$this->_cellMarginLeft = $pValue; * Create a new TableFull Font
$this->_cellMarginRight = $pValue; */
$this->_cellMarginBottom = $pValue; public function __construct($styleTable = null, $styleFirstRow = null, $styleLastRow = null)
} {
public function getCellMargin() { if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom); $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);
}
}
}
/**
* Set style 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 PHPWord_Style_TableFull
*/
public function getFirstRow()
{
return $this->_firstRow;
}
/**
* Get Last Row Style
*
* @return 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
*/
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;
}
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

@ -33,123 +33,128 @@
* @package PHPWord_TOC * @package PHPWord_TOC
* @copyright Copyright (c) 2011 PHPWord * @copyright Copyright (c) 2011 PHPWord
*/ */
class PHPWord_TOC { class PHPWord_TOC
{
/**
* Title Elements /**
* * Title Elements
* @var array *
*/ * @var array
private static $_titles = array(); */
private static $_titles = array();
/**
* TOC Style /**
* * TOC Style
* @var array *
*/ * @var array
private static $_styleTOC; */
private static $_styleTOC;
/**
* Font Style /**
* * Font Style
* @var array *
*/ * @var array
private static $_styleFont; */
private static $_styleFont;
/**
* Title Anchor /**
* * Title Anchor
* @var array *
*/ * @var array
private static $_anchor = 252634154; */
private static $_anchor = 252634154;
/**
* Title Bookmark /**
* * Title Bookmark
* @var array *
*/ * @var array
private static $_bookmarkId = 0; */
private static $_bookmarkId = 0;
/**
* Create a new Table-of-Contents Element /**
* * Create a new Table-of-Contents Element
* @param array $styleFont *
* @param array $styleTOC * @param array $styleFont
*/ * @param array $styleTOC
public function __construct($styleFont = null, $styleTOC = null) { */
self::$_styleTOC = new PHPWord_Style_TOC(); public function __construct($styleFont = null, $styleTOC = null)
{
if(!is_null($styleTOC) && is_array($styleTOC)) { self::$_styleTOC = new PHPWord_Style_TOC();
foreach($styleTOC as $key => $value) {
if(substr($key, 0, 1) != '_') { if (!is_null($styleTOC) && is_array($styleTOC)) {
$key = '_'.$key; foreach ($styleTOC as $key => $value) {
} if (substr($key, 0, 1) != '_') {
self::$_styleTOC->setStyleValue($key, $value); $key = '_' . $key;
} }
} self::$_styleTOC->setStyleValue($key, $value);
}
if(!is_null($styleFont)) { }
if(is_array($styleFont)) {
self::$_styleFont = new PHPWord_Style_Font(); if (!is_null($styleFont)) {
if (is_array($styleFont)) {
foreach($styleFont as $key => $value) { self::$_styleFont = new PHPWord_Style_Font();
if(substr($key, 0, 1) != '_') {
$key = '_'.$key; foreach ($styleFont as $key => $value) {
} if (substr($key, 0, 1) != '_') {
self::$_styleFont->setStyleValue($key, $value); $key = '_' . $key;
} }
} else { self::$_styleFont->setStyleValue($key, $value);
self::$_styleFont = $styleFont; }
} } else {
} self::$_styleFont = $styleFont;
} }
}
/** }
* Add a Title
* /**
* @return array * Add a Title
*/ *
public static function addTitle($text, $depth = 0) { * @return array
$anchor = '_Toc'.++self::$_anchor; */
$bookmarkId = self::$_bookmarkId++; public static function addTitle($text, $depth = 0)
{
$title = array(); $anchor = '_Toc' . ++self::$_anchor;
$title['text'] = $text; $bookmarkId = self::$_bookmarkId++;
$title['depth'] = $depth;
$title['anchor'] = $anchor; $title = array();
$title['bookmarkId'] = $bookmarkId; $title['text'] = $text;
$title['depth'] = $depth;
self::$_titles[] = $title; $title['anchor'] = $anchor;
$title['bookmarkId'] = $bookmarkId;
return array($anchor, $bookmarkId);
} self::$_titles[] = $title;
/** return array($anchor, $bookmarkId);
* Get all titles }
*
* @return array /**
*/ * Get all titles
public static function getTitles() { *
return self::$_titles; * @return array
} */
public static function getTitles()
/** {
* Get TOC Style return self::$_titles;
* }
* @return PHPWord_Style_TOC
*/ /**
public static function getStyleTOC() { * Get TOC Style
return self::$_styleTOC; *
} * @return PHPWord_Style_TOC
*/
/** public static function getStyleTOC()
* Get Font Style {
* return self::$_styleTOC;
* @return PHPWord_Style_Font }
*/
public static function getStyleFont() { /**
return self::$_styleFont; * Get Font Style
} *
} * @return PHPWord_Style_Font
?> */
public static function getStyleFont()
{
return self::$_styleFont;
}
}

View File

@ -33,64 +33,68 @@
* @package PHPWord * @package PHPWord
* @copyright Copyright (c) 2009 - 2011 PHPWord (http://www.codeplex.com/PHPWord) * @copyright Copyright (c) 2009 - 2011 PHPWord (http://www.codeplex.com/PHPWord)
*/ */
class PHPWord_Template { class PHPWord_Template
{
/** /**
* ZipArchive * ZipArchive
* *
* @var ZipArchive * @var ZipArchive
*/ */
private $_objZip; private $_objZip;
/** /**
* Temporary Filename * Temporary Filename
* *
* @var string * @var string
*/ */
private $_tempFileName; private $_tempFileName;
/** /**
* Document XML * Document XML
* *
* @var string * @var string
*/ */
private $_documentXML; private $_documentXML;
/** /**
* Create a new Template Object * Create a new Template Object
* *
* @param string $strFilename * @param string $strFilename
*/ */
public function __construct($strFilename) { public function __construct($strFilename)
{
$path = dirname($strFilename); $path = dirname($strFilename);
$this->_tempFileName = $path.DIRECTORY_SEPARATOR.time().'.docx'; $this->_tempFileName = $path . DIRECTORY_SEPARATOR . time() . '.docx';
copy($strFilename, $this->_tempFileName); // Copy the source File to the temp File copy($strFilename, $this->_tempFileName); // Copy the source File to the temp File
$this->_objZip = new ZipArchive(); $this->_objZip = new ZipArchive();
$this->_objZip->open($this->_tempFileName); $this->_objZip->open($this->_tempFileName);
$this->_documentXML = $this->_objZip->getFromName('word/document.xml'); $this->_documentXML = $this->_objZip->getFromName('word/document.xml');
} }
/** /**
* Set a Template value * Set a Template value
* *
* @param mixed $search * @param mixed $search
* @param mixed $replace * @param mixed $replace
*/ */
public function setValue($search, $replace) { public function setValue($search, $replace)
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { {
$search = '${'.$search.'}'; if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${' . $search . '}';
} }
if(!is_array($replace)) { if (!is_array($replace)) {
$replace = utf8_encode($replace); $replace = utf8_encode($replace);
} }
$this->_documentXML = str_replace($search, $replace, $this->_documentXML); $this->_documentXML = str_replace($search, $replace, $this->_documentXML);
} }
/** /**
* Returns array of all variables in template * Returns array of all variables in template
*/ */
@ -99,24 +103,25 @@ class PHPWord_Template {
preg_match_all('/\$\{(.*?)}/i', $this->_documentXML, $matches); preg_match_all('/\$\{(.*?)}/i', $this->_documentXML, $matches);
return $matches[1]; return $matches[1];
} }
/** /**
* Save Template * Save Template
* *
* @param string $strFilename * @param string $strFilename
*/ */
public function save($strFilename) { public function save($strFilename)
if(file_exists($strFilename)) { {
if (file_exists($strFilename)) {
unlink($strFilename); unlink($strFilename);
} }
$this->_objZip->addFromString('word/document.xml', $this->_documentXML); $this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file // Close zip file
if($this->_objZip->close() === false) { if ($this->_objZip->close() === false) {
throw new Exception('Could not close zip file.'); throw new Exception('Could not close zip file.');
} }
rename($this->_tempFileName, $strFilename); rename($this->_tempFileName, $strFilename);
} }
} }
?>

View File

@ -28,12 +28,11 @@
interface PHPWord_Writer_IWriter interface PHPWord_Writer_IWriter
{ {
/** /**
* Save PHPWord to file * Save PHPWord to file
* *
* @param string $pFileName * @param string $pFileName
* @throws Exception * @throws Exception
*/ */
public function save($pFilename = null); public function save($pFilename = null);
} }
?>

View File

@ -27,254 +27,261 @@
class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter
{ {
/** /**
* Private PHPWord * Private PHPWord
* *
* @var PHPWord * @var PHPWord
*/ */
private $_document; private $_document;
/**
* Private writer parts
*
* @var PHPWord_Writer_ODText_WriterPart[]
*/
private $_writerParts;
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var PHPWord_HashTable
*/
private $_drawingHashTable;
/**
* Use disk caching where possible?
*
* @var boolean
*/
private $_useDiskCaching = false;
/**
* Disk caching directory
*
* @var string
*/
private $_diskCachingDirectory;
/**
* Create a new PHPWord_Writer_ODText
*
* @param PHPWord $pPHPWord
*/
public function __construct(PHPWord $pPHPWord = null)
{
// Assign PHPWord
$this->setPHPWord($pPHPWord);
// Set up disk caching location
$this->_diskCachingDirectory = './';
// Initialise writer parts
$this->_writerParts['content'] = new PHPWord_Writer_ODText_Content();
$this->_writerParts['manifest'] = new PHPWord_Writer_ODText_Manifest();
$this->_writerParts['meta'] = new PHPWord_Writer_ODText_Meta();
$this->_writerParts['mimetype'] = new PHPWord_Writer_ODText_Mimetype();
$this->_writerParts['styles'] = new PHPWord_Writer_ODText_Styles();
// Assign parent IWriter
foreach ($this->_writerParts as $writer) {
$writer->setParentWriter($this);
}
// Set HashTable variables
$this->_drawingHashTable = new PHPWord_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)); * Private writer parts
*
// Add styles.xml to ZIP file * @var PHPWord_Writer_ODText_WriterPart[]
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document)); */
private $_writerParts;
// Add META-INF/manifest.xml
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_document));
// Add media
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);
} else if ($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);
}
}
// 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) { * Private unique PHPWord_Worksheet_BaseDrawing HashTable
if (copy($pFilename, $originalFilename) === false) { *
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename."); * @var PHPWord_HashTable
} */
@unlink($pFilename); private $_drawingHashTable;
}
/**
} else { * Use disk caching where possible?
throw new Exception("PHPWord object unassigned."); *
} * @var boolean
} */
private $_useDiskCaching = false;
/**
* Get PHPWord object /**
* * Disk caching directory
* @return PHPWord *
* @throws Exception * @var string
*/ */
public function getPHPWord() { private $_diskCachingDirectory;
if (!is_null($this->_document)) {
return $this->_document; /**
} else { * Create a new PHPWord_Writer_ODText
throw new Exception("No PHPWord assigned."); *
} * @param PHPWord $pPHPWord
} */
public function __construct(PHPWord $pPHPWord = null)
/** {
* Get PHPWord object // Assign PHPWord
* $this->setPHPWord($pPHPWord);
* @param PHPWord $pPHPWord PHPWord object
* @throws Exception // Set up disk caching location
* @return PHPWord_Writer_PowerPoint2007 $this->_diskCachingDirectory = './';
*/
public function setPHPWord(PHPWord $pPHPWord = null) { // Initialise writer parts
$this->_document = $pPHPWord; $this->_writerParts['content'] = new PHPWord_Writer_ODText_Content();
return $this; $this->_writerParts['manifest'] = new PHPWord_Writer_ODText_Manifest();
} $this->_writerParts['meta'] = new PHPWord_Writer_ODText_Meta();
$this->_writerParts['mimetype'] = new PHPWord_Writer_ODText_Mimetype();
/** $this->_writerParts['styles'] = new PHPWord_Writer_ODText_Styles();
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return PHPWord_HashTable // Assign parent IWriter
*/ foreach ($this->_writerParts as $writer) {
public function getDrawingHashTable() { $writer->setParentWriter($this);
return $this->_drawingHashTable; }
}
// Set HashTable variables
/** $this->_drawingHashTable = new PHPWord_HashTable();
* Get writer part }
*
* @param string $pPartName Writer part name /**
* @return PHPWord_Writer_ODText_WriterPart * Save PHPWord to file
*/ *
function getWriterPart($pPartName = '') { * @param string $pFileName
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) { * @throws Exception
return $this->_writerParts[strtolower($pPartName)]; */
} else { public function save($pFilename = null)
return 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') {
* Get use disk caching where possible? $pFilename = @tempnam('./', 'phppttmp');
* if ($pFilename == '') {
* @return boolean $pFilename = $originalFilename;
*/ }
public function getUseDiskCaching() { }
return $this->_useDiskCaching;
} // Create drawing dictionary
/** // Create new ZIP file and open it for writing
* Set use disk caching where possible? $objZip = new ZipArchive();
*
* @param boolean $pValue // Try opening the ZIP file
* @param string $pDirectory Disk caching directory if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
* @throws Exception Exception when directory does not exist if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
* @return PHPWord_Writer_PowerPoint2007 throw new Exception("Could not open " . $pFilename . " for writing.");
*/ }
public function setUseDiskCaching($pValue = false, $pDirectory = null) { }
$this->_useDiskCaching = $pValue;
// Add mimetype to ZIP file
if (!is_null($pDirectory)) { //@todo Not in ZIPARCHIVE::CM_STORE mode
if (is_dir($pDirectory)) { $objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype($this->_document));
$this->_diskCachingDirectory = $pDirectory;
} else { // Add content.xml to ZIP file
throw new Exception("Directory does not exist: $pDirectory"); $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));
return $this;
} // Add styles.xml to ZIP file
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document));
/**
* Get disk caching directory // Add META-INF/manifest.xml
* $objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_document));
* @return string
*/ // Add media
public function getDiskCachingDirectory() { for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
return $this->_diskCachingDirectory; 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);
} else if ($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);
}
}
// 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.");
}
}
/**
* Get PHPWord object
*
* @return PHPWord
* @throws Exception
*/
public function getPHPWord()
{
if (!is_null($this->_document)) {
return $this->_document;
} else {
throw new Exception("No PHPWord assigned.");
}
}
/**
* Get PHPWord object
*
* @param PHPWord $pPHPWord PHPWord object
* @throws Exception
* @return PHPWord_Writer_PowerPoint2007
*/
public function setPHPWord(PHPWord $pPHPWord = null)
{
$this->_document = $pPHPWord;
return $this;
}
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return PHPWord_HashTable
*/
public function getDrawingHashTable()
{
return $this->_drawingHashTable;
}
/**
* Get writer part
*
* @param string $pPartName Writer part name
* @return PHPWord_Writer_ODText_WriterPart
*/
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 PHPWord_Writer_PowerPoint2007
*/
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;
}
/**
* Get disk caching directory
*
* @return string
*/
public function getDiskCachingDirectory()
{
return $this->_diskCachingDirectory;
}
} }

View File

@ -35,234 +35,234 @@
*/ */
class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
{ {
/** /**
* Write content file to XML format * Write content file to XML format
* *
* @param PHPWord $pPHPWord * @param PHPWord $pPHPWord
* @return string XML Output * @return string XML Output
* @throws Exception * @throws Exception
*/ */
public function writeContent(PHPWord $pPHPWord = null) public function writeContent(PHPWord $pPHPWord = null)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0','UTF-8'); $objWriter->startDocument('1.0', 'UTF-8');
// office:document-content // office:document-content
$objWriter->startElement('office:document-content'); $objWriter->startElement('office:document-content');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
$objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2'); $objWriter->writeAttribute('office:version', '1.2');
// We firstly search all fonts used
$_sections = $pPHPWord->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 PHPWord_Section_Text) {
$fStyle = $element->getFontStyle();
$pStyle = $element->getParagraphStyle();
if($fStyle instanceof PHPWord_Style_Font){
$numFStyles++;
$arrStyle = array(
'color'=>$fStyle->getColor(),
'name' =>$fStyle->getName()
);
$pPHPWord->addFontStyle('T'.$numFStyles, $arrStyle);
$element->setFontStyle('T'.$numFStyles);
}
elseif($pStyle instanceof PHPWord_Style_Paragraph){
$numPStyles++;
$pPHPWord->addParagraphStyle('P'.$numPStyles, array());
$element->setParagraph('P'.$numPStyles);
}
}
}
}
}
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = PHPWord_Style::getStyles();
$numFonts = 0;
if(count($styles) > 0) {
foreach($styles as $styleName => $style) {
// PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) {
$numFonts++;
$name = $style->getName();
if(!in_array($name, $arrFonts)){
$arrFonts[] = $name;
// style:font-face // We firstly search all fonts used
$objWriter->startElement('style:font-face'); $_sections = $pPHPWord->getSections();
$objWriter->writeAttribute('style:name', $name); $countSections = count($_sections);
$objWriter->writeAttribute('svg:font-family', $name); if ($countSections > 0) {
$objWriter->endElement(); $pSection = 0;
} $numPStyles = 0;
} $numFStyles = 0;
}
if(!in_array('Arial', $arrFonts)){ foreach ($_sections as $section) {
$objWriter->startElement('style:font-face'); $pSection++;
$objWriter->writeAttribute('style:name', 'Arial'); $_elements = $section->getElements();
$objWriter->writeAttribute('svg:font-family', 'Arial');
$objWriter->endElement(); foreach ($_elements as $element) {
} if ($element instanceof PHPWord_Section_Text) {
} $fStyle = $element->getFontStyle();
$objWriter->endElement(); $pStyle = $element->getParagraphStyle();
$objWriter->startElement('office:automatic-styles'); if ($fStyle instanceof PHPWord_Style_Font) {
$styles = PHPWord_Style::getStyles(); $numFStyles++;
$numPStyles = 0;
if(count($styles) > 0) { $arrStyle = array(
foreach($styles as $styleName => $style) { 'color' => $fStyle->getColor(),
if(preg_match('#^T[0-9]+$#', $styleName) != 0 'name' => $fStyle->getName()
|| preg_match('#^P[0-9]+$#', $styleName) != 0){ );
// PHPWord_Style_Font $pPHPWord->addFontStyle('T' . $numFStyles, $arrStyle);
if($style instanceof PHPWord_Style_Font) { $element->setFontStyle('T' . $numFStyles);
$objWriter->startElement('style:style'); } elseif ($pStyle instanceof PHPWord_Style_Paragraph) {
$objWriter->writeAttribute('style:name', $styleName); $numPStyles++;
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties $pPHPWord->addParagraphStyle('P' . $numPStyles, array());
$objWriter->startElement('style:text-properties'); $element->setParagraph('P' . $numPStyles);
$objWriter->writeAttribute('fo:color', '#'.$style->getColor()); }
$objWriter->writeAttribute('style:font-name', $style->getName()); }
$objWriter->writeAttribute('style:font-name-complex', $style->getName()); }
$objWriter->endElement(); }
$objWriter->endElement(); }
}
if($style instanceof PHPWord_Style_Paragraph){ // office:font-face-decls
$numPStyles++; $objWriter->startElement('office:font-face-decls');
// style:style $arrFonts = array();
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName); $styles = PHPWord_Style::getStyles();
$objWriter->writeAttribute('style:family', 'paragraph'); $numFonts = 0;
$objWriter->writeAttribute('style:parent-style-name', 'Standard'); if (count($styles) > 0) {
$objWriter->writeAttribute('style:master-page-name', 'Standard'); foreach ($styles as $styleName => $style) {
// style:paragraph-properties // PHPWord_Style_Font
$objWriter->startElement('style:paragraph-properties'); if ($style instanceof PHPWord_Style_Font) {
$objWriter->writeAttribute('style:page-number', 'auto'); $numFonts++;
$objWriter->endElement(); $name = $style->getName();
$objWriter->endElement(); if (!in_array($name, $arrFonts)) {
} $arrFonts[] = $name;
}
} // style:font-face
$objWriter->startElement('style:font-face');
if($numPStyles == 0){ $objWriter->writeAttribute('style:name', $name);
// style:style $objWriter->writeAttribute('svg:font-family', $name);
$objWriter->startElement('style:style'); $objWriter->endElement();
$objWriter->writeAttribute('style:name', 'P1'); }
$objWriter->writeAttribute('style:family', 'paragraph'); }
$objWriter->writeAttribute('style:parent-style-name', 'Standard'); }
$objWriter->writeAttribute('style:master-page-name', 'Standard'); if (!in_array('Arial', $arrFonts)) {
// style:paragraph-properties $objWriter->startElement('style:font-face');
$objWriter->startElement('style:paragraph-properties'); $objWriter->writeAttribute('style:name', 'Arial');
$objWriter->writeAttribute('style:page-number', 'auto'); $objWriter->writeAttribute('svg:font-family', 'Arial');
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); }
} }
} $objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('office:automatic-styles');
// office:body $styles = PHPWord_Style::getStyles();
$objWriter->startElement('office:body'); $numPStyles = 0;
// office:text if (count($styles) > 0) {
$objWriter->startElement('office:text'); foreach ($styles as $styleName => $style) {
// text:sequence-decls if (preg_match('#^T[0-9]+$#', $styleName) != 0
$objWriter->startElement('text:sequence-decls'); || preg_match('#^P[0-9]+$#', $styleName) != 0
// text:sequence-decl ) {
$objWriter->startElement('text:sequence-decl'); // PHPWord_Style_Font
$objWriter->writeAttribute('text:display-outline-level', 0); if ($style instanceof PHPWord_Style_Font) {
$objWriter->writeAttribute('text:name', 'Illustration'); $objWriter->startElement('style:style');
$objWriter->endElement(); $objWriter->writeAttribute('style:name', $styleName);
// text:sequence-decl $objWriter->writeAttribute('style:family', 'text');
$objWriter->startElement('text:sequence-decl'); // style:text-properties
$objWriter->writeAttribute('text:display-outline-level', 0); $objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('text:name', 'Table'); $objWriter->writeAttribute('fo:color', '#' . $style->getColor());
$objWriter->endElement(); $objWriter->writeAttribute('style:font-name', $style->getName());
// text:sequence-decl $objWriter->writeAttribute('style:font-name-complex', $style->getName());
$objWriter->startElement('text:sequence-decl'); $objWriter->endElement();
$objWriter->writeAttribute('text:display-outline-level', 0); $objWriter->endElement();
$objWriter->writeAttribute('text:name', 'Text'); }
$objWriter->endElement(); if ($style instanceof PHPWord_Style_Paragraph) {
// text:sequence-decl $numPStyles++;
$objWriter->startElement('text:sequence-decl'); // style:style
$objWriter->writeAttribute('text:display-outline-level', 0); $objWriter->startElement('style:style');
$objWriter->writeAttribute('text:name', 'Drawing'); $objWriter->writeAttribute('style:name', $styleName);
$objWriter->endElement(); $objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->endElement(); $objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
$_sections = $pPHPWord->getSections(); // style:paragraph-properties
$countSections = count($_sections); $objWriter->startElement('style:paragraph-properties');
$pSection = 0; $objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
if($countSections > 0) { $objWriter->endElement();
foreach($_sections as $section) { }
$pSection++; }
}
$_elements = $section->getElements();
if ($numPStyles == 0) {
foreach($_elements as $element) { // style:style
if($element instanceof PHPWord_Section_Text) { $objWriter->startElement('style:style');
$this->_writeText($objWriter, $element); $objWriter->writeAttribute('style:name', 'P1');
}/* elseif($element instanceof PHPWord_Section_TextRun) { $objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
$objWriter->endElement();
}
}
$objWriter->endElement();
// office:body
$objWriter->startElement('office:body');
// office:text
$objWriter->startElement('office:text');
// text:sequence-decls
$objWriter->startElement('text:sequence-decls');
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Illustration');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Table');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Text');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Drawing');
$objWriter->endElement();
$objWriter->endElement();
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} /* elseif($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element); $this->_writeTextRun($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Link) { } elseif($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element); $this->_writeLink($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Title) { } elseif($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element); $this->_writeTitle($objWriter, $element);
}*/ elseif($element instanceof PHPWord_Section_TextBreak) { }*/ elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter); $this->_writeTextBreak($objWriter);
}/* elseif($element instanceof PHPWord_Section_PageBreak) { } /* elseif($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter); $this->_writePageBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Table) { } elseif($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element); $this->_writeTable($objWriter, $element);
@ -276,70 +276,71 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
} elseif($element instanceof PHPWord_TOC) { } elseif($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter); $this->_writeTOC($objWriter);
}*/ }*/
else { else {
print_r($element); print_r($element);
echo '<br />'; echo '<br />';
} }
} }
if($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
}
}
}
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// Return if ($pSection == $countSections) {
return $objWriter->getData(); $this->_writeEndSection($objWriter, $section);
} } else {
$this->_writeSection($objWriter, $section);
protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { }
$styleFont = $text->getFontStyle(); }
$styleParagraph = $text->getParagraphStyle(); }
$objWriter->endElement();
$SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; $objWriter->endElement();
$objWriter->endElement();
if($SfIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared // Return
die('PHPWord : $SfIsObject wouldn\'t be an object'); return $objWriter->getData();
} }
else {
// text:p protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false)
$objWriter->startElement('text:p'); {
if(empty($styleFont)){ $styleFont = $text->getFontStyle();
if(empty($styleParagraph)){ $styleParagraph = $text->getParagraphStyle();
$objWriter->writeAttribute('text:style-name', 'P1');
} $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
else {
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); if ($SfIsObject) {
} // Don't never be the case, because I browse all sections for cleaning all styles not declared
$objWriter->writeRaw($text->getText()); die('PHPWord : $SfIsObject wouldn\'t be an object');
} } else {
else { // text:p
if(empty($styleParagraph)){ $objWriter->startElement('text:p');
$objWriter->writeAttribute('text:style-name', 'Standard'); if (empty($styleFont)) {
} if (empty($styleParagraph)) {
else { $objWriter->writeAttribute('text:style-name', 'P1');
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); } else {
} $objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
// text:span }
$objWriter->startElement('text:span'); $objWriter->writeRaw($text->getText());
$objWriter->writeAttribute('text:style-name', $styleFont); } else {
$objWriter->writeRaw($text->getText()); if (empty($styleParagraph)) {
$objWriter->endElement(); $objWriter->writeAttribute('text:style-name', 'Standard');
} } else {
$objWriter->endElement(); $objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
} }
} // text:span
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) { $objWriter->startElement('text:span');
$objWriter->startElement('text:p'); $objWriter->writeAttribute('text:style-name', $styleFont);
$objWriter->writeAttribute('text:style-name', 'Standard'); $objWriter->writeRaw($text->getText());
$objWriter->endElement(); $objWriter->endElement();
} }
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) { $objWriter->endElement();
} }
}
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null)
{
$objWriter->startElement('text:p');
$objWriter->writeAttribute('text:style-name', 'Standard');
$objWriter->endElement();
}
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
{
}
} }

View File

@ -35,97 +35,97 @@
*/ */
class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart
{ {
/** /**
* Write Manifest file to XML format * Write Manifest file to XML format
* *
* @param PHPWord $pPHPWord * @param PHPWord $pPHPWord
* @return string XML Output * @return string XML Output
* @throws Exception * @throws Exception
*/ */
public function writeManifest(PHPWord $pPHPWord = null) public function writeManifest(PHPWord $pPHPWord = null)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0','UTF-8'); $objWriter->startDocument('1.0', 'UTF-8');
// manifest:manifest // manifest:manifest
$objWriter->startElement('manifest:manifest'); $objWriter->startElement('manifest:manifest');
$objWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'); $objWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
$objWriter->writeAttribute('manifest:version', '1.2'); $objWriter->writeAttribute('manifest:version', '1.2');
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
$objWriter->writeAttribute('manifest:version', '1.2');
$objWriter->writeAttribute('manifest:full-path', '/');
$objWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'content.xml');
$objWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'meta.xml');
$objWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'styles.xml');
$objWriter->endElement();
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() );
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', $mimeType);
$objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$objWriter->endElement();
} else if ($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();
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', $mimeType);
$objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$objWriter->endElement();
}
}
$objWriter->endElement();
// Return // manifest:file-entry
return $objWriter->getData(); $objWriter->startElement('manifest:file-entry');
} $objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text');
$objWriter->writeAttribute('manifest:version', '1.2');
$objWriter->writeAttribute('manifest:full-path', '/');
$objWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'content.xml');
$objWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'meta.xml');
$objWriter->endElement();
// manifest:file-entry
$objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', 'text/xml');
$objWriter->writeAttribute('manifest:full-path', 'styles.xml');
$objWriter->endElement();
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
/** if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
* Get image mime type $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
* $mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
* @param string $pFile Filename
* @return string Mime Type $objWriter->startElement('manifest:file-entry');
* @throws Exception $objWriter->writeAttribute('manifest:media-type', $mimeType);
*/ $objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
private function _getImageMimeType($pFile = '') $objWriter->endElement();
{ } else if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
if (PHPWord_Shared_File::file_exists($pFile)) { $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
$image = getimagesize($pFile); $extension = explode('/', $extension);
return image_type_to_mime_type($image[2]); $extension = $extension[1];
} else {
throw new Exception("File $pFile does not exist"); $mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType();
}
} $objWriter->startElement('manifest:file-entry');
$objWriter->writeAttribute('manifest:media-type', $mimeType);
$objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$objWriter->endElement();
}
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws Exception
*/
private function _getImageMimeType($pFile = '')
{
if (PHPWord_Shared_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

@ -35,64 +35,65 @@
*/ */
class PHPWord_Writer_ODText_Meta extends PHPWord_Writer_ODText_WriterPart class PHPWord_Writer_ODText_Meta extends PHPWord_Writer_ODText_WriterPart
{ {
/** /**
* Write Meta file to XML format * Write Meta file to XML format
* *
* @param PHPWord $pPHPWord * @param PHPWord $pPHPWord
* @return string XML Output * @return string XML Output
* @throws Exception * @throws Exception
*/ */
public function writeMeta(PHPWord $pPHPWord = null) { public function writeMeta(PHPWord $pPHPWord = null)
// Create XML writer {
$objWriter = null; // Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = null;
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); if ($this->getParentWriter()->getUseDiskCaching()) {
} else { $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); } else {
} $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header // XML header
$objWriter->startDocument('1.0','UTF-8'); $objWriter->startDocument('1.0', 'UTF-8');
// office:document-meta // office:document-meta
$objWriter->startElement('office:document-meta'); $objWriter->startElement('office:document-meta');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('office:version', '1.2'); $objWriter->writeAttribute('office:version', '1.2');
// office:meta
$objWriter->startElement('office:meta');
// dc:creator
$objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getLastModifiedBy());
// dc:date
$objWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000' ,$pPHPWord->getProperties()->getModified()));
// dc:description
$objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
// dc:subject
$objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
// dc:title
$objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
// meta:creation-date
$objWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000' ,$pPHPWord->getProperties()->getCreated()));
// meta:initial-creator
$objWriter->writeElement('meta:initial-creator', $pPHPWord->getProperties()->getCreator());
// meta:keyword
$objWriter->writeElement('meta:keyword', $pPHPWord->getProperties()->getKeywords());
// @todo : Where these properties are written ?
// $pPHPWord->getProperties()->getCategory()
// $pPHPWord->getProperties()->getCompany()
$objWriter->endElement();
$objWriter->endElement();
// Return // office:meta
return $objWriter->getData(); $objWriter->startElement('office:meta');
}
// dc:creator
$objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getLastModifiedBy());
// dc:date
$objWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getModified()));
// dc:description
$objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
// dc:subject
$objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
// dc:title
$objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
// meta:creation-date
$objWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getCreated()));
// meta:initial-creator
$objWriter->writeElement('meta:initial-creator', $pPHPWord->getProperties()->getCreator());
// meta:keyword
$objWriter->writeElement('meta:keyword', $pPHPWord->getProperties()->getKeywords());
// @todo : Where these properties are written ?
// $pPHPWord->getProperties()->getCategory()
// $pPHPWord->getProperties()->getCompany()
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->getData();
}
} }

View File

@ -35,17 +35,17 @@
*/ */
class PHPWord_Writer_ODText_Mimetype extends PHPWord_Writer_ODText_WriterPart class PHPWord_Writer_ODText_Mimetype extends PHPWord_Writer_ODText_WriterPart
{ {
/** /**
* Write Mimetype to Text format * Write Mimetype to Text format
* *
* @param PHPWord $pPHPWord * @param PHPWord $pPHPWord
* @return string Text Output * @return string Text Output
* @throws Exception * @throws Exception
*/ */
public function writeMimetype(PHPWord $pPHPWord = null) public function writeMimetype(PHPWord $pPHPWord = null)
{ {
return 'application/vnd.oasis.opendocument.text'; return 'application/vnd.oasis.opendocument.text';
} }
} }

View File

@ -35,240 +35,239 @@
*/ */
class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
{ {
/** /**
* Write Styles file to XML format * Write Styles file to XML format
* *
* @param PHPWord $pPHPWord * @param PHPWord $pPHPWord
* @return string XML Output * @return string XML Output
* @throws Exception * @throws Exception
*/ */
public function writeStyles(PHPWord $pPHPWord = null) public function writeStyles(PHPWord $pPHPWord = null)
{ {
// Create XML writer // Create XML writer
$objWriter = null; $objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) { if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else { } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
} }
// XML header // XML header
$objWriter->startDocument('1.0','UTF-8'); $objWriter->startDocument('1.0', 'UTF-8');
// Styles:Styles // Styles:Styles
$objWriter->startElement('office:document-styles'); $objWriter->startElement('office:document-styles');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2'); $objWriter->writeAttribute('office:version', '1.2');
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = PHPWord_Style::getStyles();
$numFonts = 0;
if(count($styles) > 0) {
foreach($styles as $styleName => $style) {
// PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) {
$numFonts++;
$name = $style->getName();
if(!in_array($name, $arrFonts)){
$arrFonts[] = $name;
// style:font-face
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
}
}
}
}
if(!in_array('Arial', $arrFonts)){
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', 'Arial');
$objWriter->writeAttribute('svg:font-family', 'Arial');
$objWriter->endElement();
}
$objWriter->endElement();
// office:styles
$objWriter->startElement('office:styles');
// style:default-style
$objWriter->startElement('style:default-style');
$objWriter->writeAttribute('style:family', 'paragraph');
// style:paragraph-properties // office:font-face-decls
$objWriter->startElement('style:paragraph-properties'); $objWriter->startElement('office:font-face-decls');
$objWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit'); $arrFonts = array();
$objWriter->writeAttribute('style:text-autospace', 'ideograph-alpha'); $styles = PHPWord_Style::getStyles();
$objWriter->writeAttribute('style:punctuation-wrap', 'hanging'); $numFonts = 0;
$objWriter->writeAttribute('style:line-break', 'strict'); if (count($styles) > 0) {
$objWriter->writeAttribute('style:tab-stop-distance', '1.249cm'); foreach ($styles as $styleName => $style) {
$objWriter->writeAttribute('style:writing-mode', 'page'); // PHPWord_Style_Font
$objWriter->endElement(); if ($style instanceof PHPWord_Style_Font) {
$numFonts++;
// style:text-properties $name = $style->getName();
$objWriter->startElement('style:text-properties'); if (!in_array($name, $arrFonts)) {
$objWriter->writeAttribute('style:use-window-font-color', 'true'); $arrFonts[] = $name;
$objWriter->writeAttribute('style:font-name', 'Arial');
$objWriter->writeAttribute('fo:font-size', '10pt');
$objWriter->writeAttribute('fo:language', 'fr');
$objWriter->writeAttribute('fo:country', 'FR');
$objWriter->writeAttribute('style:letter-kerning', 'true');
$objWriter->writeAttribute('style:font-name-asian', 'Arial2');
$objWriter->writeAttribute('style:font-size-asian', '10pt');
$objWriter->writeAttribute('style:language-asian', 'zh');
$objWriter->writeAttribute('style:country-asian', 'CN');
$objWriter->writeAttribute('style:font-name-complex', 'Arial2');
$objWriter->writeAttribute('style:font-size-complex', '10pt');
$objWriter->writeAttribute('style:language-complex', 'hi');
$objWriter->writeAttribute('style:country-complex', 'IN');
$objWriter->writeAttribute('fo:hyphenate', 'false');
$objWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
$objWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
$objWriter->endElement();
$objWriter->endElement();
// Write Style Definitions
$styles = PHPWord_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){
// PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:font-size', ($style->getSize() / 2).'pt');
$objWriter->writeAttribute('style:font-size-asian', ($style->getSize() / 2).'pt');
$objWriter->writeAttribute('style:font-size-complex', ($style->getSize() / 2).'pt');
if($style->getItalic()) {
$objWriter->writeAttribute('fo:font-style', 'italic');
$objWriter->writeAttribute('style:font-style-asian', 'italic');
$objWriter->writeAttribute('style:font-style-complex', 'italic');
}
if($style->getBold()) {
$objWriter->writeAttribute('fo:font-weight', 'bold');
$objWriter->writeAttribute('style:font-weight-asian', 'bold');
}
$objWriter->endElement();
$objWriter->endElement();
}
// PHPWord_Style_Paragraph
elseif($style instanceof PHPWord_Style_Paragraph) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
//style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)).'cm');
$objWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)).'cm');
$objWriter->writeAttribute('fo:text-align', $style->getAlign());
$objWriter->endElement();
$objWriter->endElement();
}
// PHPWord_Style_TableFull
elseif($style instanceof PHPWord_Style_TableFull) {
}
}
}
}
$objWriter->endElement();
// office:automatic-styles
$objWriter->startElement('office:automatic-styles');
// style:page-layout
$objWriter->startElement('style:page-layout');
$objWriter->writeAttribute('style:name', 'Mpm1');
// style:page-layout-properties
$objWriter->startElement('style:page-layout-properties');
$objWriter->writeAttribute('fo:page-width', "21.001cm");
$objWriter->writeAttribute('fo:page-height','29.7cm');
$objWriter->writeAttribute('style:num-format','1');
$objWriter->writeAttribute('style:print-orientation','portrait');
$objWriter->writeAttribute('fo:margin-top','2.501cm');
$objWriter->writeAttribute('fo:margin-bottom','2cm');
$objWriter->writeAttribute('fo:margin-left','2.501cm');
$objWriter->writeAttribute('fo:margin-right','2.501cm');
$objWriter->writeAttribute('style:writing-mode','lr-tb');
$objWriter->writeAttribute('style:layout-grid-color','#c0c0c0');
$objWriter->writeAttribute('style:layout-grid-lines','25199');
$objWriter->writeAttribute('style:layout-grid-base-height','0.423cm');
$objWriter->writeAttribute('style:layout-grid-ruby-height','0cm');
$objWriter->writeAttribute('style:layout-grid-mode','none');
$objWriter->writeAttribute('style:layout-grid-ruby-below','false');
$objWriter->writeAttribute('style:layout-grid-print','false');
$objWriter->writeAttribute('style:layout-grid-display','false');
$objWriter->writeAttribute('style:layout-grid-base-width','0.37cm');
$objWriter->writeAttribute('style:layout-grid-snap-to','true');
$objWriter->writeAttribute('style:footnote-max-height','0cm');
//style:footnote-sep
$objWriter->startElement('style:footnote-sep');
$objWriter->writeAttribute('style:width', '0.018cm');
$objWriter->writeAttribute('style:line-style','solid');
$objWriter->writeAttribute('style:adjustment','left');
$objWriter->writeAttribute('style:rel-width','25%');
$objWriter->writeAttribute('style:color','#000000');
$objWriter->endElement();
$objWriter->endElement();
// style:header-style
$objWriter->startElement('style:header-style');
$objWriter->endElement();
// style:footer-style
$objWriter->startElement('style:footer-style');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// office:master-styles
$objWriter->startElement('office:master-styles');
// style:master-page
$objWriter->startElement('style:master-page');
$objWriter->writeAttribute('style:name', 'Standard');
$objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// Return // style:font-face
return $objWriter->getData(); $objWriter->startElement('style:font-face');
} $objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
}
}
}
}
if (!in_array('Arial', $arrFonts)) {
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', 'Arial');
$objWriter->writeAttribute('svg:font-family', 'Arial');
$objWriter->endElement();
}
$objWriter->endElement();
// office:styles
$objWriter->startElement('office:styles');
// style:default-style
$objWriter->startElement('style:default-style');
$objWriter->writeAttribute('style:family', 'paragraph');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
$objWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
$objWriter->writeAttribute('style:punctuation-wrap', 'hanging');
$objWriter->writeAttribute('style:line-break', 'strict');
$objWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
$objWriter->writeAttribute('style:writing-mode', 'page');
$objWriter->endElement();
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('style:use-window-font-color', 'true');
$objWriter->writeAttribute('style:font-name', 'Arial');
$objWriter->writeAttribute('fo:font-size', '10pt');
$objWriter->writeAttribute('fo:language', 'fr');
$objWriter->writeAttribute('fo:country', 'FR');
$objWriter->writeAttribute('style:letter-kerning', 'true');
$objWriter->writeAttribute('style:font-name-asian', 'Arial2');
$objWriter->writeAttribute('style:font-size-asian', '10pt');
$objWriter->writeAttribute('style:language-asian', 'zh');
$objWriter->writeAttribute('style:country-asian', 'CN');
$objWriter->writeAttribute('style:font-name-complex', 'Arial2');
$objWriter->writeAttribute('style:font-size-complex', '10pt');
$objWriter->writeAttribute('style:language-complex', 'hi');
$objWriter->writeAttribute('style:country-complex', 'IN');
$objWriter->writeAttribute('fo:hyphenate', 'false');
$objWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
$objWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
$objWriter->endElement();
$objWriter->endElement();
// Write Style Definitions
$styles = PHPWord_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
) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:font-size', ($style->getSize() / 2) . 'pt');
$objWriter->writeAttribute('style:font-size-asian', ($style->getSize() / 2) . 'pt');
$objWriter->writeAttribute('style:font-size-complex', ($style->getSize() / 2) . 'pt');
if ($style->getItalic()) {
$objWriter->writeAttribute('fo:font-style', 'italic');
$objWriter->writeAttribute('style:font-style-asian', 'italic');
$objWriter->writeAttribute('style:font-style-complex', 'italic');
}
if ($style->getBold()) {
$objWriter->writeAttribute('fo:font-weight', 'bold');
$objWriter->writeAttribute('style:font-weight-asian', 'bold');
}
$objWriter->endElement();
$objWriter->endElement();
} // PHPWord_Style_Paragraph
elseif ($style instanceof PHPWord_Style_Paragraph) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
//style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)) . 'cm');
$objWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)) . 'cm');
$objWriter->writeAttribute('fo:text-align', $style->getAlign());
$objWriter->endElement();
$objWriter->endElement();
} // PHPWord_Style_TableFull
elseif ($style instanceof PHPWord_Style_TableFull) {
}
}
}
}
$objWriter->endElement();
// office:automatic-styles
$objWriter->startElement('office:automatic-styles');
// style:page-layout
$objWriter->startElement('style:page-layout');
$objWriter->writeAttribute('style:name', 'Mpm1');
// style:page-layout-properties
$objWriter->startElement('style:page-layout-properties');
$objWriter->writeAttribute('fo:page-width', "21.001cm");
$objWriter->writeAttribute('fo:page-height', '29.7cm');
$objWriter->writeAttribute('style:num-format', '1');
$objWriter->writeAttribute('style:print-orientation', 'portrait');
$objWriter->writeAttribute('fo:margin-top', '2.501cm');
$objWriter->writeAttribute('fo:margin-bottom', '2cm');
$objWriter->writeAttribute('fo:margin-left', '2.501cm');
$objWriter->writeAttribute('fo:margin-right', '2.501cm');
$objWriter->writeAttribute('style:writing-mode', 'lr-tb');
$objWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
$objWriter->writeAttribute('style:layout-grid-lines', '25199');
$objWriter->writeAttribute('style:layout-grid-base-height', '0.423cm');
$objWriter->writeAttribute('style:layout-grid-ruby-height', '0cm');
$objWriter->writeAttribute('style:layout-grid-mode', 'none');
$objWriter->writeAttribute('style:layout-grid-ruby-below', 'false');
$objWriter->writeAttribute('style:layout-grid-print', 'false');
$objWriter->writeAttribute('style:layout-grid-display', 'false');
$objWriter->writeAttribute('style:layout-grid-base-width', '0.37cm');
$objWriter->writeAttribute('style:layout-grid-snap-to', 'true');
$objWriter->writeAttribute('style:footnote-max-height', '0cm');
//style:footnote-sep
$objWriter->startElement('style:footnote-sep');
$objWriter->writeAttribute('style:width', '0.018cm');
$objWriter->writeAttribute('style:line-style', 'solid');
$objWriter->writeAttribute('style:adjustment', 'left');
$objWriter->writeAttribute('style:rel-width', '25%');
$objWriter->writeAttribute('style:color', '#000000');
$objWriter->endElement();
$objWriter->endElement();
// style:header-style
$objWriter->startElement('style:header-style');
$objWriter->endElement();
// style:footer-style
$objWriter->startElement('style:footer-style');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// office:master-styles
$objWriter->startElement('office:master-styles');
// style:master-page
$objWriter->startElement('style:master-page');
$objWriter->writeAttribute('style:name', 'Standard');
$objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->getData();
}
} }

View File

@ -35,34 +35,36 @@
*/ */
abstract class PHPWord_Writer_ODText_WriterPart abstract class PHPWord_Writer_ODText_WriterPart
{ {
/** /**
* Parent IWriter object * Parent IWriter object
* *
* @var PHPWord_Writer_IWriter * @var PHPWord_Writer_IWriter
*/ */
private $_parentWriter; private $_parentWriter;
/** /**
* Set parent IWriter object * Set parent IWriter object
* *
* @param PHPWord_Writer_IWriter $pWriter * @param PHPWord_Writer_IWriter $pWriter
* @throws Exception * @throws Exception
*/ */
public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null) { public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null)
$this->_parentWriter = $pWriter; {
} $this->_parentWriter = $pWriter;
}
/** /**
* Get parent IWriter object * Get parent IWriter object
* *
* @return PHPWord_Writer_IWriter * @return PHPWord_Writer_IWriter
* @throws Exception * @throws Exception
*/ */
public function getParentWriter() { public function getParentWriter()
if (!is_null($this->_parentWriter)) { {
return $this->_parentWriter; if (!is_null($this->_parentWriter)) {
} else { return $this->_parentWriter;
throw new Exception("No parent PHPWord_Writer_IWriter assigned."); } else {
} throw new Exception("No parent PHPWord_Writer_IWriter assigned.");
} }
}
} }

View File

@ -27,284 +27,294 @@
class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
{ {
/** /**
* Private PHPWord * Private PHPWord
* *
* @var PHPWord * @var PHPWord
*/ */
private $_document; private $_document;
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var PHPWord_HashTable
*/
private $_drawingHashTable;
private $_colorTable;
private $_fontTable;
private $_lastParagraphStyle;
/**
* Create a new PHPWord_Writer_ODText
*
* @param PHPWord $pPHPWord
*/
public function __construct(PHPWord $pPHPWord = null)
{
// Assign PHPWord
$this->setPHPWord($pPHPWord);
// Set HashTable variables
$this->_drawingHashTable = new PHPWord_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()); * Private unique PHPWord_Worksheet_BaseDrawing HashTable
fclose($hFile); *
* @var PHPWord_HashTable
*/
private $_drawingHashTable;
// If a temporary file was used, copy it to the correct file stream private $_colorTable;
if ($originalFilename != $pFilename) { private $_fontTable;
if (copy($pFilename, $originalFilename) === false) { private $_lastParagraphStyle;
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
} /**
@unlink($pFilename); * Create a new PHPWord_Writer_ODText
} *
* @param PHPWord $pPHPWord
} else { */
throw new Exception("PHPWord object unassigned."); public function __construct(PHPWord $pPHPWord = null)
} {
} // Assign PHPWord
$this->setPHPWord($pPHPWord);
/**
* Get PHPWord object // Set HashTable variables
* $this->_drawingHashTable = new PHPWord_HashTable();
* @return PHPWord }
* @throws Exception
*/ /**
public function getPHPWord() { * Save PHPWord to file
if (!is_null($this->_document)) { *
return $this->_document; * @param string $pFileName
} else { * @throws Exception
throw new Exception("No PHPWord assigned."); */
} public function save($pFilename = null)
} {
if (!is_null($this->_document)) {
/** // If $pFilename is php://output or php://stdout, make it a temporary file...
* Get PHPWord object $originalFilename = $pFilename;
* if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
* @param PHPWord $pPHPWord PHPWord object $pFilename = @tempnam('./', 'phppttmp');
* @throws Exception if ($pFilename == '') {
* @return PHPWord_Writer_PowerPoint2007 $pFilename = $originalFilename;
*/ }
public function setPHPWord(PHPWord $pPHPWord = null) { }
$this->_document = $pPHPWord;
return $this; $hFile = fopen($pFilename, 'w') or die("can't open file");
} fwrite($hFile, $this->_getData());
fclose($hFile);
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable // If a temporary file was used, copy it to the correct file stream
* if ($originalFilename != $pFilename) {
* @return PHPWord_HashTable if (copy($pFilename, $originalFilename) === false) {
*/ throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
public function getDrawingHashTable() { }
return $this->_drawingHashTable; @unlink($pFilename);
} }
private function _getData(){ } else {
// PHPWord object : $this->_document throw new Exception("PHPWord object unassigned.");
$this->_fontTable = $this->_getDataFont(); }
$this->_colorTable = $this->_getDataColor(); }
$sRTFContent = '{\rtf1'; /**
// Set the default character set * Get PHPWord object
$sRTFContent .= '\ansi\ansicpg1252'; *
// Set the default font (the first one) * @return PHPWord
$sRTFContent .= '\deff0'; * @throws Exception
// Set the default tab size (720 twips) */
$sRTFContent .= '\deftab720'; public function getPHPWord()
// Set the font tbl group {
$sRTFContent .= '{\fonttbl'; if (!is_null($this->_document)) {
foreach ($this->_fontTable as $idx => $font){ return $this->_document;
$sRTFContent .= '{\f'.$idx.'\fnil\fcharset0 '.$font.';}'; } else {
} throw new Exception("No PHPWord assigned.");
$sRTFContent .= '}'.PHP_EOL; }
// Set the color tbl group }
$sRTFContent .= '{\colortbl ';
foreach ($this->_colorTable as $idx => $color){ /**
$arrColor = PHPWord_Shared_Drawing::htmlToRGB($color); * Get PHPWord object
$sRTFContent .= ';\red'.$arrColor[0].'\green'.$arrColor[1].'\blue'.$arrColor[2].''; *
} * @param PHPWord $pPHPWord PHPWord object
$sRTFContent .= ';}'.PHP_EOL; * @throws Exception
// Set the generator * @return PHPWord_Writer_PowerPoint2007
$sRTFContent .= '{\*\generator PHPWord;}'; */
// Set the view mode of the document public function setPHPWord(PHPWord $pPHPWord = null)
$sRTFContent .= '\viewkind4'; {
// Set the numberof bytes that follows a unicode character $this->_document = $pPHPWord;
$sRTFContent .= '\uc1'; return $this;
// Resets to default paragraph properties. }
$sRTFContent .= '\pard';
// No widow/orphan control /**
$sRTFContent .= '\nowidctlpar'; * Get PHPWord_Worksheet_BaseDrawing HashTable
// Applies a language to a text run (1036 : French (France)) *
$sRTFContent .= '\lang1036'; * @return PHPWord_HashTable
// Point size (in half-points) above which to kern character pairs */
$sRTFContent .= '\kerning1'; public function getDrawingHashTable()
// Set the font size in half-points {
$sRTFContent .= '\fs20'; return $this->_drawingHashTable;
// Body }
$sRTFContent .= $this->_getDataContent();
private function _getData()
{
$sRTFContent .= '}'; // PHPWord object : $this->_document
$this->_fontTable = $this->_getDataFont();
return $sRTFContent; $this->_colorTable = $this->_getDataColor();
}
private function _getDataFont(){ $sRTFContent = '{\rtf1';
$pPHPWord = $this->_document; // Set the default character set
$sRTFContent .= '\ansi\ansicpg1252';
$arrFonts = array(); // Set the default font (the first one)
// Default font : Arial $sRTFContent .= '\deff0';
$arrFonts[] = 'Arial'; // Set the default tab size (720 twips)
// PHPWord object : $this->_document $sRTFContent .= '\deftab720';
// Set the font tbl group
// Browse styles $sRTFContent .= '{\fonttbl';
$styles = PHPWord_Style::getStyles(); foreach ($this->_fontTable as $idx => $font) {
$numPStyles = 0; $sRTFContent .= '{\f' . $idx . '\fnil\fcharset0 ' . $font . ';}';
if(count($styles) > 0) { }
foreach($styles as $styleName => $style) { $sRTFContent .= '}' . PHP_EOL;
// PHPWord_Style_Font // Set the color tbl group
if($style instanceof PHPWord_Style_Font) { $sRTFContent .= '{\colortbl ';
if(in_array($style->getName(), $arrFonts) == FALSE){ foreach ($this->_colorTable as $idx => $color) {
$arrFonts[] = $style->getName(); $arrColor = PHPWord_Shared_Drawing::htmlToRGB($color);
} $sRTFContent .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . '';
} }
} $sRTFContent .= ';}' . PHP_EOL;
} // Set the generator
$sRTFContent .= '{\*\generator PHPWord;}';
// Search all fonts used // Set the view mode of the document
$_sections = $pPHPWord->getSections(); $sRTFContent .= '\viewkind4';
$countSections = count($_sections); // Set the numberof bytes that follows a unicode character
if($countSections > 0) { $sRTFContent .= '\uc1';
$pSection = 0; // Resets to default paragraph properties.
$sRTFContent .= '\pard';
foreach($_sections as $section) { // No widow/orphan control
$pSection++; $sRTFContent .= '\nowidctlpar';
$_elements = $section->getElements(); // Applies a language to a text run (1036 : French (France))
$sRTFContent .= '\lang1036';
foreach($_elements as $element) { // Point size (in half-points) above which to kern character pairs
if($element instanceof PHPWord_Section_Text) { $sRTFContent .= '\kerning1';
$fStyle = $element->getFontStyle(); // Set the font size in half-points
$sRTFContent .= '\fs20';
if($fStyle instanceof PHPWord_Style_Font){ // Body
if(in_array($fStyle->getName(), $arrFonts) == FALSE){ $sRTFContent .= $this->_getDataContent();
$arrFonts[] = $fStyle->getName();
}
} $sRTFContent .= '}';
}
} return $sRTFContent;
} }
}
private function _getDataFont()
return $arrFonts; {
} $pPHPWord = $this->_document;
private function _getDataColor(){
$pPHPWord = $this->_document; $arrFonts = array();
// Default font : Arial
$arrColors = array(); $arrFonts[] = 'Arial';
// PHPWord object : $this->_document // PHPWord object : $this->_document
// Browse styles // Browse styles
$styles = PHPWord_Style::getStyles(); $styles = PHPWord_Style::getStyles();
$numPStyles = 0; $numPStyles = 0;
if(count($styles) > 0) { if (count($styles) > 0) {
foreach($styles as $styleName => $style) { foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font // PHPWord_Style_Font
if($style instanceof PHPWord_Style_Font) { if ($style instanceof PHPWord_Style_Font) {
$color = $style->getColor(); if (in_array($style->getName(), $arrFonts) == FALSE) {
$fgcolor = $style->getFgColor(); $arrFonts[] = $style->getName();
if(in_array($color, $arrColors) == FALSE && $color != '000000' && !empty($color)){ }
$arrColors[] = $color; }
} }
if(in_array($fgcolor, $arrColors) == FALSE && $fgcolor != '000000' && !empty($fgcolor)){ }
$arrColors[] = $fgcolor;
} // Search all fonts used
} $_sections = $pPHPWord->getSections();
} $countSections = count($_sections);
} if ($countSections > 0) {
$pSection = 0;
// Search all fonts used
$_sections = $pPHPWord->getSections(); foreach ($_sections as $section) {
$countSections = count($_sections); $pSection++;
if($countSections > 0) { $_elements = $section->getElements();
$pSection = 0;
foreach ($_elements as $element) {
foreach($_sections as $section) { if ($element instanceof PHPWord_Section_Text) {
$pSection++; $fStyle = $element->getFontStyle();
$_elements = $section->getElements();
if ($fStyle instanceof PHPWord_Style_Font) {
foreach($_elements as $element) { if (in_array($fStyle->getName(), $arrFonts) == FALSE) {
if($element instanceof PHPWord_Section_Text) { $arrFonts[] = $fStyle->getName();
$fStyle = $element->getFontStyle(); }
}
if($fStyle instanceof PHPWord_Style_Font){ }
if(in_array($fStyle->getColor(), $arrColors) == FALSE){ }
$arrColors[] = $fStyle->getColor(); }
} }
if(in_array($fStyle->getFgColor(), $arrColors) == FALSE){
$arrColors[] = $fStyle->getFgColor(); return $arrFonts;
} }
}
} private function _getDataColor()
} {
} $pPHPWord = $this->_document;
}
$arrColors = array();
return $arrColors; // PHPWord object : $this->_document
}
private function _getDataContent(){ // Browse styles
$pPHPWord = $this->_document; $styles = PHPWord_Style::getStyles();
$sRTFBody = ''; $numPStyles = 0;
if (count($styles) > 0) {
$_sections = $pPHPWord->getSections(); foreach ($styles as $styleName => $style) {
$countSections = count($_sections); // PHPWord_Style_Font
$pSection = 0; if ($style instanceof PHPWord_Style_Font) {
$color = $style->getColor();
if($countSections > 0) { $fgcolor = $style->getFgColor();
foreach($_sections as $section) { if (in_array($color, $arrColors) == FALSE && $color != '000000' && !empty($color)) {
$pSection++; $arrColors[] = $color;
$_elements = $section->getElements(); }
foreach($_elements as $element) { if (in_array($fgcolor, $arrColors) == FALSE && $fgcolor != '000000' && !empty($fgcolor)) {
if($element instanceof PHPWord_Section_Text) { $arrColors[] = $fgcolor;
$sRTFBody .= $this->_getDataContent_writeText($element); }
}/* elseif($element instanceof PHPWord_Section_TextRun) { }
}
}
// Search all fonts used
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
if ($countSections > 0) {
$pSection = 0;
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$fStyle = $element->getFontStyle();
if ($fStyle instanceof PHPWord_Style_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()
{
$pPHPWord = $this->_document;
$sRTFBody = '';
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$sRTFBody .= $this->_getDataContent_writeText($element);
} /* elseif($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element); $this->_writeTextRun($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Link) { } elseif($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element); $this->_writeLink($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Title) { } elseif($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element); $this->_writeTitle($objWriter, $element);
}*/ }*/
elseif($element instanceof PHPWord_Section_TextBreak) { elseif ($element instanceof PHPWord_Section_TextBreak) {
$sRTFBody .= $this->_getDataContent_writeTextBreak(); $sRTFBody .= $this->_getDataContent_writeTextBreak();
}/* elseif($element instanceof PHPWord_Section_PageBreak) { } /* elseif($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter); $this->_writePageBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Table) { } elseif($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element); $this->_writeTable($objWriter, $element);
@ -318,106 +328,108 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter
} elseif($element instanceof PHPWord_TOC) { } elseif($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter); $this->_writeTOC($objWriter);
}*/ }*/
else { else {
print_r($element); print_r($element);
echo '<br />'; echo '<br />';
} }
} }
} }
} }
return $sRTFBody; return $sRTFBody;
} }
private function _getDataContent_writeText(PHPWord_Section_Text $text){
$sRTFText = '';
$styleFont = $text->getFontStyle();
$SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
if(!$SfIsObject) {
$styleFont = PHPWord_Style::getStyle($styleFont);
}
$styleParagraph = $text->getParagraphStyle(); private function _getDataContent_writeText(PHPWord_Section_Text $text)
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; {
if(!$SpIsObject) { $sRTFText = '';
$styleParagraph = PHPWord_Style::getStyle($styleParagraph);
} $styleFont = $text->getFontStyle();
$SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
if($styleParagraph){ if (!$SfIsObject) {
if($this->_lastParagraphStyle != $text->getParagraphStyle()){ $styleFont = PHPWord_Style::getStyle($styleFont);
$sRTFText .= '\pard\nowidctlpar'; }
if($styleParagraph->getSpaceAfter() != null){
$sRTFText .= '\sa'.$styleParagraph->getSpaceAfter(); $styleParagraph = $text->getParagraphStyle();
} $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
if($styleParagraph->getAlign() != null){ if (!$SpIsObject) {
if($styleParagraph->getAlign() == 'center'){ $styleParagraph = PHPWord_Style::getStyle($styleParagraph);
$sRTFText .= '\qc'; }
}
} if ($styleParagraph) {
$this->_lastParagraphStyle = $text->getParagraphStyle(); if ($this->_lastParagraphStyle != $text->getParagraphStyle()) {
} $sRTFText .= '\pard\nowidctlpar';
else { if ($styleParagraph->getSpaceAfter() != null) {
$this->_lastParagraphStyle = ''; $sRTFText .= '\sa' . $styleParagraph->getSpaceAfter();
} }
} if ($styleParagraph->getAlign() != null) {
else { if ($styleParagraph->getAlign() == 'center') {
$this->_lastParagraphStyle = ''; $sRTFText .= '\qc';
} }
}
if($styleFont){ $this->_lastParagraphStyle = $text->getParagraphStyle();
if($styleFont->getColor() != null){ } else {
$idxColor = array_search($styleFont->getColor(), $this->_colorTable); $this->_lastParagraphStyle = '';
if($idxColor !== FALSE){ }
$sRTFText .= '\cf'.($idxColor+1); } else {
} $this->_lastParagraphStyle = '';
} else { }
$sRTFText .= '\cf0';
} if ($styleFont) {
if($styleFont->getName() != null){ if ($styleFont->getColor() != null) {
$idxFont = array_search($styleFont->getName(), $this->_fontTable); $idxColor = array_search($styleFont->getColor(), $this->_colorTable);
if($idxFont !== FALSE){ if ($idxColor !== FALSE) {
$sRTFText .= '\f'.$idxFont; $sRTFText .= '\cf' . ($idxColor + 1);
} }
} else { } else {
$sRTFText .= '\f0'; $sRTFText .= '\cf0';
} }
if($styleFont->getBold()){ if ($styleFont->getName() != null) {
$sRTFText .= '\b'; $idxFont = array_search($styleFont->getName(), $this->_fontTable);
} if ($idxFont !== FALSE) {
if($styleFont->getBold()){ $sRTFText .= '\f' . $idxFont;
$sRTFText .= '\i'; }
} } else {
if($styleFont->getSize()){ $sRTFText .= '\f0';
$sRTFText .= '\fs'.$styleFont->getSize(); }
} if ($styleFont->getBold()) {
} $sRTFText .= '\b';
if($this->_lastParagraphStyle != '' || $styleFont){ }
$sRTFText .= ' '; if ($styleFont->getBold()) {
} $sRTFText .= '\i';
$sRTFText .= $text->getText(); }
if ($styleFont->getSize()) {
if($styleFont){ $sRTFText .= '\fs' . $styleFont->getSize();
$sRTFText .= '\cf0'; }
$sRTFText .= '\f0'; }
if ($this->_lastParagraphStyle != '' || $styleFont) {
if($styleFont->getBold()){ $sRTFText .= ' ';
$sRTFText .= '\b0'; }
} $sRTFText .= $text->getText();
if($styleFont->getItalic()){
$sRTFText .= '\i0'; if ($styleFont) {
} $sRTFText .= '\cf0';
if($styleFont->getSize()){ $sRTFText .= '\f0';
$sRTFText .= '\fs20';
} if ($styleFont->getBold()) {
} $sRTFText .= '\b0';
}
$sRTFText .= '\par'.PHP_EOL; if ($styleFont->getItalic()) {
return $sRTFText; $sRTFText .= '\i0';
} }
private function _getDataContent_writeTextBreak(){ if ($styleFont->getSize()) {
$this->_lastParagraphStyle = ''; $sRTFText .= '\fs20';
}
return '\par'.PHP_EOL; }
}
$sRTFText .= '\par' . PHP_EOL;
return $sRTFText;
}
private function _getDataContent_writeTextBreak()
{
$this->_lastParagraphStyle = '';
return '\par' . PHP_EOL;
}
} }

View File

@ -26,216 +26,222 @@
*/ */
class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter { class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter
{
private $_document;
private $_writerParts; private $_document;
private $_diskCachingDirectory; private $_writerParts;
private $_useDiskCaching = false; private $_diskCachingDirectory;
private $_imageTypes = array(); private $_useDiskCaching = false;
private $_objectTypes = array(); private $_imageTypes = array();
private $_objectTypes = array();
public function __construct(PHPWord $PHPWord = null) {
$this->_document = $PHPWord; public function __construct(PHPWord $PHPWord = null)
{
$this->_diskCachingDirectory = './'; $this->_document = $PHPWord;
$this->_writerParts['contenttypes'] = new PHPWord_Writer_Word2007_ContentTypes(); $this->_diskCachingDirectory = './';
$this->_writerParts['rels'] = new PHPWord_Writer_Word2007_Rels();
$this->_writerParts['docprops'] = new PHPWord_Writer_Word2007_DocProps(); $this->_writerParts['contenttypes'] = new PHPWord_Writer_Word2007_ContentTypes();
$this->_writerParts['documentrels'] = new PHPWord_Writer_Word2007_DocumentRels(); $this->_writerParts['rels'] = new PHPWord_Writer_Word2007_Rels();
$this->_writerParts['document'] = new PHPWord_Writer_Word2007_Document(); $this->_writerParts['docprops'] = new PHPWord_Writer_Word2007_DocProps();
$this->_writerParts['styles'] = new PHPWord_Writer_Word2007_Styles(); $this->_writerParts['documentrels'] = new PHPWord_Writer_Word2007_DocumentRels();
$this->_writerParts['header'] = new PHPWord_Writer_Word2007_Header(); $this->_writerParts['document'] = new PHPWord_Writer_Word2007_Document();
$this->_writerParts['footer'] = new PHPWord_Writer_Word2007_Footer(); $this->_writerParts['styles'] = new PHPWord_Writer_Word2007_Styles();
$this->_writerParts['header'] = new PHPWord_Writer_Word2007_Header();
foreach($this->_writerParts as $writer) { $this->_writerParts['footer'] = new PHPWord_Writer_Word2007_Footer();
$writer->setParentWriter($this);
} foreach ($this->_writerParts as $writer) {
} $writer->setParentWriter($this);
}
public function save($pFilename = null) { }
if(!is_null($this->_document)) {
public function save($pFilename = null)
// If $pFilename is php://output or php://stdout, make it a temporary file... {
$originalFilename = $pFilename; if (!is_null($this->_document)) {
if(strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
$pFilename = @tempnam('./', 'phppttmp'); // If $pFilename is php://output or php://stdout, make it a temporary file...
if($pFilename == '') { $originalFilename = $pFilename;
$pFilename = $originalFilename; 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 // Create new ZIP file and open it for writing
if($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) { $objZip = new ZipArchive();
if($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing."); // 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 = PHPWord_Media::getSectionMediaElements();
foreach($_secElements as $element) { // loop through section media elements
if($element['type'] != 'hyperlink') { $sectionElements = array();
$this->_addFileToPackage($objZip, $element); $_secElements = PHPWord_Media::getSectionMediaElements();
} foreach ($_secElements as $element) { // loop through section media elements
$sectionElements[] = $element; if ($element['type'] != 'hyperlink') {
} $this->_addFileToPackage($objZip, $element);
}
$_hdrElements = PHPWord_Media::getHeaderMediaElements(); $sectionElements[] = $element;
foreach($_hdrElements as $_headerFile => $_hdrMedia) { // loop through headers }
if(count($_hdrMedia) > 0) {
$objZip->addFromString('word/_rels/'.$_headerFile.'.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_hdrMedia)); $_hdrElements = PHPWord_Media::getHeaderMediaElements();
foreach($_hdrMedia as $element) { // loop through header media elements foreach ($_hdrElements as $_headerFile => $_hdrMedia) { // loop through headers
$this->_addFileToPackage($objZip, $element); 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 = PHPWord_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)); $_ftrElements = PHPWord_Media::getFooterMediaElements();
foreach($_ftrMedia as $element) { // loop through footers media elements foreach ($_ftrElements as $_footerFile => $_ftrMedia) { // loop through footers
$this->_addFileToPackage($objZip, $element); 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);
}
}
}
$_cHdrs = 0;
$_cFtrs = 0;
$rID = PHPWord_Media::countSectionMediaElements() + 6; $_cHdrs = 0;
$_sections = $this->_document->getSections(); $_cFtrs = 0;
$rID = PHPWord_Media::countSectionMediaElements() + 6;
foreach($_sections as $section) { $_sections = $this->_document->getSections();
$_header = $section->getHeader();
if(!is_null($_header)) { foreach ($_sections as $section) {
$_cHdrs++; $_header = $section->getHeader();
$_header->setRelationId(++$rID); if (!is_null($_header)) {
$_headerCount = $_header->getHeaderCount(); $_cHdrs++;
$_headerFile = 'header'.$_headerCount.'.xml'; $_header->setRelationId(++$rID);
$sectionElements[] = array('target'=>$_headerFile, 'type'=>'header', 'rID'=>$rID); $_headerCount = $_header->getHeaderCount();
$objZip->addFromString('word/'.$_headerFile, $this->getWriterPart('header')->writeHeader($_header)); $_headerFile = 'header' . $_headerCount . '.xml';
} $sectionElements[] = array('target' => $_headerFile, 'type' => 'header', 'rID' => $rID);
$objZip->addFromString('word/' . $_headerFile, $this->getWriterPart('header')->writeHeader($_header));
$_footer = $section->getFooter(); }
if(!is_null($_footer)) {
$_cFtrs++; $_footer = $section->getFooter();
$_footer->setRelationId(++$rID); if (!is_null($_footer)) {
$_footerCount = $_footer->getFooterCount(); $_cFtrs++;
$_footerFile = 'footer'.$_footerCount.'.xml'; $_footer->setRelationId(++$rID);
$sectionElements[] = array('target'=>$_footerFile, 'type'=>'footer', 'rID'=>$rID); $_footerCount = $_footer->getFooterCount();
$objZip->addFromString('word/'.$_footerFile, $this->getWriterPart('footer')->writeFooter($_footer)); $_footerFile = 'footer' . $_footerCount . '.xml';
} $sectionElements[] = array('target' => $_footerFile, 'type' => 'footer', 'rID' => $rID);
} $objZip->addFromString('word/' . $_footerFile, $this->getWriterPart('footer')->writeFooter($_footer));
}
// build docx file }
// Write dynamic files
// build docx file
// Write dynamic files
$objZip->addFromString('[Content_Types].xml', $this->getWriterPart('contenttypes')->writeContentTypes($this->_imageTypes, $this->_objectTypes, $_cHdrs, $_cFtrs)); $objZip->addFromString('[Content_Types].xml', $this->getWriterPart('contenttypes')->writeContentTypes($this->_imageTypes, $this->_objectTypes, $_cHdrs, $_cFtrs));
$objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->_document)); $objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->_document));
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docprops')->writeDocPropsApp($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('docProps/core.xml', $this->getWriterPart('docprops')->writeDocPropsCore($this->_document));
$objZip->addFromString('word/document.xml', $this->getWriterPart('document')->writeDocument($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/_rels/document.xml.rels', $this->getWriterPart('documentrels')->writeDocumentRels($sectionElements));
$objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document)); $objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document));
// Write static files // Write static files
$objZip->addFile(PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/numbering.xml', 'word/numbering.xml'); $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/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/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/webSettings.xml', 'word/webSettings.xml');
$objZip->addFile(PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/fontTable.xml', 'word/fontTable.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.");
}
}
private function _chkContentTypes($src) {
$srcInfo = pathinfo($src);
$extension = strtolower($srcInfo['extension']);
if(substr($extension, 0, 3) == 'php') {
$extension = 'php';
}
$_supportedImageTypes = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff', 'php');
if(in_array($extension, $_supportedImageTypes)) {
$imagedata = getimagesize($src);
$imagetype = image_type_to_mime_type($imagedata[2]);
$imageext = image_type_to_extension($imagedata[2]);
$imageext = str_replace('.', '', $imageext);
if($imageext == 'jpeg') $imageext = 'jpg';
if(!in_array($imagetype, $this->_imageTypes)) {
$this->_imageTypes[$imageext] = $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) { // Close file
$this->_useDiskCaching = $pValue; if ($objZip->close() === false) {
throw new Exception("Could not close zip file $pFilename.");
if (!is_null($pDirectory)) { }
if (is_dir($pDirectory)) {
$this->_diskCachingDirectory = $pDirectory; // If a temporary file was used, copy it to the correct file stream
} else { if ($originalFilename != $pFilename) {
throw new Exception("Directory does not exist: $pDirectory"); if (copy($pFilename, $originalFilename) === false) {
} throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
} }
@unlink($pFilename);
return $this; }
} } else {
throw new Exception("PHPWord object unassigned.");
private function _addFileToPackage($objZip, $element) { }
if(isset($element['isMemImage']) && $element['isMemImage']) { }
$image = call_user_func($element['createfunction'], $element['source']);
ob_start(); private function _chkContentTypes($src)
call_user_func($element['imagefunction'], $image); {
$imageContents = ob_get_contents(); $srcInfo = pathinfo($src);
ob_end_clean(); $extension = strtolower($srcInfo['extension']);
$objZip->addFromString('word/'.$element['target'], $imageContents); if (substr($extension, 0, 3) == 'php') {
imagedestroy($image); $extension = 'php';
}
$this->_chkContentTypes($element['source']); $_supportedImageTypes = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff', 'php');
} else {
$objZip->addFile($element['source'], 'word/'.$element['target']); if (in_array($extension, $_supportedImageTypes)) {
$this->_chkContentTypes($element['source']); $imagedata = getimagesize($src);
} $imagetype = image_type_to_mime_type($imagedata[2]);
} $imageext = image_type_to_extension($imagedata[2]);
$imageext = str_replace('.', '', $imageext);
if ($imageext == 'jpeg') $imageext = 'jpg';
if (!in_array($imagetype, $this->_imageTypes)) {
$this->_imageTypes[$imageext] = $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->_chkContentTypes($element['source']);
} else {
$objZip->addFile($element['source'], 'word/' . $element['target']);
$this->_chkContentTypes($element['source']);
}
}
} }
?>

File diff suppressed because it is too large Load Diff

View File

@ -26,160 +26,165 @@
*/ */
class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_WriterPart { class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_WriterPart
{
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $_cFtrs) {
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $_cFtrs)
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); {
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// Types // XML header
$objWriter->startElement('Types'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
// Rels // Types
$this->_writeDefaultContentType( $objWriter->startElement('Types');
$objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml' $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
);
// XML // Rels
$this->_writeDefaultContentType( $this->_writeDefaultContentType(
$objWriter, 'xml', 'application/xml' $objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml'
); );
// Add media content-types
foreach($_imageTypes as $key => $value) {
$this->_writeDefaultContentType($objWriter, $key, $value);
}
// Add embedding content-types
if(count($_objectTypes) > 0) {
$this->_writeDefaultContentType($objWriter, 'bin', 'application/vnd.openxmlformats-officedocument.oleObject');
}
// DocProps
$this->_writeOverrideContentType(
$objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
);
$this->_writeOverrideContentType( // XML
$objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml' $this->_writeDefaultContentType(
); $objWriter, 'xml', 'application/xml'
);
// Document
$this->_writeOverrideContentType(
$objWriter, '/word/document.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
);
// Styles
$this->_writeOverrideContentType(
$objWriter, '/word/styles.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
);
// Numbering
$this->_writeOverrideContentType(
$objWriter, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
);
// Settings
$this->_writeOverrideContentType(
$objWriter, '/word/settings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
);
// Theme1
$this->_writeOverrideContentType(
$objWriter, '/word/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml'
);
// WebSettings
$this->_writeOverrideContentType(
$objWriter, '/word/webSettings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
);
// Font Table
$this->_writeOverrideContentType(
$objWriter, '/word/fontTable.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
);
for($i=1; $i<=$_cHdrs; $i++) { // Add media content-types
$this->_writeOverrideContentType( foreach ($_imageTypes as $key => $value) {
$objWriter, '/word/header'.$i.'.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml' $this->_writeDefaultContentType($objWriter, $key, $value);
); }
}
for($i=1; $i<=$_cFtrs; $i++) {
$this->_writeOverrideContentType(
$objWriter, '/word/footer'.$i.'.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
);
}
$objWriter->endElement();
// Return // Add embedding content-types
return $objWriter->getData(); if (count($_objectTypes) > 0) {
} $this->_writeDefaultContentType($objWriter, 'bin', 'application/vnd.openxmlformats-officedocument.oleObject');
}
/** // DocProps
* Get image mime type $this->_writeOverrideContentType(
* $objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml'
* @param string $pFile Filename );
* @return string Mime Type
* @throws Exception
*/
private function _getImageMimeType($pFile = '') {
if(PHPWord_Shared_File::file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
/** $this->_writeOverrideContentType(
* Write Default content type $objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml'
* );
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer
* @param string $pPartname Part name
* @param string $pContentType Content type
* @throws Exception
*/
private function _writeDefaultContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') {
if($pPartname != '' && $pContentType != '') {
// Write content type
$objWriter->startElement('Default');
$objWriter->writeAttribute('Extension', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
/** // Document
* Write Override content type $this->_writeOverrideContentType(
* $objWriter, '/word/document.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
* @param PHPPowerPoint_Shared_XMLWriter $objWriter XML Writer );
* @param string $pPartname Part name
* @param string $pContentType Content type // Styles
* @throws Exception $this->_writeOverrideContentType(
*/ $objWriter, '/word/styles.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
private function _writeOverrideContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') { );
if($pPartname != '' && $pContentType != '') {
// Write content type // Numbering
$objWriter->startElement('Override'); $this->_writeOverrideContentType(
$objWriter->writeAttribute('PartName', $pPartname); $objWriter, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
$objWriter->writeAttribute('ContentType', $pContentType); );
$objWriter->endElement();
} else { // Settings
throw new Exception("Invalid parameters passed."); $this->_writeOverrideContentType(
} $objWriter, '/word/settings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
} );
// Theme1
$this->_writeOverrideContentType(
$objWriter, '/word/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml'
);
// WebSettings
$this->_writeOverrideContentType(
$objWriter, '/word/webSettings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
);
// Font Table
$this->_writeOverrideContentType(
$objWriter, '/word/fontTable.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
);
for ($i = 1; $i <= $_cHdrs; $i++) {
$this->_writeOverrideContentType(
$objWriter, '/word/header' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
);
}
for ($i = 1; $i <= $_cFtrs; $i++) {
$this->_writeOverrideContentType(
$objWriter, '/word/footer' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
/**
* Get image mime type
*
* @param string $pFile Filename
* @return string Mime Type
* @throws Exception
*/
private function _getImageMimeType($pFile = '')
{
if (PHPWord_Shared_File::file_exists($pFile)) {
$image = getimagesize($pFile);
return image_type_to_mime_type($image[2]);
} else {
throw new Exception("File $pFile does not exist");
}
}
/**
* Write Default content type
*
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer
* @param string $pPartname Part name
* @param string $pContentType Content type
* @throws Exception
*/
private function _writeDefaultContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '')
{
if ($pPartname != '' && $pContentType != '') {
// Write content type
$objWriter->startElement('Default');
$objWriter->writeAttribute('Extension', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
/**
* Write Override content type
*
* @param PHPPowerPoint_Shared_XMLWriter $objWriter XML Writer
* @param string $pPartname Part name
* @param string $pContentType Content type
* @throws Exception
*/
private function _writeOverrideContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '')
{
if ($pPartname != '' && $pContentType != '') {
// Write content type
$objWriter->startElement('Override');
$objWriter->writeAttribute('PartName', $pPartname);
$objWriter->writeAttribute('ContentType', $pContentType);
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
} }

View File

@ -26,155 +26,158 @@
*/ */
class PHPWord_Writer_Word2007_DocProps extends PHPWord_Writer_Word2007_WriterPart { class PHPWord_Writer_Word2007_DocProps extends PHPWord_Writer_Word2007_WriterPart
{
public function writeDocPropsApp(PHPWord $pPHPWord = null) { public function writeDocPropsApp(PHPWord $pPHPWord = null)
// Create XML writer {
$objWriter = null; // Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = null;
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); if ($this->getParentWriter()->getUseDiskCaching()) {
} else { $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); } else {
} $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header // XML header
$objWriter->startDocument('1.0','UTF-8','yes'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Properties // Properties
$objWriter->startElement('Properties'); $objWriter->startElement('Properties');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
$objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
// Application // Application
$objWriter->writeElement('Application', 'Microsoft Office Word'); $objWriter->writeElement('Application', 'Microsoft Office Word');
// ScaleCrop // ScaleCrop
$objWriter->writeElement('ScaleCrop', 'false'); $objWriter->writeElement('ScaleCrop', 'false');
// HeadingPairs // HeadingPairs
$objWriter->startElement('HeadingPairs'); $objWriter->startElement('HeadingPairs');
// Vector // Vector
$objWriter->startElement('vt:vector'); $objWriter->startElement('vt:vector');
$objWriter->writeAttribute('size', '4'); $objWriter->writeAttribute('size', '4');
$objWriter->writeAttribute('baseType', 'variant'); $objWriter->writeAttribute('baseType', 'variant');
// Variant // Variant
$objWriter->startElement('vt:variant'); $objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:lpstr', 'Theme'); $objWriter->writeElement('vt:lpstr', 'Theme');
$objWriter->endElement(); $objWriter->endElement();
// Variant // Variant
$objWriter->startElement('vt:variant'); $objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:i4', '1'); $objWriter->writeElement('vt:i4', '1');
$objWriter->endElement(); $objWriter->endElement();
// Variant
$objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:lpstr', 'Slide Titles');
$objWriter->endElement();
// Variant // Variant
$objWriter->startElement('vt:variant'); $objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:i4', '1'); $objWriter->writeElement('vt:lpstr', 'Slide Titles');
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); // Variant
$objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:i4', '1');
$objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
// TitlesOfParts $objWriter->endElement();
$objWriter->startElement('TitlesOfParts');
// Vector // TitlesOfParts
$objWriter->startElement('vt:vector'); $objWriter->startElement('TitlesOfParts');
$objWriter->writeAttribute('size', '1');
$objWriter->writeAttribute('baseType', 'lpstr');
$objWriter->writeElement('vt:lpstr', 'Office Theme'); // Vector
$objWriter->startElement('vt:vector');
$objWriter->writeAttribute('size', '1');
$objWriter->writeAttribute('baseType', 'lpstr');
$objWriter->endElement(); $objWriter->writeElement('vt:lpstr', 'Office Theme');
$objWriter->endElement(); $objWriter->endElement();
// Company $objWriter->endElement();
$objWriter->writeElement('Company', $pPHPWord->getProperties()->getCompany());
// LinksUpToDate // Company
$objWriter->writeElement('LinksUpToDate', 'false'); $objWriter->writeElement('Company', $pPHPWord->getProperties()->getCompany());
// SharedDoc // LinksUpToDate
$objWriter->writeElement('SharedDoc', 'false'); $objWriter->writeElement('LinksUpToDate', 'false');
// HyperlinksChanged // SharedDoc
$objWriter->writeElement('HyperlinksChanged', 'false'); $objWriter->writeElement('SharedDoc', 'false');
// AppVersion // HyperlinksChanged
$objWriter->writeElement('AppVersion', '12.0000'); $objWriter->writeElement('HyperlinksChanged', 'false');
$objWriter->endElement(); // AppVersion
$objWriter->writeElement('AppVersion', '12.0000');
// Return $objWriter->endElement();
return $objWriter->getData();
} // Return
return $objWriter->getData();
}
public function writeDocPropsCore(PHPWord $pPHPWord = null) { public function writeDocPropsCore(PHPWord $pPHPWord = null)
// Create XML writer {
$objWriter = null; // Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = null;
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); if ($this->getParentWriter()->getUseDiskCaching()) {
} else { $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); } else {
} $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header // XML header
$objWriter->startDocument('1.0','UTF-8','yes'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
// cp:coreProperties // cp:coreProperties
$objWriter->startElement('cp:coreProperties'); $objWriter->startElement('cp:coreProperties');
$objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'); $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
$objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/'); $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
// dc:creator // dc:creator
$objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getCreator()); $objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getCreator());
// cp:lastModifiedBy // cp:lastModifiedBy
$objWriter->writeElement('cp:lastModifiedBy', $pPHPWord->getProperties()->getLastModifiedBy()); $objWriter->writeElement('cp:lastModifiedBy', $pPHPWord->getProperties()->getLastModifiedBy());
// dcterms:created // dcterms:created
$objWriter->startElement('dcterms:created'); $objWriter->startElement('dcterms:created');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getCreated())); $objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getCreated()));
$objWriter->endElement(); $objWriter->endElement();
// dcterms:modified // dcterms:modified
$objWriter->startElement('dcterms:modified'); $objWriter->startElement('dcterms:modified');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getModified())); $objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getModified()));
$objWriter->endElement(); $objWriter->endElement();
// dc:title // dc:title
$objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle()); $objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
// dc:description // dc:description
$objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription()); $objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
// dc:subject // dc:subject
$objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject()); $objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
// cp:keywords // cp:keywords
$objWriter->writeElement('cp:keywords', $pPHPWord->getProperties()->getKeywords()); $objWriter->writeElement('cp:keywords', $pPHPWord->getProperties()->getKeywords());
// cp:category // cp:category
$objWriter->writeElement('cp:category', $pPHPWord->getProperties()->getCategory()); $objWriter->writeElement('cp:category', $pPHPWord->getProperties()->getCategory());
$objWriter->endElement(); $objWriter->endElement();
// Return // Return
return $objWriter->getData(); return $objWriter->getData();
} }
} }

View File

@ -26,428 +26,437 @@
*/ */
class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base { class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
{
public function writeDocument(PHPWord $pPHPWord = null) {
// Create XML writer
if($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');
// w:document
$objWriter->startElement('w:document');
$objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$objWriter->startElement('w:body');
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if($countSections > 0) {
foreach($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach($_elements as $element) {
if($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} elseif($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element);
} elseif($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter);
} elseif($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif($element instanceof PHPWord_Section_ListItem) {
$this->_writeListItem($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) {
$this->_writeImage($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Object) {
$this->_writeObject($objWriter, $element);
} elseif($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter);
}
}
if($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
}
}
}
$objWriter->endElement(); // End w:body
$objWriter->endElement(); // End w:document
// Return public function writeDocument(PHPWord $pPHPWord = null)
return $objWriter->getData(); {
} // Create XML writer
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) {
$objWriter->startElement('w:p');
$objWriter->startElement('w:pPr');
$this->_writeEndSection($objWriter, $section, 3);
$objWriter->endElement();
$objWriter->endElement();
}
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) {
$_settings = $section->getSettings();
$_header = $section->getHeader();
$_footer = $section->getFooter();
$pgSzW = $_settings->getPageSizeW();
$pgSzH = $_settings->getPageSizeH();
$orientation = $_settings->getOrientation();
$marginTop = $_settings->getMarginTop();
$marginLeft = $_settings->getMarginLeft();
$marginRight = $_settings->getMarginRight();
$marginBottom = $_settings->getMarginBottom();
$borders = $_settings->getBorderSize();
$objWriter->startElement('w:sectPr');
if(!is_null($_header)) {
$rId = $_header->getRelationId();
$objWriter->startElement('w:headerReference');
$objWriter->writeAttribute('w:type', 'default');
$objWriter->writeAttribute('r:id', 'rId'.$rId);
$objWriter->endElement();
}
if(!is_null($_footer)) {
$rId = $_footer->getRelationId();
$objWriter->startElement('w:footerReference');
$objWriter->writeAttribute('w:type', 'default');
$objWriter->writeAttribute('r:id', 'rId'.$rId);
$objWriter->endElement();
}
$objWriter->startElement('w:pgSz');
$objWriter->writeAttribute('w:w', $pgSzW);
$objWriter->writeAttribute('w:h', $pgSzH);
if(!is_null($orientation) && strtolower($orientation) != 'portrait') {
$objWriter->writeAttribute('w:orient', $orientation);
}
$objWriter->endElement();
$objWriter->startElement('w:pgMar');
$objWriter->writeAttribute('w:top', $marginTop);
$objWriter->writeAttribute('w:right', $marginRight);
$objWriter->writeAttribute('w:bottom', $marginBottom);
$objWriter->writeAttribute('w:left', $marginLeft);
$objWriter->writeAttribute('w:header', '720');
$objWriter->writeAttribute('w:footer', '720');
$objWriter->writeAttribute('w:gutter', '0');
$objWriter->endElement();
if(!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
$borderColor = $_settings->getBorderColor();
$objWriter->startElement('w:pgBorders');
$objWriter->writeAttribute('w:offsetFrom', 'page');
if(!is_null($borders[0])) {
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[0]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[0]);
$objWriter->endElement();
}
if(!is_null($borders[1])) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[1]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[1]);
$objWriter->endElement();
}
if(!is_null($borders[2])) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[2]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[2]);
$objWriter->endElement();
}
if(!is_null($borders[3])) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[3]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[3]);
$objWriter->endElement();
}
$objWriter->endElement();
}
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter->startElement('w:cols'); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$objWriter->writeAttribute('w:space', '720'); } else {
$objWriter->endElement(); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
$objWriter->endElement(); // XML header
} $objWriter->startDocument('1.0', 'UTF-8', 'yes');
private function _writePageBreak(PHPWord_Shared_XMLWriter $objWriter = null) { // w:document
$objWriter->startElement('w:p'); $objWriter->startElement('w:document');
$objWriter->startElement('w:r');
$objWriter->startElement('w:br'); $objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('w:type', 'page'); $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->endElement(); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->endElement(); $objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->endElement(); $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
} $objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
private function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem) { $objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$textObject = $listItem->getTextObject(); $objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$text = $textObject->getText();
$objWriter->startElement('w:body');
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter);
} elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter);
} elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_ListItem) {
$this->_writeListItem($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage
) {
$this->_writeImage($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Object) {
$this->_writeObject($objWriter, $element);
} elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter);
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
}
}
}
$objWriter->endElement(); // End w:body
$objWriter->endElement(); // End w:document
// Return
return $objWriter->getData();
}
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
{
$objWriter->startElement('w:p');
$objWriter->startElement('w:pPr');
$this->_writeEndSection($objWriter, $section, 3);
$objWriter->endElement();
$objWriter->endElement();
}
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
{
$_settings = $section->getSettings();
$_header = $section->getHeader();
$_footer = $section->getFooter();
$pgSzW = $_settings->getPageSizeW();
$pgSzH = $_settings->getPageSizeH();
$orientation = $_settings->getOrientation();
$marginTop = $_settings->getMarginTop();
$marginLeft = $_settings->getMarginLeft();
$marginRight = $_settings->getMarginRight();
$marginBottom = $_settings->getMarginBottom();
$borders = $_settings->getBorderSize();
$objWriter->startElement('w:sectPr');
if (!is_null($_header)) {
$rId = $_header->getRelationId();
$objWriter->startElement('w:headerReference');
$objWriter->writeAttribute('w:type', 'default');
$objWriter->writeAttribute('r:id', 'rId' . $rId);
$objWriter->endElement();
}
if (!is_null($_footer)) {
$rId = $_footer->getRelationId();
$objWriter->startElement('w:footerReference');
$objWriter->writeAttribute('w:type', 'default');
$objWriter->writeAttribute('r:id', 'rId' . $rId);
$objWriter->endElement();
}
$objWriter->startElement('w:pgSz');
$objWriter->writeAttribute('w:w', $pgSzW);
$objWriter->writeAttribute('w:h', $pgSzH);
if (!is_null($orientation) && strtolower($orientation) != 'portrait') {
$objWriter->writeAttribute('w:orient', $orientation);
}
$objWriter->endElement();
$objWriter->startElement('w:pgMar');
$objWriter->writeAttribute('w:top', $marginTop);
$objWriter->writeAttribute('w:right', $marginRight);
$objWriter->writeAttribute('w:bottom', $marginBottom);
$objWriter->writeAttribute('w:left', $marginLeft);
$objWriter->writeAttribute('w:header', '720');
$objWriter->writeAttribute('w:footer', '720');
$objWriter->writeAttribute('w:gutter', '0');
$objWriter->endElement();
if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
$borderColor = $_settings->getBorderColor();
$objWriter->startElement('w:pgBorders');
$objWriter->writeAttribute('w:offsetFrom', 'page');
if (!is_null($borders[0])) {
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[0]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[0]);
$objWriter->endElement();
}
if (!is_null($borders[1])) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[1]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[1]);
$objWriter->endElement();
}
if (!is_null($borders[2])) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[2]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[2]);
$objWriter->endElement();
}
if (!is_null($borders[3])) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[3]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[3]);
$objWriter->endElement();
}
$objWriter->endElement();
}
$objWriter->startElement('w:cols');
$objWriter->writeAttribute('w:space', '720');
$objWriter->endElement();
$objWriter->endElement();
}
private function _writePageBreak(PHPWord_Shared_XMLWriter $objWriter = null)
{
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:br');
$objWriter->writeAttribute('w:type', 'page');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
private function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem)
{
$textObject = $listItem->getTextObject();
$text = $textObject->getText();
$styleParagraph = $textObject->getParagraphStyle(); $styleParagraph = $textObject->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
$depth = $listItem->getDepth(); $depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType(); $listType = $listItem->getStyle()->getListType();
$objWriter->startElement('w:p'); $objWriter->startElement('w:p');
$objWriter->startElement('w:pPr'); $objWriter->startElement('w:pPr');
if($SpIsObject) { if ($SpIsObject) {
$this->_writeParagraphStyle($objWriter, $styleParagraph, true); $this->_writeParagraphStyle($objWriter, $styleParagraph, true);
} elseif(!$SpIsObject && !is_null($styleParagraph)) { } elseif (!$SpIsObject && !is_null($styleParagraph)) {
$objWriter->startElement('w:pStyle'); $objWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleParagraph); $objWriter->writeAttribute('w:val', $styleParagraph);
$objWriter->endElement(); $objWriter->endElement();
} }
$objWriter->startElement('w:numPr'); $objWriter->startElement('w:numPr');
$objWriter->startElement('w:ilvl'); $objWriter->startElement('w:ilvl');
$objWriter->writeAttribute('w:val', $depth); $objWriter->writeAttribute('w:val', $depth);
$objWriter->endElement(); $objWriter->endElement();
$objWriter->startElement('w:numId'); $objWriter->startElement('w:numId');
$objWriter->writeAttribute('w:val', $listType); $objWriter->writeAttribute('w:val', $listType);
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); $objWriter->endElement();
$this->_writeText($objWriter, $textObject, true); $this->_writeText($objWriter, $textObject, true);
$objWriter->endElement(); $objWriter->endElement();
} }
protected function _writeObject(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Object $object) { protected function _writeObject(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Object $object)
$rIdObject = $object->getRelationId(); {
$rIdImage = $object->getImageRelationId(); $rIdObject = $object->getRelationId();
$shapeId = md5($rIdObject.'_'.$rIdImage); $rIdImage = $object->getImageRelationId();
$shapeId = md5($rIdObject . '_' . $rIdImage);
$objectId = $object->getObjectId();
$objectId = $object->getObjectId();
$style = $object->getStyle();
$width = $style->getWidth(); $style = $object->getStyle();
$height = $style->getHeight(); $width = $style->getWidth();
$align = $style->getAlign(); $height = $style->getHeight();
$align = $style->getAlign();
$objWriter->startElement('w:p');
$objWriter->startElement('w:p');
if(!is_null($align)) {
$objWriter->startElement('w:pPr'); if (!is_null($align)) {
$objWriter->startElement('w:jc'); $objWriter->startElement('w:pPr');
$objWriter->writeAttribute('w:val', $align); $objWriter->startElement('w:jc');
$objWriter->endElement(); $objWriter->writeAttribute('w:val', $align);
$objWriter->endElement(); $objWriter->endElement();
} $objWriter->endElement();
}
$objWriter->startElement('w:r');
$objWriter->startElement('w:r');
$objWriter->startElement('w:object');
$objWriter->writeAttribute('w:dxaOrig', '249'); $objWriter->startElement('w:object');
$objWriter->writeAttribute('w:dyaOrig', '160'); $objWriter->writeAttribute('w:dxaOrig', '249');
$objWriter->writeAttribute('w:dyaOrig', '160');
$objWriter->startElement('v:shape');
$objWriter->writeAttribute('id', $shapeId); $objWriter->startElement('v:shape');
$objWriter->writeAttribute('type', '#_x0000_t75'); $objWriter->writeAttribute('id', $shapeId);
$objWriter->writeAttribute('style', 'width:104px;height:67px'); $objWriter->writeAttribute('type', '#_x0000_t75');
$objWriter->writeAttribute('o:ole', ''); $objWriter->writeAttribute('style', 'width:104px;height:67px');
$objWriter->writeAttribute('o:ole', '');
$objWriter->startElement('v:imagedata');
$objWriter->writeAttribute('r:id', 'rId'.$rIdImage); $objWriter->startElement('v:imagedata');
$objWriter->writeAttribute('o:title', ''); $objWriter->writeAttribute('r:id', 'rId' . $rIdImage);
$objWriter->endElement(); $objWriter->writeAttribute('o:title', '');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('o:OLEObject');
$objWriter->writeAttribute('Type', 'Embed'); $objWriter->startElement('o:OLEObject');
$objWriter->writeAttribute('ProgID', 'Package'); $objWriter->writeAttribute('Type', 'Embed');
$objWriter->writeAttribute('ShapeID', $shapeId); $objWriter->writeAttribute('ProgID', 'Package');
$objWriter->writeAttribute('DrawAspect', 'Icon'); $objWriter->writeAttribute('ShapeID', $shapeId);
$objWriter->writeAttribute('ObjectID', '_'.$objectId); $objWriter->writeAttribute('DrawAspect', 'Icon');
$objWriter->writeAttribute('r:id', 'rId'.$rIdObject); $objWriter->writeAttribute('ObjectID', '_' . $objectId);
$objWriter->endElement(); $objWriter->writeAttribute('r:id', 'rId' . $rIdObject);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:p
} $objWriter->endElement(); // w:p
}
private function _writeTOC(PHPWord_Shared_XMLWriter $objWriter = null) {
$titles = PHPWord_TOC::getTitles(); private function _writeTOC(PHPWord_Shared_XMLWriter $objWriter = null)
$styleFont = PHPWord_TOC::getStyleFont(); {
$titles = PHPWord_TOC::getTitles();
$styleTOC = PHPWord_TOC::getStyleTOC(); $styleFont = PHPWord_TOC::getStyleFont();
$fIndent = $styleTOC->getIndent();
$tabLeader = $styleTOC->getTabLeader(); $styleTOC = PHPWord_TOC::getStyleTOC();
$tabPos = $styleTOC->getTabPos(); $fIndent = $styleTOC->getIndent();
$tabLeader = $styleTOC->getTabLeader();
$isObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; $tabPos = $styleTOC->getTabPos();
for($i=0; $i<count($titles); $i++) { $isObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
$title = $titles[$i];
$indent = ($title['depth'] - 1) * $fIndent; for ($i = 0; $i < count($titles); $i++) {
$title = $titles[$i];
$objWriter->startElement('w:p'); $indent = ($title['depth'] - 1) * $fIndent;
$objWriter->startElement('w:pPr'); $objWriter->startElement('w:p');
if($isObject && !is_null($styleFont->getParagraphStyle())) { $objWriter->startElement('w:pPr');
$this->_writeParagraphStyle($objWriter, $styleFont->getParagraphStyle());
} if ($isObject && !is_null($styleFont->getParagraphStyle())) {
$this->_writeParagraphStyle($objWriter, $styleFont->getParagraphStyle());
if($indent > 0) { }
$objWriter->startElement('w:ind');
$objWriter->writeAttribute('w:left', $indent); if ($indent > 0) {
$objWriter->endElement(); $objWriter->startElement('w:ind');
} $objWriter->writeAttribute('w:left', $indent);
$objWriter->endElement();
if(!empty($styleFont) && !$isObject) { }
$objWriter->startElement('w:pPr');
$objWriter->startElement('w:pStyle'); if (!empty($styleFont) && !$isObject) {
$objWriter->writeAttribute('w:val', $styleFont); $objWriter->startElement('w:pPr');
$objWriter->endElement(); $objWriter->startElement('w:pStyle');
$objWriter->endElement(); $objWriter->writeAttribute('w:val', $styleFont);
} $objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:tabs'); }
$objWriter->startElement('w:tab');
$objWriter->writeAttribute('w:val', 'right'); $objWriter->startElement('w:tabs');
if(!empty($tabLeader)) { $objWriter->startElement('w:tab');
$objWriter->writeAttribute('w:leader', $tabLeader); $objWriter->writeAttribute('w:val', 'right');
} if (!empty($tabLeader)) {
$objWriter->writeAttribute('w:pos', $tabPos); $objWriter->writeAttribute('w:leader', $tabLeader);
$objWriter->endElement(); }
$objWriter->endElement(); $objWriter->writeAttribute('w:pos', $tabPos);
$objWriter->endElement();
$objWriter->endElement(); // w:pPr $objWriter->endElement();
$objWriter->endElement(); // w:pPr
if($i == 0) {
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar'); if ($i == 0) {
$objWriter->writeAttribute('w:fldCharType', 'begin'); $objWriter->startElement('w:r');
$objWriter->endElement(); $objWriter->startElement('w:fldChar');
$objWriter->endElement(); $objWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement();
$objWriter->startElement('w:r'); $objWriter->endElement();
$objWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve'); $objWriter->startElement('w:r');
$objWriter->writeRaw('TOC \o "1-9" \h \z \u'); $objWriter->startElement('w:instrText');
$objWriter->endElement(); $objWriter->writeAttribute('xml:space', 'preserve');
$objWriter->endElement(); $objWriter->writeRaw('TOC \o "1-9" \h \z \u');
$objWriter->endElement();
$objWriter->startElement('w:r'); $objWriter->endElement();
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'separate'); $objWriter->startElement('w:r');
$objWriter->endElement(); $objWriter->startElement('w:fldChar');
$objWriter->endElement(); $objWriter->writeAttribute('w:fldCharType', 'separate');
} $objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:hyperlink'); }
$objWriter->writeAttribute('w:anchor', $title['anchor']);
$objWriter->writeAttribute('w:history', '1'); $objWriter->startElement('w:hyperlink');
$objWriter->writeAttribute('w:anchor', $title['anchor']);
$objWriter->startElement('w:r'); $objWriter->writeAttribute('w:history', '1');
if($isObject) { $objWriter->startElement('w:r');
$this->_writeTextStyle($objWriter, $styleFont);
} if ($isObject) {
$this->_writeTextStyle($objWriter, $styleFont);
$objWriter->startElement('w:t'); }
$objWriter->writeRaw($title['text']);
$objWriter->endElement(); $objWriter->startElement('w:t');
$objWriter->endElement(); $objWriter->writeRaw($title['text']);
$objWriter->endElement();
$objWriter->startElement('w:r'); $objWriter->endElement();
$objWriter->writeElement('w:tab', null);
$objWriter->endElement(); $objWriter->startElement('w:r');
$objWriter->writeElement('w:tab', null);
$objWriter->startElement('w:r'); $objWriter->endElement();
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'begin'); $objWriter->startElement('w:r');
$objWriter->endElement(); $objWriter->startElement('w:fldChar');
$objWriter->endElement(); $objWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement();
$objWriter->startElement('w:r'); $objWriter->endElement();
$objWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve'); $objWriter->startElement('w:r');
$objWriter->writeRaw('PAGEREF '.$title['anchor'].' \h'); $objWriter->startElement('w:instrText');
$objWriter->endElement(); $objWriter->writeAttribute('xml:space', 'preserve');
$objWriter->endElement(); $objWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h');
$objWriter->endElement();
$objWriter->startElement('w:r'); $objWriter->endElement();
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'end'); $objWriter->startElement('w:r');
$objWriter->endElement(); $objWriter->startElement('w:fldChar');
$objWriter->endElement(); $objWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement();
$objWriter->endElement(); // w:hyperlink $objWriter->endElement();
$objWriter->endElement(); // w:p $objWriter->endElement(); // w:hyperlink
}
$objWriter->endElement(); // w:p
$objWriter->startElement('w:p'); }
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar'); $objWriter->startElement('w:p');
$objWriter->writeAttribute('w:fldCharType', 'end'); $objWriter->startElement('w:r');
$objWriter->endElement(); $objWriter->startElement('w:fldChar');
$objWriter->endElement(); $objWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement(); $objWriter->endElement();
} $objWriter->endElement();
$objWriter->endElement();
}
} }

View File

@ -26,152 +26,155 @@
*/ */
class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_WriterPart { class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_WriterPart
{
public function writeDocumentRels($_relsCollection) {
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Relationship word/document.xml
$this->_writeRelationship(
$objWriter,
1,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
'styles.xml'
);
// Relationship word/numbering.xml
$this->_writeRelationship(
$objWriter,
2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
'numbering.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
3,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
'settings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
'theme/theme1.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
5,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
'webSettings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
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(
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/'.$relationType,
$relationName,
$targetMode
);
}
$objWriter->endElement(); public function writeDocumentRels($_relsCollection)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// Return // XML header
return $objWriter->getData(); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
}
public function writeHeaderFooterRels($_relsCollection) {
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->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(
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/'.$relationType,
$relationName
);
}
$objWriter->endElement(); // Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Return // Relationship word/document.xml
return $objWriter->getData(); $this->_writeRelationship(
} $objWriter,
1,
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
if($pType != '' && $pTarget != '') { 'styles.xml'
if(strpos($pId, 'rId') === false) { );
$pId = 'rId' . $pId;
}
// Write relationship
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if($pTargetMode != '') { // Relationship word/numbering.xml
$objWriter->writeAttribute('TargetMode', $pTargetMode); $this->_writeRelationship(
} $objWriter,
2,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
'numbering.xml'
);
$objWriter->endElement(); // Relationship word/settings.xml
} else { $this->_writeRelationship(
throw new Exception("Invalid parameters passed."); $objWriter,
} 3,
} 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
'settings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
4,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
'theme/theme1.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
5,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
'webSettings.xml'
);
// Relationship word/settings.xml
$this->_writeRelationship(
$objWriter,
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(
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName,
$targetMode
);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
public function writeHeaderFooterRels($_relsCollection)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Relationships
$objWriter->startElement('Relationships');
$objWriter->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(
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
$relationName
);
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode);
}
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
} }
?>

View File

@ -26,54 +26,56 @@
*/ */
class PHPWord_Writer_Word2007_Footer extends PHPWord_Writer_Word2007_Base { class PHPWord_Writer_Word2007_Footer extends PHPWord_Writer_Word2007_Base
{
public function writeFooter(PHPWord_Section_Footer $footer) {
// Create XML writer public function writeFooter(PHPWord_Section_Footer $footer)
$objWriter = null; {
if ($this->getParentWriter()->getUseDiskCaching()) { // Create XML writer
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); $objWriter = null;
} else { if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
// XML header }
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// XML header
$objWriter->startElement('w:ftr'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->writeAttribute('xmlns:ve','http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o','urn:schemas-microsoft-com:office:office'); $objWriter->startElement('w:ftr');
$objWriter->writeAttribute('xmlns:r','http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:m','http://schemas.openxmlformats.org/officeDocument/2006/math'); $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:v','urn:schemas-microsoft-com:vml'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:wp','http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:w10','urn:schemas-microsoft-com:office:word'); $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:w','http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:wne','http://schemas.microsoft.com/office/word/2006/wordml'); $objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$_elements = $footer->getElements(); $objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
foreach($_elements as $element) { $_elements = $footer->getElements();
if($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element); foreach ($_elements as $element) {
} elseif($element instanceof PHPWord_Section_TextRun) { if ($element instanceof PHPWord_Section_Text) {
$this->_writeTextRun($objWriter, $element); $this->_writeText($objWriter, $element);
} elseif($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextBreak($objWriter); $this->_writeTextRun($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTable($objWriter, $element); $this->_writeTextBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Image || } elseif ($element instanceof PHPWord_Section_Table) {
$element instanceof PHPWord_Section_MemoryImage) { $this->_writeTable($objWriter, $element);
$this->_writeImage($objWriter, $element); } elseif ($element instanceof PHPWord_Section_Image ||
} elseif($element instanceof PHPWord_Section_Footer_PreserveText) { $element instanceof PHPWord_Section_MemoryImage
$this->_writePreserveText($objWriter, $element); ) {
} $this->_writeImage($objWriter, $element);
} } elseif ($element instanceof PHPWord_Section_Footer_PreserveText) {
$this->_writePreserveText($objWriter, $element);
$objWriter->endElement(); }
}
// Return
return $objWriter->getData(); $objWriter->endElement();
}
// Return
return $objWriter->getData();
}
} }
?>

View File

@ -26,58 +26,60 @@
*/ */
class PHPWord_Writer_Word2007_Header extends PHPWord_Writer_Word2007_Base { class PHPWord_Writer_Word2007_Header extends PHPWord_Writer_Word2007_Base
{
public function writeHeader(PHPWord_Section_Header $header) {
// Create XML writer public function writeHeader(PHPWord_Section_Header $header)
if ($this->getParentWriter()->getUseDiskCaching()) { {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); // Create XML writer
} else { if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} } else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
// XML header }
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// XML header
$objWriter->startElement('w:hdr'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->writeAttribute('xmlns:ve','http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o','urn:schemas-microsoft-com:office:office'); $objWriter->startElement('w:hdr');
$objWriter->writeAttribute('xmlns:r','http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:m','http://schemas.openxmlformats.org/officeDocument/2006/math'); $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:v','urn:schemas-microsoft-com:vml'); $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:wp','http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); $objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:w10','urn:schemas-microsoft-com:office:word'); $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:w','http://schemas.openxmlformats.org/wordprocessingml/2006/main'); $objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:wne','http://schemas.microsoft.com/office/word/2006/wordml'); $objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$_elements = $header->getElements();
foreach($_elements as $element) { $_elements = $header->getElements();
if($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element); foreach ($_elements as $element) {
} elseif($element instanceof PHPWord_Section_TextRun) { if ($element instanceof PHPWord_Section_Text) {
$this->_writeTextRun($objWriter, $element); $this->_writeText($objWriter, $element);
} elseif($element instanceof PHPWord_Section_TextBreak) { } elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextBreak($objWriter); $this->_writeTextRun($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Table) { } elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTable($objWriter, $element); $this->_writeTextBreak($objWriter);
} elseif($element instanceof PHPWord_Section_Image || } elseif ($element instanceof PHPWord_Section_Table) {
$element instanceof PHPWord_Section_MemoryImage) { $this->_writeTable($objWriter, $element);
if(!$element->getIsWatermark()) { } elseif ($element instanceof PHPWord_Section_Image ||
$this->_writeImage($objWriter, $element); $element instanceof PHPWord_Section_MemoryImage
} else { ) {
$this->_writeWatermark($objWriter, $element); if (!$element->getIsWatermark()) {
} $this->_writeImage($objWriter, $element);
} elseif($element instanceof PHPWord_Section_Footer_PreserveText) { } else {
$this->_writePreserveText($objWriter, $element); $this->_writeWatermark($objWriter, $element);
} }
} } elseif ($element instanceof PHPWord_Section_Footer_PreserveText) {
$this->_writePreserveText($objWriter, $element);
$objWriter->endElement(); }
}
// Return
return $objWriter->getData(); $objWriter->endElement();
}
// Return
return $objWriter->getData();
}
} }
?>

View File

@ -26,85 +26,88 @@
*/ */
class PHPWord_Writer_Word2007_Rels extends PHPWord_Writer_Word2007_WriterPart { class PHPWord_Writer_Word2007_Rels extends PHPWord_Writer_Word2007_WriterPart
{
public function writeRelationships(PHPWord $pPHPWord = null) {
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header public function writeRelationships(PHPWord $pPHPWord = null)
$objWriter->startDocument('1.0','UTF-8','yes'); {
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// Relationships // XML header
$objWriter->startElement('Relationships'); $objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
$relationId = 1;
// Relationship word/document.xml
$this->_writeRelationship(
$objWriter,
$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
'word/document.xml'
);
// Relationship docProps/core.xml
$this->_writeRelationship(
$objWriter,
++$relationId,
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
'docProps/core.xml'
);
// Relationship docProps/app.xml
$this->_writeRelationship(
$objWriter,
++$relationId,
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
'docProps/app.xml'
);
$objWriter->endElement(); // Relationships
$objWriter->startElement('Relationships');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
// Return $relationId = 1;
return $objWriter->getData();
}
/** // Relationship word/document.xml
* Write Override content type $this->_writeRelationship(
* $objWriter,
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer $relationId,
* @param int $pId Relationship ID. rId will be prepended! 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
* @param string $pType Relationship type 'word/document.xml'
* @param string $pTarget Relationship target );
* @param string $pTargetMode Relationship target mode
* @throws Exception
*/
private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') {
if($pType != '' && $pTarget != '') {
if(strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if($pTargetMode != '') { // Relationship docProps/core.xml
$objWriter->writeAttribute('TargetMode', $pTargetMode); $this->_writeRelationship(
} $objWriter,
++$relationId,
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
'docProps/core.xml'
);
$objWriter->endElement(); // Relationship docProps/app.xml
} else { $this->_writeRelationship(
throw new Exception("Invalid parameters passed."); $objWriter,
} ++$relationId,
} 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
'docProps/app.xml'
);
$objWriter->endElement();
// Return
return $objWriter->getData();
}
/**
* Write Override content type
*
* @param PHPWord_Shared_XMLWriter $objWriter XML Writer
* @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(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
{
if ($pType != '' && $pTarget != '') {
if (strpos($pId, 'rId') === false) {
$pId = 'rId' . $pId;
}
// Write relationship
$objWriter->startElement('Relationship');
$objWriter->writeAttribute('Id', $pId);
$objWriter->writeAttribute('Type', $pType);
$objWriter->writeAttribute('Target', $pTarget);
if ($pTargetMode != '') {
$objWriter->writeAttribute('TargetMode', $pTargetMode);
}
$objWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
} }

View File

@ -26,321 +26,325 @@
*/ */
class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base { class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
{
private $_document;
public function writeStyles(PHPWord $pPHPWord = null) {
// Create XML writer
$objWriter = null;
if($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
$this->_document = $pPHPWord;
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');
$objWriter->startElement('w:styles');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// Write DocDefaults
$this->_writeDocDefaults($objWriter);
private $_document;
// Write Style Definitions
$styles = PHPWord_Style::getStyles();
if(count($styles) > 0) {
foreach($styles as $styleName => $style) {
if($style instanceof PHPWord_Style_Font) {
$paragraphStyle = $style->getParagraphStyle();
$styleType = $style->getStyleType();
$type = ($styleType == 'title') ? 'paragraph' : 'character';
if(!is_null($paragraphStyle)) {
$type = 'paragraph';
}
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', $type);
if($styleType == 'title') {
$arrStyle = explode('_', $styleName);
$styleId = 'Heading'.$arrStyle[1];
$styleName = 'heading '.$arrStyle[1];
$styleLink = 'Heading'.$arrStyle[1].'Char';
$objWriter->writeAttribute('w:styleId', $styleId);
$objWriter->startElement('w:link');
$objWriter->writeAttribute('w:val', $styleLink);
$objWriter->endElement();
}
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement();
if(!is_null($paragraphStyle)) {
$this->_writeParagraphStyle($objWriter, $paragraphStyle);
}
$this->_writeTextStyle($objWriter, $style);
$objWriter->endElement();
} elseif($style instanceof PHPWord_Style_Paragraph) {
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'paragraph');
$objWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:styleId', $styleName);
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement();
$this->_writeParagraphStyle($objWriter, $style);
$objWriter->endElement();
} elseif($style instanceof PHPWord_Style_TableFull) {
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'table');
$objWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:styleId', $styleName);
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement();
$objWriter->startElement('w:uiPriority');
$objWriter->writeAttribute('w:val', '99');
$objWriter->endElement();
$this->_writeFullTableStyle($objWriter, $style);
$objWriter->endElement();
}
}
}
$objWriter->endElement(); // w:styles
// Return
return $objWriter->getData();
}
private function _writeFullTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_TableFull $style) {
$brdSz = $style->getBorderSize(); public function writeStyles(PHPWord $pPHPWord = null)
$brdCol = $style->getBorderColor(); {
$bgColor = $style->getBgColor(); // Create XML writer
$cellMargin = $style->getCellMargin(); $objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$bTop = (!is_null($brdSz[0])) ? true : false; $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
$bLeft = (!is_null($brdSz[1])) ? true : false; } else {
$bRight = (!is_null($brdSz[2])) ? true : false; $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
$bBottom = (!is_null($brdSz[3])) ? true : false; }
$bInsH = (!is_null($brdSz[4])) ? true : false;
$bInsV = (!is_null($brdSz[5])) ? true : false; $this->_document = $pPHPWord;
$borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
// XML header
$mTop = (!is_null($cellMargin[0])) ? true : false; $objWriter->startDocument('1.0', 'UTF-8', 'yes');
$mLeft = (!is_null($cellMargin[1])) ? true : false;
$mRight = (!is_null($cellMargin[2])) ? true : false; $objWriter->startElement('w:styles');
$mBottom = (!is_null($cellMargin[3])) ? true : false;
$margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false; $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->startElement('w:tblPr');
// Write DocDefaults
if($margins) { $this->_writeDocDefaults($objWriter);
$objWriter->startElement('w:tblCellMar');
if($mTop) {
echo $margins[0]; // Write Style Definitions
$objWriter->startElement('w:top'); $styles = PHPWord_Style::getStyles();
$objWriter->writeAttribute('w:w', $cellMargin[0]); if (count($styles) > 0) {
$objWriter->writeAttribute('w:type', 'dxa'); foreach ($styles as $styleName => $style) {
$objWriter->endElement(); if ($style instanceof PHPWord_Style_Font) {
}
if($mLeft) { $paragraphStyle = $style->getParagraphStyle();
$objWriter->startElement('w:left'); $styleType = $style->getStyleType();
$objWriter->writeAttribute('w:w', $cellMargin[1]);
$objWriter->writeAttribute('w:type', 'dxa'); $type = ($styleType == 'title') ? 'paragraph' : 'character';
$objWriter->endElement();
} if (!is_null($paragraphStyle)) {
if($mRight) { $type = 'paragraph';
$objWriter->startElement('w:right'); }
$objWriter->writeAttribute('w:w', $cellMargin[2]);
$objWriter->writeAttribute('w:type', 'dxa'); $objWriter->startElement('w:style');
$objWriter->endElement(); $objWriter->writeAttribute('w:type', $type);
}
if($mBottom) { if ($styleType == 'title') {
$objWriter->startElement('w:bottom'); $arrStyle = explode('_', $styleName);
$objWriter->writeAttribute('w:w', $cellMargin[3]); $styleId = 'Heading' . $arrStyle[1];
$objWriter->writeAttribute('w:type', 'dxa'); $styleName = 'heading ' . $arrStyle[1];
$objWriter->endElement(); $styleLink = 'Heading' . $arrStyle[1] . 'Char';
} $objWriter->writeAttribute('w:styleId', $styleId);
$objWriter->endElement();
} $objWriter->startElement('w:link');
$objWriter->writeAttribute('w:val', $styleLink);
if($borders) { $objWriter->endElement();
$objWriter->startElement('w:tblBorders'); }
if($bTop) {
$objWriter->startElement('w:top'); $objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:val', $styleName);
$objWriter->writeAttribute('w:sz', $brdSz[0]); $objWriter->endElement();
$objWriter->writeAttribute('w:color', $brdCol[0]);
$objWriter->endElement(); if (!is_null($paragraphStyle)) {
} $this->_writeParagraphStyle($objWriter, $paragraphStyle);
if($bLeft) { }
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single'); $this->_writeTextStyle($objWriter, $style);
$objWriter->writeAttribute('w:sz', $brdSz[1]);
$objWriter->writeAttribute('w:color', $brdCol[1]); $objWriter->endElement();
$objWriter->endElement();
} } elseif ($style instanceof PHPWord_Style_Paragraph) {
if($bRight) { $objWriter->startElement('w:style');
$objWriter->startElement('w:right'); $objWriter->writeAttribute('w:type', 'paragraph');
$objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:sz', $brdSz[2]); $objWriter->writeAttribute('w:styleId', $styleName);
$objWriter->writeAttribute('w:color', $brdCol[2]);
$objWriter->endElement(); $objWriter->startElement('w:name');
} $objWriter->writeAttribute('w:val', $styleName);
if($bBottom) { $objWriter->endElement();
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single'); $this->_writeParagraphStyle($objWriter, $style);
$objWriter->writeAttribute('w:sz', $brdSz[3]); $objWriter->endElement();
$objWriter->writeAttribute('w:color', $brdCol[3]);
$objWriter->endElement(); } elseif ($style instanceof PHPWord_Style_TableFull) {
} $objWriter->startElement('w:style');
if($bInsH) { $objWriter->writeAttribute('w:type', 'table');
$objWriter->startElement('w:insideH'); $objWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:styleId', $styleName);
$objWriter->writeAttribute('w:sz', $brdSz[4]);
$objWriter->writeAttribute('w:color', $brdCol[4]); $objWriter->startElement('w:name');
$objWriter->endElement(); $objWriter->writeAttribute('w:val', $styleName);
} $objWriter->endElement();
if($bInsV) {
$objWriter->startElement('w:insideV'); $objWriter->startElement('w:uiPriority');
$objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:val', '99');
$objWriter->writeAttribute('w:sz', $brdSz[5]); $objWriter->endElement();
$objWriter->writeAttribute('w:color', $brdCol[5]);
$objWriter->endElement(); $this->_writeFullTableStyle($objWriter, $style);
}
$objWriter->endElement(); $objWriter->endElement();
} }
}
$objWriter->endElement(); }
if(!is_null($bgColor)) { $objWriter->endElement(); // w:styles
$objWriter->startElement('w:tcPr');
$objWriter->startElement('w:shd'); // Return
$objWriter->writeAttribute('w:val', 'clear'); return $objWriter->getData();
$objWriter->writeAttribute('w:color', 'auto'); }
$objWriter->writeAttribute('w:fill', $bgColor);
$objWriter->endElement(); private function _writeFullTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_TableFull $style)
$objWriter->endElement(); {
}
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
// First Row $bgColor = $style->getBgColor();
$firstRow = $style->getFirstRow(); $cellMargin = $style->getCellMargin();
if(!is_null($firstRow)) {
$this->_writeRowStyle($objWriter, 'firstRow', $firstRow); $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;
private function _writeRowStyle(PHPWord_Shared_XMLWriter $objWriter = null, $type, PHPWord_Style_TableFull $style) { $bInsH = (!is_null($brdSz[4])) ? true : false;
$brdSz = $style->getBorderSize(); $bInsV = (!is_null($brdSz[5])) ? true : false;
$brdCol = $style->getBorderColor(); $borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
$bgColor = $style->getBgColor();
$mTop = (!is_null($cellMargin[0])) ? true : false;
$bTop = (!is_null($brdSz[0])) ? true : false; $mLeft = (!is_null($cellMargin[1])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false; $mRight = (!is_null($cellMargin[2])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false; $mBottom = (!is_null($cellMargin[3])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false; $margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
$objWriter->startElement('w:tblPr');
$objWriter->startElement('w:tblStylePr');
$objWriter->writeAttribute('w:type', $type); if ($margins) {
$objWriter->startElement('w:tblCellMar');
$objWriter->startElement('w:tcPr'); if ($mTop) {
if(!is_null($bgColor)) { echo $margins[0];
$objWriter->startElement('w:shd'); $objWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'clear'); $objWriter->writeAttribute('w:w', $cellMargin[0]);
$objWriter->writeAttribute('w:color', 'auto'); $objWriter->writeAttribute('w:type', 'dxa');
$objWriter->writeAttribute('w:fill', $bgColor); $objWriter->endElement();
$objWriter->endElement(); }
} if ($mLeft) {
$objWriter->startElement('w:left');
$objWriter->startElement('w:tcBorders'); $objWriter->writeAttribute('w:w', $cellMargin[1]);
if($bTop) { $objWriter->writeAttribute('w:type', 'dxa');
$objWriter->startElement('w:top'); $objWriter->endElement();
$objWriter->writeAttribute('w:val', 'single'); }
$objWriter->writeAttribute('w:sz', $brdSz[0]); if ($mRight) {
$objWriter->writeAttribute('w:color', $brdCol[0]); $objWriter->startElement('w:right');
$objWriter->endElement(); $objWriter->writeAttribute('w:w', $cellMargin[2]);
} $objWriter->writeAttribute('w:type', 'dxa');
if($bLeft) { $objWriter->endElement();
$objWriter->startElement('w:left'); }
$objWriter->writeAttribute('w:val', 'single'); if ($mBottom) {
$objWriter->writeAttribute('w:sz', $brdSz[1]); $objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:color', $brdCol[1]); $objWriter->writeAttribute('w:w', $cellMargin[3]);
$objWriter->endElement(); $objWriter->writeAttribute('w:type', 'dxa');
} $objWriter->endElement();
if($bRight) { }
$objWriter->startElement('w:right'); $objWriter->endElement();
$objWriter->writeAttribute('w:val', 'single'); }
$objWriter->writeAttribute('w:sz', $brdSz[2]);
$objWriter->writeAttribute('w:color', $brdCol[2]); if ($borders) {
$objWriter->endElement(); $objWriter->startElement('w:tblBorders');
} if ($bTop) {
if($bBottom) { $objWriter->startElement('w:top');
$objWriter->startElement('w:bottom'); $objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:val', 'single'); $objWriter->writeAttribute('w:sz', $brdSz[0]);
$objWriter->writeAttribute('w:sz', $brdSz[3]); $objWriter->writeAttribute('w:color', $brdCol[0]);
$objWriter->writeAttribute('w:color', $brdCol[3]); $objWriter->endElement();
$objWriter->endElement(); }
} if ($bLeft) {
$objWriter->endElement(); $objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->endElement(); $objWriter->writeAttribute('w:sz', $brdSz[1]);
$objWriter->writeAttribute('w:color', $brdCol[1]);
$objWriter->endElement(); $objWriter->endElement();
} }
if ($bRight) {
$objWriter->startElement('w:right');
private function _writeDocDefaults(PHPWord_Shared_XMLWriter $objWriter = null) { $objWriter->writeAttribute('w:val', 'single');
$fontName = $this->_document->getDefaultFontName(); $objWriter->writeAttribute('w:sz', $brdSz[2]);
$fontSize = $this->_document->getDefaultFontSize(); $objWriter->writeAttribute('w:color', $brdCol[2]);
$objWriter->endElement();
$objWriter->startElement('w:docDefaults'); }
$objWriter->startElement('w:rPrDefault'); if ($bBottom) {
$objWriter->startElement('w:rPr'); $objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->startElement('w:rFonts'); $objWriter->writeAttribute('w:sz', $brdSz[3]);
$objWriter->writeAttribute('w:ascii', $fontName); $objWriter->writeAttribute('w:color', $brdCol[3]);
$objWriter->writeAttribute('w:hAnsi', $fontName); $objWriter->endElement();
$objWriter->writeAttribute('w:eastAsia', $fontName); }
$objWriter->writeAttribute('w:cs', $fontName); if ($bInsH) {
$objWriter->endElement(); $objWriter->startElement('w:insideH');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->startElement('w:sz'); $objWriter->writeAttribute('w:sz', $brdSz[4]);
$objWriter->writeAttribute('w:val', $fontSize); $objWriter->writeAttribute('w:color', $brdCol[4]);
$objWriter->endElement(); $objWriter->endElement();
}
$objWriter->startElement('w:szCs'); if ($bInsV) {
$objWriter->writeAttribute('w:val', $fontSize); $objWriter->startElement('w:insideV');
$objWriter->endElement(); $objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[5]);
$objWriter->endElement(); $objWriter->writeAttribute('w:color', $brdCol[5]);
$objWriter->endElement(); $objWriter->endElement();
$objWriter->endElement(); }
} $objWriter->endElement();
}
$objWriter->endElement();
if (!is_null($bgColor)) {
$objWriter->startElement('w:tcPr');
$objWriter->startElement('w:shd');
$objWriter->writeAttribute('w:val', 'clear');
$objWriter->writeAttribute('w:color', 'auto');
$objWriter->writeAttribute('w:fill', $bgColor);
$objWriter->endElement();
$objWriter->endElement();
}
// First Row
$firstRow = $style->getFirstRow();
if (!is_null($firstRow)) {
$this->_writeRowStyle($objWriter, 'firstRow', $firstRow);
}
}
private function _writeRowStyle(PHPWord_Shared_XMLWriter $objWriter = null, $type, PHPWord_Style_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;
$objWriter->startElement('w:tblStylePr');
$objWriter->writeAttribute('w:type', $type);
$objWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$objWriter->startElement('w:shd');
$objWriter->writeAttribute('w:val', 'clear');
$objWriter->writeAttribute('w:color', 'auto');
$objWriter->writeAttribute('w:fill', $bgColor);
$objWriter->endElement();
}
$objWriter->startElement('w:tcBorders');
if ($bTop) {
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[0]);
$objWriter->writeAttribute('w:color', $brdCol[0]);
$objWriter->endElement();
}
if ($bLeft) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[1]);
$objWriter->writeAttribute('w:color', $brdCol[1]);
$objWriter->endElement();
}
if ($bRight) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[2]);
$objWriter->writeAttribute('w:color', $brdCol[2]);
$objWriter->endElement();
}
if ($bBottom) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[3]);
$objWriter->writeAttribute('w:color', $brdCol[3]);
$objWriter->endElement();
}
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
private function _writeDocDefaults(PHPWord_Shared_XMLWriter $objWriter = null)
{
$fontName = $this->_document->getDefaultFontName();
$fontSize = $this->_document->getDefaultFontSize();
$objWriter->startElement('w:docDefaults');
$objWriter->startElement('w:rPrDefault');
$objWriter->startElement('w:rPr');
$objWriter->startElement('w:rFonts');
$objWriter->writeAttribute('w:ascii', $fontName);
$objWriter->writeAttribute('w:hAnsi', $fontName);
$objWriter->writeAttribute('w:eastAsia', $fontName);
$objWriter->writeAttribute('w:cs', $fontName);
$objWriter->endElement();
$objWriter->startElement('w:sz');
$objWriter->writeAttribute('w:val', $fontSize);
$objWriter->endElement();
$objWriter->startElement('w:szCs');
$objWriter->writeAttribute('w:val', $fontSize);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
} }
?>

View File

@ -26,18 +26,21 @@
*/ */
abstract class PHPWord_Writer_Word2007_WriterPart { abstract class PHPWord_Writer_Word2007_WriterPart
private $_parentWriter; {
private $_parentWriter;
public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null) {
$this->_parentWriter = $pWriter; public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null)
} {
$this->_parentWriter = $pWriter;
public function getParentWriter() { }
if (!is_null($this->_parentWriter)) {
return $this->_parentWriter; public function getParentWriter()
} else { {
throw new Exception("No parent PHPWord_Writer_IWriter assigned."); if (!is_null($this->_parentWriter)) {
} return $this->_parentWriter;
} } else {
throw new Exception("No parent PHPWord_Writer_IWriter assigned.");
}
}
} }