#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
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
@ -16,9 +17,10 @@ before_script:
## Composer
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --prefer-source
- composer selfupdate --quiet
## PHP_CodeSniffer
#- pyrus install pear/PHP_CodeSniffer
#- phpenv rehash
- pyrus install pear/PHP_CodeSniffer
- phpenv rehash
## PHP Copy/Paste Detector
#- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
## PHP Mess Detector
@ -33,13 +35,13 @@ before_script:
script:
## PHP_CodeSniffer
## - phpcs --standard=PSR1 Classes/
## - phpcs --standard=PSR2 Classes/
- phpcs --standard=PSR1 -n src/
- phpcs --standard=PSR2 -n src/
## PHP Copy/Paste Detector
#- php phpcpd.phar --verbose Classes/
#- php phpcpd.phar --verbose src/
## PHP Mess Detector
#- phpmd Classes/ text unusedcode,naming,design
#- phpmd src/ text unusedcode,naming,design
## PHPLOC
#- php phploc.phar Classes/
#- php phploc.phar src/
## PHPUnit
- phpunit -c ./ --coverage-text

View File

@ -1,6 +1,6 @@
# 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

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",
"description": "PHPWord - Read, Create and Write Word documents in PHP",
"keywords": ["PHP", "Word", "Writer", "docx", "doc", "rtf"],
"description": "PhpWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP",
"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",
"type": "library",
"license": "LGPL",
@ -17,10 +21,14 @@
{
"name": "Franck Lefevre",
"homepage": "http://blog.rootslabs.net"
},
{
"name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org"
}
],
"require": {
"php": ">=5.3.0",
"php": ">=5.3.3",
"ext-xml": "*",
"ext-zip": "*"
},
@ -35,8 +43,8 @@
"ext-xsl": "*"
},
"autoload": {
"psr-0": {
"PHPWord": "Classes/"
"psr-4": {
"PhpOffice\\PhpWord\\": "src/"
}
}
}

View File

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

View File

@ -1,6 +1,6 @@
# -*- 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.
#
# This file is execfile()d with the current directory set to its containing dir.
@ -40,7 +40,7 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'PHPWord'
project = u'PhpWord'
copyright = u'2014, Progi1984'
# 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
# Output file base name for HTML help builder.
htmlhelp_basename = 'PHPWorddoc'
htmlhelp_basename = 'PhpWorddoc'
# -- Options for LaTeX output --------------------------------------------------
@ -183,8 +183,8 @@ latex_elements = {
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'PHPWord.tex', u'PHPWord Documentation',
u'The PHPWord Team', 'manual'),
('index', 'PhpWord.tex', u'PhpWord Documentation',
u'The PhpWord Team', 'manual'),
]
# 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
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'phpword', u'PHPWord Documentation',
[u'The PHPWord Team'], 1)
('index', 'PhpWord', u'PhpWord Documentation',
[u'The PhpWord Team'], 1)
]
# If true, show URL addresses after external links.
@ -227,8 +227,8 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'PHPWord', u'PHPWord Documentation',
u'The PHPWord Team', 'PHPWord', 'One line description of project.',
('index', 'PhpWord', u'PhpWord Documentation',
u'The PhpWord Team', 'PhpWord', 'One line description of project.',
'Miscellaneous'),
]
@ -244,9 +244,9 @@ texinfo_documents = [
# -- Options for Epub output ---------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = u'PHPWord'
epub_author = u'The PHPWord Team'
epub_publisher = u'The PHPWord Team'
epub_title = u'PhpWord'
epub_author = u'The PhpWord Team'
epub_publisher = u'The PhpWord Team'
epub_copyright = copyright
# The language of the text. It defaults to the language option

View File

@ -44,11 +44,11 @@ Defined style examples:
.. code-block:: php
$fontStyle = array('color' => '006699', 'size' => 18, 'bold' => true);
$PHPWord->addFontStyle('fStyle', $fontStyle);
$phpWord->addFontStyle('fStyle', $fontStyle);
$text = $section->addText('Hello world!', 'fStyle');
$paragraphStyle = array('align' => 'center');
$PHPWord->addParagraphStyle('pStyle', $paragraphStyle);
$phpWord->addParagraphStyle('pStyle', $paragraphStyle);
$text = $section->addText('Hello world!', 'pStyle');
Font style
@ -97,7 +97,7 @@ need titles or headings. To add a title to the document, use the
.. code-block:: php
$PHPWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]);
$phpWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]);
$section->addTitle($text, [$depth]);
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
);
$firstRowStyle = array('bgColor' => '66BBFF');
$PHPWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
$phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
$table = $section->addTable('myTable');
Table, row, and cell styles
@ -292,7 +292,7 @@ header reference. After creating a header, you can use the
.. code-block:: php
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$header = $section->createHeader();
$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
$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.
// To create a basic section:
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// After creating a section, you can append elements:
$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
// 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'));
$section->addText('Hello world! I am formatted by a user defined style',
'myOwnStyle');
@ -40,7 +42,7 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
$myTextElement->setFontStyle($fontStyle);
// Finally, write the document:
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter = PHPWord_IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
Default font
@ -62,7 +64,7 @@ name. Use the following functions:
.. code-block:: php
$properties = $PHPWord->getProperties();
$properties = $phpWord->getProperties();
$properties->setCreator('My name');
$properties->setCompany('My factory');
$properties->setTitle('My title');

View File

@ -47,11 +47,11 @@ Manual install
To install manually, `download PHPWord package from
github <https://github.com/PHPOffice/PHPWord/archive/master.zip>`__.
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
require_once '/path/to/PHPWord/Classes/PHPWord.php';
require_once '/path/to/src/PhpWord/PhpWord.php';
Using samples
-------------
@ -59,4 +59,4 @@ Using samples
After installation, you can browse and use the samples that we've
provided, either by command line or using browser. If you can access
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
$template = $PHPWord->loadTemplate('Template.docx');
$template = $phpWord->loadTemplate('Template.docx');
$template->setValue('Name', 'Somebody someone');
$template->setValue('Street', 'Coming-Undone-Street 32');

View File

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

View File

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

View File

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

View File

@ -2,25 +2,25 @@
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// 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.');
// 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->addPageBreak();
$section->addPageBreak();
// 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.');
// 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->createHeader()->addText('Header');
$section->createFooter()->addText('Footer');
@ -29,9 +29,9 @@ $section->createFooter()->addText('Footer');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}

View File

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

View File

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

View File

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

View File

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

View File

@ -2,16 +2,16 @@
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s') , " Create new PHPWord object" , EOL;
$PHPWord = new PHPWord();
$PHPWord->setDefaultParagraphStyle(array(
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(array(
'align' => 'both',
'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(12),
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(12),
'spacing' => 120,
));
// Sample
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$section->addText('Below are the samples on how to control your paragraph ' .
'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');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,21 +1,18 @@
<?php
/**
* Link sample
*/
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// 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);
$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.yahoo.com', null, 'myOwnLinkStyle');
@ -25,9 +22,9 @@ $section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
error_reporting(E_ALL);
define('CLI', (PHP_SAPI == 'cli') ? true : false);
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
if (CLI) {
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
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,14 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_DocumentProperties
*/
class PHPWord_DocumentProperties
namespace PhpOffice\PhpWord;
class DocumentProperties
{
/** Constants */
const PROPERTY_TYPE_BOOLEAN = 'b';
@ -123,7 +120,7 @@ class PHPWord_DocumentProperties
private $_customProperties = array();
/**
* Create new PHPWord_DocumentProperties
* Create new DocumentProperties
*/
public function __construct()
{
@ -153,8 +150,8 @@ class PHPWord_DocumentProperties
/**
* Set Creator
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCreator($pValue = '')
{
@ -175,8 +172,8 @@ class PHPWord_DocumentProperties
/**
* Set Last Modified By
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setLastModifiedBy($pValue = '')
{
@ -197,8 +194,8 @@ class PHPWord_DocumentProperties
/**
* Set Created
*
* @param datetime $pValue
* @return PHPWord_DocumentProperties
* @param datetime $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCreated($pValue = null)
{
@ -222,8 +219,8 @@ class PHPWord_DocumentProperties
/**
* Set Modified
*
* @param datetime $pValue
* @return PHPWord_DocumentProperties
* @param datetime $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setModified($pValue = null)
{
@ -247,8 +244,8 @@ class PHPWord_DocumentProperties
/**
* Set Title
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setTitle($pValue = '')
{
@ -269,8 +266,8 @@ class PHPWord_DocumentProperties
/**
* Set Description
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setDescription($pValue = '')
{
@ -291,8 +288,8 @@ class PHPWord_DocumentProperties
/**
* Set Subject
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setSubject($pValue = '')
{
@ -314,7 +311,7 @@ class PHPWord_DocumentProperties
* Set Keywords
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setKeywords($pValue = '')
{
@ -336,7 +333,7 @@ class PHPWord_DocumentProperties
* Set Category
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCategory($pValue = '')
{
@ -358,7 +355,7 @@ class PHPWord_DocumentProperties
* Set Company
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCompany($pValue = '')
{
@ -380,7 +377,7 @@ class PHPWord_DocumentProperties
* Set Manager
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setManager($pValue = '')
{
@ -448,7 +445,7 @@ class PHPWord_DocumentProperties
* 's': String
* 'd': Date/Time
* 'b': Boolean
* @return PHPExcel_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
{

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,20 +18,15 @@
* 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
* @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;
/**
* PHPWord_Footnote
*/
class PHPWord_Footnote
class Footnote
{
/**
* Footnote Elements
*
@ -54,7 +49,7 @@ class PHPWord_Footnote
*
* @return mixed
*/
public static function addFootnoteElement(PHPWord_Section_Footnote $footnote)
public static function addFootnoteElement(\PhpOffice\PhpWord\Section\Footnote $footnote)
{
$refID = self::countFootnoteElements() + 2;

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,19 @@
* 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
* @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;
/**
* PHPWord_HashTable
*
* @codeCoverageIgnore Legacy from PHPExcel
* @codeCoverageIgnore Legacy from PHPExcel
*/
class PHPWord_HashTable
class HashTable
{
/**
* HashTable elements
@ -47,15 +47,11 @@ class PHPWord_HashTable
public $_keyMap = array();
/**
* Create a new PHPWord_HashTable
*
* @param PHPWord_IComparable[] $pSource Optional source array to create HashTable from
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable[] $pSource Optional source array to create HashTable from
*/
public function __construct($pSource = null)
{
if (!is_null($pSource)) {
// Create HashTable
$this->addFromSource($pSource);
}
}
@ -63,8 +59,8 @@ class PHPWord_HashTable
/**
* Add HashTable items from source
*
* @param PHPWord_IComparable[] $pSource Source array to create HashTable from
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
public function addFromSource($pSource = null)
{
@ -83,10 +79,9 @@ class PHPWord_HashTable
/**
* Add HashTable item
*
* @param PHPWord_IComparable $pSource Item to add
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable $pSource Item to add
*/
public function add(PHPWord_IComparable $pSource = null)
public function add(IComparable $pSource = null)
{
// Determine hashcode
$hashCode = null;
@ -113,10 +108,9 @@ class PHPWord_HashTable
/**
* Remove HashTable item
*
* @param PHPWord_IComparable $pSource Item to remove
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable $pSource Item to remove
*/
public function remove(PHPWord_IComparable $pSource = null)
public function remove(IComparable $pSource = null)
{
if (isset($this->_items[$pSource->getHashCode()])) {
unset($this->_items[$pSource->getHashCode()]);
@ -146,8 +140,6 @@ class PHPWord_HashTable
}
/**
* Count
*
* @return int
*/
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 = '')
{
@ -167,11 +157,8 @@ class PHPWord_HashTable
}
/**
* Get by index
*
* @param int $pIndex
* @return PHPWord_IComparable
*
* @param int $pIndex
* @return \PhpOffice\PhpWord\IComparable
*/
public function getByIndex($pIndex = 0)
{
@ -183,10 +170,8 @@ class PHPWord_HashTable
}
/**
* Get by hashcode
*
* @param string $pHashCode
* @return PHPWord_IComparable
* @param string $pHashCode
* @return \PhpOffice\PhpWord\IComparable
*
*/
public function getByHashCode($pHashCode = '')
@ -199,9 +184,7 @@ class PHPWord_HashTable
}
/**
* HashTable to array
*
* @return PHPWord_IComparable[]
* @return \PhpOffice\PhpWord\IComparable[]
*/
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
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,16 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Media
*/
class PHPWord_Media
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Section\MemoryImage;
class Media
{
/**
* Section Media Elements
@ -36,9 +35,9 @@ class PHPWord_Media
* @var array
*/
private static $_sectionMedia = array(
'images' => array(),
'images' => array(),
'embeddings' => array(),
'links' => array()
'links' => array()
);
/**
@ -65,12 +64,12 @@ class PHPWord_Media
/**
* Add new Section Media Element
*
* @param string $src
* @param string $type
* @param PHPWord_Section_MemoryImage|null $memoryImage
* @param string $src
* @param string $type
* @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @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);
$key = ($type === 'image') ? 'images' : 'embeddings';
@ -92,15 +91,27 @@ class PHPWord_Media
$isMemImage = true;
}
if (!$isMemImage) {
$isMemImage = (filter_var($src, FILTER_VALIDATE_URL) !== false);
$isMemImage = (filter_var($src, \FILTER_VALIDATE_URL) !== false);
}
$extension = '';
if ($isMemImage) {
$extension = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
} else {
$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';
@ -191,12 +202,12 @@ class PHPWord_Media
/**
* Add new Header Media Element
*
* @param int $headerCount
* @param string $src
* @param PHPWord_Section_MemoryImage|null $memoryImage
* @param int $headerCount
* @param string $src
* @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @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);
$key = 'header' . $headerCount;
@ -263,12 +274,12 @@ class PHPWord_Media
/**
* Add new Footer Media Element
*
* @param int $footerCount
* @param string $src
* @param PHPWord_Section_MemoryImage|null $memoryImage
* @param int $footerCount
* @param string $src
* @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @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);
$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
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,21 +18,19 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\Exceptions\Exception;
/**
* 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?
@ -63,7 +61,7 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
* Set read data only
*
* @param bool $pValue
* @return PHPWord_Reader_IReader
* @return \PhpOffice\PhpWord\Reader\IReader
*/
public function setReadDataOnly($pValue = true)
{
@ -76,7 +74,7 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
*
* @param string $pFilename
* @return resource
* @throws Exception
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
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
* @return bool

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,30 +18,27 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* PHPWord_Reader_IReader
*/
interface PHPWord_Reader_IReader
namespace PhpOffice\PhpWord\Reader;
interface IReader
{
/**
* Can the current PHPWord_Reader_IReader read the file?
* Can the current IReader read the file?
*
* @param string $pFilename
* @return boolean
* @param string $pFilename
* @return boolean
*/
public function canRead($pFilename);
/**
* Loads PHPWord from file
* Loads PhpWord from file
*
* @param string $pFilename
* @param string $pFilename
*/
public function load($pFilename);
}

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,32 +18,31 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/** PHPWord root directory */
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/../../');
require(PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php');
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
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;
/**
* PHPWord_Reader_Word2007
*/
class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
class Word2007 extends AbstractReader implements IReader
{
/**
* Can the current PHPWord_Reader_IReader read the file?
* Can the current IReader read the file?
*
* @param string $pFilename
* @return bool
* @throws Exception
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
public function canRead($pFilename)
{
@ -54,7 +53,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
$return = false;
// Load file
$zip = new ZipArchive;
$zip = new \ZipArchive();
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$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 bool $removeNamespace
* @return mixed
@ -90,7 +87,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
if (strpos($fileName, '//') !== false) {
$fileName = substr($fileName, strpos($fileName, '//') + 1);
}
$fileName = PHPWord_Shared_File::realpath($fileName);
$fileName = File::realpath($fileName);
// Apache POI fixes
$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
* @return PHPWord|null
* @return \PhpOffice\PhpWord\PhpWord|null
*/
public function load($pFilename)
{
@ -120,8 +117,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
}
// Initialisations
$word = new PHPWord;
$zip = new ZipArchive;
$word = new PhpWord();
$zip = new \ZipArchive();
$zip->open($pFilename);
// 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("dcterms", "http://purl.org/dc/terms/");
$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->setLastModifiedBy((string)self::arrayItem($xmlCore->xpath("cp:lastModifiedBy")));
$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":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$docProps = $word->getProperties();
$docProps = $word->getDocumentProperties();
if (isset($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":
$xmlCore = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$docProps = $word->getProperties();
$docProps = $word->getDocumentProperties();
foreach ($xmlCore as $xmlProperty) {
$cellDataOfficeAttributes = $xmlProperty->attributes();
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");
$attributeType = $cellDataOfficeChildren->getName();
$attributeValue = (string)$cellDataOfficeChildren->{$attributeType};
$attributeValue = PHPWord_DocumentProperties::convertProperty($attributeValue, $attributeType);
$attributeType = PHPWord_DocumentProperties::convertPropertyType($attributeType);
$attributeValue = DocumentProperties::convertProperty($attributeValue, $attributeType);
$attributeType = DocumentProperties::convertPropertyType($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
*
* @param SimpleXMLElement $elm
* @param \SimpleXMLElement $elm
* @return array|string|null
*
* @todo Implement gutter
* @todo Implement gutter
*/
private function loadSectionSettings($elm)
{
@ -334,7 +331,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
/**
* Load paragraph style from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @param \SimpleXMLElement $elm
* @return array|string|null
*/
private function loadParagraphStyle($elm)
@ -395,7 +392,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord
/**
* Load font style from SimpleXMLElement
*
* @param SimpleXMLElement $elm
* @param \SimpleXMLElement $elm
* @return array|string|null
*/
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 mixed $key
* @return mixed|null

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

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

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,20 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* PHPWord_Section_Footer
*/
class PHPWord_Section_Footer
{
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
class Footer
{
/**
* Footer Count
*
@ -54,8 +55,6 @@ class PHPWord_Section_Footer
/**
* Create a new Footer
*
* @param int $sectionCount
*/
public function __construct($sectionCount)
{
@ -68,14 +67,14 @@ class PHPWord_Section_Footer
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PHPWord_Section_Text
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!PHPWord_Shared_String::IsUTF8($text)) {
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
@ -83,26 +82,25 @@ class PHPWord_Section_Footer
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|PHPWord_Style_Font $fontStyle
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new TextRun
*
* @param null|string|array|PHPWord_Style_Paragraph $styleParagraph
* @return PHPWord_Section_TextRun
* @return \PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new PHPWord_Section_TextRun($styleParagraph);
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
@ -111,11 +109,11 @@ class PHPWord_Section_Footer
* Add a Table Element
*
* @param mixed $style
* @return PHPWord_Section_Table
* @return \PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new PHPWord_Section_Table('footer', $this->_footerCount, $style);
$table = new Table('footer', $this->_footerCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
@ -125,14 +123,14 @@ class PHPWord_Section_Footer
*
* @param string $src
* @param mixed $style
* @return PHPWord_Section_Image
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new PHPWord_Section_Image($src, $style);
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $src);
$rID = Media::addFooterMediaElement($this->_footerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
@ -147,13 +145,13 @@ class PHPWord_Section_Footer
*
* @param string $link
* @param mixed $style
* @return PHPWord_Section_MemoryImage
* @return \PhpOffice\PhpWord\Section\MemoryImage
*/
public function addMemoryImage($link, $style = null)
{
$memoryImage = new PHPWord_Section_MemoryImage($link, $style);
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = PHPWord_Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
$rID = Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
@ -169,14 +167,14 @@ class PHPWord_Section_Footer
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText
* @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if (!PHPWord_Shared_String::IsUTF8($text)) {
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
}

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,18 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_Footer_PreserveText
*/
class PHPWord_Section_Footer_PreserveText
{
namespace PhpOffice\PhpWord\Section\Footer;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class PreserveText
{
/**
* Text content
*
@ -41,14 +40,14 @@ class PHPWord_Section_Footer_PreserveText
/**
* Text style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Font
*/
private $_styleFont;
/**
* Paragraph style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
@ -65,7 +64,7 @@ class PHPWord_Section_Footer_PreserveText
{
// Set font style
if (is_array($styleFont)) {
$this->_styleFont = new PHPWord_Style_Font('text');
$this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -79,7 +78,7 @@ class PHPWord_Section_Footer_PreserveText
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph();
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -91,7 +90,7 @@ class PHPWord_Section_Footer_PreserveText
$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])) {
$this->_text = $matches;
}
@ -102,7 +101,7 @@ class PHPWord_Section_Footer_PreserveText
/**
* Get Text style
*
* @return PHPWord_Style_Font
* @return \PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
@ -112,7 +111,7 @@ class PHPWord_Section_Footer_PreserveText
/**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,23 +18,21 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* PHPWord_Section_Footnote
*/
class PHPWord_Section_Footnote
{
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Paragraph;
class Footnote
{
/**
* Paragraph style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
@ -54,8 +52,6 @@ class PHPWord_Section_Footnote
/**
* Create a new Footnote Element
*
* @param mixed $styleParagraph
*/
public function __construct($styleParagraph = null)
{
@ -63,7 +59,7 @@ class PHPWord_Section_Footnote
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph();
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -80,14 +76,14 @@ class PHPWord_Section_Footnote
/**
* Add a Text Element
*
* @param null|string $text
* @param mixed $styleFont
* @return PHPWord_Section_Text
* @var string $text
* @var mixed $styleFont
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text = null, $styleFont = null)
{
$givenText = $text;
$text = new PHPWord_Section_Text($givenText, $styleFont);
$text = new Text($givenText, $styleFont);
$this->_elementCollection[] = $text;
return $text;
}
@ -98,13 +94,13 @@ class PHPWord_Section_Footnote
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @return PHPWord_Section_Link
* @return \PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont);
$rID = PHPWord_Footnote::addFootnoteLinkElement($linkSrc);
$link = new Link($linkSrc, $linkName, $styleFont);
$rID = \PhpOffice\PhpWord\Footnote::addFootnoteLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
@ -122,9 +118,7 @@ class PHPWord_Section_Footnote
}
/**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,20 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* PHPWord_Section_Header
*/
class PHPWord_Section_Header
{
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
class Header
{
/**
* Header Count
*
@ -51,7 +52,7 @@ class PHPWord_Section_Header
* @var string
* @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
@ -83,8 +84,6 @@ class PHPWord_Section_Header
/**
* Create a new Header
*
* @param int $sectionCount
*/
public function __construct($sectionCount)
{
@ -97,14 +96,14 @@ class PHPWord_Section_Header
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PHPWord_Section_Text
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!PHPWord_Shared_String::IsUTF8($text)) {
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
@ -112,26 +111,25 @@ class PHPWord_Section_Header
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|PHPWord_Style_Font $fontStyle
* @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new TextRun
*
* @param mixed $styleParagraph
* @return PHPWord_Section_TextRun
* @return \PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new PHPWord_Section_TextRun($styleParagraph);
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
@ -140,11 +138,11 @@ class PHPWord_Section_Header
* Add a Table Element
*
* @param mixed $style
* @return PHPWord_Section_Table
* @return \PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new PHPWord_Section_Table('header', $this->_headerCount, $style);
$table = new Table('header', $this->_headerCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
@ -154,14 +152,14 @@ class PHPWord_Section_Header
*
* @param string $src
* @param mixed $style
* @return PHPWord_Section_Image
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new PHPWord_Section_Image($src, $style);
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
@ -176,13 +174,13 @@ class PHPWord_Section_Header
*
* @param string $link
* @param mixed $style
* @return PHPWord_Section_MemoryImage
* @return \PhpOffice\PhpWord\Section\MemoryImage
*/
public function addMemoryImage($link, $style = null)
{
$memoryImage = new PHPWord_Section_MemoryImage($link, $style);
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
$rID = Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
@ -198,14 +196,14 @@ class PHPWord_Section_Header
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return PHPWord_Section_Footer_PreserveText
* @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if (!PHPWord_Shared_String::IsUTF8($text)) {
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph);
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
}
@ -215,14 +213,14 @@ class PHPWord_Section_Header
*
* @param string $src
* @param mixed $style
* @return PHPWord_Section_Image
* @return \PhpOffice\PhpWord\Section\Image
*/
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())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
@ -279,7 +277,7 @@ class PHPWord_Section_Header
*/
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()
{
return $this->_type = PHPWord_Section_Header::FIRST;
return $this->_type = self::FIRST;
}
/**
@ -295,6 +293,6 @@ class PHPWord_Section_Header
*/
public function evenPage()
{
return $this->_type = PHPWord_Section_Header::EVEN;
return $this->_type = self::EVEN;
}
}

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,20 +18,17 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
/**
* Class PHPWord_Section_Image
*/
class PHPWord_Section_Image
class Image
{
/**
* Image Src
@ -43,7 +40,7 @@ class PHPWord_Section_Image
/**
* Image Style
*
* @var PHPWord_Style_Image
* @var \PhpOffice\PhpWord\Style\Image
*/
private $_style;
@ -61,27 +58,31 @@ class PHPWord_Section_Image
*/
private $_isWatermark;
/**
* Create a new Image
*
* @param string $src
* @param mixed $style
* @param bool $isWatermark
* @throws InvalidImageException|UnsupportedImageTypeException
* @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
* @throws \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
*/
public function __construct($src, $style = null, $isWatermark = false)
{
$supportedImageTypes = array(\IMAGETYPE_JPEG, \IMAGETYPE_GIF, \IMAGETYPE_PNG, \IMAGETYPE_BMP, \IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM);
if (!file_exists($src)) {
throw new InvalidImageException;
}
if (!PHPWord_Shared_File::imagetype($src)) {
if (!in_array(exif_imagetype($src), $supportedImageTypes)) {
throw new UnsupportedImageTypeException;
}
$this->_src = $src;
$this->_isWatermark = $isWatermark;
$this->_style = new PHPWord_Style_Image();
$this->_style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
@ -106,7 +107,7 @@ class PHPWord_Section_Image
/**
* Get Image style
*
* @return PHPWord_Style_Image
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,18 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_Link
*/
class PHPWord_Section_Link
{
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class Link
{
/**
* Link source
*
@ -55,14 +54,14 @@ class PHPWord_Section_Link
/**
* Link style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Font
*/
private $_styleFont;
/**
* Paragraph style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
@ -82,7 +81,7 @@ class PHPWord_Section_Link
// Set font style
if (is_array($styleFont)) {
$this->_styleFont = new PHPWord_Style_Font('text');
$this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -96,7 +95,7 @@ class PHPWord_Section_Link
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph();
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -154,7 +153,7 @@ class PHPWord_Section_Link
/**
* Get Text style
*
* @return PHPWord_Style_Font
* @return \PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
@ -164,7 +163,7 @@ class PHPWord_Section_Link
/**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,30 +18,26 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_ListItem
*/
class PHPWord_Section_ListItem
{
namespace PhpOffice\PhpWord\Section;
class ListItem
{
/**
* ListItem Style
*
* @var PHPWord_Style_ListItem
* @var \PhpOffice\PhpWord\Style\ListItem
*/
private $_style;
/**
* Textrun
*
* @var PHPWord_Section_Text
* @var \PhpOffice\PhpWord\Section\Text
*/
private $_textObject;
@ -64,8 +60,8 @@ class PHPWord_Section_ListItem
*/
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
{
$this->_style = new PHPWord_Style_ListItem();
$this->_textObject = new PHPWord_Section_Text($text, $styleFont, $styleParagraph);
$this->_style = new \PhpOffice\PhpWord\Style\ListItem();
$this->_textObject = new Text($text, $styleFont, $styleParagraph);
$this->_depth = $depth;
if (!is_null($styleList) && is_array($styleList)) {

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,14 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_MemoryImage
*/
class PHPWord_Section_MemoryImage
namespace PhpOffice\PhpWord\Section;
class MemoryImage
{
/**
* Image Src
@ -40,7 +37,7 @@ class PHPWord_Section_MemoryImage
/**
* Image Style
*
* @var PHPWord_Style_Image
* @var \PhpOffice\PhpWord\Style\Image
*/
private $_style;
@ -95,7 +92,7 @@ class PHPWord_Section_MemoryImage
if (in_array($this->_imageType, $_supportedImageTypes)) {
$this->_src = $src;
$this->_style = new PHPWord_Style_Image();
$this->_style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
@ -143,7 +140,7 @@ class PHPWord_Section_MemoryImage
/**
* Get Image style
*
* @return PHPWord_Style_Image
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,15 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_Object
*/
class PHPWord_Section_Object
{
namespace PhpOffice\PhpWord\Section;
class Object
{
/**
* Ole-Object Src
*
@ -41,7 +37,7 @@ class PHPWord_Section_Object
/**
* Image Style
*
* @var PHPWord_Style_Image
* @var \PhpOffice\PhpWord\Style\Image
*/
private $_style;
@ -80,7 +76,7 @@ class PHPWord_Section_Object
if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
$this->_src = $src;
$this->_style = new PHPWord_Style_Image();
$this->_style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
@ -100,7 +96,7 @@ class PHPWord_Section_Object
/**
* Get Image style
*
* @return PHPWord_Style_Image
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,22 +18,15 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_PageBreak
*/
class PHPWord_Section_PageBreak
{
namespace PhpOffice\PhpWord\Section;
/**
* Create a new PageBreak Element
*/
class PageBreak
{
public function __construct()
{
}

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,15 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_Settings
*/
class PHPWord_Section_Settings
{
namespace PhpOffice\PhpWord\Section;
class Settings
{
/**
* Default Page Size Width
*

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,23 +18,21 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_Table
*/
class PHPWord_Section_Table
{
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Section\Table\Row;
class Table
{
/**
* Table style
*
* @var PHPWord_Style_Table
* @var \PhpOffice\PhpWord\Style\Table
*/
private $_style;
@ -81,7 +79,7 @@ class PHPWord_Section_Table
if (!is_null($style)) {
if (is_array($style)) {
$this->_style = new PHPWord_Style_Table();
$this->_style = new \PhpOffice\PhpWord\Style\Table();
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -103,7 +101,7 @@ class PHPWord_Section_Table
*/
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;
return $row;
}
@ -113,7 +111,7 @@ class PHPWord_Section_Table
*
* @param int $width
* @param mixed $style
* @return PHPWord_Section_Table_Cell
* @return \PhpOffice\PhpWord\Section\Table\Cell
*/
public function addCell($width = null, $style = null)
{
@ -135,7 +133,7 @@ class PHPWord_Section_Table
/**
* Get table style
*
* @return PHPWord_Style_Table
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getStyle()
{

View File

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

View File

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

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,17 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_Text
*/
class PHPWord_Section_Text
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class Text
{
/**
* Text content
@ -40,14 +40,14 @@ class PHPWord_Section_Text
/**
* Text style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Font
*/
private $fontStyle;
/**
* Paragraph style
*
* @var PHPWord_Style_Paragraph
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $paragraphStyle;
@ -55,8 +55,8 @@ class PHPWord_Section_Text
* Create a new Text Element
*
* @param string $text
* @param null|array|\PHPWord_Style_Font $fontStyle
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle
* @param null|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
@ -68,20 +68,20 @@ class PHPWord_Section_Text
/**
* Set Text style
*
* @param null|array|\PHPWord_Style_Font $style
* @param null|array|\PHPWord_Style_Paragraph $paragraphStyle
* @return PHPWord_Style_Font
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return \PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
if ($style instanceof PHPWord_Style_Font) {
if ($style instanceof Font) {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
$this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setArrayStyle($style);
} elseif (null === $style) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
$this->fontStyle = new Font('text', $paragraphStyle);
} else {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
@ -92,7 +92,7 @@ class PHPWord_Section_Text
/**
* Get Text style
*
* @return PHPWord_Style_Font
* @return \PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
@ -102,18 +102,18 @@ class PHPWord_Section_Text
/**
* Set Paragraph style
*
* @param null|array|\PHPWord_Style_Paragraph $style
* @return null|\PHPWord_Style_Paragraph
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return null|\PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new PHPWord_Style_Paragraph;
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle->setArrayStyle($style);
} elseif ($style instanceof PHPWord_Style_Paragraph) {
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} elseif (null === $style) {
$this->paragraphStyle = new PHPWord_Style_Paragraph;
$this->paragraphStyle = new Paragraph;
} else {
$this->paragraphStyle = $style;
}
@ -123,7 +123,7 @@ class PHPWord_Section_Text
/**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,37 +18,34 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_TextBreak
*/
class PHPWord_Section_TextBreak
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
class TextBreak
{
/**
* Paragraph style
*
* @var PHPWord_Style_Pagaraph
* @var \PhpOffice\PhpWord\Style\Pagaraph
*/
private $paragraphStyle = null;
/**
* Text style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Font
*/
private $fontStyle = null;
/**
* Create a new TextBreak Element
*
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($fontStyle = null, $paragraphStyle = null)
{
@ -63,17 +60,17 @@ class PHPWord_Section_TextBreak
/**
* Set Text style
*
* @param mixed $style
* @param mixed $paragraphStyle
* @return PHPWord_Style_Font
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
* @return \PhpOffice\PhpWord\Style\Font
*/
public function setFontStyle($style = null, $paragraphStyle = null)
{
if ($style instanceof PHPWord_Style_Font) {
if ($style instanceof Font) {
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
} elseif (is_array($style)) {
$this->fontStyle = new PHPWord_Style_Font('text', $paragraphStyle);
$this->fontStyle = new Font('text', $paragraphStyle);
$this->fontStyle->setArrayStyle($style);
} else {
$this->fontStyle = $style;
@ -85,7 +82,7 @@ class PHPWord_Section_TextBreak
/**
* Get Text style
*
* @return PHPWord_Style_Font
* @return \PhpOffice\PhpWord\Style\Font
*/
public function getFontStyle()
{
@ -95,15 +92,15 @@ class PHPWord_Section_TextBreak
/**
* Set Paragraph style
*
* @param null|array|\PHPWord_Style_Paragraph $style
* @return null|\PHPWord_Style_Paragraph
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return null|\PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new PHPWord_Style_Paragraph;
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle->setArrayStyle($style);
} elseif ($style instanceof PHPWord_Style_Paragraph) {
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} else {
$this->paragraphStyle = $style;
@ -114,7 +111,7 @@ class PHPWord_Section_TextBreak
/**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,23 +18,24 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* PHPWord_Section_TextRun
*/
class PHPWord_Section_TextRun
{
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Paragraph;
class TextRun
{
/**
* Paragraph style
*
* @var PHPWord_Style_Font
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
@ -48,8 +49,6 @@ class PHPWord_Section_TextRun
/**
* Create a new TextRun Element
*
* @param mixed $styleParagraph
*/
public function __construct($styleParagraph = null)
{
@ -57,7 +56,7 @@ class PHPWord_Section_TextRun
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new PHPWord_Style_Paragraph();
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
@ -74,16 +73,16 @@ class PHPWord_Section_TextRun
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @return PHPWord_Section_Text
* @var string $text
* @var mixed $styleFont
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text = null, $styleFont = null)
{
if (!PHPWord_Shared_String::IsUTF8($text)) {
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new PHPWord_Section_Text($text, $styleFont);
$text = new Text($text, $styleFont);
$this->_elementCollection[] = $text;
return $text;
}
@ -94,7 +93,7 @@ class PHPWord_Section_TextRun
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @return PHPWord_Section_Link
* @return \PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
@ -103,8 +102,8 @@ class PHPWord_Section_TextRun
$linkName = utf8_encode($linkName);
}
$link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont);
$rID = PHPWord_Media::addSectionLinkElement($linkSrc);
$link = new Link($linkSrc, $linkName, $styleFont);
$rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
@ -115,15 +114,15 @@ class PHPWord_Section_TextRun
* Add a Image Element
*
* @param string $imageSrc
* @param mixed $style
* @return PHPWord_Section_Image
* @param mixed $styleFont
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($imageSrc, $style = null)
{
$image = new PHPWord_Section_Image($imageSrc, $style);
$image = new Image($imageSrc, $style);
if (!is_null($image->getSource())) {
$rID = PHPWord_Media::addSectionMediaElement($imageSrc, 'image');
$rID = Media::addSectionMediaElement($imageSrc, 'image');
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
@ -137,26 +136,26 @@ class PHPWord_Section_TextRun
* Add TextBreak
*
* @param int $count
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new PHPWord_Section_TextBreak($fontStyle, $paragraphStyle);
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new Footnote Element
*
* @param mixed $styleParagraph
* @return PHPWord_Section_Footnote
* @param string $text
* @return \PhpOffice\PhpWord\Section\Footnote
*/
public function createFootnote($styleParagraph = null)
{
$footnote = new PHPWord_Section_Footnote($styleParagraph);
$refID = PHPWord_Footnote::addFootnoteElement($footnote);
$footnote = new \PhpOffice\PhpWord\Section\Footnote($styleParagraph);
$refID = \PhpOffice\PhpWord\Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID);
$this->_elementCollection[] = $footnote;
return $footnote;
@ -175,7 +174,7 @@ class PHPWord_Section_TextRun
/**
* Get Paragraph style
*
* @return PHPWord_Style_Paragraph
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,19 +18,15 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_Title
*/
class PHPWord_Section_Title
{
namespace PhpOffice\PhpWord\Section;
class Title
{
/**
* Title Text content
*

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,14 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* PHPWord_Settings
*/
class PHPWord_Settings
namespace PhpOffice\PhpWord;
class Settings
{
/**
* Compatibility option for XMLWriter

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,14 @@
* 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
* @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_Drawing
*/
class PHPWord_Shared_Drawing
namespace PhpOffice\PhpWord\Shared;
class Drawing
{
/**
* 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
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,14 @@
* 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
* @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_Font
*/
class PHPWord_Shared_Font
namespace PhpOffice\PhpWord\Shared;
class Font
{
/**
* Calculate an (approximate) pixel size, based on a font points size

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,17 +18,14 @@
* 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
* @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_String
*/
class PHPWord_Shared_String
namespace PhpOffice\PhpWord\Shared;
class String
{
/**
* Control characters array
@ -65,7 +62,7 @@ class PHPWord_Shared_String
* @param string $value Value to unescape
* @return string
*/
public static function ControlCharacterOOXML2PHP($value = '')
public static function controlCharacterOOXML2PHP($value = '')
{
if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
@ -88,7 +85,7 @@ class PHPWord_Shared_String
* @param string $value Value to escape
* @return string
*/
public static function ControlCharacterPHP2OOXML($value = '')
public static function controlCharacterPHP2OOXML($value = '')
{
if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
@ -103,7 +100,7 @@ class PHPWord_Shared_String
* @param string $value
* @return boolean
*/
public static function IsUTF8($value = '')
public static function isUTF8($value = '')
{
return $value === '' || preg_match('/^./su', $value) === 1;
}

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,25 +18,25 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Settings;
if (!defined('DATE_W3C')) {
define('DATE_W3C', 'Y-m-d\TH:i:sP');
}
/**
* Class PHPWord_Shared_XMLWriter
*
* @method bool startElement(string $name)
* @method bool writeAttribute(string $name, string $value)
* @method bool endElement()
*/
class PHPWord_Shared_XMLWriter
class XMLWriter
{
/** Temporary storage method */
const STORAGE_MEMORY = 1;
@ -45,7 +45,7 @@ class PHPWord_Shared_XMLWriter
/**
* Internal XMLWriter
*
* @var XMLWriter
* @var \XMLWriter
*/
private $_xmlWriter;
@ -57,15 +57,13 @@ class PHPWord_Shared_XMLWriter
private $_tempFileName = '';
/**
* Create a new PHPWord_Shared_XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageFolder Temporary storage folder
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './')
{
// Create internal XMLWriter
$this->_xmlWriter = new XMLWriter();
$this->_xmlWriter = new \XMLWriter();
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
@ -82,7 +80,7 @@ class PHPWord_Shared_XMLWriter
}
// Set xml Compatibility
$compatibility = PHPWord_Settings::getCompatibility();
$compatibility = Settings::getCompatibility();
if ($compatibility) {
$this->_xmlWriter->setIndent(false);
$this->_xmlWriter->setIndentString('');
@ -131,7 +129,7 @@ class PHPWord_Shared_XMLWriter
{
try {
@call_user_func_array(array($this->_xmlWriter, $function), $args);
} catch (Exception $ex) {
} catch (\Exception $ex) {
// Do nothing!
}
}

View File

@ -1,8 +1,8 @@
<?php
/**
* PHPWord
* PhpWord
*
* Copyright (c) 2014 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
@ -18,24 +18,24 @@
* 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
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Exceptions\Exception;
/**
* Class PHPWord_Shared_ZipStreamWrapper
*
* @codeCoverageIgnore Legacy from PHPExcel
*/
class PHPWord_Shared_ZipStreamWrapper
class ZipStreamWrapper
{
/**
* Internal ZipAcrhive
*
* @var ZipAcrhive
* @var \ZipAcrhive
*/
private $_archive;
@ -104,7 +104,7 @@ class PHPWord_Shared_ZipStreamWrapper
}
// Open archive
$this->_archive = new ZipArchive();
$this->_archive = new \ZipArchive();
$this->_archive->open($url['host']);
$this->_fileNameInArchive = $url['fragment'];
@ -159,7 +159,7 @@ class PHPWord_Shared_ZipStreamWrapper
public function stream_seek($offset, $whence)
{
switch ($whence) {
case SEEK_SET:
case \SEEK_SET:
if ($offset < strlen($this->_data) && $offset >= 0) {
$this->_position = $offset;
return true;
@ -168,7 +168,7 @@ class PHPWord_Shared_ZipStreamWrapper
}
break;
case SEEK_CUR:
case \SEEK_CUR:
if ($offset >= 0) {
$this->_position += $offset;
return true;
@ -177,7 +177,7 @@ class PHPWord_Shared_ZipStreamWrapper
}
break;
case SEEK_END:
case \SEEK_END:
if (strlen($this->_data) + $offset >= 0) {
$this->_position = strlen($this->_data) + $offset;
return true;

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