#159 #58 Merge branch 'develop' of https://github.com/RomanSyroeshko/PHPWord into develop

This commit is contained in:
Ivan Lanin 2014-03-23 17:37:26 +07:00
commit c7f03ecdf3
226 changed files with 6736 additions and 7848 deletions

View File

@ -1,6 +1,7 @@
language: php language: php
php: php:
- 5.3.3
- 5.3 - 5.3
- 5.4 - 5.4
- 5.5 - 5.5
@ -11,14 +12,15 @@ matrix:
allow_failures: allow_failures:
- php: 5.6 - php: 5.6
- php: hhvm - php: hhvm
before_script: before_script:
## Composer ## Composer
- curl -s http://getcomposer.org/installer | php - curl -s http://getcomposer.org/installer | php
- php composer.phar install --prefer-source - php composer.phar install --prefer-source
- composer selfupdate --quiet
## PHP_CodeSniffer ## PHP_CodeSniffer
#- pyrus install pear/PHP_CodeSniffer - pyrus install pear/PHP_CodeSniffer
#- phpenv rehash - phpenv rehash
## PHP Copy/Paste Detector ## PHP Copy/Paste Detector
#- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar #- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
## PHP Mess Detector ## PHP Mess Detector
@ -33,13 +35,13 @@ before_script:
script: script:
## PHP_CodeSniffer ## PHP_CodeSniffer
## - phpcs --standard=PSR1 Classes/ - phpcs --standard=PSR1 -n src/
## - phpcs --standard=PSR2 Classes/ - phpcs --standard=PSR2 -n src/
## PHP Copy/Paste Detector ## PHP Copy/Paste Detector
#- php phpcpd.phar --verbose Classes/ #- php phpcpd.phar --verbose src/
## PHP Mess Detector ## PHP Mess Detector
#- phpmd Classes/ text unusedcode,naming,design #- phpmd src/ text unusedcode,naming,design
## PHPLOC ## PHPLOC
#- php phploc.phar Classes/ #- php phploc.phar src/
## PHPUnit ## PHPUnit
- phpunit -c ./ --coverage-text - phpunit -c ./ --coverage-text

View File

@ -1,6 +1,6 @@
# Changelog # Changelog
This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version are listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub. This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub.
## 0.9.0 - Not yet released ## 0.9.0 - Not yet released

View File

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

View File

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

View File

@ -1,158 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
use PhpOffice\PhpWord\Exceptions\Exception;
/**
* Class PHPWord_IOFactory
*/
class PHPWord_IOFactory
{
/**
* Search locations
*
* @var array
*/
private static $_searchLocations = array(
array('type' => 'IWriter', 'path' => 'PHPWord/Writer/{0}.php', 'class' => 'PHPWord_Writer_{0}'),
array('type' => 'IReader', 'path' => 'PHPWord/Reader/{0}.php', 'class' => 'PHPWord_Reader_{0}' ),
);
/**
* Autoresolve classes
*
* @var array
*/
private static $_autoResolveClasses = array(
'Serialized'
);
/**
* Private constructor for PHPWord_IOFactory
*/
private function __construct()
{
}
/**
* Get search locations
*
* @return array
*/
public static function getSearchLocations()
{
return self::$_searchLocations;
}
/**
* Set search locations
*
* @param array $value
* @throws Exception
*/
public static function setSearchLocations(array $value)
{
self::$_searchLocations = $value;
}
/**
* Add search location
*
* @param string $type Example: IWriter
* @param string $location Example: PHPWord/Writer/{0}.php
* @param string $classname Example: PHPWord_Writer_{0}
*/
public static function addSearchLocation($type = '', $location = '', $classname = '')
{
self::$_searchLocations[] = array('type' => $type, 'path' => $location, 'class' => $classname);
}
/**
* Create PHPWord_Writer_IWriter
*
* @param PHPWord $PHPWord
* @param string $writerType Example: Word2007
* @return PHPWord_Writer_IWriter
* @throws Exception
*/
public static function createWriter(PHPWord $PHPWord, $writerType = '')
{
$searchType = 'IWriter';
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $writerType, $searchLocation['class']);
$classFile = str_replace('{0}', $writerType, $searchLocation['path']);
$instance = new $className($PHPWord);
if (!is_null($instance)) {
return $instance;
}
}
}
throw new Exception("No $searchType found for type $writerType");
}
/**
* Create PHPWord_Reader_IReader
*
* @param string $readerType Example: Word2007
* @return PHPWord_Reader_IReader
* @throws Exception
*/
public static function createReader($readerType = '')
{
$searchType = 'IReader';
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $readerType, $searchLocation['class']);
$instance = new $className();
if ($instance !== null) {
return $instance;
}
}
}
throw new Exception("No $searchType found for type $readerType");
}
/**
* Loads PHPWord from file
*
* @param string $pFilename The name of the file
* @param string $readerType
* @return PHPWord
*/
public static function load($pFilename, $readerType = 'Word2007')
{
$reader = self::createReader($readerType);
return $reader->load($pFilename);
}
}

View File

@ -1,128 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Shared_File
*/
class PHPWord_Shared_File
{
const IMAGETYPE_JPEG = 'jpg';
const IMAGETYPE_GIF = 'gif';
const IMAGETYPE_PNG = 'png';
const IMAGETYPE_BMP = 'bmp';
const IMAGETYPE_TIFF = 'tif';
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function file_exists($pFilename)
{
return file_exists($pFilename);
}
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename)
{
$returnValue = realpath($pFilename);
if (!$returnValue) {
$pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] !== '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] === '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
return $returnValue;
}
/**
* PHP Words version of exif_imagetype to return the Image Type from a file
*
* @param string $filename
* @return int|bool
*/
private static function fallbackImagetype($filename)
{
if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) {
if ($type === 2) {
return self::IMAGETYPE_JPEG;
} elseif ($type === 1) {
return self::IMAGETYPE_GIF;
} elseif ($type === 3) {
return self::IMAGETYPE_PNG;
} elseif ($type === 6) {
return self::IMAGETYPE_BMP;
} elseif ($type === 7 || $type === 8) {
return self::IMAGETYPE_TIFF;
}
}
return false;
}
/**
* Return the Image Type from a file
*
* @param string $filename
* @param bool $useFallbackFunction
* @return int|bool
*/
public static function imagetype($filename, $useFallbackFunction = false)
{
if ($useFallbackFunction || !function_exists('exif_imagetype')) {
return self::fallbackImagetype($filename);
}
$imagetype = exif_imagetype($filename);
if ($imagetype === IMAGETYPE_JPEG) {
return self::IMAGETYPE_JPEG;
} elseif ($imagetype === IMAGETYPE_GIF) {
return self::IMAGETYPE_GIF;
} elseif ($imagetype === IMAGETYPE_PNG) {
return self::IMAGETYPE_PNG;
} elseif ($imagetype === IMAGETYPE_BMP) {
return self::IMAGETYPE_BMP;
} elseif ($imagetype === IMAGETYPE_TIFF_II || $imagetype === IMAGETYPE_TIFF_MM) {
return self::IMAGETYPE_TIFF;
}
return false;
}
}

View File

@ -1,411 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Manifest
*/
class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
{
/**
* Write content file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
*/
public function writeContent(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
$objWriter->startDocument('1.0', 'UTF-8');
// office:document-content
$objWriter->startElement('office:document-content');
$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: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: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:xlink', 'http://www.w3.org/1999/xlink');
$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: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: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:math', 'http://www.w3.org/1998/Math/MathML');
$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:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$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:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$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: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('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->setParagraphStyle('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
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
}
}
}
if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$objWriter->endElement();
}
}
$objWriter->endElement();
$objWriter->startElement('office:automatic-styles');
$styles = PHPWord_Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if (preg_match('#^T[0-9]+$#', $styleName) != 0
|| preg_match('#^P[0-9]+$#', $styleName) != 0
) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
$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: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) {
$numPStyles++;
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$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();
}
}
}
if ($numPStyles == 0) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', 'P1');
$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);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter);
} elseif ($element instanceof PHPWord_Section_Link) {
$this->writeUnsupportedElement($objWriter, 'Link');
} elseif ($element instanceof PHPWord_Section_Title) {
$this->writeUnsupportedElement($objWriter, 'Title');
} elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->writeUnsupportedElement($objWriter, 'Page Break');
} elseif ($element instanceof PHPWord_Section_Table) {
$this->writeUnsupportedElement($objWriter, 'Table');
} elseif ($element instanceof PHPWord_Section_ListItem) {
$this->writeUnsupportedElement($objWriter, 'List Item');
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) {
$this->writeUnsupportedElement($objWriter, 'Image');
} elseif ($element instanceof PHPWord_Section_Object) {
$this->writeUnsupportedElement($objWriter, 'Object');
} elseif ($element instanceof PHPWord_TOC) {
$this->writeUnsupportedElement($objWriter, 'TOC');
} else {
$this->writeUnsupportedElement($objWriter, 'Element');
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
}
}
}
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->getData();
}
/**
* Write text
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section_Text $text
* @param bool $withoutP
*/
protected function _writeText(
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section_Text $text,
$withoutP = false
) {
$styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value
// $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
$SfIsObject = false;
if ($SfIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared
die('PHPWord : $SfIsObject wouldn\'t be an object');
} else {
if (!$withoutP) {
$objWriter->startElement('text:p'); // text:p
}
if (empty($styleFont)) {
if (empty($styleParagraph)) {
$objWriter->writeAttribute('text:style-name', 'P1');
} else {
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
$objWriter->writeRaw($text->getText());
} else {
if (empty($styleParagraph)) {
$objWriter->writeAttribute('text:style-name', 'Standard');
} else {
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
// text:span
$objWriter->startElement('text:span');
$objWriter->writeAttribute('text:style-name', $styleFont);
$objWriter->writeRaw($text->getText());
$objWriter->endElement();
}
if (!$withoutP) {
$objWriter->endElement(); // text:p
}
}
}
/**
* Write TextRun section
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section_TextRun $textrun
* @todo Enable all other section types
*/
protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun)
{
$elements = $textrun->getElements();
$objWriter->startElement('text:p');
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element, true);
}
}
}
$objWriter->endElement();
}
/**
* Write TextBreak
*
* @param PHPWord_Shared_XMLWriter $objWriter
*/
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null)
{
$objWriter->startElement('text:p');
$objWriter->writeAttribute('text:style-name', 'Standard');
$objWriter->endElement();
}
// @codeCoverageIgnoreStart
/**
* Write end section
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section $section
*/
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
{
}
/**
* Write section
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section $section
*/
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
{
}
// @codeCoverageIgnoreEnd
/**
* Write unsupported element
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param string $element
*/
private function writeUnsupportedElement($objWriter, $element)
{
$objWriter->startElement('text:p');
$objWriter->writeRaw("{$element}");
$objWriter->endElement();
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Meta
*/
class PHPWord_Writer_ODText_Meta extends PHPWord_Writer_ODText_WriterPart
{
/**
* Write Meta file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
*/
public function writeMeta(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
$objWriter->startDocument('1.0', 'UTF-8');
// office:document-meta
$objWriter->startElement('office:document-meta');
$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:dc', 'http://purl.org/dc/elements/1.1/');
$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:grddl', 'http://www.w3.org/2003/g/data-view#');
$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
return $objWriter->getData();
}
}

View File

@ -1,267 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Styles
*/
class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
{
/**
* Write Styles file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
*/
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);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
// Styles:Styles
$objWriter->startElement('office:document-styles');
$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: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: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:xlink', 'http://www.w3.org/1999/xlink');
$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: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: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:math', 'http://www.w3.org/1998/Math/MathML');
$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:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$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:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$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(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$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', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('fo:font-size', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('fo:language', 'fr');
$objWriter->writeAttribute('fo:country', 'FR');
$objWriter->writeAttribute('style:letter-kerning', 'true');
$objWriter->writeAttribute('style:font-name-asian', PHPWord::DEFAULT_FONT_NAME . '2');
$objWriter->writeAttribute('style:font-size-asian', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('style:language-asian', 'zh');
$objWriter->writeAttribute('style:country-asian', 'CN');
$objWriter->writeAttribute('style:font-name-complex', PHPWord::DEFAULT_FONT_NAME . '2');
$objWriter->writeAttribute('style:font-size-complex', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$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()) . 'pt');
$objWriter->writeAttribute('style:font-size-asian', ($style->getSize()) . 'pt');
$objWriter->writeAttribute('style:font-size-complex', ($style->getSize()) . '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();
} elseif ($style instanceof PHPWord_Style_Paragraph) {
// 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();
} elseif ($style instanceof PHPWord_Style_TableFull) {
// 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();
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,511 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Document
*/
class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
{
/**
* Write document.xml
*/
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, $element);
} 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);
} elseif ($element instanceof PHPWord_Section_Footnote) {
$this->_writeFootnoteReference($objWriter, $element);
}
}
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();
}
/**
* Write section start
*/
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();
}
/**
* Write section end
*/
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
{
$settings = $section->getSettings();
$_headers = $section->getHeaders();
$_footer = $section->getFooter();
$pgSzW = $settings->getPageSizeW();
$pgSzH = $settings->getPageSizeH();
$orientation = $settings->getOrientation();
$marginTop = $settings->getMarginTop();
$marginLeft = $settings->getMarginLeft();
$marginRight = $settings->getMarginRight();
$marginBottom = $settings->getMarginBottom();
$headerHeight = $settings->getHeaderHeight();
$footerHeight = $settings->getFooterHeight();
$borders = $settings->getBorderSize();
$colsNum = $settings->getColsNum();
$colsSpace = $settings->getColsSpace();
$breakType = $settings->getBreakType();
$objWriter->startElement('w:sectPr');
foreach ($_headers as &$_header) {
$rId = $_header->getRelationId();
$objWriter->startElement('w:headerReference');
$objWriter->writeAttribute('w:type', $_header->getType());
$objWriter->writeAttribute('r:id', 'rId' . $rId);
$objWriter->endElement();
}
if ($section->hasDifferentFirstPage()) {
$objWriter->startElement('w:titlePg');
$objWriter->endElement();
}
if (!is_null($breakType)) {
$objWriter->startElement('w:type');
$objWriter->writeAttribute('w:val', $breakType);
$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', $headerHeight);
$objWriter->writeAttribute('w:footer', $footerHeight);
$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();
}
// Page numbering
if (null !== $settings->getPageNumberingStart()) {
$objWriter->startElement('w:pgNumType');
$objWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart());
$objWriter->endElement();
}
$objWriter->startElement('w:cols');
$objWriter->writeAttribute('w:num', $colsNum);
$objWriter->writeAttribute('w:space', $colsSpace);
$objWriter->endElement();
$objWriter->endElement();
}
/**
* Write page break element
*/
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();
}
/**
* Write list item element
*/
public function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem)
{
$textObject = $listItem->getTextObject();
$text = $textObject->getText();
$styleParagraph = $textObject->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
$depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType();
$objWriter->startElement('w:p');
$objWriter->startElement('w:pPr');
if ($SpIsObject) {
$this->_writeParagraphStyle($objWriter, $styleParagraph, true);
} elseif (!$SpIsObject && !is_null($styleParagraph)) {
$objWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleParagraph);
$objWriter->endElement();
}
$objWriter->startElement('w:numPr');
$objWriter->startElement('w:ilvl');
$objWriter->writeAttribute('w:val', $depth);
$objWriter->endElement();
$objWriter->startElement('w:numId');
$objWriter->writeAttribute('w:val', $listType);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$this->_writeText($objWriter, $textObject, true);
$objWriter->endElement();
}
/**
* Write object element
*/
protected function _writeObject(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Object $object)
{
$rIdObject = $object->getRelationId();
$rIdImage = $object->getImageRelationId();
$shapeId = md5($rIdObject . '_' . $rIdImage);
$objectId = $object->getObjectId();
$style = $object->getStyle();
$width = $style->getWidth();
$height = $style->getHeight();
$align = $style->getAlign();
$objWriter->startElement('w:p');
if (!is_null($align)) {
$objWriter->startElement('w:pPr');
$objWriter->startElement('w:jc');
$objWriter->writeAttribute('w:val', $align);
$objWriter->endElement();
$objWriter->endElement();
}
$objWriter->startElement('w:r');
$objWriter->startElement('w:object');
$objWriter->writeAttribute('w:dxaOrig', '249');
$objWriter->writeAttribute('w:dyaOrig', '160');
$objWriter->startElement('v:shape');
$objWriter->writeAttribute('id', $shapeId);
$objWriter->writeAttribute('type', '#_x0000_t75');
$objWriter->writeAttribute('style', 'width:104px;height:67px');
$objWriter->writeAttribute('o:ole', '');
$objWriter->startElement('v:imagedata');
$objWriter->writeAttribute('r:id', 'rId' . $rIdImage);
$objWriter->writeAttribute('o:title', '');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('o:OLEObject');
$objWriter->writeAttribute('Type', 'Embed');
$objWriter->writeAttribute('ProgID', 'Package');
$objWriter->writeAttribute('ShapeID', $shapeId);
$objWriter->writeAttribute('DrawAspect', 'Icon');
$objWriter->writeAttribute('ObjectID', '_' . $objectId);
$objWriter->writeAttribute('r:id', 'rId' . $rIdObject);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:p
}
/**
* Write TOC element
*/
private function _writeTOC(PHPWord_Shared_XMLWriter $objWriter = null)
{
$titles = PHPWord_TOC::getTitles();
$styleFont = PHPWord_TOC::getStyleFont();
$styleTOC = PHPWord_TOC::getStyleTOC();
$fIndent = $styleTOC->getIndent();
$tabLeader = $styleTOC->getTabLeader();
$tabPos = $styleTOC->getTabPos();
$isObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
for ($i = 0; $i < count($titles); $i++) {
$title = $titles[$i];
$indent = ($title['depth'] - 1) * $fIndent;
$objWriter->startElement('w:p');
$objWriter->startElement('w:pPr');
if ($isObject && !is_null($styleFont->getParagraphStyle())) {
$this->_writeParagraphStyle($objWriter, $styleFont->getParagraphStyle());
}
if ($indent > 0) {
$objWriter->startElement('w:ind');
$objWriter->writeAttribute('w:left', $indent);
$objWriter->endElement();
}
if (!empty($styleFont) && !$isObject) {
$objWriter->startElement('w:pPr');
$objWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleFont);
$objWriter->endElement();
$objWriter->endElement();
}
$objWriter->startElement('w:tabs');
$objWriter->startElement('w:tab');
$objWriter->writeAttribute('w:val', 'right');
if (!empty($tabLeader)) {
$objWriter->writeAttribute('w:leader', $tabLeader);
}
$objWriter->writeAttribute('w:pos', $tabPos);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement(); // w:pPr
if ($i == 0) {
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve');
$objWriter->writeRaw('TOC \o "1-9" \h \z \u');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$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:r');
if ($isObject) {
$this->_writeTextStyle($objWriter, $styleFont);
}
$objWriter->startElement('w:t');
$objWriter->writeRaw($title['text']);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->writeElement('w:tab', null);
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve');
$objWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement(); // w:hyperlink
$objWriter->endElement(); // w:p
}
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
}

View File

@ -1,88 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Footer
*/
class PHPWord_Writer_Word2007_Footer extends PHPWord_Writer_Word2007_Base
{
/**
* Write footer
*
* @param PHPWord_Section_Footer $footer
* @return string XML data
*/
public function writeFooter(PHPWord_Section_Footer $footer)
{
// 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');
$objWriter->startElement('w:ftr');
$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');
$_elements = $footer->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_TextBreak) {
$this->_writeTextBreak($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage
) {
$this->_writeImage($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Footer_PreserveText) {
$this->_writePreserveText($objWriter, $element);
}
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,91 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Footnotes
*/
class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base
{
/**
* Write footnotes.xml
*
* @param array $allFootnotesCollection
* @return string XML data
*/
public function writeFootnotes($allFootnotesCollection)
{
// 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');
$objWriter->startElement('w:footnotes');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// write separator and continuation separator
$objWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', 0);
$objWriter->writeAttribute('w:type', 'separator');
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:separator');
$objWriter->endElement(); // w:separator
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:p
$objWriter->endElement(); // w:footnote
$objWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', 1);
$objWriter->writeAttribute('w:type', 'continuationSeparator');
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:continuationSeparator');
$objWriter->endElement(); // w:continuationSeparator
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:p
$objWriter->endElement(); // w:footnote
foreach ($allFootnotesCollection as $footnote) {
if ($footnote instanceof PHPWord_Section_Footnote) {
$this->_writeFootnote($objWriter, $footnote);
}
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,92 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Header
*/
class PHPWord_Writer_Word2007_Header extends PHPWord_Writer_Word2007_Base
{
/**
* Write header
*
* @param PHPWord_Section_Header $header
* @return string XML data
*/
public function writeHeader(PHPWord_Section_Header $header)
{
// 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');
$objWriter->startElement('w:hdr');
$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');
$_elements = $header->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_TextBreak) {
$this->_writeTextBreak($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage
) {
if (!$element->getIsWatermark()) {
$this->_writeImage($objWriter, $element);
} else {
$this->_writeWatermark($objWriter, $element);
}
} elseif ($element instanceof PHPWord_Section_Footer_PreserveText) {
$this->_writePreserveText($objWriter, $element);
}
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,420 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Styles
*/
class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
{
/**
* PHPWord object
*
* @var PHPWord
*/
private $_document;
/**
* Write styles
*
* @param PHPWord $pPHPWord
*/
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);
// Write Style Definitions
$styles = PHPWord_Style::getStyles();
// Write normal paragraph style
$normalStyle = null;
if (array_key_exists('Normal', $styles)) {
$normalStyle = $styles['Normal'];
}
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'paragraph');
$objWriter->writeAttribute('w:default', '1');
$objWriter->writeAttribute('w:styleId', 'Normal');
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', 'Normal');
$objWriter->endElement();
if (!is_null($normalStyle)) {
$this->_writeParagraphStyle($objWriter, $normalStyle);
}
$objWriter->endElement();
// Write other styles
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if ($styleName == 'Normal') {
continue;
}
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)) {
// Point parent style to Normal
$objWriter->startElement('w:basedOn');
$objWriter->writeAttribute('w:val', 'Normal');
$objWriter->endElement();
$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();
// Parent style
$basedOn = $style->getBasedOn();
if (!is_null($basedOn)) {
$objWriter->startElement('w:basedOn');
$objWriter->writeAttribute('w:val', $basedOn);
$objWriter->endElement();
}
// Next paragraph style
$next = $style->getNext();
if (!is_null($next)) {
$objWriter->startElement('w:next');
$objWriter->writeAttribute('w:val', $next);
$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();
}
/**
* Write style
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Style_TableFull $style
*/
private function _writeFullTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_TableFull $style)
{
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$cellMargin = $style->getCellMargin();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$bInsH = (!is_null($brdSz[4])) ? true : false;
$bInsV = (!is_null($brdSz[5])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
$mTop = (!is_null($cellMargin[0])) ? true : false;
$mLeft = (!is_null($cellMargin[1])) ? true : false;
$mRight = (!is_null($cellMargin[2])) ? true : false;
$mBottom = (!is_null($cellMargin[3])) ? true : false;
$margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
$objWriter->startElement('w:tblPr');
if ($margins) {
$objWriter->startElement('w:tblCellMar');
if ($mTop) {
echo $margins[0];
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:w', $cellMargin[0]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
if ($mLeft) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:w', $cellMargin[1]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
if ($mRight) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:w', $cellMargin[2]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
if ($mBottom) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:w', $cellMargin[3]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
$objWriter->endElement();
}
if ($borders) {
$objWriter->startElement('w:tblBorders');
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();
}
if ($bInsH) {
$objWriter->startElement('w:insideH');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[4]);
$objWriter->writeAttribute('w:color', $brdCol[4]);
$objWriter->endElement();
}
if ($bInsV) {
$objWriter->startElement('w:insideV');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[5]);
$objWriter->writeAttribute('w:color', $brdCol[5]);
$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);
}
}
/**
* Write row style
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param string $type
* @param PHPWord_Style_TableFull $style
*/
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();
}
/**
* Write doc defaults
*
* @param PHPWord_Shared_XMLWriter $objWriter
*/
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 * 2);
$objWriter->endElement();
$objWriter->startElement('w:szCs');
$objWriter->writeAttribute('w:val', $fontSize * 2);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
}

View File

@ -1,49 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Autoloader;
use PHPWord_Autoloader as Autoloader;
class AutoloaderTest extends \PHPUnit_Framework_TestCase
{
public function testRegister()
{
PHPWord_Autoloader::register();
$this->assertContains(array('PHPWord_Autoloader', 'load'), spl_autoload_functions());
$this->assertContains(array('PHPWord_Autoloader', 'autoload'), spl_autoload_functions());
}
public function testAutoloadLegacy()
{
$this->assertNull(
PHPWord_Autoloader::load('Foo'),
'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace'
);
$this->assertTrue(
PHPWord_Autoloader::load('PHPWord'),
'PHPWord_Autoloader::load() failed to autoload the PHPWord class'
);
}
public function testAutoload()
{
$declared = get_declared_classes();
$declaredCount = count($declared);
Autoloader::autoload('Foo');
$this->assertEquals(
$declaredCount,
count(get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes ' .
'outside of the PhpOffice\\PhpWord namespace'
);
// TODO change this class to the main PHPWord class when it is namespaced
Autoloader::autoload(
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'
);
$this->assertTrue(
in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
);
}
}

View File

@ -1,63 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord;
use PHPWord_IOFactory;
use PHPWord_Writer_Word2007;
use Exception;
/**
* Class IOFactoryTest
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class IOFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testGetSearchLocations()
{
$this->assertAttributeEquals(
PHPWord_IOFactory::getSearchLocations(),
'_searchLocations',
'PHPWord_IOFactory'
);
}
public function testSetSearchLocationsWithArray()
{
PHPWord_IOFactory::setSearchLocations(array());
$this->assertAttributeEquals(array(), '_searchLocations', 'PHPWord_IOFactory');
}
public function testAddSearchLocation()
{
PHPWord_IOFactory::setSearchLocations(array());
PHPWord_IOFactory::addSearchLocation('type', 'location', 'classname');
$this->assertAttributeEquals(
array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')),
'_searchLocations',
'PHPWord_IOFactory'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage No IWriter found for type
*/
public function testCreateWriterException()
{
$oPHPWord = new PHPWord();
PHPWord_IOFactory::setSearchLocations(array());
PHPWord_IOFactory::createWriter($oPHPWord);
}
public function testCreateWriter()
{
$oPHPWord = new PHPWord();
$this->assertEquals(
PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'),
new PHPWord_Writer_Word2007($oPHPWord)
);
}
}

View File

@ -1,50 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Media;
use PHPWord_Section;
class MediaTest extends \PHPUnit_Framework_TestCase
{
public function testGetSectionMediaElementsWithNull()
{
$this->assertEquals(PHPWord_Media::getSectionMediaElements(), array());
}
public function testCountSectionMediaElementsWithNull()
{
$this->assertEquals(PHPWord_Media::countSectionMediaElements(), 0);
}
public function testGetHeaderMediaElements()
{
$this->assertAttributeEquals(PHPWord_Media::getHeaderMediaElements(), '_headerMedia', 'PHPWord_Media');
}
public function testGetFooterMediaElements()
{
$this->assertAttributeEquals(PHPWord_Media::getFooterMediaElements(), '_footerMedia', 'PHPWord_Media');
}
/**
* Todo: add memory image to this test
*
* @covers PHPWord_Media::addSectionMediaElement
*/
public function testAddSectionMediaElement()
{
$section = new PHPWord_Section(0);
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
$elements = $section->getElements();
$this->assertEquals(6, count($elements));
foreach ($elements as $element) {
$this->assertInstanceOf('PHPWord_Section_Image', $element);
}
}
}

View File

@ -1,68 +0,0 @@
<?php
namespace PHPWord\Tests\Reader;
use PHPWord_Reader_Word2007;
use PHPWord_IOFactory;
/**
* Class Word2007Test
*
* @package PHPWord\Tests
*/
class Word2007Test extends \PHPUnit_Framework_TestCase
{
/** @var Test file directory */
private $dir;
/**
* Init
*/
public function tearDown()
{
}
/**
* Test canRead() method
*/
public function testCanRead()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$object = new PHPWord_Reader_Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$this->assertTrue($object->canRead($file));
}
/**
* Test canRead() failure
*
* @expectedException Exception
*/
public function testCanReadFailed()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$object = new PHPWord_Reader_Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'foo.docx';
$this->assertFalse($object->canRead($file));
$object = PHPWord_IOFactory::load($file);
}
/**
* Test load document
*/
public function testLoad()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$object = PHPWord_IOFactory::load($file);
$this->assertInstanceOf('PHPWord', $object);
}
}

View File

@ -1,102 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_Image;
use PHPWord_Style_Image;
class ImageTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oImage = new PHPWord_Section_Image($src);
$this->assertInstanceOf('PHPWord_Section_Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getIsWatermark(), false);
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
}
public function testConstructWithStyle()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oImage = new PHPWord_Section_Image(
$src,
array('width' => 210, 'height' => 210, 'align' => 'center',
'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND)
);
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
}
/**
* @covers PHPWord_Section_Image::__construct
*/
public function testValidImageTypes()
{
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
}
/**
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
* @covers PHPWord_Section_Image::__construct
*/
public function testImageNotFound()
{
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/thisisnotarealimage");
}
/**
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
* @covers PHPWord_Section_Image::__construct
*/
public function testInvalidImageTypes()
{
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx");
}
public function testStyle()
{
$oImage = new PHPWord_Section_Image(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width' => 210, 'height' => 210, 'align' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
}
public function testRelationID()
{
$oImage = new PHPWord_Section_Image(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$iVal = rand(1, 1000);
$oImage->setRelationId($iVal);
$this->assertEquals($oImage->getRelationId(), $iVal);
}
public function testWatermark()
{
$oImage = new PHPWord_Section_Image(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$oImage->setIsWatermark(true);
$this->assertEquals($oImage->getIsWatermark(), true);
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_ListItem;
use PHPWord_Style_ListItem;
class ListItemTest extends \PHPUnit_Framework_TestCase
{
public function testText()
{
$oListItem = new PHPWord_Section_ListItem('text');
$this->assertInstanceOf('PHPWord_Section_Text', $oListItem->getTextObject());
}
public function testStyle()
{
$oListItem = new PHPWord_Section_ListItem(
'text',
1,
null,
array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER)
);
$this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle());
$this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER);
}
public function testDepth()
{
$iVal = rand(1, 1000);
$oListItem = new PHPWord_Section_ListItem('text', $iVal);
$this->assertEquals($oListItem->getDepth(), $iVal);
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_Text;
class TextTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$oText = new PHPWord_Section_Text();
$this->assertInstanceOf('PHPWord_Section_Text', $oText);
$this->assertEquals(null, $oText->getText());
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
}
public function testText()
{
$oText = new PHPWord_Section_Text('text');
$this->assertEquals($oText->getText(), 'text');
}
public function testFont()
{
$oText = new PHPWord_Section_Text('text', 'fontStyle');
$this->assertEquals($oText->getFontStyle(), 'fontStyle');
$oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle());
}
public function testParagraph()
{
$oText = new PHPWord_Section_Text('text', 'fontStyle', 'paragraphStyle');
$this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle');
$oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
}
}

View File

@ -1,26 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Settings;
/**
* Class TOCTest
*
* @package PHPWord\Tests
* @covers PHPWord_Settings
* @runTestsInSeparateProcesses
*/
class SettingsTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_Settings::setCompatibility
* @covers PHPWord_Settings::getCompatibility
*/
public function testGetSetCompatibility()
{
$this->assertTrue(PHPWord_Settings::getCompatibility());
$this->assertTrue(PHPWord_Settings::setCompatibility(false));
$this->assertFalse(PHPWord_Settings::getCompatibility());
$this->assertFalse(PHPWord_Settings::setCompatibility('Non boolean'));
}
}

View File

@ -1,92 +0,0 @@
<?php
namespace PHPWord\Tests\Shared;
use PHPWord_Shared_File;
/**
* Class FileTest
*
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_Shared_File
* @runTestsInSeparateProcesses
*/
class FileTest extends \PHPUnit_Framework_TestCase
{
/**
* Test file_exists()
*/
public function testFileExists()
{
$dir = join(DIRECTORY_SEPARATOR, array(
PHPWORD_TESTS_DIR_ROOT,
'_files',
'templates'
));
chdir($dir);
$this->assertTrue(PHPWord_Shared_File::file_exists('blank.docx'));
}
/**
* Test file_exists()
*/
public function testNoFileExists()
{
$dir = join(DIRECTORY_SEPARATOR, array(
PHPWORD_TESTS_DIR_ROOT,
'_files',
'templates'
));
chdir($dir);
$this->assertFalse(PHPWord_Shared_File::file_exists('404.docx'));
}
/**
* Test realpath()
*/
public function testRealpath()
{
$dir = join(DIRECTORY_SEPARATOR, array(
PHPWORD_TESTS_DIR_ROOT,
'_files',
'templates'
));
chdir($dir);
$file = 'blank.docx';
$expected = $dir . DIRECTORY_SEPARATOR . $file;
$this->assertEquals($expected, PHPWord_Shared_File::realpath($file));
}
/**
* @covers PHPWord_Shared_File::imagetype
* @covers PHPWord_Shared_File::fallbackImagetype
*/
public function testImagetype()
{
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx";
$this->assertFalse(PHPWord_Shared_File::imagetype($filename, true));
$this->assertFalse(PHPWord_Shared_File::imagetype($filename));
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace PHPWord\Tests\Shared;
use PHPWord_Shared_String;
/**
* Class StringTest
*
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_Shared_String
* @runTestsInSeparateProcesses
*/
class StringTest extends \PHPUnit_Framework_TestCase
{
public function testIsUTF8()
{
$this->assertTrue(PHPWord_Shared_String::IsUTF8(''));
$this->assertTrue(PHPWord_Shared_String::IsUTF8('éééé'));
$this->assertFalse(PHPWord_Shared_String::IsUTF8(utf8_decode('éééé')));
}
public function testControlCharacterOOXML2PHP()
{
$this->assertEquals('', PHPWord_Shared_String::ControlCharacterOOXML2PHP(''));
$this->assertEquals(chr(0x08), PHPWord_Shared_String::ControlCharacterOOXML2PHP('_x0008_'));
}
public function testControlCharacterPHP2OOXML()
{
$this->assertEquals('', PHPWord_Shared_String::ControlCharacterPHP2OOXML(''));
$this->assertEquals('_x0008_', PHPWord_Shared_String::ControlCharacterPHP2OOXML(chr(0x08)));
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Style;
/**
* Class StyleTest
*
* @package PHPWord\Tests
* @covers PHPWord_Style
* @runTestsInSeparateProcesses
*/
class StyleTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_Style::addParagraphStyle
* @covers PHPWord_Style::addFontStyle
* @covers PHPWord_Style::addLinkStyle
* @covers PHPWord_Style::addTitleStyle
*/
public function testStyles()
{
$paragraph = array('align' => 'center');
$font = array('italic' => true);
$table = array('bgColor' => 'CCCCCC');
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
'Link' => 'Font', 'Table' => 'TableFull',
'Heading_1' => 'Font', 'Normal' => 'Paragraph');
$elementCount = 6;
PHPWord_Style::addParagraphStyle('Paragraph', $paragraph);
PHPWord_Style::addFontStyle('Font', $font);
PHPWord_Style::addLinkStyle('Link', $font);
PHPWord_Style::addTableStyle('Table', $table);
PHPWord_Style::addTitleStyle(1, $font);
PHPWord_Style::setDefaultParagraphStyle($paragraph);
$this->assertEquals($elementCount, count(PHPWord_Style::getStyles()));
foreach ($styles as $name => $style) {
$expected = "PHPWord_Style_{$style}";
$this->assertInstanceOf($expected, PHPWord_Style::getStyle($name));
}
$this->assertNull(PHPWord_Style::getStyle('Unknown'));
}
}

View File

@ -1,96 +0,0 @@
<?php
namespace PHPWord\Tests\Writer;
use PHPWord_Writer_RTF;
use PHPWord;
/**
* Class RTFTest
*
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_Writer_RTF
* @runTestsInSeparateProcesses
*/
class RTFTest extends \PHPUnit_Framework_TestCase
{
/**
* covers ::construct
*/
public function testConstruct()
{
$object = new PHPWord_Writer_RTF(new PHPWord);
$this->assertInstanceOf('PHPWord', $object->getPHPWord());
$this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable());
}
/**
* covers ::__construct
* @expectedException Exception
* @expectedExceptionMessage No PHPWord assigned.
*/
public function testConstructWithNull()
{
$object = new PHPWord_Writer_RTF();
$object->getPHPWord();
}
/**
* @covers ::save
* @expectedException Exception
* @expectedExceptionMessage PHPWord object unassigned.
*/
public function testSaveException()
{
$writer = new PHPWord_Writer_RTF();
$writer->save();
}
/**
* @covers ::save
* @covers ::<private>
*/
public function testSave()
{
$imageSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
);
$objectSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$file = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
);
$fontStyle = array('name' => 'Verdana', 'size' => 11, 'bold' => true, 'italic' => true, 'color' => 'F29101', 'fgColor' => '123456');
$paragraphStyle = array('align' => 'center', 'spaceAfter' => 120);
$phpWord = new PHPWord();
$phpWord->addFontStyle('Font', $fontStyle);
$phpWord->addParagraphStyle('Paragraph', $paragraphStyle);
$section = $phpWord->createSection();
$section->addText('Test 1', 'Font');
$section->addText('Test 2', array('name' => 'Tahoma'), 'Paragraph');
$section->addTextBreak();
$section->addLink('http://test.com');
$section->addTitle('Test', 1);
$section->addPageBreak();
$section->addTable();
$section->addListItem('Test');
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$section = $phpWord->createSection();
$textrun = $section->createTextRun();
$textrun->addText('Test 3');
$textrun->addTextBreak();
$writer = new PHPWord_Writer_RTF($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
}

View File

@ -1,186 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord;
use PHPWord_DocumentProperties;
use PHPWord_Section;
use PHPWord_Style;
/**
* Class PHPWordTest
*
* @package PHPWord\Tests
* @covers PHPWord
* @runTestsInSeparateProcesses
*/
class PHPWordTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PHPWord
*/
protected $object;
/**
* @covers PHPWord::__construct
* @covers PHPWord::getProperties
* @covers PHPWord::getDefaultFontName
* @covers PHPWord::getDefaultFontSize
*/
public function testConstruct()
{
$object = new PHPWord();
$this->assertEquals(
new PHPWord_DocumentProperties(),
$object->getProperties()
);
$this->assertEquals(
PHPWord::DEFAULT_FONT_NAME,
$object->getDefaultFontName()
);
$this->assertEquals(
PHPWord::DEFAULT_FONT_SIZE,
$object->getDefaultFontSize()
);
}
/**
* @covers PHPWord::setProperties
* @covers PHPWord::getProperties
*/
public function testSetGetProperties()
{
$object = new PHPWord();
$creator = 'PHPWord';
$properties = $object->getProperties();
$properties->setCreator($creator);
$object->setProperties($properties);
$this->assertEquals($creator, $object->getProperties()->getCreator());
}
/**
* @covers PHPWord::createSection
* @covers PHPWord::getSections
*/
public function testCreateGetSections()
{
$object = new PHPWord();
$this->assertEquals(new PHPWord_Section(1), $object->createSection());
$object->createSection();
$this->assertEquals(2, count($object->getSections()));
}
/**
* @covers PHPWord::setDefaultFontName
* @covers PHPWord::getDefaultFontName
*/
public function testSetGetDefaultFontName()
{
$object = new PHPWord();
$fontName = 'Times New Roman';
$this->assertEquals(
PHPWord::DEFAULT_FONT_NAME,
$object->getDefaultFontName()
);
$object->setDefaultFontName($fontName);
$this->assertEquals($fontName, $object->getDefaultFontName());
}
/**
* @covers PHPWord::setDefaultFontSize
* @covers PHPWord::getDefaultFontSize
*/
public function testSetGetDefaultFontSize()
{
$object = new PHPWord();
$fontSize = 16;
$this->assertEquals(
PHPWord::DEFAULT_FONT_SIZE,
$object->getDefaultFontSize()
);
$object->setDefaultFontSize($fontSize);
$this->assertEquals($fontSize, $object->getDefaultFontSize());
}
/**
* @covers PHPWord::setDefaultParagraphStyle
* @covers PHPWord::loadTemplate
*/
public function testSetDefaultParagraphStyle()
{
$object = new PHPWord();
$object->setDefaultParagraphStyle(array());
$this->assertInstanceOf(
'PHPWord_Style_Paragraph',
PHPWord_Style::getStyle('Normal')
);
}
/**
* @covers PHPWord::addParagraphStyle
* @covers PHPWord::addFontStyle
* @covers PHPWord::addTableStyle
* @covers PHPWord::addLinkStyle
*/
public function testAddStyles()
{
$object = new PHPWord();
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
'Table' => 'TableFull', 'Link' => 'Font');
foreach ($styles as $key => $value) {
$method = "add{$key}Style";
$styleId = "{$key} Style";
$styleType = "PHPWord_Style_{$value}";
$object->$method($styleId, array());
$this->assertInstanceOf(
$styleType,
PHPWord_Style::getStyle($styleId)
);
}
}
/**
* @covers PHPWord::addTitleStyle
*/
public function testAddTitleStyle()
{
$object = new PHPWord();
$titleLevel = 1;
$titleName = "Heading_{$titleLevel}";
$object->addTitleStyle($titleLevel, array());
$this->assertInstanceOf(
'PHPWord_Style_Font',
PHPWord_Style::getStyle($titleName)
);
}
/**
* @covers PHPWord::loadTemplate
*/
public function testLoadTemplate()
{
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx')
);
$object = new PHPWord();
$this->assertInstanceOf(
'PHPWord_Template',
$object->loadTemplate($file)
);
}
/**
* @covers PHPWord::loadTemplate
* @expectedException Exception
*/
public function testLoadTemplateException()
{
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blanks.docx')
);
$object = new PHPWord();
$object->loadTemplate($file);
}
}

View File

@ -1,15 +0,0 @@
<?php
date_default_timezone_set('UTC');
// Constantes
if (!defined('PHPWORD_TESTS_DIR_ROOT')) {
define('PHPWORD_TESTS_DIR_ROOT', __DIR__);
}
// Includes
require_once __DIR__ . '/../Classes/PHPWord/Autoloader.php';
PHPWord_Autoloader::Register();
require_once __DIR__ . '/_inc/TestHelperDOCX.php';
require_once __DIR__ . '/_inc/XmlDocument.php';

View File

@ -1,7 +1,11 @@
{ {
"name": "phpoffice/phpword", "name": "phpoffice/phpword",
"description": "PHPWord - Read, Create and Write Word documents in PHP", "description": "PhpWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP",
"keywords": ["PHP", "Word", "Writer", "docx", "doc", "rtf"], "keywords": [
"PHP", "PhpOffice", "office", "PhpWord", "word", "template", "reader", "writer",
"docx", "OOXML", "OpenXML", "Office Open XML", "ISO/IEC 29500", "WordprocessingML",
"RTF", "Rich Text Format", "doc", "odt", "OpenDocument"
],
"homepage": "http://phpoffice.github.io", "homepage": "http://phpoffice.github.io",
"type": "library", "type": "library",
"license": "LGPL", "license": "LGPL",
@ -17,10 +21,14 @@
{ {
"name": "Franck Lefevre", "name": "Franck Lefevre",
"homepage": "http://blog.rootslabs.net" "homepage": "http://blog.rootslabs.net"
},
{
"name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org"
} }
], ],
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.3",
"ext-xml": "*", "ext-xml": "*",
"ext-zip": "*" "ext-zip": "*"
}, },
@ -35,8 +43,8 @@
"ext-xsl": "*" "ext-xsl": "*"
}, },
"autoload": { "autoload": {
"psr-0": { "psr-4": {
"PHPWord": "Classes/" "PhpOffice\\PhpWord\\": "src/"
} }
} }
} }

View File

@ -77,17 +77,17 @@ qthelp:
@echo @echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:" ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PHPWord.qhcp" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PhpWord.qhcp"
@echo "To view the help file:" @echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PHPWord.qhc" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PhpWord.qhc"
devhelp: devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo @echo
@echo "Build finished." @echo "Build finished."
@echo "To view the help file:" @echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/PHPWord" @echo "# mkdir -p $$HOME/.local/share/devhelp/PhpWord"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PHPWord" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PhpWord"
@echo "# devhelp" @echo "# devhelp"
epub: epub:

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# PHPWord documentation build configuration file, created by # PhpWord documentation build configuration file, created by
# sphinx-quickstart on Fri Mar 14 23:09:26 2014. # sphinx-quickstart on Fri Mar 14 23:09:26 2014.
# #
# This file is execfile()d with the current directory set to its containing dir. # This file is execfile()d with the current directory set to its containing dir.
@ -40,7 +40,7 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'PHPWord' project = u'PhpWord'
copyright = u'2014, Progi1984' copyright = u'2014, Progi1984'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
@ -164,7 +164,7 @@ html_static_path = ['_static']
#html_file_suffix = None #html_file_suffix = None
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'PHPWorddoc' htmlhelp_basename = 'PhpWorddoc'
# -- Options for LaTeX output -------------------------------------------------- # -- Options for LaTeX output --------------------------------------------------
@ -183,8 +183,8 @@ latex_elements = {
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]). # (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [ latex_documents = [
('index', 'PHPWord.tex', u'PHPWord Documentation', ('index', 'PhpWord.tex', u'PhpWord Documentation',
u'The PHPWord Team', 'manual'), u'The PhpWord Team', 'manual'),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -213,8 +213,8 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
('index', 'phpword', u'PHPWord Documentation', ('index', 'PhpWord', u'PhpWord Documentation',
[u'The PHPWord Team'], 1) [u'The PhpWord Team'], 1)
] ]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
@ -227,8 +227,8 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
('index', 'PHPWord', u'PHPWord Documentation', ('index', 'PhpWord', u'PhpWord Documentation',
u'The PHPWord Team', 'PHPWord', 'One line description of project.', u'The PhpWord Team', 'PhpWord', 'One line description of project.',
'Miscellaneous'), 'Miscellaneous'),
] ]
@ -244,9 +244,9 @@ texinfo_documents = [
# -- Options for Epub output --------------------------------------------------- # -- Options for Epub output ---------------------------------------------------
# Bibliographic Dublin Core info. # Bibliographic Dublin Core info.
epub_title = u'PHPWord' epub_title = u'PhpWord'
epub_author = u'The PHPWord Team' epub_author = u'The PhpWord Team'
epub_publisher = u'The PHPWord Team' epub_publisher = u'The PhpWord Team'
epub_copyright = copyright epub_copyright = copyright
# The language of the text. It defaults to the language option # The language of the text. It defaults to the language option

View File

@ -44,11 +44,11 @@ Defined style examples:
.. code-block:: php .. code-block:: php
$fontStyle = array('color' => '006699', 'size' => 18, 'bold' => true); $fontStyle = array('color' => '006699', 'size' => 18, 'bold' => true);
$PHPWord->addFontStyle('fStyle', $fontStyle); $phpWord->addFontStyle('fStyle', $fontStyle);
$text = $section->addText('Hello world!', 'fStyle'); $text = $section->addText('Hello world!', 'fStyle');
$paragraphStyle = array('align' => 'center'); $paragraphStyle = array('align' => 'center');
$PHPWord->addParagraphStyle('pStyle', $paragraphStyle); $phpWord->addParagraphStyle('pStyle', $paragraphStyle);
$text = $section->addText('Hello world!', 'pStyle'); $text = $section->addText('Hello world!', 'pStyle');
Font style Font style
@ -97,7 +97,7 @@ need titles or headings. To add a title to the document, use the
.. code-block:: php .. code-block:: php
$PHPWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]); $phpWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]);
$section->addTitle($text, [$depth]); $section->addTitle($text, [$depth]);
Its necessary to add a title style to your document because otherwise Its necessary to add a title style to your document because otherwise
@ -193,7 +193,7 @@ Table style can be defined with ``addTableStyle``:
'cellMargin' => 50 'cellMargin' => 50
); );
$firstRowStyle = array('bgColor' => '66BBFF'); $firstRowStyle = array('bgColor' => '66BBFF');
$PHPWord->addTableStyle('myTable', $tableStyle, $firstRowStyle); $phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
$table = $section->addTable('myTable'); $table = $section->addTable('myTable');
Table, row, and cell styles Table, row, and cell styles
@ -292,7 +292,7 @@ header reference. After creating a header, you can use the
.. code-block:: php .. code-block:: php
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$header = $section->createHeader(); $header = $section->createHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); $header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));

View File

@ -11,11 +11,13 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
.. code-block:: php .. code-block:: php
$PHPWord = new PHPWord(); require_once '../src/PhpWord/PhpWord.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section. // Every element you want to append to the word document is placed in a section.
// To create a basic section: // To create a basic section:
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// After creating a section, you can append elements: // After creating a section, you can append elements:
$section->addText('Hello world!'); $section->addText('Hello world!');
@ -26,7 +28,7 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
// If you often need the same style again you can create a user defined style // If you often need the same style again you can create a user defined style
// to the word document and give the addText function the name of the style: // to the word document and give the addText function the name of the style:
$PHPWord->addFontStyle('myOwnStyle', $phpWord->addFontStyle('myOwnStyle',
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
$section->addText('Hello world! I am formatted by a user defined style', $section->addText('Hello world! I am formatted by a user defined style',
'myOwnStyle'); 'myOwnStyle');
@ -40,7 +42,7 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
$myTextElement->setFontStyle($fontStyle); $myTextElement->setFontStyle($fontStyle);
// Finally, write the document: // Finally, write the document:
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter = PHPWord_IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx'); $objWriter->save('helloWorld.docx');
Default font Default font
@ -62,7 +64,7 @@ name. Use the following functions:
.. code-block:: php .. code-block:: php
$properties = $PHPWord->getProperties(); $properties = $phpWord->getProperties();
$properties->setCreator('My name'); $properties->setCreator('My name');
$properties->setCompany('My factory'); $properties->setCompany('My factory');
$properties->setTitle('My title'); $properties->setTitle('My title');

View File

@ -47,11 +47,11 @@ Manual install
To install manually, `download PHPWord package from To install manually, `download PHPWord package from
github <https://github.com/PHPOffice/PHPWord/archive/master.zip>`__. github <https://github.com/PHPOffice/PHPWord/archive/master.zip>`__.
Extract the package and put the contents to your machine. To use the Extract the package and put the contents to your machine. To use the
library, include ``Classes/PHPWord.php`` in your script like below. library, include ``src/PhpWord/PhpWord.php`` in your script like below.
.. code-block:: php .. code-block:: php
require_once '/path/to/PHPWord/Classes/PHPWord.php'; require_once '/path/to/src/PhpWord/PhpWord.php';
Using samples Using samples
------------- -------------
@ -59,4 +59,4 @@ Using samples
After installation, you can browse and use the samples that we've After installation, you can browse and use the samples that we've
provided, either by command line or using browser. If you can access provided, either by command line or using browser. If you can access
your PHPWord library folder using browser, point your browser to the your PHPWord library folder using browser, point your browser to the
``samples`` folder, e.g. ``http://localhost/PHPWord/samples/``. ``samples`` folder, e.g. ``http://localhost/PhpWord/samples/``.

View File

@ -15,7 +15,7 @@ Example:
.. code-block:: php .. code-block:: php
$template = $PHPWord->loadTemplate('Template.docx'); $template = $phpWord->loadTemplate('Template.docx');
$template->setValue('Name', 'Somebody someone'); $template->setValue('Name', 'Somebody someone');
$template->setValue('Street', 'Coming-Undone-Street 32'); $template->setValue('Street', 'Coming-Undone-Street 32');

View File

@ -1,6 +1,6 @@
<phpunit backupGlobals="false" <phpunit backupGlobals="false"
backupStaticAttributes="false" backupStaticAttributes="false"
bootstrap="./Tests/bootstrap.php" bootstrap="./tests/common/bootstrap.php"
colors="true" colors="true"
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
@ -9,13 +9,13 @@
stopOnFailure="false" stopOnFailure="false"
syntaxCheck="false"> syntaxCheck="false">
<testsuites> <testsuites>
<testsuite name="PHPWord Unit Test Suite"> <testsuite name="PhpWord Test Suite">
<directory>./Tests/PHPWord/</directory> <directory>./tests/PhpWord/</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter> <filter>
<whitelist> <whitelist>
<directory suffix=".php">./Classes</directory> <directory suffix=".php">./src</directory>
</whitelist> </whitelist>
</filter> </filter>
</phpunit> </phpunit>

View File

@ -2,17 +2,17 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , " Create new PHPWord object" , EOL; echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$PHPWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16)); $phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16));
$PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
$PHPWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
// New portrait section // New portrait section
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Simple text // Simple text
$section->addTitle('Welcome to PHPWord', 1); $section->addTitle('Welcome to PhpWord', 1);
$section->addText('Hello World!'); $section->addText('Hello World!');
// Two text break // Two text break
@ -48,9 +48,9 @@ $section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,30 +2,30 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL; echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Ads styles // Ads styles
$PHPWord->addParagraphStyle('multipleTab', array( $phpWord->addParagraphStyle('multipleTab', array(
'tabs' => array( 'tabs' => array(
new PHPWord_Style_Tab('left', 1550), new \PhpOffice\PhpWord\Style\Tab('left', 1550),
new PHPWord_Style_Tab('center', 3200), new \PhpOffice\PhpWord\Style\Tab('center', 3200),
new PHPWord_Style_Tab('right', 5300) new \PhpOffice\PhpWord\Style\Tab('right', 5300)
) )
)); ));
$PHPWord->addParagraphStyle('rightTab', array( $phpWord->addParagraphStyle('rightTab', array(
'tabs' => array( 'tabs' => array(
new PHPWord_Style_Tab('right', 9090) new \PhpOffice\PhpWord\Style\Tab('right', 9090)
) )
)); ));
$PHPWord->addParagraphStyle('centerTab', array( $phpWord->addParagraphStyle('centerTab', array(
'tabs' => array( 'tabs' => array(
new PHPWord_Style_Tab('center', 4680) new \PhpOffice\PhpWord\Style\Tab('center', 4680)
) )
)); ));
// New portrait section // New portrait section
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Add listitem elements // Add listitem elements
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab'); $section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');
@ -36,9 +36,9 @@ $section->addText("\tCenter Aligned", NULL, 'centerTab');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,25 +2,25 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL; echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section // New portrait section
$section = $PHPWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12)); $section = $phpWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section->addText('I am placed on a default section.'); $section->addText('I am placed on a default section.');
// New landscape section // New landscape section
$section = $PHPWord->createSection(array('orientation' => 'landscape')); $section = $phpWord->createSection(array('orientation' => 'landscape'));
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.'); $section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
$section->addPageBreak(); $section->addPageBreak();
$section->addPageBreak(); $section->addPageBreak();
// New portrait section // New portrait section
$section = $PHPWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)); $section = $phpWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins.'); $section->addText('This section uses other margins.');
// New portrait section with Header & Footer // New portrait section with Header & Footer
$section = $PHPWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,)); $section = $phpWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
$section->addText('This section and we play with header/footer height.'); $section->addText('This section and we play with header/footer height.');
$section->createHeader()->addText('Header'); $section->createHeader()->addText('Header');
$section->createFooter()->addText('Footer'); $section->createFooter()->addText('Footer');
@ -29,9 +29,9 @@ $section->createFooter()->addText('Footer');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,18 +2,17 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL; echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Ads styles // Ads styles
$PHPWord->addParagraphStyle('pStyle', array('spacing'=>100)); $phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
$PHPWord->addFontStyle('BoldText', array('bold'=>true)); $phpWord->addFontStyle('BoldText', array('bold'=>true));
$PHPWord->addFontStyle('ColoredText', array('color'=>'FF8080')); $phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$PHPWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE)); $phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// New portrait section // New portrait section
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Add text run // Add text run
$textrun = $section->createTextRun('pStyle'); $textrun = $section->createTextRun('pStyle');
@ -36,9 +35,9 @@ $textrun->addText(' Here is some more text. ');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,46 +2,46 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , " Create new PHPWord object" , EOL; echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' . $filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' . 'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' .
'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' . 'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' .
'Suspendisse congue congue leo sed pellentesque.'; 'Suspendisse congue congue leo sed pellentesque.';
// Normal // Normal
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$section->addText('Normal paragraph. ' . $filler); $section->addText('Normal paragraph. ' . $filler);
// Two columns // Two columns
$section = $PHPWord->createSection(array( $section = $phpWord->createSection(array(
'colsNum' => 2, 'colsNum' => 2,
'colsSpace' => 1440, 'colsSpace' => 1440,
'breakType' => 'continuous')); 'breakType' => 'continuous'));
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler); $section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
// Normal // Normal
$section = $PHPWord->createSection(array('breakType' => 'continuous')); $section = $phpWord->createSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again. ' . $filler); $section->addText('Normal paragraph again. ' . $filler);
// Three columns // Three columns
$section = $PHPWord->createSection(array( $section = $phpWord->createSection(array(
'colsNum' => 3, 'colsNum' => 3,
'colsSpace' => 720, 'colsSpace' => 720,
'breakType' => 'continuous')); 'breakType' => 'continuous'));
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler); $section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
// Normal // Normal
$section = $PHPWord->createSection(array('breakType' => 'continuous')); $section = $phpWord->createSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again.'); $section->addText('Normal paragraph again.');
// Save file // Save file
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,17 +2,17 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , " Create new PHPWord object" , EOL; echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section // New portrait section
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Add style definitions // Add style definitions
$PHPWord->addParagraphStyle('pStyle', array('spacing'=>100)); $phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
$PHPWord->addFontStyle('BoldText', array('bold'=>true)); $phpWord->addFontStyle('BoldText', array('bold'=>true));
$PHPWord->addFontStyle('ColoredText', array('color'=>'FF8080')); $phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$PHPWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE)); $phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// Add text elements // Add text elements
$textrun = $section->createTextRun('pStyle'); $textrun = $section->createTextRun('pStyle');
@ -37,9 +37,9 @@ $footnote->addText('The reference for this is wrapped in its own line');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,10 +2,10 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s') , " Create new PHPWord object" , EOL; echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$document = $PHPWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx'); $document = $phpWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
// Simple table // Simple table
$document->cloneRow('rowValue', 10); $document->cloneRow('rowValue', 10);
@ -53,8 +53,8 @@ $document->setValue('userFirstName#3', 'Michael');
$document->setValue('userName#3', 'Ray'); $document->setValue('userName#3', 'Ray');
$document->setValue('userPhone#3', '+1 428 889 775'); $document->setValue('userPhone#3', '+1 428 889 775');
$name = 'Sample_07_TemplateCloneRow.docx'; $name = 'Sample_07_TemplateCloneRow_result.docx';
echo date('H:i:s'), " Write to Word2007 format", EOL; echo date('H:i:s'), " Write to Word2007 format", \EOL;
$document->saveAs($name); $document->saveAs($name);
rename($name, "results/{$name}"); rename($name, "results/{$name}");

View File

@ -2,16 +2,16 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s') , " Create new PHPWord object" , EOL; echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$PHPWord->setDefaultParagraphStyle(array( $phpWord->setDefaultParagraphStyle(array(
'align' => 'both', 'align' => 'both',
'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(12), 'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(12),
'spacing' => 120, 'spacing' => 120,
)); ));
// Sample // Sample
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$section->addText('Below are the samples on how to control your paragraph ' . $section->addText('Below are the samples on how to control your paragraph ' .
'pagination. See "Line and Page Break" tab on paragraph properties ' . 'pagination. See "Line and Page Break" tab on paragraph properties ' .
@ -49,9 +49,9 @@ $section->addText('Paragraph with pageBreakBefore = true (default: false). ' .
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,9 +2,9 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL; echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$header = array('size' => 16, 'bold' => true); $header = array('size' => 16, 'bold' => true);
// 1. Basic table // 1. Basic table
@ -29,9 +29,9 @@ $section->addText("Fancy table", $header);
$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80); $styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80);
$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); $styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
$styleCell = array('valign' => 'center'); $styleCell = array('valign' => 'center');
$styleCellBTLR = array('valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); $styleCellBTLR = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
$fontStyle = array('bold' => true, 'align' => 'center'); $fontStyle = array('bold' => true, 'align' => 'center');
$PHPWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow); $phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
$table = $section->addTable('Fancy Table'); $table = $section->addTable('Fancy Table');
$table->addRow(900); $table->addRow(900);
$table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle); $table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle);
@ -61,7 +61,7 @@ $cellColSpan = array('gridSpan' => 2, 'valign' => 'center');
$cellHCentered = array('align' => 'center'); $cellHCentered = array('align' => 'center');
$cellVCentered = array('valign' => 'center'); $cellVCentered = array('valign' => 'center');
$PHPWord->addTableStyle('Colspan Rowspan', $styleTable); $phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan'); $table = $section->addTable('Colspan Rowspan');
$table->addRow(); $table->addRow();
$table->addCell(2000, $cellRowSpan)->addText('A', null, $cellHCentered); $table->addCell(2000, $cellRowSpan)->addText('A', null, $cellHCentered);
@ -77,9 +77,9 @@ $table->addCell(null, $cellRowContinue);
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,9 +2,9 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word Document // New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL; echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$header = array('size' => 16, 'bold' => true); $header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle //1.Use EastAisa FontStyle
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); $section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
@ -13,9 +13,9 @@ $section->addText('中文楷体样式测试',array('name' => '楷体', 'size' =>
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -4,15 +4,15 @@ include_once 'Sample_Header.php';
// Read contents // Read contents
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$source = "resources/{$name}.docx"; $source = "resources/{$name}.docx";
echo date('H:i:s'), " Reading contents from `{$source}`", EOL; echo date('H:i:s'), " Reading contents from `{$source}`", \EOL;
$PHPWord = PHPWord_IOFactory::load($source); $phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
// (Re)write contents // (Re)write contents
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -2,11 +2,11 @@
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s') , " Create new PHPWord object" , EOL; echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section // New portrait section
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Add first page header // Add first page header
$header = $section->createHeader(); $header = $section->createHeader();
@ -15,7 +15,7 @@ $table = $header->addTable();
$table->addRow(); $table->addRow();
$table->addCell(4500)->addText('This is the header.'); $table->addCell(4500)->addText('This is the header.');
$table->addCell(4500)->addImage( $table->addCell(4500)->addImage(
'resources/PHPWord.png', 'resources/PhpWord.png',
array('width' => 80, 'height' => 80, 'align' => 'right') array('width' => 80, 'height' => 80, 'align' => 'right')
); );
@ -25,7 +25,7 @@ $subsequent->addText("Subsequent pages in Section 1 will Have this!");
// Add footer // Add footer
$footer = $section->createFooter(); $footer = $section->createFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}', array('color' => 'FF0000'), array('align' => 'center')); $footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center'));
// Write some text // Write some text
$section->addTextBreak(); $section->addTextBreak();
@ -46,7 +46,7 @@ $section->addTextBreak();
$section->addText('Some text...'); $section->addText('Some text...');
// New portrait section // New portrait section
$section2 = $PHPWord->createSection(); $section2 = $phpWord->createSection();
$sec2Header = $section2->createHeader(); $sec2Header = $section2->createHeader();
$sec2Header->addText("All pages in Section 2 will Have this!"); $sec2Header->addText("All pages in Section 2 will Have this!");
@ -60,9 +60,9 @@ $section2->addText('Some text...');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -1,15 +1,12 @@
<?php <?php
/**
* Image creation
*/
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL; echo date('H:i:s'), " Create new PhpWord object", \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$section->addText('Local image without any styles:'); $section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg'); $section->addImage('resources/_mars.jpg');
$section->addTextBreak(2); $section->addTextBreak(2);
@ -27,9 +24,9 @@ $section->addMemoryImage($source);
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -1,15 +1,12 @@
<?php <?php
/**
* List item sample
*/
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL; echo date('H:i:s'), " Create new PhpWord object", \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Add listitem elements // Add listitem elements
$section->addListItem('List Item 1', 0); $section->addListItem('List Item 1', 0);
@ -27,16 +24,16 @@ $section->addListItem('List Item 1.3.2', 2);
$section->addTextBreak(2); $section->addTextBreak(2);
// Add listitem elements // Add listitem elements
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER); $listStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER);
$section->addListItem('List Item 1', 0, null, $listStyle); $section->addListItem('List Item 1', 0, null, $listStyle);
$section->addListItem('List Item 2', 0, null, $listStyle); $section->addListItem('List Item 2', 0, null, $listStyle);
$section->addListItem('List Item 3', 0, null, $listStyle); $section->addListItem('List Item 3', 0, null, $listStyle);
$section->addTextBreak(2); $section->addTextBreak(2);
// Add listitem elements // Add listitem elements
$PHPWord->addFontStyle('myOwnStyle', array('color'=>'FF0000')); $phpWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
$PHPWord->addParagraphStyle('P-Style', array('spaceAfter'=>95)); $phpWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER_NESTED); $listStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
$section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style');
$section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style');
$section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style');
@ -51,9 +48,9 @@ $section->addListItem('List Item 7', 0, 'myOwnStyle', $listStyle, 'P-Style');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -1,21 +1,18 @@
<?php <?php
/**
* Link sample
*/
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL; echo date('H:i:s'), " Create new PhpWord object", \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Add hyperlink elements // Add hyperlink elements
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE)); $section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
$section->addTextBreak(2); $section->addTextBreak(2);
$PHPWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000')); $phpWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'));
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle'); $section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle'); $section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
@ -25,9 +22,9 @@ $section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -1,15 +1,12 @@
<?php <?php
/**
* Object sample
*/
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL; echo date('H:i:s'), " Create new PhpWord object", \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$section->addText('You can open this OLE object by double clicking on the icon:'); $section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2); $section->addTextBreak(2);
$section->addObject('resources/_sheet.xls'); $section->addObject('resources/_sheet.xls');
@ -20,9 +17,9 @@ $section->addObject('resources/_sheet.xls');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -1,22 +1,19 @@
<?php <?php
/**
* Titles and TOC
*/
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL; echo date('H:i:s'), " Create new PhpWord object", \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
// Define the TOC font style // Define the TOC font style
$fontStyle = array('spaceAfter'=>60, 'size'=>12); $fontStyle = array('spaceAfter'=>60, 'size'=>12);
// Add title styles // Add title styles
$PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true)); $phpWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
$PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666')); $phpWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
// Add text elements // Add text elements
$section->addText('Table of contents:'); $section->addText('Table of contents:');
@ -45,16 +42,16 @@ $section->addTextBreak(2);
$section->addTitle('I am a Subtitle of Title 3', 2); $section->addTitle('I am a Subtitle of Title 3', 2);
$section->addText('Again and again, more text...'); $section->addText('Again and again, more text...');
echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL; echo date('H:i:s'), " Note: Please refresh TOC manually.", \EOL;
// End code // End code
// Save file // Save file
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -1,16 +1,13 @@
<?php <?php
/**
* Watermark
*/
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL; echo date('H:i:s'), " Create new PhpWord object", \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$header = $section->createHeader(); $header = $section->createHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); $header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
$section->addText('The header reference to the current section includes a watermark image.'); $section->addText('The header reference to the current section includes a watermark image.');
@ -21,9 +18,9 @@ $section->addText('The header reference to the current section includes a waterm
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -1,21 +1,18 @@
<?php <?php
/**
* Text break
*/
include_once 'Sample_Header.php'; include_once 'Sample_Header.php';
// New Word document // New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL; echo date('H:i:s'), " Create new PhpWord object", \EOL;
$PHPWord = new PHPWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$fontStyle = array('size' => 24); $fontStyle = array('size' => 24);
$paragraphStyle = array('spacing' => 240, 'size' => 24); $paragraphStyle = array('spacing' => 240, 'size' => 24);
$PHPWord->addFontStyle('fontStyle', array('size' => 9)); $phpWord->addFontStyle('fontStyle', array('size' => 9));
$PHPWord->addParagraphStyle('paragraphStyle', array('spacing' => 480)); $phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
$fontStyle = array('size' => 24); $fontStyle = array('size' => 24);
$section = $PHPWord->createSection(); $section = $phpWord->createSection();
$section->addText('Text break with no style:'); $section->addText('Text break with no style:');
$section->addTextBreak(); $section->addTextBreak();
$section->addText('Text break with defined font style:'); $section->addText('Text break with defined font style:');
@ -34,9 +31,9 @@ $section->addText('Done.');
$name = basename(__FILE__, '.php'); $name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) { foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL; echo date('H:i:s'), " Write to {$writer} format", \EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$objWriter->save("{$name}.{$extension}"); $xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}");
} }

View File

@ -5,7 +5,7 @@
error_reporting(E_ALL); error_reporting(E_ALL);
define('CLI', (PHP_SAPI == 'cli') ? true : false); define('CLI', (PHP_SAPI == 'cli') ? true : false);
define('EOL', CLI ? PHP_EOL : '<br />'); define('EOL', CLI ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php'; require_once '../src/PhpWord/PhpWord.php';
// Return to the caller script when runs by CLI // Return to the caller script when runs by CLI
if (CLI) { if (CLI) {
return; return;

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,64 @@
<?php
/**
* PhpWord
*
* Copyright (c) 2014 PhpWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord;
if (!\defined('PHPWORD_BASE_DIR')) {
\define('PHPWORD_BASE_DIR', \realpath(__DIR__) . \DIRECTORY_SEPARATOR);
}
class Autoloader
{
const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\';
/**
* @return void
*/
public static function register()
{
\spl_autoload_register(array(new self, 'autoload'));
}
/**
* @param string $fqClassName
*/
public static function autoload($fqClassName)
{
$namespacePrefixLength = \strlen(self::NAMESPACE_PREFIX);
$className = \substr($fqClassName, $namespacePrefixLength);
if (0 === \strncmp(self::NAMESPACE_PREFIX, $fqClassName, $namespacePrefixLength)) {
$fqFilename = \PHPWORD_BASE_DIR
. \str_replace('\\', \DIRECTORY_SEPARATOR, $className)
. '.php';
if (\file_exists($fqFilename)) {
require_once $fqFilename;
} else {
throw new \Exception("Could not instantiate class.");
}
}
}
}

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,14 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord;
* Class PHPWord_DocumentProperties
*/ class DocumentProperties
class PHPWord_DocumentProperties
{ {
/** Constants */ /** Constants */
const PROPERTY_TYPE_BOOLEAN = 'b'; const PROPERTY_TYPE_BOOLEAN = 'b';
@ -123,7 +120,7 @@ class PHPWord_DocumentProperties
private $_customProperties = array(); private $_customProperties = array();
/** /**
* Create new PHPWord_DocumentProperties * Create new DocumentProperties
*/ */
public function __construct() public function __construct()
{ {
@ -153,8 +150,8 @@ class PHPWord_DocumentProperties
/** /**
* Set Creator * Set Creator
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setCreator($pValue = '') public function setCreator($pValue = '')
{ {
@ -175,8 +172,8 @@ class PHPWord_DocumentProperties
/** /**
* Set Last Modified By * Set Last Modified By
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setLastModifiedBy($pValue = '') public function setLastModifiedBy($pValue = '')
{ {
@ -197,8 +194,8 @@ class PHPWord_DocumentProperties
/** /**
* Set Created * Set Created
* *
* @param datetime $pValue * @param datetime $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setCreated($pValue = null) public function setCreated($pValue = null)
{ {
@ -222,8 +219,8 @@ class PHPWord_DocumentProperties
/** /**
* Set Modified * Set Modified
* *
* @param datetime $pValue * @param datetime $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setModified($pValue = null) public function setModified($pValue = null)
{ {
@ -247,8 +244,8 @@ class PHPWord_DocumentProperties
/** /**
* Set Title * Set Title
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setTitle($pValue = '') public function setTitle($pValue = '')
{ {
@ -269,8 +266,8 @@ class PHPWord_DocumentProperties
/** /**
* Set Description * Set Description
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setDescription($pValue = '') public function setDescription($pValue = '')
{ {
@ -291,8 +288,8 @@ class PHPWord_DocumentProperties
/** /**
* Set Subject * Set Subject
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setSubject($pValue = '') public function setSubject($pValue = '')
{ {
@ -314,7 +311,7 @@ class PHPWord_DocumentProperties
* Set Keywords * Set Keywords
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setKeywords($pValue = '') public function setKeywords($pValue = '')
{ {
@ -336,7 +333,7 @@ class PHPWord_DocumentProperties
* Set Category * Set Category
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setCategory($pValue = '') public function setCategory($pValue = '')
{ {
@ -358,7 +355,7 @@ class PHPWord_DocumentProperties
* Set Company * Set Company
* *
* @param string $pValue * @param string $pValue
* @return PHPWord_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setCompany($pValue = '') public function setCompany($pValue = '')
{ {
@ -380,7 +377,7 @@ class PHPWord_DocumentProperties
* Set Manager * Set Manager
* *
* @param string $pValue * @param string $pValue
* @return PHPExcel_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setManager($pValue = '') public function setManager($pValue = '')
{ {
@ -448,7 +445,7 @@ class PHPWord_DocumentProperties
* 's': String * 's': String
* 'd': Date/Time * 'd': Date/Time
* 'b': Boolean * 'b': Boolean
* @return PHPExcel_DocumentProperties * @return \PhpOffice\PhpWord\DocumentProperties
*/ */
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null) public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
{ {

View File

@ -26,9 +26,6 @@
*/ */
namespace PhpOffice\PhpWord\Exceptions; namespace PhpOffice\PhpWord\Exceptions;
/**
* Class Exception
*/
class Exception extends \Exception class Exception extends \Exception
{ {
} }

View File

@ -27,11 +27,7 @@
namespace PhpOffice\PhpWord\Exceptions; namespace PhpOffice\PhpWord\Exceptions;
/** /**
* InvalidImageException
*
* Exception used for when an image is not found * Exception used for when an image is not found
*
* @package PHPWord
*/ */
class InvalidImageException extends Exception class InvalidImageException extends Exception
{ {

View File

@ -29,12 +29,8 @@ namespace PhpOffice\PhpWord\Exceptions;
use InvalidArgumentException; use InvalidArgumentException;
/** /**
* InvalidStyleException
*
* Exception used for when a style value is invalid * Exception used for when a style value is invalid
*
* @package PHPWord
*/ */
class InvalidStyleException extends InvalidArgumentException class InvalidStyleException extends InvalidArgumentException
{ {
} }

View File

@ -27,11 +27,7 @@
namespace PhpOffice\PhpWord\Exceptions; namespace PhpOffice\PhpWord\Exceptions;
/** /**
* UnsupportedImageTypeException
*
* Exception used for when an image type is unsupported * Exception used for when an image type is unsupported
*
* @package PHPWord
*/ */
class UnsupportedImageTypeException extends Exception class UnsupportedImageTypeException extends Exception
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,20 +18,15 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord;
/** class Footnote
* PHPWord_Footnote
*/
class PHPWord_Footnote
{ {
/** /**
* Footnote Elements * Footnote Elements
* *
@ -54,7 +49,7 @@ class PHPWord_Footnote
* *
* @return mixed * @return mixed
*/ */
public static function addFootnoteElement(PHPWord_Section_Footnote $footnote) public static function addFootnoteElement(\PhpOffice\PhpWord\Section\Footnote $footnote)
{ {
$refID = self::countFootnoteElements() + 2; $refID = self::countFootnoteElements() + 2;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,19 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
/** /**
* PHPWord_HashTable * @codeCoverageIgnore Legacy from PHPExcel
*
* @codeCoverageIgnore Legacy from PHPExcel
*/ */
class PHPWord_HashTable class HashTable
{ {
/** /**
* HashTable elements * HashTable elements
@ -47,15 +47,11 @@ class PHPWord_HashTable
public $_keyMap = array(); public $_keyMap = array();
/** /**
* Create a new PHPWord_HashTable * @param \PhpOffice\PhpWord\IComparable[] $pSource Optional source array to create HashTable from
*
* @param PHPWord_IComparable[] $pSource Optional source array to create HashTable from
* @throws Exception
*/ */
public function __construct($pSource = null) public function __construct($pSource = null)
{ {
if (!is_null($pSource)) { if (!is_null($pSource)) {
// Create HashTable
$this->addFromSource($pSource); $this->addFromSource($pSource);
} }
} }
@ -63,8 +59,8 @@ class PHPWord_HashTable
/** /**
* Add HashTable items from source * Add HashTable items from source
* *
* @param PHPWord_IComparable[] $pSource Source array to create HashTable from * @param \PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from
* @throws Exception * @throws \PhpOffice\PhpWord\Exceptions\Exception
*/ */
public function addFromSource($pSource = null) public function addFromSource($pSource = null)
{ {
@ -83,10 +79,9 @@ class PHPWord_HashTable
/** /**
* Add HashTable item * Add HashTable item
* *
* @param PHPWord_IComparable $pSource Item to add * @param \PhpOffice\PhpWord\IComparable $pSource Item to add
* @throws Exception
*/ */
public function add(PHPWord_IComparable $pSource = null) public function add(IComparable $pSource = null)
{ {
// Determine hashcode // Determine hashcode
$hashCode = null; $hashCode = null;
@ -113,10 +108,9 @@ class PHPWord_HashTable
/** /**
* Remove HashTable item * Remove HashTable item
* *
* @param PHPWord_IComparable $pSource Item to remove * @param \PhpOffice\PhpWord\IComparable $pSource Item to remove
* @throws Exception
*/ */
public function remove(PHPWord_IComparable $pSource = null) public function remove(IComparable $pSource = null)
{ {
if (isset($this->_items[$pSource->getHashCode()])) { if (isset($this->_items[$pSource->getHashCode()])) {
unset($this->_items[$pSource->getHashCode()]); unset($this->_items[$pSource->getHashCode()]);
@ -146,8 +140,6 @@ class PHPWord_HashTable
} }
/** /**
* Count
*
* @return int * @return int
*/ */
public function count() public function count()
@ -156,10 +148,8 @@ class PHPWord_HashTable
} }
/** /**
* Get index for hash code * @param string $pHashCode
* * @return int Index
* @param string $pHashCode
* @return int Index
*/ */
public function getIndexForHashCode($pHashCode = '') public function getIndexForHashCode($pHashCode = '')
{ {
@ -167,11 +157,8 @@ class PHPWord_HashTable
} }
/** /**
* Get by index * @param int $pIndex
* * @return \PhpOffice\PhpWord\IComparable
* @param int $pIndex
* @return PHPWord_IComparable
*
*/ */
public function getByIndex($pIndex = 0) public function getByIndex($pIndex = 0)
{ {
@ -183,10 +170,8 @@ class PHPWord_HashTable
} }
/** /**
* Get by hashcode * @param string $pHashCode
* * @return \PhpOffice\PhpWord\IComparable
* @param string $pHashCode
* @return PHPWord_IComparable
* *
*/ */
public function getByHashCode($pHashCode = '') public function getByHashCode($pHashCode = '')
@ -199,9 +184,7 @@ class PHPWord_HashTable
} }
/** /**
* HashTable to array * @return \PhpOffice\PhpWord\IComparable[]
*
* @return PHPWord_IComparable[]
*/ */
public function toArray() public function toArray()
{ {

77
src/PhpWord/IOFactory.php Normal file
View File

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

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,16 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord;
* Class PHPWord_Media
*/ use PhpOffice\PhpWord\Section\MemoryImage;
class PHPWord_Media
class Media
{ {
/** /**
* Section Media Elements * Section Media Elements
@ -36,9 +35,9 @@ class PHPWord_Media
* @var array * @var array
*/ */
private static $_sectionMedia = array( private static $_sectionMedia = array(
'images' => array(), 'images' => array(),
'embeddings' => array(), 'embeddings' => array(),
'links' => array() 'links' => array()
); );
/** /**
@ -65,12 +64,12 @@ class PHPWord_Media
/** /**
* Add new Section Media Element * Add new Section Media Element
* *
* @param string $src * @param string $src
* @param string $type * @param string $type
* @param PHPWord_Section_MemoryImage|null $memoryImage * @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @return mixed * @return mixed
*/ */
public static function addSectionMediaElement($src, $type, PHPWord_Section_MemoryImage $memoryImage = null) public static function addSectionMediaElement($src, $type, MemoryImage $memoryImage = null)
{ {
$mediaId = md5($src); $mediaId = md5($src);
$key = ($type === 'image') ? 'images' : 'embeddings'; $key = ($type === 'image') ? 'images' : 'embeddings';
@ -92,15 +91,27 @@ class PHPWord_Media
$isMemImage = true; $isMemImage = true;
} }
if (!$isMemImage) { if (!$isMemImage) {
$isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false); $isMemImage = (filter_var($src, \FILTER_VALIDATE_URL) !== false);
} }
$extension = '';
if ($isMemImage) { if ($isMemImage) {
$extension = $memoryImage->getImageExtension(); $extension = $memoryImage->getImageExtension();
$media['isMemImage'] = true; $media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction(); $media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction(); $media['imagefunction'] = $memoryImage->getImageFunction();
} else { } else {
$extension = PHPWord_Shared_File::imagetype($src); $imageType = exif_imagetype($src);
if ($imageType === \IMAGETYPE_JPEG) {
$extension = 'jpg';
} elseif ($imageType === \IMAGETYPE_GIF) {
$extension = 'gif';
} elseif ($imageType === \IMAGETYPE_PNG) {
$extension = 'png';
} elseif ($imageType === \IMAGETYPE_BMP) {
$extension = 'bmp';
} elseif ($imageType === \IMAGETYPE_TIFF_II || $imageType === \IMAGETYPE_TIFF_MM) {
$extension = 'tif';
}
} }
$folder = 'media'; $folder = 'media';
@ -191,12 +202,12 @@ class PHPWord_Media
/** /**
* Add new Header Media Element * Add new Header Media Element
* *
* @param int $headerCount * @param int $headerCount
* @param string $src * @param string $src
* @param PHPWord_Section_MemoryImage|null $memoryImage * @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @return int * @return int
*/ */
public static function addHeaderMediaElement($headerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null) public static function addHeaderMediaElement($headerCount, $src, MemoryImage $memoryImage = null)
{ {
$mediaId = md5($src); $mediaId = md5($src);
$key = 'header' . $headerCount; $key = 'header' . $headerCount;
@ -263,12 +274,12 @@ class PHPWord_Media
/** /**
* Add new Footer Media Element * Add new Footer Media Element
* *
* @param int $footerCount * @param int $footerCount
* @param string $src * @param string $src
* @param PHPWord_Section_MemoryImage|null $memoryImage * @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @return int * @return int
*/ */
public static function addFooterMediaElement($footerCount, $src, PHPWord_Section_MemoryImage $memoryImage = null) public static function addFooterMediaElement($footerCount, $src, MemoryImage $memoryImage = null)
{ {
$mediaId = md5($src); $mediaId = md5($src);
$key = 'footer' . $footerCount; $key = 'footer' . $footerCount;

231
src/PhpWord/PhpWord.php Normal file
View File

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

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,21 +18,19 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\Exceptions\Exception; use PhpOffice\PhpWord\Exceptions\Exception;
/** /**
* PHPWord_Reader_Abstract * @codeCoverageIgnore Abstract class
*
* @codeCoverageIgnore Abstract class
*/ */
abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader abstract class AbstractReader implements IReader
{ {
/** /**
* Read data only? * Read data only?
@ -63,7 +61,7 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
* Set read data only * Set read data only
* *
* @param bool $pValue * @param bool $pValue
* @return PHPWord_Reader_IReader * @return \PhpOffice\PhpWord\Reader\IReader
*/ */
public function setReadDataOnly($pValue = true) public function setReadDataOnly($pValue = true)
{ {
@ -76,7 +74,7 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
* *
* @param string $pFilename * @param string $pFilename
* @return resource * @return resource
* @throws Exception * @throws \PhpOffice\PhpWord\Exceptions\Exception
*/ */
protected function openFile($pFilename) protected function openFile($pFilename)
{ {
@ -93,7 +91,7 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
} }
/** /**
* Can the current PHPWord_Reader_IReader read the file? * Can the current IReader read the file?
* *
* @param string $pFilename * @param string $pFilename
* @return bool * @return bool
@ -109,4 +107,4 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
fclose($this->fileHandle); fclose($this->fileHandle);
return true; return true;
} }
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,30 +18,27 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Reader;
* PHPWord_Reader_IReader
*/ interface IReader
interface PHPWord_Reader_IReader
{ {
/** /**
* Can the current PHPWord_Reader_IReader read the file? * Can the current IReader read the file?
* *
* @param string $pFilename * @param string $pFilename
* @return boolean * @return boolean
*/ */
public function canRead($pFilename); public function canRead($pFilename);
/** /**
* Loads PHPWord from file * Loads PhpWord from file
* *
* @param string $pFilename * @param string $pFilename
*/ */
public function load($pFilename); public function load($pFilename);
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,32 +18,31 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** PHPWord root directory */ namespace PhpOffice\PhpWord\Reader;
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/../../'); use PhpOffice\PhpWord\PhpWord;
require(PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php'); use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Shared\File;
if (!defined('PHPWORD_BASE_DIR')) {
define('PHPWORD_BASE_DIR', \dirname(__FILE__) . '/../../');
require(PHPWORD_BASE_DIR . 'Autoloader.php');
} }
use PhpOffice\PhpWord\Exceptions\Exception; class Word2007 extends AbstractReader implements IReader
/**
* PHPWord_Reader_Word2007
*/
class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
{ {
/** /**
* Can the current PHPWord_Reader_IReader read the file? * Can the current IReader read the file?
* *
* @param string $pFilename * @param string $pFilename
* @return bool * @return bool
* @throws Exception * @throws \PhpOffice\PhpWord\Exceptions\Exception
*/ */
public function canRead($pFilename) public function canRead($pFilename)
{ {
@ -54,7 +53,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
$return = false; $return = false;
// Load file // Load file
$zip = new ZipArchive; $zip = new \ZipArchive();
if ($zip->open($pFilename) === true) { if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive // check if it is an OOXML archive
$rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels")); $rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels"));
@ -77,9 +76,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
} }
/** /**
* Get from zip archive * @param \ZipArchive $archive
*
* @param ZipArchive $archive
* @param string $fileName * @param string $fileName
* @param bool $removeNamespace * @param bool $removeNamespace
* @return mixed * @return mixed
@ -90,7 +87,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
if (strpos($fileName, '//') !== false) { if (strpos($fileName, '//') !== false) {
$fileName = substr($fileName, strpos($fileName, '//') + 1); $fileName = substr($fileName, strpos($fileName, '//') + 1);
} }
$fileName = PHPWord_Shared_File::realpath($fileName); $fileName = File::realpath($fileName);
// Apache POI fixes // Apache POI fixes
$contents = $archive->getFromName($fileName); $contents = $archive->getFromName($fileName);
@ -107,10 +104,10 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
} }
/** /**
* Loads PHPWord from file * Loads PhpWord from file
* *
* @param string $pFilename * @param string $pFilename
* @return PHPWord|null * @return \PhpOffice\PhpWord\PhpWord|null
*/ */
public function load($pFilename) public function load($pFilename)
{ {
@ -120,8 +117,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
} }
// Initialisations // Initialisations
$word = new PHPWord; $word = new PhpWord();
$zip = new ZipArchive; $zip = new \ZipArchive();
$zip->open($pFilename); $zip->open($pFilename);
// Read properties and documents // Read properties and documents
@ -135,7 +132,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
$xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/"); $xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/"); $xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
$xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); $xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
$docProps = $word->getProperties(); $docProps = $word->getDocumentProperties();
$docProps->setCreator((string)self::arrayItem($xmlCore->xpath("dc:creator"))); $docProps->setCreator((string)self::arrayItem($xmlCore->xpath("dc:creator")));
$docProps->setLastModifiedBy((string)self::arrayItem($xmlCore->xpath("cp:lastModifiedBy"))); $docProps->setLastModifiedBy((string)self::arrayItem($xmlCore->xpath("cp:lastModifiedBy")));
$docProps->setCreated(strtotime(self::arrayItem($xmlCore->xpath("dcterms:created")))); $docProps->setCreated(strtotime(self::arrayItem($xmlCore->xpath("dcterms:created"))));
@ -151,7 +148,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties": case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}")); $xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) { if (is_object($xmlCore)) {
$docProps = $word->getProperties(); $docProps = $word->getDocumentProperties();
if (isset($xmlCore->Company)) { if (isset($xmlCore->Company)) {
$docProps->setCompany((string)$xmlCore->Company); $docProps->setCompany((string)$xmlCore->Company);
} }
@ -164,7 +161,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties": case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}")); $xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) { if (is_object($xmlCore)) {
$docProps = $word->getProperties(); $docProps = $word->getDocumentProperties();
foreach ($xmlCore as $xmlProperty) { foreach ($xmlCore as $xmlProperty) {
$cellDataOfficeAttributes = $xmlProperty->attributes(); $cellDataOfficeAttributes = $xmlProperty->attributes();
if (isset($cellDataOfficeAttributes['name'])) { if (isset($cellDataOfficeAttributes['name'])) {
@ -172,8 +169,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
$cellDataOfficeChildren = $xmlProperty->children("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); $cellDataOfficeChildren = $xmlProperty->children("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
$attributeType = $cellDataOfficeChildren->getName(); $attributeType = $cellDataOfficeChildren->getName();
$attributeValue = (string)$cellDataOfficeChildren->{$attributeType}; $attributeValue = (string)$cellDataOfficeChildren->{$attributeType};
$attributeValue = PHPWord_DocumentProperties::convertProperty($attributeValue, $attributeType); $attributeValue = DocumentProperties::convertProperty($attributeValue, $attributeType);
$attributeType = PHPWord_DocumentProperties::convertPropertyType($attributeType); $attributeType = DocumentProperties::convertPropertyType($attributeType);
$docProps->setCustomProperty($propertyName, $attributeValue, $attributeType); $docProps->setCustomProperty($propertyName, $attributeValue, $attributeType);
} }
} }
@ -272,10 +269,10 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
/** /**
* Load section settings from SimpleXMLElement * Load section settings from SimpleXMLElement
* *
* @param SimpleXMLElement $elm * @param \SimpleXMLElement $elm
* @return array|string|null * @return array|string|null
* *
* @todo Implement gutter * @todo Implement gutter
*/ */
private function loadSectionSettings($elm) private function loadSectionSettings($elm)
{ {
@ -334,7 +331,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
/** /**
* Load paragraph style from SimpleXMLElement * Load paragraph style from SimpleXMLElement
* *
* @param SimpleXMLElement $elm * @param \SimpleXMLElement $elm
* @return array|string|null * @return array|string|null
*/ */
private function loadParagraphStyle($elm) private function loadParagraphStyle($elm)
@ -395,7 +392,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
/** /**
* Load font style from SimpleXMLElement * Load font style from SimpleXMLElement
* *
* @param SimpleXMLElement $elm * @param \SimpleXMLElement $elm
* @return array|string|null * @return array|string|null
*/ */
private function loadFontStyle($elm) private function loadFontStyle($elm)
@ -442,8 +439,6 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
} }
/** /**
* Get array item
*
* @param array $array * @param array $array
* @param mixed $key * @param mixed $key
* @return mixed|null * @return mixed|null
@ -452,4 +447,4 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
{ {
return (isset($array[$key]) ? $array[$key] : null); return (isset($array[$key]) ? $array[$key] : null);
} }
} }

151
Classes/PHPWord/Section.php → src/PhpWord/Section.php Executable file → Normal file
View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,31 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
use PhpOffice\PhpWord\Exceptions\Exception; namespace PhpOffice\PhpWord;
/** use PhpOffice\PhpWord\Exceptions\Exception;
* Class PHPWord_Section use PhpOffice\PhpWord\Section\Footer;
*/ use PhpOffice\PhpWord\Section\Image;
class PHPWord_Section use PhpOffice\PhpWord\Section\Header;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Settings;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Shared\String;
class Section
{ {
/** /**
* Section count * Section count
@ -42,7 +54,7 @@ class PHPWord_Section
/** /**
* Section settings * Section settings
* *
* @var PHPWord_Section_Settings * @var \PhpOffice\PhpWord\Section\Settings
*/ */
private $_settings; private $_settings;
@ -63,7 +75,7 @@ class PHPWord_Section
/** /**
* Section Footer * Section Footer
* *
* @var PHPWord_Section_Footer * @var \PhpOffice\PhpWord\Section\Footer
*/ */
private $_footer = null; private $_footer = null;
@ -77,7 +89,7 @@ class PHPWord_Section
public function __construct($sectionCount, $settings = null) public function __construct($sectionCount, $settings = null)
{ {
$this->_sectionCount = $sectionCount; $this->_sectionCount = $sectionCount;
$this->_settings = new PHPWord_Section_Settings(); $this->_settings = new Settings();
$this->setSettings($settings); $this->setSettings($settings);
} }
@ -101,7 +113,7 @@ class PHPWord_Section
/** /**
* Get Section Settings * Get Section Settings
* *
* @return PHPWord_Section_Settings * @return \PhpOffice\PhpWord\Section\Settings
*/ */
public function getSettings() public function getSettings()
{ {
@ -114,14 +126,14 @@ class PHPWord_Section
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Text * @return \PhpOffice\PhpWord\Section\Text
*/ */
public function addText($text, $styleFont = null, $styleParagraph = null) public function addText($text, $styleFont = null, $styleParagraph = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::IsUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text; $this->_elementCollection[] = $text;
return $text; return $text;
} }
@ -133,21 +145,21 @@ class PHPWord_Section
* @param string $linkName * @param string $linkName
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Link * @return \PhpOffice\PhpWord\Section\Link
*/ */
public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null) public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($linkSrc)) { if (!String::IsUTF8($linkSrc)) {
$linkSrc = utf8_encode($linkSrc); $linkSrc = utf8_encode($linkSrc);
} }
if (!is_null($linkName)) { if (!is_null($linkName)) {
if (!PHPWord_Shared_String::IsUTF8($linkName)) { if (!String::IsUTF8($linkName)) {
$linkName = utf8_encode($linkName); $linkName = utf8_encode($linkName);
} }
} }
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont, $styleParagraph); $link = new Link($linkSrc, $linkName, $styleFont, $styleParagraph);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc); $rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID); $link->setRelationId($rID);
$this->_elementCollection[] = $link; $this->_elementCollection[] = $link;
@ -157,14 +169,14 @@ class PHPWord_Section
/** /**
* Add a TextBreak Element * Add a TextBreak Element
* *
* @param int $count * @param int $count
* @param null|string|array|PHPWord_Style_Font $fontStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/ */
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{ {
for ($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
} }
} }
@ -173,18 +185,18 @@ class PHPWord_Section
*/ */
public function addPageBreak() public function addPageBreak()
{ {
$this->_elementCollection[] = new PHPWord_Section_PageBreak(); $this->_elementCollection[] = new PageBreak();
} }
/** /**
* Add a Table Element * Add a Table Element
* *
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Table * @return \PhpOffice\PhpWord\Section\Table
*/ */
public function addTable($style = null) public function addTable($style = null)
{ {
$table = new PHPWord_Section_Table('section', $this->_sectionCount, $style); $table = new Table('section', $this->_sectionCount, $style);
$this->_elementCollection[] = $table; $this->_elementCollection[] = $table;
return $table; return $table;
} }
@ -197,14 +209,14 @@ class PHPWord_Section
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleList * @param mixed $styleList
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_ListItem * @return \PhpOffice\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)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleFont, $styleList, $styleParagraph); $listItem = new ListItem($text, $depth, $styleFont, $styleList, $styleParagraph);
$this->_elementCollection[] = $listItem; $this->_elementCollection[] = $listItem;
return $listItem; return $listItem;
} }
@ -214,12 +226,12 @@ class PHPWord_Section
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Object * @return \PhpOffice\PhpWord\Section\Object
* @throws Exception * @throws \PhpOffice\PhpWord\Exceptions\Exception
*/ */
public function addObject($src, $style = null) public function addObject($src, $style = null)
{ {
$object = new PHPWord_Section_Object($src, $style); $object = new Object($src, $style);
if (!is_null($object->getSource())) { if (!is_null($object->getSource())) {
$inf = pathinfo($src); $inf = pathinfo($src);
@ -228,15 +240,15 @@ class PHPWord_Section
$ext = substr($ext, 0, -1); $ext = substr($ext, 0, -1);
} }
$iconSrc = PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/'; $iconSrc = \PHPWORD_BASE_DIR . '_staticDocParts/';
if (!file_exists($iconSrc . '_' . $ext . '.png')) { if (!file_exists($iconSrc . '_' . $ext . '.png')) {
$iconSrc = $iconSrc . '_default.png'; $iconSrc = $iconSrc . '_default.png';
} else { } else {
$iconSrc .= '_' . $ext . '.png'; $iconSrc .= '_' . $ext . '.png';
} }
$rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image'); $rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
$data = PHPWord_Media::addSectionMediaElement($src, 'oleObject'); $data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0]; $rID = $data[0];
$objectId = $data[1]; $objectId = $data[1];
@ -255,15 +267,15 @@ class PHPWord_Section
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Image * @return \PhpOffice\PhpWord\Section\Image
* @throws Exception * @throws \PhpOffice\PhpWord\Exceptions\Exception
*/ */
public function addImage($src, $style = null) public function addImage($src, $style = null)
{ {
$image = new PHPWord_Section_Image($src, $style); $image = new Image($src, $style);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addSectionMediaElement($src, 'image'); $rID = Media::addSectionMediaElement($src, 'image');
$image->setRelationId($rID); $image->setRelationId($rID);
$this->_elementCollection[] = $image; $this->_elementCollection[] = $image;
@ -277,14 +289,14 @@ class PHPWord_Section
* *
* @param string $link * @param string $link
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_MemoryImage * @return \PhpOffice\PhpWord\Section\MemoryImage
* @throws Exception * @throws \PhpOffice\PhpWord\Exceptions\Exception
*/ */
public function addMemoryImage($link, $style = null) public function addMemoryImage($link, $style = null)
{ {
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); $memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) { if (!is_null($memoryImage->getSource())) {
$rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage); $rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
$memoryImage->setRelationId($rID); $memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage; $this->_elementCollection[] = $memoryImage;
@ -298,11 +310,11 @@ class PHPWord_Section
* *
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleTOC * @param mixed $styleTOC
* @return PHPWord_TOC * @return \PhpOffice\PhpWord\TOC
*/ */
public function addTOC($styleFont = null, $styleTOC = null) public function addTOC($styleFont = null, $styleTOC = null)
{ {
$toc = new PHPWord_TOC($styleFont, $styleTOC); $toc = new TOC($styleFont, $styleTOC);
$this->_elementCollection[] = $toc; $this->_elementCollection[] = $toc;
return $toc; return $toc;
} }
@ -312,23 +324,23 @@ class PHPWord_Section
* *
* @param string $text * @param string $text
* @param int $depth * @param int $depth
* @return PHPWord_Section_Title * @return \PhpOffice\PhpWord\Section\Title
*/ */
public function addTitle($text, $depth = 1) public function addTitle($text, $depth = 1)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$styles = PHPWord_Style::getStyles(); $styles = Style::getStyles();
if (array_key_exists('Heading_' . $depth, $styles)) { if (array_key_exists('Heading_' . $depth, $styles)) {
$style = 'Heading' . $depth; $style = 'Heading' . $depth;
} else { } else {
$style = null; $style = null;
} }
$title = new PHPWord_Section_Title($text, $depth, $style); $title = new Title($text, $depth, $style);
$data = PHPWord_TOC::addTitle($text, $depth); $data = TOC::addTitle($text, $depth);
$anchor = $data[0]; $anchor = $data[0];
$bookmarkId = $data[1]; $bookmarkId = $data[1];
@ -343,11 +355,11 @@ class PHPWord_Section
* Create a new TextRun * Create a new TextRun
* *
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_TextRun * @return \PhpOffice\PhpWord\Section\TextRun
*/ */
public function createTextRun($styleParagraph = null) public function createTextRun($styleParagraph = null)
{ {
$textRun = new PHPWord_Section_TextRun($styleParagraph); $textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun; $this->_elementCollection[] = $textRun;
return $textRun; return $textRun;
} }
@ -365,11 +377,11 @@ class PHPWord_Section
/** /**
* Create a new Header * Create a new Header
* *
* @return PHPWord_Section_Header * @return \PhpOffice\PhpWord\Section\Header
*/ */
public function createHeader() public function createHeader()
{ {
$header = new PHPWord_Section_Header($this->_sectionCount); $header = new Header($this->_sectionCount);
$this->_headers[] = $header; $this->_headers[] = $header;
return $header; return $header;
} }
@ -387,16 +399,15 @@ class PHPWord_Section
/** /**
* Is there a header for this section that is for the first page only? * Is there a header for this section that is for the first page only?
* *
* If any of the PHPWord_Section_Header instances have a type of * If any of the Header instances have a type of Header::FIRST then this method returns true.
* PHPWord_Section_Header::FIRST then this method returns true. False * False otherwise.
* otherwise.
* *
* @return Boolean * @return Boolean
*/ */
public function hasDifferentFirstPage() public function hasDifferentFirstPage()
{ {
$value = array_filter($this->_headers, function (PHPWord_Section_Header &$header) { $value = array_filter($this->_headers, function (Header &$header) {
return $header->getType() == PHPWord_Section_Header::FIRST; return $header->getType() == Header::FIRST;
}); });
return count($value) > 0; return count($value) > 0;
} }
@ -404,19 +415,17 @@ class PHPWord_Section
/** /**
* Create a new Footer * Create a new Footer
* *
* @return PHPWord_Section_Footer * @return \PhpOffice\PhpWord\Section\Footer
*/ */
public function createFooter() public function createFooter()
{ {
$footer = new PHPWord_Section_Footer($this->_sectionCount); $footer = new Footer($this->_sectionCount);
$this->_footer = $footer; $this->_footer = $footer;
return $footer; return $footer;
} }
/** /**
* Get Footer * @return \PhpOffice\PhpWord\Section\Footer
*
* @return PHPWord_Section_Footer
*/ */
public function getFooter() public function getFooter()
{ {
@ -427,14 +436,14 @@ class PHPWord_Section
* Create a new Footnote Element * Create a new Footnote Element
* *
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Footnote * @return \PhpOffice\PhpWord\Section\Footnote
*/ */
public function createFootnote($styleParagraph = null) public function createFootnote($styleParagraph = null)
{ {
$footnote = new PHPWord_Section_Footnote($styleParagraph); $footnote = new \PhpOffice\PhpWord\Section\Footnote($styleParagraph);
$refID = PHPWord_Footnote::addFootnoteElement($footnote); $refID = Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID); $footnote->setReferenceId($refID);
$this->_elementCollection[] = $footnote; $this->_elementCollection[] = $footnote;
return $footnote; return $footnote;
} }
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,20 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* PHPWord_Section_Footer
*/
class PHPWord_Section_Footer
{
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
class Footer
{
/** /**
* Footer Count * Footer Count
* *
@ -54,8 +55,6 @@ class PHPWord_Section_Footer
/** /**
* Create a new Footer * Create a new Footer
*
* @param int $sectionCount
*/ */
public function __construct($sectionCount) public function __construct($sectionCount)
{ {
@ -68,14 +67,14 @@ class PHPWord_Section_Footer
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Text * @return \PhpOffice\PhpWord\Section\Text
*/ */
public function addText($text, $styleFont = null, $styleParagraph = null) public function addText($text, $styleFont = null, $styleParagraph = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text; $this->_elementCollection[] = $text;
return $text; return $text;
} }
@ -83,26 +82,25 @@ class PHPWord_Section_Footer
/** /**
* Add TextBreak * Add TextBreak
* *
* @param int $count * @param int $count
* @param null|string|array|PHPWord_Style_Font $fontStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/ */
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{ {
for ($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
} }
} }
/** /**
* Create a new TextRun * Create a new TextRun
* *
* @param null|string|array|PHPWord_Style_Paragraph $styleParagraph * @return \PhpOffice\PhpWord\Section\TextRun
* @return PHPWord_Section_TextRun
*/ */
public function createTextRun($styleParagraph = null) public function createTextRun($styleParagraph = null)
{ {
$textRun = new PHPWord_Section_TextRun($styleParagraph); $textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun; $this->_elementCollection[] = $textRun;
return $textRun; return $textRun;
} }
@ -111,11 +109,11 @@ class PHPWord_Section_Footer
* Add a Table Element * Add a Table Element
* *
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Table * @return \PhpOffice\PhpWord\Section\Table
*/ */
public function addTable($style = null) public function addTable($style = null)
{ {
$table = new PHPWord_Section_Table('footer', $this->_footerCount, $style); $table = new Table('footer', $this->_footerCount, $style);
$this->_elementCollection[] = $table; $this->_elementCollection[] = $table;
return $table; return $table;
} }
@ -125,14 +123,14 @@ class PHPWord_Section_Footer
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Image * @return \PhpOffice\PhpWord\Section\Image
*/ */
public function addImage($src, $style = null) public function addImage($src, $style = null)
{ {
$image = new PHPWord_Section_Image($src, $style); $image = new Image($src, $style);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $src); $rID = Media::addFooterMediaElement($this->_footerCount, $src);
$image->setRelationId($rID); $image->setRelationId($rID);
$this->_elementCollection[] = $image; $this->_elementCollection[] = $image;
@ -147,13 +145,13 @@ class PHPWord_Section_Footer
* *
* @param string $link * @param string $link
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_MemoryImage * @return \PhpOffice\PhpWord\Section\MemoryImage
*/ */
public function addMemoryImage($link, $style = null) public function addMemoryImage($link, $style = null)
{ {
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); $memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) { if (!is_null($memoryImage->getSource())) {
$rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage); $rID = Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID); $memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage; $this->_elementCollection[] = $memoryImage;
@ -169,14 +167,14 @@ class PHPWord_Section_Footer
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText * @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/ */
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext; $this->_elementCollection[] = $ptext;
return $ptext; return $ptext;
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,18 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section\Footer;
* Class PHPWord_Section_Footer_PreserveText
*/
class PHPWord_Section_Footer_PreserveText
{
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class PreserveText
{
/** /**
* Text content * Text content
* *
@ -41,14 +40,14 @@ class PHPWord_Section_Footer_PreserveText
/** /**
* Text style * Text style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Font
*/ */
private $_styleFont; private $_styleFont;
/** /**
* Paragraph style * Paragraph style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Paragraph
*/ */
private $_styleParagraph; private $_styleParagraph;
@ -65,7 +64,7 @@ class PHPWord_Section_Footer_PreserveText
{ {
// Set font style // Set font style
if (is_array($styleFont)) { if (is_array($styleFont)) {
$this->_styleFont = new PHPWord_Style_Font('text'); $this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) { foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -79,7 +78,7 @@ class PHPWord_Section_Footer_PreserveText
// Set paragraph style // Set paragraph style
if (is_array($styleParagraph)) { if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); $this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) { foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -91,7 +90,7 @@ class PHPWord_Section_Footer_PreserveText
$this->_styleParagraph = $styleParagraph; $this->_styleParagraph = $styleParagraph;
} }
$matches = preg_split('/({.*?})/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $matches = preg_split('/({.*?})/', $text, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) { if (isset($matches[0])) {
$this->_text = $matches; $this->_text = $matches;
} }
@ -102,7 +101,7 @@ class PHPWord_Section_Footer_PreserveText
/** /**
* Get Text style * Get Text style
* *
* @return PHPWord_Style_Font * @return \PhpOffice\PhpWord\Style\Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -112,7 +111,7 @@ class PHPWord_Section_Footer_PreserveText
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return PHPWord_Style_Paragraph * @return \PhpOffice\PhpWord\Style\Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,23 +18,21 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* PHPWord_Section_Footnote
*/
class PHPWord_Section_Footnote
{
use PhpOffice\PhpWord\Style\Paragraph;
class Footnote
{
/** /**
* Paragraph style * Paragraph style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Paragraph
*/ */
private $_styleParagraph; private $_styleParagraph;
@ -54,8 +52,6 @@ class PHPWord_Section_Footnote
/** /**
* Create a new Footnote Element * Create a new Footnote Element
*
* @param mixed $styleParagraph
*/ */
public function __construct($styleParagraph = null) public function __construct($styleParagraph = null)
{ {
@ -63,7 +59,7 @@ class PHPWord_Section_Footnote
// Set paragraph style // Set paragraph style
if (is_array($styleParagraph)) { if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); $this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) { foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -80,14 +76,14 @@ class PHPWord_Section_Footnote
/** /**
* Add a Text Element * Add a Text Element
* *
* @param null|string $text * @var string $text
* @param mixed $styleFont * @var mixed $styleFont
* @return PHPWord_Section_Text * @return \PhpOffice\PhpWord\Section\Text
*/ */
public function addText($text = null, $styleFont = null) public function addText($text = null, $styleFont = null)
{ {
$givenText = $text; $givenText = $text;
$text = new PHPWord_Section_Text($givenText, $styleFont); $text = new Text($givenText, $styleFont);
$this->_elementCollection[] = $text; $this->_elementCollection[] = $text;
return $text; return $text;
} }
@ -98,13 +94,13 @@ class PHPWord_Section_Footnote
* @param string $linkSrc * @param string $linkSrc
* @param string $linkName * @param string $linkName
* @param mixed $styleFont * @param mixed $styleFont
* @return PHPWord_Section_Link * @return \PhpOffice\PhpWord\Section\Link
*/ */
public function addLink($linkSrc, $linkName = null, $styleFont = null) public function addLink($linkSrc, $linkName = null, $styleFont = null)
{ {
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont); $link = new Link($linkSrc, $linkName, $styleFont);
$rID = PHPWord_Footnote::addFootnoteLinkElement($linkSrc); $rID = \PhpOffice\PhpWord\Footnote::addFootnoteLinkElement($linkSrc);
$link->setRelationId($rID); $link->setRelationId($rID);
$this->_elementCollection[] = $link; $this->_elementCollection[] = $link;
@ -122,9 +118,7 @@ class PHPWord_Section_Footnote
} }
/** /**
* Get Paragraph style * @return \PhpOffice\PhpWord\Style\Paragraph
*
* @return PHPWord_Style_Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,20 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* PHPWord_Section_Header
*/
class PHPWord_Section_Header
{
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
class Header
{
/** /**
* Header Count * Header Count
* *
@ -51,7 +52,7 @@ class PHPWord_Section_Header
* @var string * @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type * @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/ */
private $_type = PHPWord_Section_Header::AUTO; private $_type = self::AUTO;
/** /**
* Even Numbered Pages Only * Even Numbered Pages Only
@ -83,8 +84,6 @@ class PHPWord_Section_Header
/** /**
* Create a new Header * Create a new Header
*
* @param int $sectionCount
*/ */
public function __construct($sectionCount) public function __construct($sectionCount)
{ {
@ -97,14 +96,14 @@ class PHPWord_Section_Header
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Text * @return \PhpOffice\PhpWord\Section\Text
*/ */
public function addText($text, $styleFont = null, $styleParagraph = null) public function addText($text, $styleFont = null, $styleParagraph = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text; $this->_elementCollection[] = $text;
return $text; return $text;
} }
@ -112,26 +111,25 @@ class PHPWord_Section_Header
/** /**
* Add TextBreak * Add TextBreak
* *
* @param int $count * @param int $count
* @param null|string|array|PHPWord_Style_Font $fontStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/ */
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{ {
for ($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
} }
} }
/** /**
* Create a new TextRun * Create a new TextRun
* *
* @param mixed $styleParagraph * @return \PhpOffice\PhpWord\Section\TextRun
* @return PHPWord_Section_TextRun
*/ */
public function createTextRun($styleParagraph = null) public function createTextRun($styleParagraph = null)
{ {
$textRun = new PHPWord_Section_TextRun($styleParagraph); $textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun; $this->_elementCollection[] = $textRun;
return $textRun; return $textRun;
} }
@ -140,11 +138,11 @@ class PHPWord_Section_Header
* Add a Table Element * Add a Table Element
* *
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Table * @return \PhpOffice\PhpWord\Section\Table
*/ */
public function addTable($style = null) public function addTable($style = null)
{ {
$table = new PHPWord_Section_Table('header', $this->_headerCount, $style); $table = new Table('header', $this->_headerCount, $style);
$this->_elementCollection[] = $table; $this->_elementCollection[] = $table;
return $table; return $table;
} }
@ -154,14 +152,14 @@ class PHPWord_Section_Header
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Image * @return \PhpOffice\PhpWord\Section\Image
*/ */
public function addImage($src, $style = null) public function addImage($src, $style = null)
{ {
$image = new PHPWord_Section_Image($src, $style); $image = new Image($src, $style);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src); $rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID); $image->setRelationId($rID);
$this->_elementCollection[] = $image; $this->_elementCollection[] = $image;
@ -176,13 +174,13 @@ class PHPWord_Section_Header
* *
* @param string $link * @param string $link
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_MemoryImage * @return \PhpOffice\PhpWord\Section\MemoryImage
*/ */
public function addMemoryImage($link, $style = null) public function addMemoryImage($link, $style = null)
{ {
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); $memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) { if (!is_null($memoryImage->getSource())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage); $rID = Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID); $memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage; $this->_elementCollection[] = $memoryImage;
@ -198,14 +196,14 @@ class PHPWord_Section_Header
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText * @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/ */
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext; $this->_elementCollection[] = $ptext;
return $ptext; return $ptext;
} }
@ -215,14 +213,14 @@ class PHPWord_Section_Header
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Image * @return \PhpOffice\PhpWord\Section\Image
*/ */
public function addWatermark($src, $style = null) public function addWatermark($src, $style = null)
{ {
$image = new PHPWord_Section_Image($src, $style, true); $image = new Image($src, $style, true);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src); $rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID); $image->setRelationId($rID);
$this->_elementCollection[] = $image; $this->_elementCollection[] = $image;
@ -279,7 +277,7 @@ class PHPWord_Section_Header
*/ */
public function resetType() public function resetType()
{ {
return $this->_type = PHPWord_Section_Header::AUTO; return $this->_type = self::AUTO;
} }
/** /**
@ -287,7 +285,7 @@ class PHPWord_Section_Header
*/ */
public function firstPage() public function firstPage()
{ {
return $this->_type = PHPWord_Section_Header::FIRST; return $this->_type = self::FIRST;
} }
/** /**
@ -295,6 +293,6 @@ class PHPWord_Section_Header
*/ */
public function evenPage() public function evenPage()
{ {
return $this->_type = PHPWord_Section_Header::EVEN; return $this->_type = self::EVEN;
} }
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,20 +18,17 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\InvalidImageException; use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException; use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
/** class Image
* Class PHPWord_Section_Image
*/
class PHPWord_Section_Image
{ {
/** /**
* Image Src * Image Src
@ -43,7 +40,7 @@ class PHPWord_Section_Image
/** /**
* Image Style * Image Style
* *
* @var PHPWord_Style_Image * @var \PhpOffice\PhpWord\Style\Image
*/ */
private $_style; private $_style;
@ -61,27 +58,31 @@ class PHPWord_Section_Image
*/ */
private $_isWatermark; private $_isWatermark;
/** /**
* Create a new Image * Create a new Image
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @param bool $isWatermark * @param bool $isWatermark
* @throws InvalidImageException|UnsupportedImageTypeException * @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
* @throws \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
*/ */
public function __construct($src, $style = null, $isWatermark = false) public function __construct($src, $style = null, $isWatermark = false)
{ {
$supportedImageTypes = array(\IMAGETYPE_JPEG, \IMAGETYPE_GIF, \IMAGETYPE_PNG, \IMAGETYPE_BMP, \IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM);
if (!file_exists($src)) { if (!file_exists($src)) {
throw new InvalidImageException; throw new InvalidImageException;
} }
if (!PHPWord_Shared_File::imagetype($src)) { if (!in_array(exif_imagetype($src), $supportedImageTypes)) {
throw new UnsupportedImageTypeException; throw new UnsupportedImageTypeException;
} }
$this->_src = $src; $this->_src = $src;
$this->_isWatermark = $isWatermark; $this->_isWatermark = $isWatermark;
$this->_style = new PHPWord_Style_Image(); $this->_style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) { if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) { foreach ($style as $key => $value) {
@ -106,7 +107,7 @@ class PHPWord_Section_Image
/** /**
* Get Image style * Get Image style
* *
* @return PHPWord_Style_Image * @return \PhpOffice\PhpWord\Style\Image
*/ */
public function getStyle() public function getStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,18 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_Link
*/
class PHPWord_Section_Link
{
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class Link
{
/** /**
* Link source * Link source
* *
@ -55,14 +54,14 @@ class PHPWord_Section_Link
/** /**
* Link style * Link style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Font
*/ */
private $_styleFont; private $_styleFont;
/** /**
* Paragraph style * Paragraph style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Paragraph
*/ */
private $_styleParagraph; private $_styleParagraph;
@ -82,7 +81,7 @@ class PHPWord_Section_Link
// Set font style // Set font style
if (is_array($styleFont)) { if (is_array($styleFont)) {
$this->_styleFont = new PHPWord_Style_Font('text'); $this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) { foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -96,7 +95,7 @@ class PHPWord_Section_Link
// Set paragraph style // Set paragraph style
if (is_array($styleParagraph)) { if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); $this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) { foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -154,7 +153,7 @@ class PHPWord_Section_Link
/** /**
* Get Text style * Get Text style
* *
* @return PHPWord_Style_Font * @return \PhpOffice\PhpWord\Style\Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -164,7 +163,7 @@ class PHPWord_Section_Link
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return PHPWord_Style_Paragraph * @return \PhpOffice\PhpWord\Style\Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,30 +18,26 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_ListItem
*/
class PHPWord_Section_ListItem
{
class ListItem
{
/** /**
* ListItem Style * ListItem Style
* *
* @var PHPWord_Style_ListItem * @var \PhpOffice\PhpWord\Style\ListItem
*/ */
private $_style; private $_style;
/** /**
* Textrun * Textrun
* *
* @var PHPWord_Section_Text * @var \PhpOffice\PhpWord\Section\Text
*/ */
private $_textObject; private $_textObject;
@ -64,8 +60,8 @@ class PHPWord_Section_ListItem
*/ */
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null) public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
{ {
$this->_style = new PHPWord_Style_ListItem(); $this->_style = new \PhpOffice\PhpWord\Style\ListItem();
$this->_textObject = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $this->_textObject = new Text($text, $styleFont, $styleParagraph);
$this->_depth = $depth; $this->_depth = $depth;
if (!is_null($styleList) && is_array($styleList)) { if (!is_null($styleList) && is_array($styleList)) {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,14 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_MemoryImage
*/ class MemoryImage
class PHPWord_Section_MemoryImage
{ {
/** /**
* Image Src * Image Src
@ -40,7 +37,7 @@ class PHPWord_Section_MemoryImage
/** /**
* Image Style * Image Style
* *
* @var PHPWord_Style_Image * @var \PhpOffice\PhpWord\Style\Image
*/ */
private $_style; private $_style;
@ -95,7 +92,7 @@ class PHPWord_Section_MemoryImage
if (in_array($this->_imageType, $_supportedImageTypes)) { if (in_array($this->_imageType, $_supportedImageTypes)) {
$this->_src = $src; $this->_src = $src;
$this->_style = new PHPWord_Style_Image(); $this->_style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) { if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) { foreach ($style as $key => $value) {
@ -143,7 +140,7 @@ class PHPWord_Section_MemoryImage
/** /**
* Get Image style * Get Image style
* *
* @return PHPWord_Style_Image * @return \PhpOffice\PhpWord\Style\Image
*/ */
public function getStyle() public function getStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,15 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_Object
*/
class PHPWord_Section_Object
{
class Object
{
/** /**
* Ole-Object Src * Ole-Object Src
* *
@ -41,7 +37,7 @@ class PHPWord_Section_Object
/** /**
* Image Style * Image Style
* *
* @var PHPWord_Style_Image * @var \PhpOffice\PhpWord\Style\Image
*/ */
private $_style; private $_style;
@ -80,7 +76,7 @@ class PHPWord_Section_Object
if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) { if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
$this->_src = $src; $this->_src = $src;
$this->_style = new PHPWord_Style_Image(); $this->_style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) { if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) { foreach ($style as $key => $value) {
@ -100,7 +96,7 @@ class PHPWord_Section_Object
/** /**
* Get Image style * Get Image style
* *
* @return PHPWord_Style_Image * @return \PhpOffice\PhpWord\Style\Image
*/ */
public function getStyle() public function getStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,22 +18,15 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_PageBreak
*/
class PHPWord_Section_PageBreak
{
/** class PageBreak
* Create a new PageBreak Element {
*/
public function __construct() public function __construct()
{ {
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,15 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_Settings
*/
class PHPWord_Section_Settings
{
class Settings
{
/** /**
* Default Page Size Width * Default Page Size Width
* *

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,23 +18,21 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_Table
*/
class PHPWord_Section_Table
{
use PhpOffice\PhpWord\Section\Table\Row;
class Table
{
/** /**
* Table style * Table style
* *
* @var PHPWord_Style_Table * @var \PhpOffice\PhpWord\Style\Table
*/ */
private $_style; private $_style;
@ -81,7 +79,7 @@ class PHPWord_Section_Table
if (!is_null($style)) { if (!is_null($style)) {
if (is_array($style)) { if (is_array($style)) {
$this->_style = new PHPWord_Style_Table(); $this->_style = new \PhpOffice\PhpWord\Style\Table();
foreach ($style as $key => $value) { foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -103,7 +101,7 @@ class PHPWord_Section_Table
*/ */
public function addRow($height = null, $style = null) public function addRow($height = null, $style = null)
{ {
$row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style); $row = new Row($this->_insideOf, $this->_pCount, $height, $style);
$this->_rows[] = $row; $this->_rows[] = $row;
return $row; return $row;
} }
@ -113,7 +111,7 @@ class PHPWord_Section_Table
* *
* @param int $width * @param int $width
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Table_Cell * @return \PhpOffice\PhpWord\Section\Table\Cell
*/ */
public function addCell($width = null, $style = null) public function addCell($width = null, $style = null)
{ {
@ -135,7 +133,7 @@ class PHPWord_Section_Table
/** /**
* Get table style * Get table style
* *
* @return PHPWord_Style_Table * @return \PhpOffice\PhpWord\Style\Table
*/ */
public function getStyle() public function getStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,28 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section\Table;
* PHPWord_Section_Table_Cell
*/
class PHPWord_Section_Table_Cell
{
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Shared\String;
class Cell
{
/** /**
* Cell Width * Cell Width
* *
@ -41,7 +50,7 @@ class PHPWord_Section_Table_Cell
/** /**
* Cell Style * Cell Style
* *
* @var PHPWord_Style_Cell * @var \PhpOffice\PhpWord\Style\Cell
*/ */
private $_style; private $_style;
@ -80,7 +89,7 @@ class PHPWord_Section_Table_Cell
$this->_insideOf = $insideOf; $this->_insideOf = $insideOf;
$this->_pCount = $pCount; $this->_pCount = $pCount;
$this->_width = $width; $this->_width = $width;
$this->_style = new PHPWord_Style_Cell; $this->_style = new \PhpOffice\PhpWord\Style\Cell();
if (!is_null($style)) { if (!is_null($style)) {
if (is_array($style)) { if (is_array($style)) {
@ -100,16 +109,15 @@ class PHPWord_Section_Table_Cell
* Add a Text Element * Add a Text Element
* *
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $style
* @param mixed $styleParagraph * @return \PhpOffice\PhpWord\Section\Text
* @return PHPWord_Section_Text
*/ */
public function addText($text, $styleFont = null, $styleParagraph = null) public function addText($text, $styleFont = null, $styleParagraph = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph); $text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text; $this->_elementCollection[] = $text;
return $text; return $text;
} }
@ -120,22 +128,22 @@ class PHPWord_Section_Table_Cell
* @param string $linkSrc * @param string $linkSrc
* @param string $linkName * @param string $linkName
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Link * @return \PhpOffice\PhpWord\Section\Link
*/ */
public function addLink($linkSrc, $linkName = null, $style = null) public function addLink($linkSrc, $linkName = null, $style = null)
{ {
if ($this->_insideOf == 'section') { if ($this->_insideOf == 'section') {
if (!PHPWord_Shared_String::IsUTF8($linkSrc)) { if (!String::isUTF8($linkSrc)) {
$linkSrc = utf8_encode($linkSrc); $linkSrc = utf8_encode($linkSrc);
} }
if (!is_null($linkName)) { if (!is_null($linkName)) {
if (!PHPWord_Shared_String::IsUTF8($linkName)) { if (!String::isUTF8($linkName)) {
$linkName = utf8_encode($linkName); $linkName = utf8_encode($linkName);
} }
} }
$link = new PHPWord_Section_Link($linkSrc, $linkName, $style); $link = new Link($linkSrc, $linkName, $style);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc); $rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID); $link->setRelationId($rID);
$this->_elementCollection[] = $link; $this->_elementCollection[] = $link;
@ -149,14 +157,14 @@ class PHPWord_Section_Table_Cell
/** /**
* Add TextBreak * Add TextBreak
* *
* @param int $count * @param int $count
* @param null|string|array|PHPWord_Style_Font $fontStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/ */
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{ {
for ($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
} }
} }
@ -167,14 +175,14 @@ class PHPWord_Section_Table_Cell
* @param int $depth * @param int $depth
* @param mixed $styleText * @param mixed $styleText
* @param mixed $styleList * @param mixed $styleList
* @return PHPWord_Section_ListItem * @return \PhpOffice\PhpWord\Section\ListItem
*/ */
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) public function addListItem($text, $depth = 0, $styleText = null, $styleList = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList); $listItem = new ListItem($text, $depth, $styleText, $styleList);
$this->_elementCollection[] = $listItem; $this->_elementCollection[] = $listItem;
return $listItem; return $listItem;
} }
@ -184,19 +192,19 @@ class PHPWord_Section_Table_Cell
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Image * @return \PhpOffice\PhpWord\Section\Image
*/ */
public function addImage($src, $style = null) public function addImage($src, $style = null)
{ {
$image = new PHPWord_Section_Image($src, $style); $image = new Image($src, $style);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
if ($this->_insideOf == 'section') { if ($this->_insideOf == 'section') {
$rID = PHPWord_Media::addSectionMediaElement($src, 'image'); $rID = Media::addSectionMediaElement($src, 'image');
} elseif ($this->_insideOf == 'header') { } elseif ($this->_insideOf == 'header') {
$rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $src); $rID = Media::addHeaderMediaElement($this->_pCount, $src);
} elseif ($this->_insideOf == 'footer') { } elseif ($this->_insideOf == 'footer') {
$rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $src); $rID = Media::addFooterMediaElement($this->_pCount, $src);
} }
$image->setRelationId($rID); $image->setRelationId($rID);
@ -212,18 +220,18 @@ class PHPWord_Section_Table_Cell
* *
* @param string $link * @param string $link
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_MemoryImage * @return \PhpOffice\PhpWord\Section\MemoryImage
*/ */
public function addMemoryImage($link, $style = null) public function addMemoryImage($link, $style = null)
{ {
$memoryImage = new PHPWord_Section_MemoryImage($link, $style); $memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) { if (!is_null($memoryImage->getSource())) {
if ($this->_insideOf == 'section') { if ($this->_insideOf == 'section') {
$rID = PHPWord_Media::addSectionMediaElement($link, 'image', $memoryImage); $rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
} elseif ($this->_insideOf == 'header') { } elseif ($this->_insideOf == 'header') {
$rID = PHPWord_Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage); $rID = Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage);
} elseif ($this->_insideOf == 'footer') { } elseif ($this->_insideOf == 'footer') {
$rID = PHPWord_Media::addFooterMediaElement($this->_pCount, $link, $memoryImage); $rID = Media::addFooterMediaElement($this->_pCount, $link, $memoryImage);
} }
$memoryImage->setRelationId($rID); $memoryImage->setRelationId($rID);
@ -239,11 +247,11 @@ class PHPWord_Section_Table_Cell
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Object * @return \PhpOffice\PhpWord\Section\Object
*/ */
public function addObject($src, $style = null) public function addObject($src, $style = null)
{ {
$object = new PHPWord_Section_Object($src, $style); $object = new Object($src, $style);
if (!is_null($object->getSource())) { if (!is_null($object->getSource())) {
$inf = pathinfo($src); $inf = pathinfo($src);
@ -252,15 +260,15 @@ class PHPWord_Section_Table_Cell
$ext = substr($ext, 0, -1); $ext = substr($ext, 0, -1);
} }
$iconSrc = PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/'; $iconSrc = \PHPWORD_BASE_DIR . '_staticDocParts/';
if (!file_exists($iconSrc . '_' . $ext . '.png')) { if (!file_exists($iconSrc . '_' . $ext . '.png')) {
$iconSrc = $iconSrc . '_default.png'; $iconSrc = $iconSrc . '_default.png';
} else { } else {
$iconSrc .= '_' . $ext . '.png'; $iconSrc .= '_' . $ext . '.png';
} }
$rIDimg = PHPWord_Media::addSectionMediaElement($iconSrc, 'image'); $rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
$data = PHPWord_Media::addSectionMediaElement($src, 'oleObject'); $data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0]; $rID = $data[0];
$objectId = $data[1]; $objectId = $data[1];
@ -281,15 +289,15 @@ class PHPWord_Section_Table_Cell
* @param string $text * @param string $text
* @param mixed $styleFont * @param mixed $styleFont
* @param mixed $styleParagraph * @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText * @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/ */
public function addPreserveText($text, $styleFont = null, $styleParagraph = null) public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{ {
if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') { if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext; $this->_elementCollection[] = $ptext;
return $ptext; return $ptext;
} else { } else {
@ -300,12 +308,11 @@ class PHPWord_Section_Table_Cell
/** /**
* Create a new TextRun * Create a new TextRun
* *
* @param mixed $styleParagraph * @return \PhpOffice\PhpWord\Section\TextRun
* @return PHPWord_Section_TextRun
*/ */
public function createTextRun($styleParagraph = null) public function createTextRun($styleParagraph = null)
{ {
$textRun = new PHPWord_Section_TextRun($styleParagraph); $textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun; $this->_elementCollection[] = $textRun;
return $textRun; return $textRun;
} }
@ -323,7 +330,7 @@ class PHPWord_Section_Table_Cell
/** /**
* Get Cell Style * Get Cell Style
* *
* @return PHPWord_Style_Cell * @return \PhpOffice\PhpWord\Style\Cell
*/ */
public function getStyle() public function getStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,15 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2013 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2013 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section\Table;
* PHPWord_Section_Table_Row
*/
class PHPWord_Section_Table_Row
{
class Row
{
/** /**
* Row height * Row height
* *
@ -41,7 +37,7 @@ class PHPWord_Section_Table_Row
/** /**
* Row style * Row style
* *
* @var PHPWord_Style_Row * @var \PhpOffice\PhpWord\Style\Row
*/ */
private $_style; private $_style;
@ -80,7 +76,7 @@ class PHPWord_Section_Table_Row
$this->_insideOf = $insideOf; $this->_insideOf = $insideOf;
$this->_pCount = $pCount; $this->_pCount = $pCount;
$this->_height = $height; $this->_height = $height;
$this->_style = new PHPWord_Style_Row(); $this->_style = new \PhpOffice\PhpWord\Style\Row();
if (!is_null($style)) { if (!is_null($style)) {
if (is_array($style)) { if (is_array($style)) {
@ -100,11 +96,11 @@ class PHPWord_Section_Table_Row
* *
* @param int $width * @param int $width
* @param mixed $style * @param mixed $style
* @return PHPWord_Section_Table_Cell * @return \PhpOffice\PhpWord\Section\Table\Cell
*/ */
public function addCell($width = null, $style = null) public function addCell($width = null, $style = null)
{ {
$cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style); $cell = new Cell($this->_insideOf, $this->_pCount, $width, $style);
$this->_cells[] = $cell; $this->_cells[] = $cell;
return $cell; return $cell;
} }
@ -122,7 +118,7 @@ class PHPWord_Section_Table_Row
/** /**
* Get row style * Get row style
* *
* @return PHPWord_Style_Row * @return \PhpOffice\PhpWord\Style\Row
*/ */
public function getStyle() public function getStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,17 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_Text
*/ use PhpOffice\PhpWord\Style\Font;
class PHPWord_Section_Text use PhpOffice\PhpWord\Style\Paragraph;
class Text
{ {
/** /**
* Text content * Text content
@ -40,14 +40,14 @@ class PHPWord_Section_Text
/** /**
* Text style * Text style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Font
*/ */
private $fontStyle; private $fontStyle;
/** /**
* Paragraph style * Paragraph style
* *
* @var PHPWord_Style_Paragraph * @var \PhpOffice\PhpWord\Style\Paragraph
*/ */
private $paragraphStyle; private $paragraphStyle;
@ -55,8 +55,8 @@ class PHPWord_Section_Text
* Create a new Text Element * Create a new Text Element
* *
* @param string $text * @param string $text
* @param null|array|\PHPWord_Style_Font $fontStyle * @param null|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle * @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/ */
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{ {
@ -68,20 +68,20 @@ class PHPWord_Section_Text
/** /**
* Set Text style * Set Text style
* *
* @param null|array|\PHPWord_Style_Font $style * @param null|array|\PhpOffice\PhpWord\Style\Font $style
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle * @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return PHPWord_Style_Font * @return \PhpOffice\PhpWord\Style\Font
*/ */
public function setFontStyle($style = null, $paragraphStyle = null) public function setFontStyle($style = null, $paragraphStyle = null)
{ {
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof Font) {
$this->fontStyle = $style; $this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle); $this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) { } elseif (is_array($style)) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle); $this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setArrayStyle($style); $this->fontStyle->setArrayStyle($style);
} elseif (null === $style) { } elseif (null === $style) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle); $this->fontStyle = new Font('text', $paragraphStyle);
} else { } else {
$this->fontStyle = $style; $this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle); $this->setParagraphStyle($paragraphStyle);
@ -92,7 +92,7 @@ class PHPWord_Section_Text
/** /**
* Get Text style * Get Text style
* *
* @return PHPWord_Style_Font * @return \PhpOffice\PhpWord\Style\Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -102,18 +102,18 @@ class PHPWord_Section_Text
/** /**
* Set Paragraph style * Set Paragraph style
* *
* @param null|array|\PHPWord_Style_Paragraph $style * @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return null|\PHPWord_Style_Paragraph * @return null|\PhpOffice\PhpWord\Style\Paragraph
*/ */
public function setParagraphStyle($style = null) public function setParagraphStyle($style = null)
{ {
if (is_array($style)) { if (is_array($style)) {
$this->paragraphStyle = new PHPWord_Style_Paragraph; $this->paragraphStyle = new Paragraph;
$this->paragraphStyle->setArrayStyle($style); $this->paragraphStyle->setArrayStyle($style);
} elseif ($style instanceof PHPWord_Style_Paragraph) { } elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style; $this->paragraphStyle = $style;
} elseif (null === $style) { } elseif (null === $style) {
$this->paragraphStyle = new PHPWord_Style_Paragraph; $this->paragraphStyle = new Paragraph;
} else { } else {
$this->paragraphStyle = $style; $this->paragraphStyle = $style;
} }
@ -123,7 +123,7 @@ class PHPWord_Section_Text
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return PHPWord_Style_Paragraph * @return \PhpOffice\PhpWord\Style\Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,37 +18,34 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_TextBreak
*/ use PhpOffice\PhpWord\Style\Font;
class PHPWord_Section_TextBreak use PhpOffice\PhpWord\Style\Paragraph;
class TextBreak
{ {
/** /**
* Paragraph style * Paragraph style
* *
* @var PHPWord_Style_Pagaraph * @var \PhpOffice\PhpWord\Style\Pagaraph
*/ */
private $paragraphStyle = null; private $paragraphStyle = null;
/** /**
* Text style * Text style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Font
*/ */
private $fontStyle = null; private $fontStyle = null;
/** /**
* Create a new TextBreak Element * Create a new TextBreak Element
*
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/ */
public function __construct($fontStyle = null, $paragraphStyle = null) public function __construct($fontStyle = null, $paragraphStyle = null)
{ {
@ -63,17 +60,17 @@ class PHPWord_Section_TextBreak
/** /**
* Set Text style * Set Text style
* *
* @param mixed $style * @param null|array|\PhpOffice\PhpWord\Style\Font $style
* @param mixed $paragraphStyle * @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return PHPWord_Style_Font * @return \PhpOffice\PhpWord\Style\Font
*/ */
public function setFontStyle($style = null, $paragraphStyle = null) public function setFontStyle($style = null, $paragraphStyle = null)
{ {
if ($style instanceof PHPWord_Style_Font) { if ($style instanceof Font) {
$this->fontStyle = $style; $this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle); $this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) { } elseif (is_array($style)) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle); $this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setArrayStyle($style); $this->fontStyle->setArrayStyle($style);
} else { } else {
$this->fontStyle = $style; $this->fontStyle = $style;
@ -85,7 +82,7 @@ class PHPWord_Section_TextBreak
/** /**
* Get Text style * Get Text style
* *
* @return PHPWord_Style_Font * @return \PhpOffice\PhpWord\Style\Font
*/ */
public function getFontStyle() public function getFontStyle()
{ {
@ -95,15 +92,15 @@ class PHPWord_Section_TextBreak
/** /**
* Set Paragraph style * Set Paragraph style
* *
* @param null|array|\PHPWord_Style_Paragraph $style * @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return null|\PHPWord_Style_Paragraph * @return null|\PhpOffice\PhpWord\Style\Paragraph
*/ */
public function setParagraphStyle($style = null) public function setParagraphStyle($style = null)
{ {
if (is_array($style)) { if (is_array($style)) {
$this->paragraphStyle = new PHPWord_Style_Paragraph; $this->paragraphStyle = new Paragraph;
$this->paragraphStyle->setArrayStyle($style); $this->paragraphStyle->setArrayStyle($style);
} elseif ($style instanceof PHPWord_Style_Paragraph) { } elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style; $this->paragraphStyle = $style;
} else { } else {
$this->paragraphStyle = $style; $this->paragraphStyle = $style;
@ -114,7 +111,7 @@ class PHPWord_Section_TextBreak
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return PHPWord_Style_Paragraph * @return \PhpOffice\PhpWord\Style\Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,23 +18,24 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* PHPWord_Section_TextRun
*/
class PHPWord_Section_TextRun
{
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Paragraph;
class TextRun
{
/** /**
* Paragraph style * Paragraph style
* *
* @var PHPWord_Style_Font * @var \PhpOffice\PhpWord\Style\Paragraph
*/ */
private $_styleParagraph; private $_styleParagraph;
@ -48,8 +49,6 @@ class PHPWord_Section_TextRun
/** /**
* Create a new TextRun Element * Create a new TextRun Element
*
* @param mixed $styleParagraph
*/ */
public function __construct($styleParagraph = null) public function __construct($styleParagraph = null)
{ {
@ -57,7 +56,7 @@ class PHPWord_Section_TextRun
// Set paragraph style // Set paragraph style
if (is_array($styleParagraph)) { if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph(); $this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) { foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') { if (substr($key, 0, 1) != '_') {
@ -74,16 +73,16 @@ class PHPWord_Section_TextRun
/** /**
* Add a Text Element * Add a Text Element
* *
* @param string $text * @var string $text
* @param mixed $styleFont * @var mixed $styleFont
* @return PHPWord_Section_Text * @return \PhpOffice\PhpWord\Section\Text
*/ */
public function addText($text = null, $styleFont = null) public function addText($text = null, $styleFont = null)
{ {
if (!PHPWord_Shared_String::IsUTF8($text)) { if (!String::isUTF8($text)) {
$text = utf8_encode($text); $text = utf8_encode($text);
} }
$text = new PHPWord_Section_Text($text, $styleFont); $text = new Text($text, $styleFont);
$this->_elementCollection[] = $text; $this->_elementCollection[] = $text;
return $text; return $text;
} }
@ -94,7 +93,7 @@ class PHPWord_Section_TextRun
* @param string $linkSrc * @param string $linkSrc
* @param string $linkName * @param string $linkName
* @param mixed $styleFont * @param mixed $styleFont
* @return PHPWord_Section_Link * @return \PhpOffice\PhpWord\Section\Link
*/ */
public function addLink($linkSrc, $linkName = null, $styleFont = null) public function addLink($linkSrc, $linkName = null, $styleFont = null)
{ {
@ -103,8 +102,8 @@ class PHPWord_Section_TextRun
$linkName = utf8_encode($linkName); $linkName = utf8_encode($linkName);
} }
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont); $link = new Link($linkSrc, $linkName, $styleFont);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc); $rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID); $link->setRelationId($rID);
$this->_elementCollection[] = $link; $this->_elementCollection[] = $link;
@ -115,15 +114,15 @@ class PHPWord_Section_TextRun
* Add a Image Element * Add a Image Element
* *
* @param string $imageSrc * @param string $imageSrc
* @param mixed $style * @param mixed $styleFont
* @return PHPWord_Section_Image * @return \PhpOffice\PhpWord\Section\Image
*/ */
public function addImage($imageSrc, $style = null) public function addImage($imageSrc, $style = null)
{ {
$image = new PHPWord_Section_Image($imageSrc, $style); $image = new Image($imageSrc, $style);
if (!is_null($image->getSource())) { if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addSectionMediaElement($imageSrc, 'image'); $rID = Media::addSectionMediaElement($imageSrc, 'image');
$image->setRelationId($rID); $image->setRelationId($rID);
$this->_elementCollection[] = $image; $this->_elementCollection[] = $image;
@ -137,26 +136,26 @@ class PHPWord_Section_TextRun
* Add TextBreak * Add TextBreak
* *
* @param int $count * @param int $count
* @param mixed $fontStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param mixed $paragraphStyle * @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/ */
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{ {
for ($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle); $this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
} }
} }
/** /**
* Create a new Footnote Element * Create a new Footnote Element
* *
* @param mixed $styleParagraph * @param string $text
* @return PHPWord_Section_Footnote * @return \PhpOffice\PhpWord\Section\Footnote
*/ */
public function createFootnote($styleParagraph = null) public function createFootnote($styleParagraph = null)
{ {
$footnote = new PHPWord_Section_Footnote($styleParagraph); $footnote = new \PhpOffice\PhpWord\Section\Footnote($styleParagraph);
$refID = PHPWord_Footnote::addFootnoteElement($footnote); $refID = \PhpOffice\PhpWord\Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID); $footnote->setReferenceId($refID);
$this->_elementCollection[] = $footnote; $this->_elementCollection[] = $footnote;
return $footnote; return $footnote;
@ -175,7 +174,7 @@ class PHPWord_Section_TextRun
/** /**
* Get Paragraph style * Get Paragraph style
* *
* @return PHPWord_Style_Paragraph * @return \PhpOffice\PhpWord\Style\Paragraph
*/ */
public function getParagraphStyle() public function getParagraphStyle()
{ {

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,19 +18,15 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Section;
* Class PHPWord_Section_Title
*/
class PHPWord_Section_Title
{
class Title
{
/** /**
* Title Text content * Title Text content
* *

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,14 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord;
* PHPWord_Settings
*/ class Settings
class PHPWord_Settings
{ {
/** /**
* Compatibility option for XMLWriter * Compatibility option for XMLWriter
@ -61,4 +58,4 @@ class PHPWord_Settings
{ {
return self::$_xmlWriterCompatibility; return self::$_xmlWriterCompatibility;
} }
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,14 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Shared;
* Class PHPWord_Shared_Drawing
*/ class Drawing
class PHPWord_Shared_Drawing
{ {
/** /**
* Convert pixels to EMU * Convert pixels to EMU

74
src/PhpWord/Shared/File.php Executable file
View File

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

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,14 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Shared;
* Class PHPWord_Shared_Font
*/ class 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

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,17 +18,14 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
/** namespace PhpOffice\PhpWord\Shared;
* Class PHPWord_Shared_String
*/ class String
class PHPWord_Shared_String
{ {
/** /**
* Control characters array * Control characters array
@ -65,7 +62,7 @@ class PHPWord_Shared_String
* @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)) { if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters(); self::_buildControlCharacters();
@ -88,7 +85,7 @@ class PHPWord_Shared_String
* @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)) { if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters(); self::_buildControlCharacters();
@ -103,7 +100,7 @@ class PHPWord_Shared_String
* @param string $value * @param string $value
* @return boolean * @return boolean
*/ */
public static function IsUTF8($value = '') public static function isUTF8($value = '')
{ {
return $value === '' || preg_match('/^./su', $value) === 1; return $value === '' || preg_match('/^./su', $value) === 1;
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,25 +18,25 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Settings;
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
*
* @method bool startElement(string $name) * @method bool startElement(string $name)
* @method bool writeAttribute(string $name, string $value) * @method bool writeAttribute(string $name, string $value)
* @method bool endElement() * @method bool endElement()
*/ */
class PHPWord_Shared_XMLWriter class XMLWriter
{ {
/** Temporary storage method */ /** Temporary storage method */
const STORAGE_MEMORY = 1; const STORAGE_MEMORY = 1;
@ -45,7 +45,7 @@ class PHPWord_Shared_XMLWriter
/** /**
* Internal XMLWriter * Internal XMLWriter
* *
* @var XMLWriter * @var \XMLWriter
*/ */
private $_xmlWriter; private $_xmlWriter;
@ -57,15 +57,13 @@ class PHPWord_Shared_XMLWriter
private $_tempFileName = ''; private $_tempFileName = '';
/** /**
* Create a new PHPWord_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 // Create internal XMLWriter
$this->_xmlWriter = new XMLWriter(); $this->_xmlWriter = new \XMLWriter();
// Open temporary storage // Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) { if ($pTemporaryStorage == self::STORAGE_MEMORY) {
@ -82,7 +80,7 @@ class PHPWord_Shared_XMLWriter
} }
// Set xml Compatibility // Set xml Compatibility
$compatibility = PHPWord_Settings::getCompatibility(); $compatibility = Settings::getCompatibility();
if ($compatibility) { if ($compatibility) {
$this->_xmlWriter->setIndent(false); $this->_xmlWriter->setIndent(false);
$this->_xmlWriter->setIndentString(''); $this->_xmlWriter->setIndentString('');
@ -131,7 +129,7 @@ class PHPWord_Shared_XMLWriter
{ {
try { try {
@call_user_func_array(array($this->_xmlWriter, $function), $args); @call_user_func_array(array($this->_xmlWriter, $function), $args);
} catch (Exception $ex) { } catch (\Exception $ex) {
// Do nothing! // Do nothing!
} }
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPWord * PhpWord
* *
* Copyright (c) 2014 PHPWord * Copyright (c) 2014 PhpWord
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,24 +18,24 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPWord * @copyright Copyright (c) 2014 PhpWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0 * @version 0.8.0
*/ */
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Exceptions\Exception;
/** /**
* Class PHPWord_Shared_ZipStreamWrapper
*
* @codeCoverageIgnore Legacy from PHPExcel * @codeCoverageIgnore Legacy from PHPExcel
*/ */
class PHPWord_Shared_ZipStreamWrapper class ZipStreamWrapper
{ {
/** /**
* Internal ZipAcrhive * Internal ZipAcrhive
* *
* @var ZipAcrhive * @var \ZipAcrhive
*/ */
private $_archive; private $_archive;
@ -104,7 +104,7 @@ class PHPWord_Shared_ZipStreamWrapper
} }
// 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'];
@ -159,7 +159,7 @@ class PHPWord_Shared_ZipStreamWrapper
public function stream_seek($offset, $whence) public function stream_seek($offset, $whence)
{ {
switch ($whence) { switch ($whence) {
case SEEK_SET: case \SEEK_SET:
if ($offset < strlen($this->_data) && $offset >= 0) { if ($offset < strlen($this->_data) && $offset >= 0) {
$this->_position = $offset; $this->_position = $offset;
return true; return true;
@ -168,7 +168,7 @@ class PHPWord_Shared_ZipStreamWrapper
} }
break; break;
case SEEK_CUR: case \SEEK_CUR:
if ($offset >= 0) { if ($offset >= 0) {
$this->_position += $offset; $this->_position += $offset;
return true; return true;
@ -177,7 +177,7 @@ class PHPWord_Shared_ZipStreamWrapper
} }
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;

Some files were not shown because too many files have changed in this diff Show More