diff --git a/.travis.yml b/.travis.yml index 8b131b1c49..c73dfc7bcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - 5.3.3 - 5.3 - 5.4 - 5.5 @@ -11,14 +12,15 @@ matrix: allow_failures: - php: 5.6 - php: hhvm - + 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index c866707898..845629ea6c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Classes/PHPWord.php b/Classes/PHPWord.php deleted file mode 100755 index e7501d85fa..0000000000 --- a/Classes/PHPWord.php +++ /dev/null @@ -1,279 +0,0 @@ -_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); - } -} diff --git a/Classes/PHPWord/Autoloader.php b/Classes/PHPWord/Autoloader.php deleted file mode 100755 index 6a9155632f..0000000000 --- a/Classes/PHPWord/Autoloader.php +++ /dev/null @@ -1,85 +0,0 @@ - '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); - } -} \ No newline at end of file diff --git a/Classes/PHPWord/Shared/File.php b/Classes/PHPWord/Shared/File.php deleted file mode 100755 index 8a77703d84..0000000000 --- a/Classes/PHPWord/Shared/File.php +++ /dev/null @@ -1,128 +0,0 @@ - 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; - } -} \ No newline at end of file diff --git a/Classes/PHPWord/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php deleted file mode 100755 index 772e5408f3..0000000000 --- a/Classes/PHPWord/Writer/ODText/Content.php +++ /dev/null @@ -1,411 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/ODText/Meta.php b/Classes/PHPWord/Writer/ODText/Meta.php deleted file mode 100755 index 5397861496..0000000000 --- a/Classes/PHPWord/Writer/ODText/Meta.php +++ /dev/null @@ -1,94 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/ODText/Styles.php b/Classes/PHPWord/Writer/ODText/Styles.php deleted file mode 100755 index b5f87332d6..0000000000 --- a/Classes/PHPWord/Writer/ODText/Styles.php +++ /dev/null @@ -1,267 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php deleted file mode 100755 index d829bf9299..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ /dev/null @@ -1,1035 +0,0 @@ -getFontStyle(); - - $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; - - if (!$withoutP) { - $objWriter->startElement('w:p'); - - $styleParagraph = $text->getParagraphStyle(); - $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; - - if ($SpIsObject) { - $this->_writeParagraphStyle($objWriter, $styleParagraph); - } elseif (!$SpIsObject && !is_null($styleParagraph)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:pStyle'); - $objWriter->writeAttribute('w:val', $styleParagraph); - $objWriter->endElement(); - $objWriter->endElement(); - } - } - - $strText = htmlspecialchars($text->getText()); - $strText = PHPWord_Shared_String::ControlCharacterPHP2OOXML($strText); - - $objWriter->startElement('w:r'); - - if ($SfIsObject) { - $this->_writeTextStyle($objWriter, $styleFont); - } elseif (!$SfIsObject && !is_null($styleFont)) { - $objWriter->startElement('w:rPr'); - $objWriter->startElement('w:rStyle'); - $objWriter->writeAttribute('w:val', $styleFont); - $objWriter->endElement(); - $objWriter->endElement(); - } - - $objWriter->startElement('w:t'); - $objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text - $objWriter->writeRaw($strText); - $objWriter->endElement(); - - $objWriter->endElement(); // w:r - - if (!$withoutP) { - $objWriter->endElement(); // w:p - } - } - - /** - * Write text run - */ - protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) - { - $elements = $textrun->getElements(); - $styleParagraph = $textrun->getParagraphStyle(); - - $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; - - $objWriter->startElement('w:p'); - - if ($SpIsObject) { - $this->_writeParagraphStyle($objWriter, $styleParagraph); - } elseif (!$SpIsObject && !is_null($styleParagraph)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:pStyle'); - $objWriter->writeAttribute('w:val', $styleParagraph); - $objWriter->endElement(); - $objWriter->endElement(); - } - - if (count($elements) > 0) { - foreach ($elements as $element) { - if ($element instanceof PHPWord_Section_Text) { - $this->_writeText($objWriter, $element, true); - } elseif ($element instanceof PHPWord_Section_Link) { - $this->_writeLink($objWriter, $element, true); - } elseif ($element instanceof PHPWord_Section_Image) { - $this->_writeImage($objWriter, $element, true); - } elseif ($element instanceof PHPWord_Section_Footnote) { - $this->_writeFootnoteReference($objWriter, $element, true); - } elseif ($element instanceof PHPWord_Section_TextBreak) { - $objWriter->writeElement('w:br'); - } - } - } - - $objWriter->endElement(); - } - - /** - * Write paragraph style - * - * @param PHPWord_Shared_XMLWriter $objWriter - * @param PHPWord_Style_Paragraph $style - * @param bool $withoutPPR - * @return void - */ - protected function _writeParagraphStyle( - PHPWord_Shared_XMLWriter $objWriter = null, - PHPWord_Style_Paragraph $style, - $withoutPPR = false - ) { - - $align = $style->getAlign(); - $spacing = $style->getSpacing(); - $spaceBefore = $style->getSpaceBefore(); - $spaceAfter = $style->getSpaceAfter(); - $indent = $style->getIndent(); - $hanging = $style->getHanging(); - $tabs = $style->getTabs(); - $widowControl = $style->getWidowControl(); - $keepNext = $style->getKeepNext(); - $keepLines = $style->getKeepLines(); - $pageBreakBefore = $style->getPageBreakBefore(); - - if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || - !is_null($spaceAfter) || !is_null($indent) || !is_null($hanging) || - !is_null($tabs) || !is_null($widowControl) || !is_null($keepNext) || - !is_null($keepLines) || !is_null($pageBreakBefore)) { - if (!$withoutPPR) { - $objWriter->startElement('w:pPr'); - } - - // Alignment - if (!is_null($align)) { - $objWriter->startElement('w:jc'); - $objWriter->writeAttribute('w:val', $align); - $objWriter->endElement(); - } - - // Indentation - if (!is_null($indent) || !is_null($hanging)) { - $objWriter->startElement('w:ind'); - $objWriter->writeAttribute('w:firstLine', 0); - if (!is_null($indent)) { - $objWriter->writeAttribute('w:left', $indent); - } - if (!is_null($hanging)) { - $objWriter->writeAttribute('w:hanging', $hanging); - } - $objWriter->endElement(); - } - - // Spacing - if (!is_null($spaceBefore) || !is_null($spaceAfter) || - !is_null($spacing)) { - $objWriter->startElement('w:spacing'); - if (!is_null($spaceBefore)) { - $objWriter->writeAttribute('w:before', $spaceBefore); - } - if (!is_null($spaceAfter)) { - $objWriter->writeAttribute('w:after', $spaceAfter); - } - if (!is_null($spacing)) { - $objWriter->writeAttribute('w:line', $spacing); - $objWriter->writeAttribute('w:lineRule', 'auto'); - } - $objWriter->endElement(); - } - - // Pagination - if (!$widowControl) { - $objWriter->startElement('w:widowControl'); - $objWriter->writeAttribute('w:val', '0'); - $objWriter->endElement(); - } - if ($keepNext) { - $objWriter->startElement('w:keepNext'); - $objWriter->writeAttribute('w:val', '1'); - $objWriter->endElement(); - } - if ($keepLines) { - $objWriter->startElement('w:keepLines'); - $objWriter->writeAttribute('w:val', '1'); - $objWriter->endElement(); - } - if ($pageBreakBefore) { - $objWriter->startElement('w:pageBreakBefore'); - $objWriter->writeAttribute('w:val', '1'); - $objWriter->endElement(); - } - - // Tabs - if (!is_null($tabs)) { - $tabs->toXml($objWriter); - } - - if (!$withoutPPR) { - $objWriter->endElement(); // w:pPr - } - } - } - - /** - * Write link - * - * @param boolean $withoutP - */ - protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) - { - $rID = $link->getRelationId(); - $linkName = $link->getLinkName(); - if (is_null($linkName)) { - $linkName = $link->getLinkSrc(); - } - - $styleFont = $link->getFontStyle(); - $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; - - if (!$withoutP) { - $objWriter->startElement('w:p'); - - $styleParagraph = $link->getParagraphStyle(); - $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; - - if ($SpIsObject) { - $this->_writeParagraphStyle($objWriter, $styleParagraph); - } elseif (!$SpIsObject && !is_null($styleParagraph)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:pStyle'); - $objWriter->writeAttribute('w:val', $styleParagraph); - $objWriter->endElement(); - $objWriter->endElement(); - } - } - - $objWriter->startElement('w:hyperlink'); - $objWriter->writeAttribute('r:id', 'rId' . $rID); - $objWriter->writeAttribute('w:history', '1'); - - $objWriter->startElement('w:r'); - if ($SfIsObject) { - $this->_writeTextStyle($objWriter, $styleFont); - } elseif (!$SfIsObject && !is_null($styleFont)) { - $objWriter->startElement('w:rPr'); - $objWriter->startElement('w:rStyle'); - $objWriter->writeAttribute('w:val', $styleFont); - $objWriter->endElement(); - $objWriter->endElement(); - } - - $objWriter->startElement('w:t'); - $objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text - $objWriter->writeRaw($linkName); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->endElement(); - - if (!$withoutP) { - $objWriter->endElement(); // w:p - } - } - - /** - * Write preserve text - */ - protected function _writePreserveText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footer_PreserveText $textrun) - { - $styleFont = $textrun->getFontStyle(); - $styleParagraph = $textrun->getParagraphStyle(); - - $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; - $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; - - $arrText = $textrun->getText(); - if (!is_array($arrText)) { - $arrText = array($arrText); - } - - $objWriter->startElement('w:p'); - - if ($SpIsObject) { - $this->_writeParagraphStyle($objWriter, $styleParagraph); - } elseif (!$SpIsObject && !is_null($styleParagraph)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:pStyle'); - $objWriter->writeAttribute('w:val', $styleParagraph); - $objWriter->endElement(); - $objWriter->endElement(); - } - - foreach ($arrText as $text) { - - if (substr($text, 0, 1) == '{') { - $text = substr($text, 1, -1); - - $objWriter->startElement('w:r'); - $objWriter->startElement('w:fldChar'); - $objWriter->writeAttribute('w:fldCharType', 'begin'); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('w:r'); - - if ($SfIsObject) { - $this->_writeTextStyle($objWriter, $styleFont); - } elseif (!$SfIsObject && !is_null($styleFont)) { - $objWriter->startElement('w:rPr'); - $objWriter->startElement('w:rStyle'); - $objWriter->writeAttribute('w:val', $styleFont); - $objWriter->endElement(); - $objWriter->endElement(); - } - - $objWriter->startElement('w:instrText'); - $objWriter->writeAttribute('xml:space', 'preserve'); - $objWriter->writeRaw($text); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('w:r'); - $objWriter->startElement('w:fldChar'); - $objWriter->writeAttribute('w:fldCharType', 'separate'); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('w:r'); - $objWriter->startElement('w:fldChar'); - $objWriter->writeAttribute('w:fldCharType', 'end'); - $objWriter->endElement(); - $objWriter->endElement(); - } else { - $text = htmlspecialchars($text); - $text = PHPWord_Shared_String::ControlCharacterPHP2OOXML($text); - - $objWriter->startElement('w:r'); - - if ($SfIsObject) { - $this->_writeTextStyle($objWriter, $styleFont); - } elseif (!$SfIsObject && !is_null($styleFont)) { - $objWriter->startElement('w:rPr'); - $objWriter->startElement('w:rStyle'); - $objWriter->writeAttribute('w:val', $styleFont); - $objWriter->endElement(); - $objWriter->endElement(); - } - - $objWriter->startElement('w:t'); - $objWriter->writeAttribute('xml:space', 'preserve'); - $objWriter->writeRaw($text); - $objWriter->endElement(); - $objWriter->endElement(); - } - } - - $objWriter->endElement(); // p - } - - /** - * Write text style - */ - protected function _writeTextStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Font $style) - { - $font = $style->getName(); - $bold = $style->getBold(); - $italic = $style->getItalic(); - $color = $style->getColor(); - $size = $style->getSize(); - $fgColor = $style->getFgColor(); - $strikethrough = $style->getStrikethrough(); - $underline = $style->getUnderline(); - $superscript = $style->getSuperScript(); - $subscript = $style->getSubScript(); - $hint = $style->getHint(); - - $objWriter->startElement('w:rPr'); - - // Font - if ($font != PHPWord::DEFAULT_FONT_NAME) { - $objWriter->startElement('w:rFonts'); - $objWriter->writeAttribute('w:ascii', $font); - $objWriter->writeAttribute('w:hAnsi', $font); - $objWriter->writeAttribute('w:eastAsia', $font); - $objWriter->writeAttribute('w:cs', $font); - //Font Content Type - if ($hint != PHPWord::DEFAULT_FONT_CONTENT_TYPE) { - $objWriter->writeAttribute('w:hint', $hint); - } - $objWriter->endElement(); - } - - - // Color - if ($color != PHPWord::DEFAULT_FONT_COLOR) { - $objWriter->startElement('w:color'); - $objWriter->writeAttribute('w:val', $color); - $objWriter->endElement(); - } - - // Size - if ($size != PHPWord::DEFAULT_FONT_SIZE) { - $objWriter->startElement('w:sz'); - $objWriter->writeAttribute('w:val', $size * 2); - $objWriter->endElement(); - $objWriter->startElement('w:szCs'); - $objWriter->writeAttribute('w:val', $size * 2); - $objWriter->endElement(); - } - - // Bold - if ($bold) { - $objWriter->writeElement('w:b', null); - } - - // Italic - if ($italic) { - $objWriter->writeElement('w:i', null); - $objWriter->writeElement('w:iCs', null); - } - - // Underline - if (!is_null($underline) && $underline != 'none') { - $objWriter->startElement('w:u'); - $objWriter->writeAttribute('w:val', $underline); - $objWriter->endElement(); - } - - // Strikethrough - if ($strikethrough) { - $objWriter->writeElement('w:strike', null); - } - - // Foreground-Color - if (!is_null($fgColor)) { - $objWriter->startElement('w:highlight'); - $objWriter->writeAttribute('w:val', $fgColor); - $objWriter->endElement(); - } - - // Superscript/subscript - if ($superscript || $subscript) { - $objWriter->startElement('w:vertAlign'); - $objWriter->writeAttribute('w:val', $superscript ? 'superscript' : 'subscript'); - $objWriter->endElement(); - } - - $objWriter->endElement(); - } - - /** - * Write text break - * - * @param PHPWord_Shared_XMLWriter $objWriter - * @param PHPWord_Section_TextBreak $element - */ - protected function _writeTextBreak($objWriter, $element = null) - { - $hasStyle = false; - if (!is_null($element)) { - $fontStyle = $element->getFontStyle(); - $sfIsObject = ($fontStyle instanceof PHPWord_Style_Font) ? true : false; - $paragraphStyle = $element->getParagraphStyle(); - $spIsObject = ($paragraphStyle instanceof PHPWord_Style_Paragraph) ? true : false; - $hasStyle = !is_null($fontStyle) || !is_null($paragraphStyle); - } - if ($hasStyle) { - // Paragraph style - $objWriter->startElement('w:p'); - if ($spIsObject) { - $this->_writeParagraphStyle($objWriter, $paragraphStyle); - } elseif (!$spIsObject && !is_null($paragraphStyle)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:pStyle'); - $objWriter->writeAttribute('w:val', $paragraphStyle); - $objWriter->endElement(); // w:pStyle - $objWriter->endElement(); // w:pPr - } - // Font style - if (!is_null($fontStyle)) { - $objWriter->startElement('w:pPr'); - if ($sfIsObject) { - $this->_writeTextStyle($objWriter, $fontStyle); - } elseif (!$sfIsObject && !is_null($fontStyle)) { - $objWriter->startElement('w:rPr'); - $objWriter->startElement('w:rStyle'); - $objWriter->writeAttribute('w:val', $fontStyle); - $objWriter->endElement(); // w:rStyle - $objWriter->endElement(); // w:rPr - } - $objWriter->endElement(); // w:pPr - } - $objWriter->endElement(); // w:p - } else { - // Null element. No paragraph nor font style - $objWriter->writeElement('w:p', null); - } - } - - /** - * Write table - */ - protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table) - { - $_rows = $table->getRows(); - $_cRows = count($_rows); - - if ($_cRows > 0) { - $objWriter->startElement('w:tbl'); - $tblStyle = $table->getStyle(); - $tblWidth = $table->getWidth(); - if ($tblStyle instanceof PHPWord_Style_Table) { - $this->_writeTableStyle($objWriter, $tblStyle); - } else { - if (!empty($tblStyle)) { - $objWriter->startElement('w:tblPr'); - $objWriter->startElement('w:tblStyle'); - $objWriter->writeAttribute('w:val', $tblStyle); - $objWriter->endElement(); - if (!is_null($tblWidth)) { - $objWriter->startElement('w:tblW'); - $objWriter->writeAttribute('w:w', $tblWidth); - $objWriter->writeAttribute('w:type', 'pct'); - $objWriter->endElement(); - } - $objWriter->endElement(); - } - } - - for ($i = 0; $i < $_cRows; $i++) { - $row = $_rows[$i]; - $height = $row->getHeight(); - $rowStyle = $row->getStyle(); - $tblHeader = $rowStyle->getTblHeader(); - $cantSplit = $rowStyle->getCantSplit(); - - $objWriter->startElement('w:tr'); - - if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) { - $objWriter->startElement('w:trPr'); - if (!is_null($height)) { - $objWriter->startElement('w:trHeight'); - $objWriter->writeAttribute('w:val', $height); - $objWriter->endElement(); - } - if ($tblHeader) { - $objWriter->startElement('w:tblHeader'); - $objWriter->writeAttribute('w:val', '1'); - $objWriter->endElement(); - } - if ($cantSplit) { - $objWriter->startElement('w:cantSplit'); - $objWriter->writeAttribute('w:val', '1'); - $objWriter->endElement(); - } - $objWriter->endElement(); - } - - foreach ($row->getCells() as $cell) { - $objWriter->startElement('w:tc'); - - $cellStyle = $cell->getStyle(); - $width = $cell->getWidth(); - - $objWriter->startElement('w:tcPr'); - $objWriter->startElement('w:tcW'); - $objWriter->writeAttribute('w:w', $width); - $objWriter->writeAttribute('w:type', 'dxa'); - $objWriter->endElement(); - - if ($cellStyle instanceof PHPWord_Style_Cell) { - $this->_writeCellStyle($objWriter, $cellStyle); - } - - $objWriter->endElement(); - - $_elements = $cell->getElements(); - if (count($_elements) > 0) { - 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_TextBreak) { - $this->_writeTextBreak($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_Section_Footer_PreserveText) { - $this->_writePreserveText($objWriter, $element); - } - } - } else { - $this->_writeTextBreak($objWriter); - } - - $objWriter->endElement(); - } - $objWriter->endElement(); - } - $objWriter->endElement(); - } - } - - /** - * Write table style - */ - protected function _writeTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Table $style = null) - { - $margins = $style->getCellMargin(); - $mTop = (!is_null($margins[0])) ? true : false; - $mLeft = (!is_null($margins[1])) ? true : false; - $mRight = (!is_null($margins[2])) ? true : false; - $mBottom = (!is_null($margins[3])) ? true : false; - - if ($mTop || $mLeft || $mRight || $mBottom) { - $objWriter->startElement('w:tblPr'); - $objWriter->startElement('w:tblCellMar'); - - if ($mTop) { - $objWriter->startElement('w:top'); - $objWriter->writeAttribute('w:w', $margins[0]); - $objWriter->writeAttribute('w:type', 'dxa'); - $objWriter->endElement(); - } - - if ($mLeft) { - $objWriter->startElement('w:left'); - $objWriter->writeAttribute('w:w', $margins[1]); - $objWriter->writeAttribute('w:type', 'dxa'); - $objWriter->endElement(); - } - - if ($mRight) { - $objWriter->startElement('w:right'); - $objWriter->writeAttribute('w:w', $margins[2]); - $objWriter->writeAttribute('w:type', 'dxa'); - $objWriter->endElement(); - } - - if ($mBottom) { - $objWriter->startElement('w:bottom'); - $objWriter->writeAttribute('w:w', $margins[3]); - $objWriter->writeAttribute('w:type', 'dxa'); - $objWriter->endElement(); - } - - $objWriter->endElement(); - $objWriter->endElement(); - } - } - - /** - * Write cell style - */ - protected function _writeCellStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Cell $style = null) - { - $bgColor = $style->getBgColor(); - $valign = $style->getVAlign(); - $textDir = $style->getTextDirection(); - $brdSz = $style->getBorderSize(); - $brdCol = $style->getBorderColor(); - - $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; - - $styles = (!is_null($bgColor) || !is_null($valign) || !is_null($textDir) || $borders) ? true : false; - - if ($styles) { - if (!is_null($textDir)) { - $objWriter->startElement('w:textDirection'); - $objWriter->writeAttribute('w:val', $textDir); - $objWriter->endElement(); - } - - 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(); - } - - if (!is_null($valign)) { - $objWriter->startElement('w:vAlign'); - $objWriter->writeAttribute('w:val', $valign); - $objWriter->endElement(); - } - - if ($borders) { - $_defaultColor = $style->getDefaultBorderColor(); - - $objWriter->startElement('w:tcBorders'); - if ($bTop) { - if (is_null($brdCol[0])) { - $brdCol[0] = $_defaultColor; - } - $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) { - if (is_null($brdCol[1])) { - $brdCol[1] = $_defaultColor; - } - $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) { - if (is_null($brdCol[2])) { - $brdCol[2] = $_defaultColor; - } - $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) { - if (is_null($brdCol[3])) { - $brdCol[3] = $_defaultColor; - } - $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(); - } - } - $gridSpan = $style->getGridSpan(); - if (!is_null($gridSpan)) { - $objWriter->startElement('w:gridSpan'); - $objWriter->writeAttribute('w:val', $gridSpan); - $objWriter->endElement(); - } - - $vMerge = $style->getVMerge(); - if (!is_null($vMerge)) { - $objWriter->startElement('w:vMerge'); - $objWriter->writeAttribute('w:val', $vMerge); - $objWriter->endElement(); - } - } - - /** - * Write image - * - * @param \PHPWord_Shared_XMLWriter $objWriter - * @param \PHPWord_Section_Image|\PHPWord_Section_MemoryImage $image - * @param boolean $withoutP - */ - protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, $image, $withoutP = false) - { - $rId = $image->getRelationId(); - - $style = $image->getStyle(); - $width = $style->getWidth(); - $height = $style->getHeight(); - $align = $style->getAlign(); - $marginTop = $style->getMarginTop(); - $marginLeft = $style->getMarginLeft(); - $wrappingStyle = $style->getWrappingStyle(); - - if (!$withoutP) { - $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:pict'); - - $objWriter->startElement('v:shape'); - $objWriter->writeAttribute('type', '#_x0000_t75'); - - $imgStyle = ''; - if (null !== $width) { - $imgStyle .= 'width:' . $width . 'px;'; - } - if (null !== $height) { - $imgStyle .= 'height:' . $height . 'px;'; - } - if (null !== $marginTop) { - $imgStyle .= 'margin-top:' . $marginTop . 'in;'; - } - if (null !== $marginLeft) { - $imgStyle .= 'margin-left:' . $marginLeft . 'in;'; - } - - switch ($wrappingStyle) { - case PHPWord_Style_Image::WRAPPING_STYLE_BEHIND: - $imgStyle .= 'position:absolute;z-index:-251658752;'; - break; - case PHPWord_Style_Image::WRAPPING_STYLE_SQUARE: - $imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; - break; - case PHPWord_Style_Image::WRAPPING_STYLE_TIGHT: - $imgStyle .= 'position:absolute;z-index:251659264;mso-wrap-edited:f;mso-position-horizontal:absolute;mso-position-vertical:absolute'; - break; - case PHPWord_Style_Image::WRAPPING_STYLE_INFRONT: - $imgStyle .= 'position:absolute;zz-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; - break; - } - - $objWriter->writeAttribute('style', $imgStyle); - - $objWriter->startElement('v:imagedata'); - $objWriter->writeAttribute('r:id', 'rId' . $rId); - $objWriter->writeAttribute('o:title', ''); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->endElement(); - - $objWriter->endElement(); - - if (!$withoutP) { - $objWriter->endElement(); // w:p - } - } - - /** - * Write watermark - * - * @param PHP_Section_Image|PHP_Section_MemoryImage $image - */ - protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) - { - $rId = $image->getRelationId(); - - $style = $image->getStyle(); - $width = $style->getWidth(); - $height = $style->getHeight(); - $marginLeft = $style->getMarginLeft(); - $marginTop = $style->getMarginTop(); - - $objWriter->startElement('w:p'); - - $objWriter->startElement('w:r'); - - $objWriter->startElement('w:pict'); - - $objWriter->startElement('v:shape'); - $objWriter->writeAttribute('type', '#_x0000_t75'); - - $strStyle = 'position:absolute;'; - $strStyle .= ' width:' . $width . 'px;'; - $strStyle .= ' height:' . $height . 'px;'; - if (!is_null($marginTop)) { - $strStyle .= ' margin-top:' . $marginTop . 'px;'; - } - if (!is_null($marginLeft)) { - $strStyle .= ' margin-left:' . $marginLeft . 'px;'; - } - - $objWriter->writeAttribute('style', $strStyle); - - $objWriter->startElement('v:imagedata'); - $objWriter->writeAttribute('r:id', 'rId' . $rId); - $objWriter->writeAttribute('o:title', ''); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->endElement(); - - $objWriter->endElement(); - - $objWriter->endElement(); - } - - /** - * Write title - */ - protected function _writeTitle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Title $title) - { - $text = htmlspecialchars($title->getText()); - $text = PHPWord_Shared_String::ControlCharacterPHP2OOXML($text); - $anchor = $title->getAnchor(); - $bookmarkId = $title->getBookmarkId(); - $style = $title->getStyle(); - - $objWriter->startElement('w:p'); - - if (!empty($style)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:pStyle'); - $objWriter->writeAttribute('w:val', $style); - $objWriter->endElement(); - $objWriter->endElement(); - } - - $objWriter->startElement('w:r'); - $objWriter->startElement('w:fldChar'); - $objWriter->writeAttribute('w:fldCharType', 'end'); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('w:bookmarkStart'); - $objWriter->writeAttribute('w:id', $bookmarkId); - $objWriter->writeAttribute('w:name', $anchor); - $objWriter->endElement(); - - $objWriter->startElement('w:r'); - $objWriter->startElement('w:t'); - $objWriter->writeRaw($text); - $objWriter->endElement(); - $objWriter->endElement(); - - $objWriter->startElement('w:bookmarkEnd'); - $objWriter->writeAttribute('w:id', $bookmarkId); - $objWriter->endElement(); - - $objWriter->endElement(); - } - - /** - * Write footnote - */ - protected function _writeFootnote(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote) - { - $objWriter->startElement('w:footnote'); - $objWriter->writeAttribute('w:id', $footnote->getReferenceId()); - - $styleParagraph = $footnote->getParagraphStyle(); - $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; - - $objWriter->startElement('w:p'); - - if ($SpIsObject) { - $this->_writeParagraphStyle($objWriter, $styleParagraph); - } elseif (!$SpIsObject && !is_null($styleParagraph)) { - $objWriter->startElement('w:pPr'); - $objWriter->startElement('w:pStyle'); - $objWriter->writeAttribute('w:val', $styleParagraph); - $objWriter->endElement(); - $objWriter->endElement(); - } - - $elements = $footnote->getElements(); - if (count($elements) > 0) { - foreach ($elements as $element) { - if ($element instanceof PHPWord_Section_Text) { - $this->_writeText($objWriter, $element, true); - } elseif ($element instanceof PHPWord_Section_Link) { - $this->_writeLink($objWriter, $element, true); - } - } - } - - $objWriter->endElement(); // w:p - $objWriter->endElement(); // w:footnote - } - - /** - * Write footnote reference - * - * @param boolean $withoutP - */ - protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false) - { - if (!$withoutP) { - $objWriter->startElement('w:p'); - } - - $objWriter->startElement('w:r'); - - $objWriter->startElement('w:footnoteReference'); - $objWriter->writeAttribute('w:id', $footnote->getReferenceId()); - $objWriter->endElement(); // w:footnoteReference - - $objWriter->endElement(); // w:r - - if (!$withoutP) { - $objWriter->endElement(); // w:p - } - } -} diff --git a/Classes/PHPWord/Writer/Word2007/DocProps.php b/Classes/PHPWord/Writer/Word2007/DocProps.php deleted file mode 100755 index b2ec6f3902..0000000000 --- a/Classes/PHPWord/Writer/Word2007/DocProps.php +++ /dev/null @@ -1,195 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php deleted file mode 100755 index 1bd861527c..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ /dev/null @@ -1,511 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/Word2007/Footer.php b/Classes/PHPWord/Writer/Word2007/Footer.php deleted file mode 100755 index ef81fdb0c9..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Footer.php +++ /dev/null @@ -1,88 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/Word2007/Footnotes.php b/Classes/PHPWord/Writer/Word2007/Footnotes.php deleted file mode 100644 index 5d0680ce4b..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Footnotes.php +++ /dev/null @@ -1,91 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/Word2007/Header.php b/Classes/PHPWord/Writer/Word2007/Header.php deleted file mode 100755 index 0c11183b64..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Header.php +++ /dev/null @@ -1,92 +0,0 @@ -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(); - } -} diff --git a/Classes/PHPWord/Writer/Word2007/Styles.php b/Classes/PHPWord/Writer/Word2007/Styles.php deleted file mode 100755 index 1f61051abb..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Styles.php +++ /dev/null @@ -1,420 +0,0 @@ -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(); - } -} diff --git a/Tests/PHPWord/AutoloaderTest.php b/Tests/PHPWord/AutoloaderTest.php deleted file mode 100644 index 03e16db073..0000000000 --- a/Tests/PHPWord/AutoloaderTest.php +++ /dev/null @@ -1,49 +0,0 @@ -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' - ); - } -} diff --git a/Tests/PHPWord/IOFactoryTest.php b/Tests/PHPWord/IOFactoryTest.php deleted file mode 100644 index 0ed6a06510..0000000000 --- a/Tests/PHPWord/IOFactoryTest.php +++ /dev/null @@ -1,63 +0,0 @@ -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) - ); - } -} \ No newline at end of file diff --git a/Tests/PHPWord/MediaTest.php b/Tests/PHPWord/MediaTest.php deleted file mode 100644 index b2ebd6ae89..0000000000 --- a/Tests/PHPWord/MediaTest.php +++ /dev/null @@ -1,50 +0,0 @@ -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); - } - } -} diff --git a/Tests/PHPWord/Reader/Word2007Test.php b/Tests/PHPWord/Reader/Word2007Test.php deleted file mode 100644 index 6fb6684609..0000000000 --- a/Tests/PHPWord/Reader/Word2007Test.php +++ /dev/null @@ -1,68 +0,0 @@ -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); - } -} diff --git a/Tests/PHPWord/Section/ImageTest.php b/Tests/PHPWord/Section/ImageTest.php deleted file mode 100644 index 50cc4d2acc..0000000000 --- a/Tests/PHPWord/Section/ImageTest.php +++ /dev/null @@ -1,102 +0,0 @@ -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); - } -} diff --git a/Tests/PHPWord/Section/ListItemTest.php b/Tests/PHPWord/Section/ListItemTest.php deleted file mode 100644 index a2a4d43832..0000000000 --- a/Tests/PHPWord/Section/ListItemTest.php +++ /dev/null @@ -1,36 +0,0 @@ -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); - } -} diff --git a/Tests/PHPWord/Section/TextTest.php b/Tests/PHPWord/Section/TextTest.php deleted file mode 100644 index 1a33a730d7..0000000000 --- a/Tests/PHPWord/Section/TextTest.php +++ /dev/null @@ -1,42 +0,0 @@ -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()); - } -} diff --git a/Tests/PHPWord/SettingsTest.php b/Tests/PHPWord/SettingsTest.php deleted file mode 100644 index e61a212915..0000000000 --- a/Tests/PHPWord/SettingsTest.php +++ /dev/null @@ -1,26 +0,0 @@ -assertTrue(PHPWord_Settings::getCompatibility()); - $this->assertTrue(PHPWord_Settings::setCompatibility(false)); - $this->assertFalse(PHPWord_Settings::getCompatibility()); - $this->assertFalse(PHPWord_Settings::setCompatibility('Non boolean')); - } -} diff --git a/Tests/PHPWord/Shared/FileTest.php b/Tests/PHPWord/Shared/FileTest.php deleted file mode 100644 index fe825b8f8d..0000000000 --- a/Tests/PHPWord/Shared/FileTest.php +++ /dev/null @@ -1,92 +0,0 @@ -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)); - } -} \ No newline at end of file diff --git a/Tests/PHPWord/Shared/StringTest.php b/Tests/PHPWord/Shared/StringTest.php deleted file mode 100644 index 3698e2e0e1..0000000000 --- a/Tests/PHPWord/Shared/StringTest.php +++ /dev/null @@ -1,33 +0,0 @@ -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))); - } -} diff --git a/Tests/PHPWord/StyleTest.php b/Tests/PHPWord/StyleTest.php deleted file mode 100644 index 9e442cb13e..0000000000 --- a/Tests/PHPWord/StyleTest.php +++ /dev/null @@ -1,44 +0,0 @@ - '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')); - } -} diff --git a/Tests/PHPWord/Writer/RTFTest.php b/Tests/PHPWord/Writer/RTFTest.php deleted file mode 100644 index 8735c7d704..0000000000 --- a/Tests/PHPWord/Writer/RTFTest.php +++ /dev/null @@ -1,96 +0,0 @@ -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 :: - */ - 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); - } -} diff --git a/Tests/PHPWordTest.php b/Tests/PHPWordTest.php deleted file mode 100644 index c08d0885a5..0000000000 --- a/Tests/PHPWordTest.php +++ /dev/null @@ -1,186 +0,0 @@ -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); - } -} diff --git a/Tests/_files/templates/clone-row.docx b/Tests/_files/templates/clone-row.docx deleted file mode 100644 index 8bea4f0383..0000000000 Binary files a/Tests/_files/templates/clone-row.docx and /dev/null differ diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php deleted file mode 100755 index 1066a0d42c..0000000000 --- a/Tests/bootstrap.php +++ /dev/null @@ -1,15 +0,0 @@ -=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/" } } -} +} \ No newline at end of file diff --git a/docs/Makefile b/docs/Makefile index bd38cd5d9d..5631b06028 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -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: diff --git a/docs/conf.py b/docs/conf.py index 9908b2b726..f5c38581f1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 @@ 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_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 @@ # 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 @@ # 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 @@ # (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 @@ # -- 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 diff --git a/docs/elements.rst b/docs/elements.rst index 2b740ec217..891d5a3503 100644 --- a/docs/elements.rst +++ b/docs/elements.rst @@ -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)); diff --git a/docs/general.rst b/docs/general.rst index 52147e815a..7cbfd4b47a 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -11,11 +11,13 @@ are provided in the `samples folder 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 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 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'); diff --git a/docs/setup.rst b/docs/setup.rst index c29ef0dc4a..10664b8377 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -47,11 +47,11 @@ Manual install To install manually, `download PHPWord package from github `__. 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/``. diff --git a/docs/templates.rst b/docs/templates.rst index ea7b9d151a..6b627b06be 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -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'); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 908304adea..a57f5bb6a2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - - ./Tests/PHPWord/ + + ./tests/PhpWord/ - ./Classes + ./src - + \ No newline at end of file diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index a6d593ec2f..7ada399ada 100755 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -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 @@ $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}"); } diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php index dc0fea42ff..f08f1e15de 100755 --- a/samples/Sample_02_TabStops.php +++ b/samples/Sample_02_TabStops.php @@ -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 @@ $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}"); } diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php index 383bf4e782..c16b73dbee 100755 --- a/samples/Sample_03_Sections.php +++ b/samples/Sample_03_Sections.php @@ -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 @@ $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}"); } diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index d3e577bd6c..94bc3d5bb2 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -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 @@ $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}"); } diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php index e636f8ad76..541e2e8aa0 100644 --- a/samples/Sample_05_Multicolumn.php +++ b/samples/Sample_05_Multicolumn.php @@ -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}"); } diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php index 3c52cfcfeb..c430e54802 100755 --- a/samples/Sample_06_Footnote.php +++ b/samples/Sample_06_Footnote.php @@ -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 @@ $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}"); } diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php index e322001e74..addde3635e 100755 --- a/samples/Sample_07_TemplateCloneRow.php +++ b/samples/Sample_07_TemplateCloneRow.php @@ -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('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}"); diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php index 79879ad12e..eeef605863 100644 --- a/samples/Sample_08_ParagraphPagination.php +++ b/samples/Sample_08_ParagraphPagination.php @@ -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 @@ $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}"); } diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php index 62e5045759..ea10eec9f7 100644 --- a/samples/Sample_09_Tables.php +++ b/samples/Sample_09_Tables.php @@ -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 @@ $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 @@ $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 @@ $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}"); } diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php index 164cf4950c..6e8b26a0d6 100644 --- a/samples/Sample_10_EastAsianFontStyle.php +++ b/samples/Sample_10_EastAsianFontStyle.php @@ -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 @@ $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}"); } diff --git a/samples/Sample_11_ReadWord2007.php b/samples/Sample_11_ReadWord2007.php index fff1057263..b2420a53d8 100644 --- a/samples/Sample_11_ReadWord2007.php +++ b/samples/Sample_11_ReadWord2007.php @@ -4,15 +4,15 @@ // 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}"); } diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php index 5d1cdfe20a..3c5775ef6b 100644 --- a/samples/Sample_12_HeaderFooter.php +++ b/samples/Sample_12_HeaderFooter.php @@ -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->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 @@ // 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->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 @@ $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}"); } diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php index e0f943239f..6841ed64ca 100644 --- a/samples/Sample_13_Images.php +++ b/samples/Sample_13_Images.php @@ -1,15 +1,12 @@ createSection(); +$section = $phpWord->createSection(); $section->addText('Local image without any styles:'); $section->addImage('resources/_mars.jpg'); $section->addTextBreak(2); @@ -27,9 +24,9 @@ $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}"); } diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php index 40fcea9e0a..45cb73ab20 100644 --- a/samples/Sample_14_ListItem.php +++ b/samples/Sample_14_ListItem.php @@ -1,15 +1,12 @@ createSection(); +$section = $phpWord->createSection(); // Add listitem elements $section->addListItem('List Item 1', 0); @@ -27,16 +24,16 @@ $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 @@ $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}"); } diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php index 8fcd181651..06628de54a 100644 --- a/samples/Sample_15_Link.php +++ b/samples/Sample_15_Link.php @@ -1,21 +1,18 @@ 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 @@ $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}"); } diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php index dda23be2ff..1a7f557ab8 100644 --- a/samples/Sample_16_Object.php +++ b/samples/Sample_16_Object.php @@ -1,15 +1,12 @@ 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 @@ $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}"); } diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php index 3edf03e00b..27982921b5 100644 --- a/samples/Sample_17_TitleTOC.php +++ b/samples/Sample_17_TitleTOC.php @@ -1,22 +1,19 @@ 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->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}"); } diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php index df1d581a2e..ff299c97ba 100644 --- a/samples/Sample_18_Watermark.php +++ b/samples/Sample_18_Watermark.php @@ -1,16 +1,13 @@ 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 @@ $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}"); } diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php index 6aad699f77..9433222c93 100644 --- a/samples/Sample_19_TextBreak.php +++ b/samples/Sample_19_TextBreak.php @@ -1,21 +1,18 @@ 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 @@ $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}"); } diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php index d9daf89fc6..5fcb383d37 100644 --- a/samples/Sample_Header.php +++ b/samples/Sample_Header.php @@ -5,7 +5,7 @@ error_reporting(E_ALL); define('CLI', (PHP_SAPI == 'cli') ? true : false); define('EOL', CLI ? PHP_EOL : '
'); -require_once '../Classes/PHPWord.php'; +require_once '../src/PhpWord/PhpWord.php'; // Return to the caller script when runs by CLI if (CLI) { return; diff --git a/Tests/_files/images/PHPWord.png b/samples/resources/PhpWord.png similarity index 100% rename from Tests/_files/images/PHPWord.png rename to samples/resources/PhpWord.png diff --git a/src/PhpWord/Autoloader.php b/src/PhpWord/Autoloader.php new file mode 100644 index 0000000000..554d7cb13a --- /dev/null +++ b/src/PhpWord/Autoloader.php @@ -0,0 +1,64 @@ +addFromSource($pSource); } } @@ -63,8 +59,8 @@ public function __construct($pSource = null) /** * 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 @@ public function addFromSource($pSource = null) /** * 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 @@ public function add(PHPWord_IComparable $pSource = null) /** * 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 @@ public function clear() } /** - * Count - * * @return int */ public function count() @@ -156,10 +148,8 @@ public function count() } /** - * 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 @@ public function getIndexForHashCode($pHashCode = '') } /** - * 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 @@ public function getByIndex($pIndex = 0) } /** - * Get by hashcode - * - * @param string $pHashCode - * @return PHPWord_IComparable + * @param string $pHashCode + * @return \PhpOffice\PhpWord\IComparable * */ public function getByHashCode($pHashCode = '') @@ -199,9 +184,7 @@ public function getByHashCode($pHashCode = '') } /** - * HashTable to array - * - * @return PHPWord_IComparable[] + * @return \PhpOffice\PhpWord\IComparable[] */ public function toArray() { diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php new file mode 100644 index 0000000000..854bcab40d --- /dev/null +++ b/src/PhpWord/IOFactory.php @@ -0,0 +1,77 @@ +load($filename); + } +} diff --git a/Classes/PHPWord/Media.php b/src/PhpWord/Media.php similarity index 85% rename from Classes/PHPWord/Media.php rename to src/PhpWord/Media.php index 1d422775ba..f7954df3d3 100755 --- a/Classes/PHPWord/Media.php +++ b/src/PhpWord/Media.php @@ -1,8 +1,8 @@ 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 @@ public static function addSectionMediaElement($src, $type, PHPWord_Section_Memor $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 @@ public static function countSectionMediaElements($key = null) /** * 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 @@ public static function getHeaderMediaElements() /** * 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; diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php new file mode 100644 index 0000000000..dd7d55d16d --- /dev/null +++ b/src/PhpWord/PhpWord.php @@ -0,0 +1,231 @@ +_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."); + } + } +} diff --git a/Classes/PHPWord/Reader/Abstract.php b/src/PhpWord/Reader/AbstractReader.php similarity index 86% rename from Classes/PHPWord/Reader/Abstract.php rename to src/PhpWord/Reader/AbstractReader.php index 63b794f827..af67337d95 100644 --- a/Classes/PHPWord/Reader/Abstract.php +++ b/src/PhpWord/Reader/AbstractReader.php @@ -1,8 +1,8 @@ fileHandle); return true; } -} \ No newline at end of file +} diff --git a/Classes/PHPWord/Reader/IReader.php b/src/PhpWord/Reader/IReader.php similarity index 71% rename from Classes/PHPWord/Reader/IReader.php rename to src/PhpWord/Reader/IReader.php index 703db57620..f29d71d40e 100644 --- a/Classes/PHPWord/Reader/IReader.php +++ b/src/PhpWord/Reader/IReader.php @@ -1,8 +1,8 @@ open($pFilename) === true) { // check if it is an OOXML archive $rels = simplexml_load_string($this->getFromZipArchive($zip, "_rels/.rels")); @@ -77,9 +76,7 @@ public function canRead($pFilename) } /** - * Get from zip archive - * - * @param ZipArchive $archive + * @param \ZipArchive $archive * @param string $fileName * @param bool $removeNamespace * @return mixed @@ -90,7 +87,7 @@ public function getFromZipArchive($archive, $fileName = '', $removeNamespace = f 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 @@ public function getFromZipArchive($archive, $fileName = '', $removeNamespace = f } /** - * 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 @@ public function load($pFilename) } // Initialisations - $word = new PHPWord; - $zip = new ZipArchive; + $word = new PhpWord(); + $zip = new \ZipArchive(); $zip->open($pFilename); // Read properties and documents @@ -135,7 +132,7 @@ public function load($pFilename) $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 @@ public function load($pFilename) 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 @@ public function load($pFilename) 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 @@ public function load($pFilename) $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 @@ public function load($pFilename) /** * 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 @@ private function loadSectionSettings($elm) /** * Load paragraph style from SimpleXMLElement * - * @param SimpleXMLElement $elm + * @param \SimpleXMLElement $elm * @return array|string|null */ private function loadParagraphStyle($elm) @@ -395,7 +392,7 @@ private function loadParagraphStyle($elm) /** * Load font style from SimpleXMLElement * - * @param SimpleXMLElement $elm + * @param \SimpleXMLElement $elm * @return array|string|null */ private function loadFontStyle($elm) @@ -442,8 +439,6 @@ private function loadFontStyle($elm) } /** - * Get array item - * * @param array $array * @param mixed $key * @return mixed|null @@ -452,4 +447,4 @@ private static function arrayItem($array, $key = 0) { return (isset($array[$key]) ? $array[$key] : null); } -} \ No newline at end of file +} diff --git a/Classes/PHPWord/Section.php b/src/PhpWord/Section.php old mode 100755 new mode 100644 similarity index 68% rename from Classes/PHPWord/Section.php rename to src/PhpWord/Section.php index a9402dab72..32727d323d --- a/Classes/PHPWord/Section.php +++ b/src/PhpWord/Section.php @@ -1,8 +1,8 @@ _sectionCount = $sectionCount; - $this->_settings = new PHPWord_Section_Settings(); + $this->_settings = new Settings(); $this->setSettings($settings); } @@ -101,7 +113,7 @@ public function setSettings($settings = null) /** * Get Section Settings * - * @return PHPWord_Section_Settings + * @return \PhpOffice\PhpWord\Section\Settings */ public function getSettings() { @@ -114,14 +126,14 @@ public function getSettings() * @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 @@ public function addText($text, $styleFont = null, $styleParagraph = null) * @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 @@ public function addLink($linkSrc, $linkName = null, $styleFont = null, $stylePar /** * 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 @@ public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = nu */ 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 @@ public function addTable($style = null) * @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 @@ public function addListItem($text, $depth = 0, $styleFont = null, $styleList = n * * @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 @@ public function addObject($src, $style = null) $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 @@ public function addObject($src, $style = null) * * @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 @@ public function addImage($src, $style = null) * * @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 @@ public function addMemoryImage($link, $style = null) * * @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 @@ public function addTOC($styleFont = null, $styleTOC = null) * * @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 @@ public function addTitle($text, $depth = 1) * 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 @@ public function getElements() /** * 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 @@ public function getHeaders() /** * 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 @@ public function hasDifferentFirstPage() /** * 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,14 +436,14 @@ public function getFooter() * 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; } -} \ No newline at end of file +} diff --git a/Classes/PHPWord/Section/Footer.php b/src/PhpWord/Section/Footer.php similarity index 72% rename from Classes/PHPWord/Section/Footer.php rename to src/PhpWord/Section/Footer.php index ba9cb68c87..13b097e6da 100755 --- a/Classes/PHPWord/Section/Footer.php +++ b/src/PhpWord/Section/Footer.php @@ -1,8 +1,8 @@ _elementCollection[] = $text; return $text; } @@ -83,26 +82,25 @@ public function addText($text, $styleFont = null, $styleParagraph = null) /** * 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 @@ public function createTextRun($styleParagraph = null) * 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 @@ public function addTable($style = null) * * @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 @@ public function addImage($src, $style = null) * * @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 @@ public function addMemoryImage($link, $style = null) * @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; } diff --git a/Classes/PHPWord/Section/Footer/PreserveText.php b/src/PhpWord/Section/Footer/PreserveText.php old mode 100755 new mode 100644 similarity index 81% rename from Classes/PHPWord/Section/Footer/PreserveText.php rename to src/PhpWord/Section/Footer/PreserveText.php index 0cac9b0484..c83d38ecec --- a/Classes/PHPWord/Section/Footer/PreserveText.php +++ b/src/PhpWord/Section/Footer/PreserveText.php @@ -1,8 +1,8 @@ _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 @@ public function __construct($text = null, $styleFont = null, $styleParagraph = n // 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 @@ public function __construct($text = null, $styleFont = null, $styleParagraph = n $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 @@ public function __construct($text = null, $styleFont = null, $styleParagraph = n /** * Get Text style * - * @return PHPWord_Style_Font + * @return \PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { @@ -112,7 +111,7 @@ public function getFontStyle() /** * Get Paragraph style * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { diff --git a/Classes/PHPWord/Section/Footnote.php b/src/PhpWord/Section/Footnote.php similarity index 78% rename from Classes/PHPWord/Section/Footnote.php rename to src/PhpWord/Section/Footnote.php index 7e77aca483..2a9eacaf31 100644 --- a/Classes/PHPWord/Section/Footnote.php +++ b/src/PhpWord/Section/Footnote.php @@ -1,8 +1,8 @@ _styleParagraph = new PHPWord_Style_Paragraph(); + $this->_styleParagraph = new Paragraph(); foreach ($styleParagraph as $key => $value) { if (substr($key, 0, 1) != '_') { @@ -80,14 +76,14 @@ public function __construct($styleParagraph = null) /** * 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 @@ public function addText($text = null, $styleFont = null) * @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 @@ public function getElements() } /** - * Get Paragraph style - * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { diff --git a/Classes/PHPWord/Section/Header.php b/src/PhpWord/Section/Header.php similarity index 74% rename from Classes/PHPWord/Section/Header.php rename to src/PhpWord/Section/Header.php index 89672e6e03..9c35767032 100755 --- a/Classes/PHPWord/Section/Header.php +++ b/src/PhpWord/Section/Header.php @@ -1,8 +1,8 @@ _elementCollection[] = $text; return $text; } @@ -112,26 +111,25 @@ public function addText($text, $styleFont = null, $styleParagraph = null) /** * 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 @@ public function createTextRun($styleParagraph = null) * 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 @@ public function addTable($style = null) * * @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 @@ public function addImage($src, $style = null) * * @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 @@ public function addMemoryImage($link, $style = null) * @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 @@ public function addPreserveText($text, $styleFont = null, $styleParagraph = null * * @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 @@ public function getType() */ public function resetType() { - return $this->_type = PHPWord_Section_Header::AUTO; + return $this->_type = self::AUTO; } /** @@ -287,7 +285,7 @@ public function resetType() */ public function firstPage() { - return $this->_type = PHPWord_Section_Header::FIRST; + return $this->_type = self::FIRST; } /** @@ -295,6 +293,6 @@ public function firstPage() */ public function evenPage() { - return $this->_type = PHPWord_Section_Header::EVEN; + return $this->_type = self::EVEN; } } diff --git a/Classes/PHPWord/Section/Image.php b/src/PhpWord/Section/Image.php similarity index 84% rename from Classes/PHPWord/Section/Image.php rename to src/PhpWord/Section/Image.php index 30a1044962..2c04125396 100755 --- a/Classes/PHPWord/Section/Image.php +++ b/src/PhpWord/Section/Image.php @@ -1,8 +1,8 @@ _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 @@ public function __construct($src, $style = null, $isWatermark = false) /** * Get Image style * - * @return PHPWord_Style_Image + * @return \PhpOffice\PhpWord\Style\Image */ public function getStyle() { diff --git a/Classes/PHPWord/Section/Link.php b/src/PhpWord/Section/Link.php old mode 100755 new mode 100644 similarity index 87% rename from Classes/PHPWord/Section/Link.php rename to src/PhpWord/Section/Link.php index 26659b6f27..bc1b9e8e56 --- a/Classes/PHPWord/Section/Link.php +++ b/src/PhpWord/Section/Link.php @@ -1,8 +1,8 @@ _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 @@ public function __construct($linkSrc, $linkName = null, $styleFont = null, $styl // 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 @@ public function getLinkName() /** * Get Text style * - * @return PHPWord_Style_Font + * @return \PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { @@ -164,7 +163,7 @@ public function getFontStyle() /** * Get Paragraph style * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { diff --git a/Classes/PHPWord/Section/ListItem.php b/src/PhpWord/Section/ListItem.php old mode 100755 new mode 100644 similarity index 83% rename from Classes/PHPWord/Section/ListItem.php rename to src/PhpWord/Section/ListItem.php index 7d37f3d89d..8b8afc4237 --- a/Classes/PHPWord/Section/ListItem.php +++ b/src/PhpWord/Section/ListItem.php @@ -1,8 +1,8 @@ _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)) { diff --git a/Classes/PHPWord/Section/MemoryImage.php b/src/PhpWord/Section/MemoryImage.php old mode 100755 new mode 100644 similarity index 93% rename from Classes/PHPWord/Section/MemoryImage.php rename to src/PhpWord/Section/MemoryImage.php index 9d4ed97c0e..89e867ac19 --- a/Classes/PHPWord/Section/MemoryImage.php +++ b/src/PhpWord/Section/MemoryImage.php @@ -1,8 +1,8 @@ _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 @@ private function _setFunctions() /** * Get Image style * - * @return PHPWord_Style_Image + * @return \PhpOffice\PhpWord\Style\Image */ public function getStyle() { diff --git a/Classes/PHPWord/Section/Object.php b/src/PhpWord/Section/Object.php old mode 100755 new mode 100644 similarity index 91% rename from Classes/PHPWord/Section/Object.php rename to src/PhpWord/Section/Object.php index 33d8cad9bc..3a6784972e --- a/Classes/PHPWord/Section/Object.php +++ b/src/PhpWord/Section/Object.php @@ -1,8 +1,8 @@ _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 @@ public function __construct($src, $style = null) /** * Get Image style * - * @return PHPWord_Style_Image + * @return \PhpOffice\PhpWord\Style\Image */ public function getStyle() { diff --git a/Classes/PHPWord/Section/PageBreak.php b/src/PhpWord/Section/PageBreak.php old mode 100755 new mode 100644 similarity index 77% rename from Classes/PHPWord/Section/PageBreak.php rename to src/PhpWord/Section/PageBreak.php index 76536304cb..e97d4b40d5 --- a/Classes/PHPWord/Section/PageBreak.php +++ b/src/PhpWord/Section/PageBreak.php @@ -1,8 +1,8 @@ _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 @@ public function __construct($insideOf, $pCount, $style = null) */ public function addRow($height = null, $style = null) { - $row = new PHPWord_Section_Table_Row($this->_insideOf, $this->_pCount, $height, $style); + $row = new Row($this->_insideOf, $this->_pCount, $height, $style); $this->_rows[] = $row; return $row; } @@ -113,7 +111,7 @@ public function addRow($height = null, $style = null) * * @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 @@ public function getRows() /** * Get table style * - * @return PHPWord_Style_Table + * @return \PhpOffice\PhpWord\Style\Table */ public function getStyle() { diff --git a/Classes/PHPWord/Section/Table/Cell.php b/src/PhpWord/Section/Table/Cell.php similarity index 71% rename from Classes/PHPWord/Section/Table/Cell.php rename to src/PhpWord/Section/Table/Cell.php index 4b620217e7..d94c2c4a1c 100755 --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/src/PhpWord/Section/Table/Cell.php @@ -1,8 +1,8 @@ _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 @@ public function __construct($insideOf, $pCount, $width = null, $style = null) * 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 @@ public function addText($text, $styleFont = null, $styleParagraph = null) * @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 @@ public function addLink($linkSrc, $linkName = null, $style = null) /** * 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 @@ public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = nu * @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 @@ public function addListItem($text, $depth = 0, $styleText = null, $styleList = n * * @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 @@ public function addImage($src, $style = null) * * @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 @@ public function addMemoryImage($link, $style = null) * * @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 @@ public function addObject($src, $style = null) $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 @@ public function addObject($src, $style = null) * @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 @@ public function addPreserveText($text, $styleFont = null, $styleParagraph = null /** * 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 @@ public function getElements() /** * Get Cell Style * - * @return PHPWord_Style_Cell + * @return \PhpOffice\PhpWord\Style\Cell */ public function getStyle() { diff --git a/Classes/PHPWord/Section/Table/Row.php b/src/PhpWord/Section/Table/Row.php similarity index 85% rename from Classes/PHPWord/Section/Table/Row.php rename to src/PhpWord/Section/Table/Row.php index dd8ea65c12..b9092295b3 100644 --- a/Classes/PHPWord/Section/Table/Row.php +++ b/src/PhpWord/Section/Table/Row.php @@ -1,8 +1,8 @@ _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 @@ public function __construct($insideOf, $pCount, $height = null, $style = null) * * @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 @@ public function getCells() /** * Get row style * - * @return PHPWord_Style_Row + * @return \PhpOffice\PhpWord\Style\Row */ public function getStyle() { diff --git a/Classes/PHPWord/Section/Text.php b/src/PhpWord/Section/Text.php old mode 100755 new mode 100644 similarity index 71% rename from Classes/PHPWord/Section/Text.php rename to src/PhpWord/Section/Text.php index d9062520b5..46edf34e88 --- a/Classes/PHPWord/Section/Text.php +++ b/src/PhpWord/Section/Text.php @@ -1,8 +1,8 @@ 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 @@ public function setFontStyle($style = null, $paragraphStyle = null) /** * Get Text style * - * @return PHPWord_Style_Font + * @return \PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { @@ -102,18 +102,18 @@ public function getFontStyle() /** * 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 @@ public function setParagraphStyle($style = null) /** * Get Paragraph style * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { diff --git a/Classes/PHPWord/Section/TextBreak.php b/src/PhpWord/Section/TextBreak.php similarity index 73% rename from Classes/PHPWord/Section/TextBreak.php rename to src/PhpWord/Section/TextBreak.php index 859eb6215b..3993430345 100755 --- a/Classes/PHPWord/Section/TextBreak.php +++ b/src/PhpWord/Section/TextBreak.php @@ -1,8 +1,8 @@ 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 @@ public function setFontStyle($style = null, $paragraphStyle = null) /** * Get Text style * - * @return PHPWord_Style_Font + * @return \PhpOffice\PhpWord\Style\Font */ public function getFontStyle() { @@ -95,15 +92,15 @@ public function getFontStyle() /** * 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 @@ public function setParagraphStyle($style = null) /** * Get Paragraph style * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { diff --git a/Classes/PHPWord/Section/TextRun.php b/src/PhpWord/Section/TextRun.php similarity index 71% rename from Classes/PHPWord/Section/TextRun.php rename to src/PhpWord/Section/TextRun.php index 890ea45bb5..0320d30c5c 100755 --- a/Classes/PHPWord/Section/TextRun.php +++ b/src/PhpWord/Section/TextRun.php @@ -1,8 +1,8 @@ _styleParagraph = new PHPWord_Style_Paragraph(); + $this->_styleParagraph = new Paragraph(); foreach ($styleParagraph as $key => $value) { if (substr($key, 0, 1) != '_') { @@ -74,16 +73,16 @@ public function __construct($styleParagraph = null) /** * 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 @@ public function addText($text = null, $styleFont = null) * @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 @@ public function addLink($linkSrc, $linkName = null, $styleFont = null) $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 @@ public function addLink($linkSrc, $linkName = null, $styleFont = null) * 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 @@ public function addImage($imageSrc, $style = null) * 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 @@ public function getElements() /** * Get Paragraph style * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { diff --git a/Classes/PHPWord/Section/Title.php b/src/PhpWord/Section/Title.php old mode 100755 new mode 100644 similarity index 92% rename from Classes/PHPWord/Section/Title.php rename to src/PhpWord/Section/Title.php index 2cc71e1132..9e71e46336 --- a/Classes/PHPWord/Section/Title.php +++ b/src/PhpWord/Section/Title.php @@ -1,8 +1,8 @@ 0) { + unset($pathArray[$i]); + unset($pathArray[$i - 1]); + break; + } + } + } + $returnValue = implode('/', $pathArray); + } + + // Return + return $returnValue; + } +} diff --git a/Classes/PHPWord/Shared/Font.php b/src/PhpWord/Shared/Font.php old mode 100755 new mode 100644 similarity index 93% rename from Classes/PHPWord/Shared/Font.php rename to src/PhpWord/Shared/Font.php index 9d5a42a52b..e3d6eb6094 --- a/Classes/PHPWord/Shared/Font.php +++ b/src/PhpWord/Shared/Font.php @@ -1,8 +1,8 @@ _xmlWriter = new XMLWriter(); + $this->_xmlWriter = new \XMLWriter(); // Open temporary storage if ($pTemporaryStorage == self::STORAGE_MEMORY) { @@ -82,7 +80,7 @@ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTempora } // Set xml Compatibility - $compatibility = PHPWord_Settings::getCompatibility(); + $compatibility = Settings::getCompatibility(); if ($compatibility) { $this->_xmlWriter->setIndent(false); $this->_xmlWriter->setIndentString(''); @@ -131,7 +129,7 @@ public function __call($function, $args) { try { @call_user_func_array(array($this->_xmlWriter, $function), $args); - } catch (Exception $ex) { + } catch (\Exception $ex) { // Do nothing! } } diff --git a/Classes/PHPWord/Shared/ZipStreamWrapper.php b/src/PhpWord/Shared/ZipStreamWrapper.php old mode 100755 new mode 100644 similarity index 92% rename from Classes/PHPWord/Shared/ZipStreamWrapper.php rename to src/PhpWord/Shared/ZipStreamWrapper.php index afebe7efc2..a9339570d6 --- a/Classes/PHPWord/Shared/ZipStreamWrapper.php +++ b/src/PhpWord/Shared/ZipStreamWrapper.php @@ -1,8 +1,8 @@ _archive = new ZipArchive(); + $this->_archive = new \ZipArchive(); $this->_archive->open($url['host']); $this->_fileNameInArchive = $url['fragment']; @@ -159,7 +159,7 @@ public function stream_eof() 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 @@ public function stream_seek($offset, $whence) } break; - case SEEK_CUR: + case \SEEK_CUR: if ($offset >= 0) { $this->_position += $offset; return true; @@ -177,7 +177,7 @@ public function stream_seek($offset, $whence) } break; - case SEEK_END: + case \SEEK_END: if (strlen($this->_data) + $offset >= 0) { $this->_position = strlen($this->_data) + $offset; return true; diff --git a/Classes/PHPWord/Style.php b/src/PhpWord/Style.php similarity index 78% rename from Classes/PHPWord/Style.php rename to src/PhpWord/Style.php index e82728e154..8758a767ef 100755 --- a/Classes/PHPWord/Style.php +++ b/src/PhpWord/Style.php @@ -1,8 +1,8 @@ $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; @@ -61,8 +56,6 @@ public static function addParagraphStyle($styleName, $styles) } /** - * Add a font style - * * @param string $styleName * @param array $styleFont * @param array $styleParagraph @@ -70,7 +63,7 @@ public static function addParagraphStyle($styleName, $styles) public static function addFontStyle($styleName, $styleFont, $styleParagraph = null) { if (!array_key_exists($styleName, self::$_styleElements)) { - $font = new PHPWord_Style_Font('text', $styleParagraph); + $font = new Font('text', $styleParagraph); foreach ($styleFont as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; @@ -82,15 +75,13 @@ public static function addFontStyle($styleName, $styleFont, $styleParagraph = nu } /** - * Add a link style - * * @param string $styleName * @param array $styles */ public static function addLinkStyle($styleName, $styles) { if (!array_key_exists($styleName, self::$_styleElements)) { - $style = new PHPWord_Style_Font('link'); + $style = new Font('link'); foreach ($styles as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; @@ -103,34 +94,28 @@ public static function addLinkStyle($styleName, $styles) } /** - * Add a table style - * * @param string $styleName - * @param array $styleTable - * @param null|array $styleFirstRow - * @param null|array $styleLastRow + * @param array $styles */ - public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null, $styleLastRow = null) + public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null) { if (!array_key_exists($styleName, self::$_styleElements)) { - $style = new PHPWord_Style_TableFull($styleTable, $styleFirstRow, $styleLastRow); + $style = new TableFull($styleTable, $styleFirstRow); self::$_styleElements[$styleName] = $style; } } /** - * Add a title style - * - * @param int $titleCount + * @param string $styleName * @param array $styleFont - * @param nullarray $styleParagraph + * @param array $styleParagraph */ public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null) { $styleName = 'Heading_' . $titleCount; if (!array_key_exists($styleName, self::$_styleElements)) { - $font = new PHPWord_Style_Font('title', $styleParagraph); + $font = new Font('title', $styleParagraph); foreach ($styleFont as $key => $value) { if (substr($key, 0, 1) != '_') { $key = '_' . $key; @@ -143,8 +128,6 @@ public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = } /** - * Set default paragraph style - * * @param array $styles Paragraph style definition */ public static function setDefaultParagraphStyle($styles) @@ -155,7 +138,7 @@ public static function setDefaultParagraphStyle($styles) /** * Get all styles * - * @return array + * @return \PhpOffice\PhpWord\Style\Font[] */ public static function getStyles() { @@ -163,10 +146,7 @@ public static function getStyles() } /** - * Get style - * - * @param string $styleName - * @return null|PHPWord_Style + * @param string */ public static function getStyle($styleName) { diff --git a/Classes/PHPWord/Style/Cell.php b/src/PhpWord/Style/Cell.php old mode 100755 new mode 100644 similarity index 97% rename from Classes/PHPWord/Style/Cell.php rename to src/PhpWord/Style/Cell.php index 2f733784e9..2ae3cf8a0b --- a/Classes/PHPWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -1,8 +1,8 @@ _type = $type; - if ($paragraphStyle instanceof PHPWord_Style_Paragraph) { + if ($paragraphStyle instanceof Paragraph) { $this->_paragraphStyle = $paragraphStyle; } elseif (is_array($paragraphStyle)) { - $this->_paragraphStyle = new PHPWord_Style_Paragraph; + $this->_paragraphStyle = new Paragraph; $this->_paragraphStyle->setArrayStyle($paragraphStyle); } else { $this->_paragraphStyle = $paragraphStyle; @@ -206,10 +188,8 @@ public function setArrayStyle(array $style = array()) } /** - * Set style value - * - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value */ public function setStyleValue($key, $value) { @@ -222,7 +202,7 @@ public function setStyleValue($key, $value) /** * Get font name * - * @return bool + * @return bool */ public function getName() { @@ -232,13 +212,13 @@ public function getName() /** * Set font name * - * @param string $pValue - * @return PHPWord_Style_Font + * @param string $pValue + * @return \PhpOffice\PhpWord\Style\Font */ - public function setName($pValue = PHPWord::DEFAULT_FONT_NAME) + public function setName($pValue = PhpWord::DEFAULT_FONT_NAME) { if (is_null($pValue) || $pValue == '') { - $pValue = PHPWord::DEFAULT_FONT_NAME; + $pValue = PhpWord::DEFAULT_FONT_NAME; } $this->_name = $pValue; return $this; @@ -258,22 +238,20 @@ public function getSize() /** * Set font size * - * @param int|float $pValue - * @return PHPWord_Style_Font + * @param int|float $pValue + * @return \PhpOffice\PhpWord\Style\Font */ - public function setSize($pValue = PHPWord::DEFAULT_FONT_SIZE) + public function setSize($pValue = PhpWord::DEFAULT_FONT_SIZE) { if (!is_numeric($pValue)) { - $pValue = PHPWord::DEFAULT_FONT_SIZE; + $pValue = PhpWord::DEFAULT_FONT_SIZE; } $this->_size = $pValue; return $this; } /** - * Get bold - * - * @return bool + * @return bool */ public function getBold() { @@ -281,10 +259,8 @@ public function getBold() } /** - * Set bold - * - * @param bool $pValue - * @return PHPWord_Style_Font + * @param bool $pValue + * @return \PhpOffice\PhpWord\Style\Font */ public function setBold($pValue = false) { @@ -296,9 +272,7 @@ public function setBold($pValue = false) } /** - * Get italics - * - * @return bool + * @return bool */ public function getItalic() { @@ -306,10 +280,8 @@ public function getItalic() } /** - * Set italics - * - * @param bool $pValue - * @return PHPWord_Style_Font + * @param bool $pValue + * @return \PhpOffice\PhpWord\Style\Font */ public function setItalic($pValue = false) { @@ -321,9 +293,7 @@ public function setItalic($pValue = false) } /** - * Get superscript - * - * @return bool + * @return bool */ public function getSuperScript() { @@ -331,10 +301,8 @@ public function getSuperScript() } /** - * Set superscript - * - * @param bool $pValue - * @return PHPWord_Style_Font + * @param bool $pValue + * @return \PhpOffice\PhpWord\Style\Font */ public function setSuperScript($pValue = false) { @@ -347,9 +315,7 @@ public function setSuperScript($pValue = false) } /** - * Get superscript - * - * @return bool + * @return bool */ public function getSubScript() { @@ -357,10 +323,8 @@ public function getSubScript() } /** - * Set subscript - * - * @param bool $pValue - * @return PHPWord_Style_Font + * @param bool $pValue + * @return \PhpOffice\PhpWord\Style\Font */ public function setSubScript($pValue = false) { @@ -373,9 +337,7 @@ public function setSubScript($pValue = false) } /** - * Get underline - * - * @return string + * @return string */ public function getUnderline() { @@ -383,24 +345,20 @@ public function getUnderline() } /** - * Set underline - * - * @param string $pValue - * @return PHPWord_Style_Font + * @param string $pValue + * @return \PhpOffice\PhpWord\Style\Font */ - public function setUnderline($pValue = PHPWord_Style_Font::UNDERLINE_NONE) + public function setUnderline($pValue = self::UNDERLINE_NONE) { if ($pValue == '') { - $pValue = PHPWord_Style_Font::UNDERLINE_NONE; + $pValue = self::UNDERLINE_NONE; } $this->_underline = $pValue; return $this; } /** - * Get strikethrough - * - * @return bool + * @return bool */ public function getStrikethrough() { @@ -408,10 +366,8 @@ public function getStrikethrough() } /** - * Set strikethrough - * - * @param bool $pValue - * @return PHPWord_Style_Font + * @param bool $pValue + * @return \PhpOffice\PhpWord\Style\Font */ public function setStrikethrough($pValue = false) { @@ -425,7 +381,7 @@ public function setStrikethrough($pValue = false) /** * Get font color * - * @return string + * @return string */ public function getColor() { @@ -433,15 +389,13 @@ public function getColor() } /** - * Set font color - * - * @param string $pValue - * @return PHPWord_Style_Font + * @param string $pValue + * @return \PhpOffice\PhpWord\Style\Font */ - public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR) + public function setColor($pValue = PhpWord::DEFAULT_FONT_COLOR) { if (is_null($pValue) || $pValue == '') { - $pValue = PHPWord::DEFAULT_FONT_COLOR; + $pValue = PhpWord::DEFAULT_FONT_COLOR; } $this->_color = $pValue; return $this; @@ -450,7 +404,7 @@ public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR) /** * Get foreground/highlight color * - * @return bool + * @return bool */ public function getFgColor() { @@ -460,8 +414,8 @@ public function getFgColor() /** * Set foreground/highlight color * - * @param string $pValue - * @return PHPWord_Style_Font + * @param string $pValue + * @return \PhpOffice\PhpWord\Style\Font */ public function setFgColor($pValue = null) { @@ -470,8 +424,6 @@ public function setFgColor($pValue = null) } /** - * Get style type - * * @return string */ public function getStyleType() @@ -480,9 +432,7 @@ public function getStyleType() } /** - * Get paragraph style - * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { @@ -490,11 +440,9 @@ public function getParagraphStyle() } /** - * Set the line height - * - * @param int|float|string $lineHeight + * @param int|float|string $lineHeight * @return $this - * @throws InvalidStyleException + * @throws \PhpOffice\PhpWord\Exceptions\InvalidStyleException */ public function setLineHeight($lineHeight) { @@ -534,13 +482,13 @@ public function getHint() /** * Set Font Content Type * - * @param string $pValue - * @return PHPWord_Style_Font + * @param string $pValue + * @return \PhpOffice\PhpWord\Style\Font */ - public function setHint($pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE) + public function setHint($pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE) { if (is_null($pValue) || $pValue == '') { - $pValue = PHPWord::DEFAULT_FONT_CONTENT_TYPE; + $pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE; } $this->_hint = $pValue; return $this; diff --git a/Classes/PHPWord/Style/Image.php b/src/PhpWord/Style/Image.php old mode 100755 new mode 100644 similarity index 93% rename from Classes/PHPWord/Style/Image.php rename to src/PhpWord/Style/Image.php index a6a128c9ab..5db9446c53 --- a/Classes/PHPWord/Style/Image.php +++ b/src/PhpWord/Style/Image.php @@ -1,8 +1,8 @@ wrappingStyle = $wrappingStyle; break; default: - throw new InvalidArgumentException('Wrapping style does not exists'); + throw new \InvalidArgumentException('Wrapping style does not exists'); break; } return $this; diff --git a/Classes/PHPWord/Style/ListItem.php b/src/PhpWord/Style/ListItem.php old mode 100755 new mode 100644 similarity index 82% rename from Classes/PHPWord/Style/ListItem.php rename to src/PhpWord/Style/ListItem.php index 5fbff0d6fb..d0d6c75086 --- a/Classes/PHPWord/Style/ListItem.php +++ b/src/PhpWord/Style/ListItem.php @@ -1,8 +1,8 @@ _listType = PHPWord_Style_ListItem::TYPE_BULLET_FILLED; + $this->_listType = self::TYPE_BULLET_FILLED; } /** @@ -67,7 +63,7 @@ public function setStyleValue($key, $value) * * @param int $pValue */ - public function setListType($pValue = PHPWord_Style_ListItem::TYPE_BULLET_FILLED) + public function setListType($pValue = self::TYPE_BULLET_FILLED) { $this->_listType = $pValue; } diff --git a/Classes/PHPWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php similarity index 90% rename from Classes/PHPWord/Style/Paragraph.php rename to src/PhpWord/Style/Paragraph.php index 14e1f8e0cd..b4d9006f67 100755 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -1,8 +1,8 @@ _tabs; } - /** + /* * Set tabs * - * @param array $pValue - * @return PHPWord_Style_Paragraph + * @param array $pValue + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function setTabs($pValue = null) { if (is_array($pValue)) { - $this->_tabs = new PHPWord_Style_Tabs($pValue); + $this->_tabs = new Tabs($pValue); } return $this; } @@ -349,7 +344,7 @@ public function getBasedOn() * Set parent style ID * * @param string $pValue - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function setBasedOn($pValue = 'Normal') { @@ -371,7 +366,7 @@ public function getNext() * Set style for next paragraph * * @param string $pValue - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function setNext($pValue = null) { @@ -393,7 +388,7 @@ public function getWidowControl() * Set keep paragraph with next paragraph setting * * @param bool $pValue - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function setWidowControl($pValue = true) { @@ -418,7 +413,7 @@ public function getKeepNext() * Set keep paragraph with next paragraph setting * * @param bool $pValue - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function setKeepNext($pValue = false) { @@ -443,7 +438,7 @@ public function getKeepLines() * Set keep all lines on one page setting * * @param bool $pValue - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function setKeepLines($pValue = false) { @@ -468,7 +463,7 @@ public function getPageBreakBefore() * Set start paragraph on next page setting * * @param bool $pValue - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function setPageBreakBefore($pValue = false) { @@ -484,7 +479,7 @@ public function setPageBreakBefore($pValue = false) * * @param int|float|string $lineHeight * @return $this - * @throws InvalidStyleException + * @throws \PhpOffice\PhpWord\Exceptions\InvalidStyleException */ public function setLineHeight($lineHeight) { @@ -502,8 +497,6 @@ public function setLineHeight($lineHeight) } /** - * Get line height - * * @return int|float */ public function getLineHeight() diff --git a/Classes/PHPWord/Style/Row.php b/src/PhpWord/Style/Row.php similarity index 92% rename from Classes/PHPWord/Style/Row.php rename to src/PhpWord/Style/Row.php index da039d84b5..e039ee5e0b 100644 --- a/Classes/PHPWord/Style/Row.php +++ b/src/PhpWord/Style/Row.php @@ -1,8 +1,8 @@ _tabPos = 9062; - $this->_tabLeader = PHPWord_Style_TOC::TABLEADER_DOT; + $this->_tabLeader = self::TABLEADER_DOT; $this->_indent = 200; } @@ -103,7 +99,7 @@ public function getTabLeader() * * @param string $pValue */ - public function setTabLeader($pValue = PHPWord_Style_TOC::TABLEADER_DOT) + public function setTabLeader($pValue = self::TABLEADER_DOT) { $this->_tabLeader = $pValue; } diff --git a/Classes/PHPWord/Style/Tab.php b/src/PhpWord/Style/Tab.php old mode 100755 new mode 100644 similarity index 82% rename from Classes/PHPWord/Style/Tab.php rename to src/PhpWord/Style/Tab.php index 8db7abae17..d55e914abb --- a/Classes/PHPWord/Style/Tab.php +++ b/src/PhpWord/Style/Tab.php @@ -1,8 +1,8 @@ startElement("w:tab"); - $objWriter->writeAttribute("w:val", $this->_val); + if (isset($xmlWriter)) { + $xmlWriter->startElement("w:tab"); + $xmlWriter->writeAttribute("w:val", $this->_val); if (!is_null($this->_leader)) { - $objWriter->writeAttribute("w:leader", $this->_leader); + $xmlWriter->writeAttribute("w:leader", $this->_leader); } - $objWriter->writeAttribute("w:pos", $this->_position); - $objWriter->endElement(); + $xmlWriter->writeAttribute("w:pos", $this->_position); + $xmlWriter->endElement(); } } diff --git a/Classes/PHPWord/Style/Table.php b/src/PhpWord/Style/Table.php similarity index 67% rename from Classes/PHPWord/Style/Table.php rename to src/PhpWord/Style/Table.php index 223e31c260..15c766d21b 100755 --- a/Classes/PHPWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -1,8 +1,8 @@ _cellMarginTop = null; @@ -69,92 +40,51 @@ public function __construct() $this->_cellMarginBottom = null; } - /** - * Set style value - * - * @param string $key - * @param mixed $value - */ public function setStyleValue($key, $value) { $this->$key = $value; } - /** - * Set cell margin top - * - * @param int $pValue - */ public function setCellMarginTop($pValue = null) { $this->_cellMarginTop = $pValue; } - /** - * Get cell margin top - */ public function getCellMarginTop() { return $this->_cellMarginTop; } - /** - * Set cell margin left - * - * @param int $pValue - */ public function setCellMarginLeft($pValue = null) { $this->_cellMarginLeft = $pValue; } - /** - * Get cell margin left - */ public function getCellMarginLeft() { return $this->_cellMarginLeft; } - /** - * Set cell margin right - * - * @param int $pValue - */ public function setCellMarginRight($pValue = null) { $this->_cellMarginRight = $pValue; } - /** - * Get cell margin right - */ public function getCellMarginRight() { return $this->_cellMarginRight; } - /** - * Set cell margin bottom - * - * @param int $pValue - */ public function setCellMarginBottom($pValue = null) { $this->_cellMarginBottom = $pValue; } - /** - * Get cell margin bottom - */ public function getCellMarginBottom() { return $this->_cellMarginBottom; } - /** - * Get cell margin - */ public function getCellMargin() { return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom); diff --git a/Classes/PHPWord/Style/TableFull.php b/src/PhpWord/Style/TableFull.php similarity index 73% rename from Classes/PHPWord/Style/TableFull.php rename to src/PhpWord/Style/TableFull.php index 8d14536622..f6d8114b11 100755 --- a/Classes/PHPWord/Style/TableFull.php +++ b/src/PhpWord/Style/TableFull.php @@ -1,8 +1,8 @@ _firstRow = clone $this; @@ -199,8 +153,6 @@ public function __construct($styleTable = null, $styleFirstRow = null, $styleLas } /** - * Set style value - * * @param string $key * @param mixed $value */ @@ -220,7 +172,7 @@ public function setStyleValue($key, $value) /** * Get First Row Style * - * @return PHPWord_Style_TableFull + * @return \PhpOffice\PhpWord\Style\TableFull */ public function getFirstRow() { @@ -230,26 +182,18 @@ public function getFirstRow() /** * Get Last Row Style * - * @return PHPWord_Style_TableFull + * @return \PhpOffice\PhpWord\Style\TableFull */ public function getLastRow() { return $this->_lastRow; } - /** - * Get background color - */ public function getBgColor() { return $this->_bgColor; } - /** - * Set background color - * - * @param string $pValue - */ public function setBgColor($pValue = null) { $this->_bgColor = $pValue; @@ -258,7 +202,7 @@ public function setBgColor($pValue = null) /** * Set TLRBVH Border Size * - * @param int $pValue Border size in eighths of a point (1/8 point) + * @param int $pValue Border size in eighths of a point (1/8 point) */ public function setBorderSize($pValue = null) { @@ -289,8 +233,6 @@ public function getBorderSize() /** * Set TLRBVH Border Color - * - * @param string $pValue */ public function setBorderColor($pValue = null) { @@ -319,293 +261,161 @@ public function getBorderColor() return array($t, $l, $r, $b, $h, $v); } - /** - * Set border top size - * - * @param int $pValue - */ public function setBorderTopSize($pValue = null) { $this->_borderTopSize = $pValue; } - /** - * Get border top size - */ public function getBorderTopSize() { return $this->_borderTopSize; } - /** - * Set border top color - * - * @param string $pValue - */ public function setBorderTopColor($pValue = null) { $this->_borderTopColor = $pValue; } - /** - * Get border top color - */ public function getBorderTopColor() { return $this->_borderTopColor; } - /** - * Set border left size - * - * @param int $pValue - */ public function setBorderLeftSize($pValue = null) { $this->_borderLeftSize = $pValue; } - /** - * Get border left size - */ public function getBorderLeftSize() { return $this->_borderLeftSize; } - /** - * Set border left color - * - * @param string $pValue - */ public function setBorderLeftColor($pValue = null) { $this->_borderLeftColor = $pValue; } - /** - * Get border left color - */ public function getBorderLeftColor() { return $this->_borderLeftColor; } - /** - * Set border right size - * - * @param int $pValue - */ public function setBorderRightSize($pValue = null) { $this->_borderRightSize = $pValue; } - /** - * Get border right size - * - * @param int $pValue - */ public function getBorderRightSize() { return $this->_borderRightSize; } - /** - * Set border right color - * - * @param string $pValue - */ public function setBorderRightColor($pValue = null) { $this->_borderRightColor = $pValue; } - /** - * Get border right color - */ public function getBorderRightColor() { return $this->_borderRightColor; } - /** - * Set border bottom size - * - * - * @param string $pValue - * @param int $pValue - */ public function setBorderBottomSize($pValue = null) { $this->_borderBottomSize = $pValue; } - /** - * Get border bottom size - */ public function getBorderBottomSize() { return $this->_borderBottomSize; } - /** - * Set border bottom color - * - * @param string $pValue - */ public function setBorderBottomColor($pValue = null) { $this->_borderBottomColor = $pValue; } - /** - * Get border bottom color - */ public function getBorderBottomColor() { return $this->_borderBottomColor; } - /** - * Set border inside horizontal color - * - * @param string $pValue - */ public function setBorderInsideHColor($pValue = null) { $this->_borderInsideHColor = $pValue; } - /** - * Get border inside horizontal color - */ public function getBorderInsideHColor() { return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null; } - /** - * Set border inside vertical color - * - * @param string $pValue - */ public function setBorderInsideVColor($pValue = null) { $this->_borderInsideVColor = $pValue; } - /** - * Get border inside vertical color - */ public function getBorderInsideVColor() { return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null; } - /** - * Set border inside horizontal size - * - * @param int $pValue - */ public function setBorderInsideHSize($pValue = null) { $this->_borderInsideHSize = $pValue; } - /** - * Get border inside horizontal size - */ public function getBorderInsideHSize() { return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null; } - /** - * Set border inside vertical size - * - * @param int $pValue - */ public function setBorderInsideVSize($pValue = null) { $this->_borderInsideVSize = $pValue; } - /** - * Get border inside vertical size - */ public function getBorderInsideVSize() { return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null; } - /** - * Set cell margin top - * - * @param int $pValue - */ public function setCellMarginTop($pValue = null) { $this->_cellMarginTop = $pValue; } - /** - * Get cell margin top - */ public function getCellMarginTop() { return $this->_cellMarginTop; } - /** - * Set cell margin left - * - * @param int $pValue - */ public function setCellMarginLeft($pValue = null) { $this->_cellMarginLeft = $pValue; } - /** - * Get cell margin left - */ public function getCellMarginLeft() { return $this->_cellMarginLeft; } - /** - * Set cell margin right - * - * @param int $pValue - */ public function setCellMarginRight($pValue = null) { $this->_cellMarginRight = $pValue; } - /** - * Get cell margin right - */ public function getCellMarginRight() { return $this->_cellMarginRight; } - /** - * Set cell margin bottom - * - * @param int $pValue - */ public function setCellMarginBottom($pValue = null) { $this->_cellMarginBottom = $pValue; } - /** - * Get cell margin bottom - */ public function getCellMarginBottom() { return $this->_cellMarginBottom; @@ -624,9 +434,6 @@ public function setCellMargin($pValue = null) $this->_cellMarginBottom = $pValue; } - /** - * Get cell margin - */ public function getCellMargin() { return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom); diff --git a/Classes/PHPWord/Style/Tabs.php b/src/PhpWord/Style/Tabs.php similarity index 69% rename from Classes/PHPWord/Style/Tabs.php rename to src/PhpWord/Style/Tabs.php index ece1315f6e..f836532f32 100755 --- a/Classes/PHPWord/Style/Tabs.php +++ b/src/PhpWord/Style/Tabs.php @@ -1,8 +1,8 @@ startElement("w:tabs"); + if (isset($xmlWriter)) { + $xmlWriter->startElement("w:tabs"); foreach ($this->_tabs as &$tab) { - $tab->toXml($objWriter); + $tab->toXml($xmlWriter); } - $objWriter->endElement(); + $xmlWriter->endElement(); } } } diff --git a/Classes/PHPWord/TOC.php b/src/PhpWord/TOC.php old mode 100755 new mode 100644 similarity index 90% rename from Classes/PHPWord/TOC.php rename to src/PhpWord/TOC.php index 499fdd64cf..d4cffead95 --- a/Classes/PHPWord/TOC.php +++ b/src/PhpWord/TOC.php @@ -1,8 +1,8 @@ $value) { @@ -88,7 +86,7 @@ public function __construct($styleFont = null, $styleTOC = null) if (!is_null($styleFont)) { if (is_array($styleFont)) { - self::$_styleFont = new PHPWord_Style_Font(); + self::$_styleFont = new Font(); foreach ($styleFont as $key => $value) { if (substr($key, 0, 1) != '_') { @@ -138,7 +136,7 @@ public static function getTitles() /** * Get TOC Style * - * @return PHPWord_Style_TOC + * @return \PhpOffice\PhpWord\Style\TOC */ public static function getStyleTOC() { @@ -148,7 +146,7 @@ public static function getStyleTOC() /** * Get Font Style * - * @return PHPWord_Style_Font + * @return \PhpOffice\PhpWord\Style\Font */ public static function getStyleFont() { diff --git a/Classes/PHPWord/Template.php b/src/PhpWord/Template.php old mode 100755 new mode 100644 similarity index 91% rename from Classes/PHPWord/Template.php rename to src/PhpWord/Template.php index 752fa79222..b779b91d7f --- a/Classes/PHPWord/Template.php +++ b/src/PhpWord/Template.php @@ -1,8 +1,8 @@ _tempFileName}."); } - $this->_objZip = new ZipArchive(); + $this->_objZip = new \ZipArchive(); $this->_objZip->open($this->_tempFileName); $this->_documentXML = $this->_objZip->getFromName('word/document.xml'); @@ -82,14 +73,14 @@ public function __construct($strFilename) /** * Applies XSL style sheet to template's parts * - * @param DOMDocument $xslDOMDocument + * @param \DOMDocument $xslDOMDocument * @param array $xslOptions * @param string $xslOptionsURI - * @throws Exception + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ public function applyXslStyleSheet(&$xslDOMDocument, $xslOptions = array(), $xslOptionsURI = '') { - $processor = new XSLTProcessor(); + $processor = new \XSLTProcessor(); $processor->importStylesheet($xslDOMDocument); @@ -97,7 +88,7 @@ public function applyXslStyleSheet(&$xslDOMDocument, $xslOptions = array(), $xsl throw new Exception('Could not set values for the given XSL style sheet parameters.'); } - $xmlDOMDocument = new DOMDocument(); + $xmlDOMDocument = new \DOMDocument(); if ($xmlDOMDocument->loadXML($this->_documentXML) === false) { throw new Exception('Could not load XML from the given template.'); } @@ -132,7 +123,7 @@ public function setValue($search, $replace, $limit = -1) } if (!is_array($replace)) { - if (!PHPWord_Shared_String::IsUTF8($replace)) { + if (!String::isUTF8($replace)) { $replace = utf8_encode($replace); } $replace = htmlspecialchars($replace); @@ -161,7 +152,7 @@ public function getVariables() * * @param int $offset * @return int - * @throws Exception + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ private function _findRowStart($offset) { @@ -207,7 +198,7 @@ private function _getSlice($startPosition, $endPosition = 0) * * @param string $search * @param int $numberOfClones - * @throws Exception + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ public function cloneRow($search, $numberOfClones) { @@ -258,10 +249,8 @@ public function cloneRow($search, $numberOfClones) } /** - * Save Template - * * @return string - * @throws Exception + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ public function save() { @@ -276,8 +265,6 @@ public function save() } /** - * Save Template As... - * * @param string $strFilename */ public function saveAs($strFilename) @@ -290,4 +277,4 @@ public function saveAs($strFilename) rename($tempFilename, $strFilename); } -} \ No newline at end of file +} diff --git a/Classes/PHPWord/Writer/IWriter.php b/src/PhpWord/Writer/IWriter.php similarity index 76% rename from Classes/PHPWord/Writer/IWriter.php rename to src/PhpWord/Writer/IWriter.php index d00d2d404d..6f124d2960 100755 --- a/Classes/PHPWord/Writer/IWriter.php +++ b/src/PhpWord/Writer/IWriter.php @@ -1,8 +1,8 @@ setPHPWord($pPHPWord); + // Assign PhpWord + $this->setPhpWord($phpWord); // Set up disk caching location $this->_diskCachingDirectory = './'; // Initialise writer parts - $this->_writerParts['content'] = new PHPWord_Writer_ODText_Content(); - $this->_writerParts['manifest'] = new PHPWord_Writer_ODText_Manifest(); - $this->_writerParts['meta'] = new PHPWord_Writer_ODText_Meta(); - $this->_writerParts['mimetype'] = new PHPWord_Writer_ODText_Mimetype(); - $this->_writerParts['styles'] = new PHPWord_Writer_ODText_Styles(); + $this->_writerParts['content'] = new Content(); + $this->_writerParts['manifest'] = new Manifest(); + $this->_writerParts['meta'] = new Meta(); + $this->_writerParts['mimetype'] = new Mimetype(); + $this->_writerParts['styles'] = new Styles(); // Assign parent IWriter @@ -92,14 +90,14 @@ public function __construct(PHPWord $pPHPWord = null) } // Set HashTable variables - $this->_drawingHashTable = new PHPWord_HashTable(); + $this->_drawingHashTable = new HashTable(); } /** - * Save PHPWord to file + * Save PhpWord to file * - * @param string $pFilename - * @throws Exception + * @param string $pFileName + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ public function save($pFilename = null) { @@ -116,17 +114,17 @@ public function save($pFilename = null) // Create drawing dictionary // Create new ZIP file and open it for writing - $objZip = new ZipArchive(); + $objZip = new \ZipArchive(); // Try opening the ZIP file - if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) { - if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) { + if ($objZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) { + if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) { throw new Exception("Could not open " . $pFilename . " for writing."); } } // Add mimetype to ZIP file - //@todo Not in ZIPARCHIVE::CM_STORE mode + //@todo Not in \ZipArchive::CM_STORE mode $objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype($this->_document)); // Add content.xml to ZIP file @@ -152,7 +150,7 @@ public function save($pFilename = null) $imagePath = substr($imagePath, 6); $imagePathSplitted = explode('#', $imagePath); - $imageZip = new ZipArchive(); + $imageZip = new \ZipArchive(); $imageZip->open($imagePathSplitted[0]); $imageContents = $imageZip->getFromName($imagePathSplitted[1]); $imageZip->close(); @@ -190,43 +188,37 @@ public function save($pFilename = null) } } else { - throw new Exception("PHPWord object unassigned."); + throw new Exception("PhpWord object unassigned."); } } /** - * Get PHPWord object - * - * @return PHPWord - * @throws Exception + * @return \PhpOffice\PhpWord\PhpWord + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ - public function getPHPWord() + public function getPhpWord() { if (!is_null($this->_document)) { return $this->_document; } else { - throw new Exception("No PHPWord assigned."); + throw new Exception("No PhpWord assigned."); } } /** - * Get PHPWord object - * - * @param PHPWord $pPHPWord PHPWord object - * @throws Exception - * @return PHPWord_Writer_ODText + * @param \PhpOffice\PhpWord\PhpWord $phpWord + * @return \PhpOffice\PhpWord\Writer\ODText */ - public function setPHPWord(PHPWord $pPHPWord = null) + public function setPhpWord(PhpWord $phpWord = null) { - $this->_document = $pPHPWord; + $this->_document = $phpWord; return $this; } /** * Get PHPWord_Worksheet_BaseDrawing HashTable * - * @return PHPWord_HashTable - * @codeCoverageIgnore + * @return \PhpOffice\PhpWord\HashTable */ public function getDrawingHashTable() { @@ -234,10 +226,8 @@ public function getDrawingHashTable() } /** - * Get writer part - * * @param string $pPartName Writer part name - * @return PHPWord_Writer_ODText_WriterPart + * @return \PhpOffice\PhpWord\Writer\ODText\WriterPart */ public function getWriterPart($pPartName = '') { @@ -263,8 +253,8 @@ public function getUseDiskCaching() * * @param boolean $pValue * @param string $pDirectory Disk caching directory - * @throws Exception Exception when directory does not exist - * @return PHPWord_Writer_ODText + * @throws \PhpOffice\PhpWord\Exceptions\Exception Exception when directory does not exist + * @return \PhpOffice\PhpWord\Writer\ODText */ public function setUseDiskCaching($pValue = false, $pDirectory = null) { @@ -282,8 +272,6 @@ public function setUseDiskCaching($pValue = false, $pDirectory = null) } /** - * Get disk caching directory - * * @return string */ public function getDiskCachingDirectory() diff --git a/src/PhpWord/Writer/ODText/Content.php b/src/PhpWord/Writer/ODText/Content.php new file mode 100644 index 0000000000..8c725fa08b --- /dev/null +++ b/src/PhpWord/Writer/ODText/Content.php @@ -0,0 +1,409 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8'); + + // office:document-content + $xmlWriter->startElement('office:document-content'); + $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); + $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); + $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); + $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); + $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); + $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); + $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); + $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); + $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); + $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); + $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); + $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); + $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); + $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); + $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); + $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); + $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); + $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); + $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); + $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); + $xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); + $xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); + $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); + $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); + $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); + $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); + $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); + $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); + $xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); + $xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0'); + $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); + $xmlWriter->writeAttribute('office:version', '1.2'); + + // We firstly search all fonts used + $_sections = $phpWord->getSections(); + $countSections = count($_sections); + if ($countSections > 0) { + $pSection = 0; + $numPStyles = 0; + $numFStyles = 0; + + foreach ($_sections as $section) { + $pSection++; + $_elements = $section->getElements(); + + foreach ($_elements as $element) { + if ($element instanceof Text) { + $fStyle = $element->getFontStyle(); + $pStyle = $element->getParagraphStyle(); + + if ($fStyle instanceof Font) { + $numFStyles++; + + $arrStyle = array( + 'color' => $fStyle->getColor(), + 'name' => $fStyle->getName() + ); + $phpWord->addFontStyle('T' . $numFStyles, $arrStyle); + $element->setFontStyle('T' . $numFStyles); + } elseif ($pStyle instanceof Paragraph) { + $numPStyles++; + + $phpWord->addParagraphStyle('P' . $numPStyles, array()); + $element->setParagraphStyle('P' . $numPStyles); + } + } + } + } + } + + // office:font-face-decls + $xmlWriter->startElement('office:font-face-decls'); + $arrFonts = array(); + + $styles = Style::getStyles(); + $numFonts = 0; + if (count($styles) > 0) { + foreach ($styles as $styleName => $style) { + // PhpOffice\PhpWord\Style\Font + if ($style instanceof Font) { + $numFonts++; + $name = $style->getName(); + if (!in_array($name, $arrFonts)) { + $arrFonts[] = $name; + + // style:font-face + $xmlWriter->startElement('style:font-face'); + $xmlWriter->writeAttribute('style:name', $name); + $xmlWriter->writeAttribute('svg:font-family', $name); + $xmlWriter->endElement(); + } + } + } + if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) { + $xmlWriter->startElement('style:font-face'); + $xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME); + $xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME); + $xmlWriter->endElement(); + } + } + $xmlWriter->endElement(); + + $xmlWriter->startElement('office:automatic-styles'); + $styles = Style::getStyles(); + $numPStyles = 0; + if (count($styles) > 0) { + foreach ($styles as $styleName => $style) { + if (preg_match('#^T[0-9]+$#', $styleName) != 0 + || preg_match('#^P[0-9]+$#', $styleName) != 0 + ) { + // PhpOffice\PhpWord\Style\Font + if ($style instanceof Font) { + $xmlWriter->startElement('style:style'); + $xmlWriter->writeAttribute('style:name', $styleName); + $xmlWriter->writeAttribute('style:family', 'text'); + // style:text-properties + $xmlWriter->startElement('style:text-properties'); + $xmlWriter->writeAttribute('fo:color', '#' . $style->getColor()); + $xmlWriter->writeAttribute('style:font-name', $style->getName()); + $xmlWriter->writeAttribute('style:font-name-complex', $style->getName()); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + if ($style instanceof Paragraph) { + $numPStyles++; + // style:style + $xmlWriter->startElement('style:style'); + $xmlWriter->writeAttribute('style:name', $styleName); + $xmlWriter->writeAttribute('style:family', 'paragraph'); + $xmlWriter->writeAttribute('style:parent-style-name', 'Standard'); + $xmlWriter->writeAttribute('style:master-page-name', 'Standard'); + // style:paragraph-properties + $xmlWriter->startElement('style:paragraph-properties'); + $xmlWriter->writeAttribute('style:page-number', 'auto'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + } + } + + if ($numPStyles == 0) { + // style:style + $xmlWriter->startElement('style:style'); + $xmlWriter->writeAttribute('style:name', 'P1'); + $xmlWriter->writeAttribute('style:family', 'paragraph'); + $xmlWriter->writeAttribute('style:parent-style-name', 'Standard'); + $xmlWriter->writeAttribute('style:master-page-name', 'Standard'); + // style:paragraph-properties + $xmlWriter->startElement('style:paragraph-properties'); + $xmlWriter->writeAttribute('style:page-number', 'auto'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + } + $xmlWriter->endElement(); + + // office:body + $xmlWriter->startElement('office:body'); + // office:text + $xmlWriter->startElement('office:text'); + // text:sequence-decls + $xmlWriter->startElement('text:sequence-decls'); + // text:sequence-decl + $xmlWriter->startElement('text:sequence-decl'); + $xmlWriter->writeAttribute('text:display-outline-level', 0); + $xmlWriter->writeAttribute('text:name', 'Illustration'); + $xmlWriter->endElement(); + // text:sequence-decl + $xmlWriter->startElement('text:sequence-decl'); + $xmlWriter->writeAttribute('text:display-outline-level', 0); + $xmlWriter->writeAttribute('text:name', 'Table'); + $xmlWriter->endElement(); + // text:sequence-decl + $xmlWriter->startElement('text:sequence-decl'); + $xmlWriter->writeAttribute('text:display-outline-level', 0); + $xmlWriter->writeAttribute('text:name', 'Text'); + $xmlWriter->endElement(); + // text:sequence-decl + $xmlWriter->startElement('text:sequence-decl'); + $xmlWriter->writeAttribute('text:display-outline-level', 0); + $xmlWriter->writeAttribute('text:name', 'Drawing'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $_sections = $phpWord->getSections(); + $countSections = count($_sections); + $pSection = 0; + + if ($countSections > 0) { + foreach ($_sections as $section) { + $pSection++; + + $_elements = $section->getElements(); + + foreach ($_elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element); + } elseif ($element instanceof TextRun) { + $this->_writeTextRun($xmlWriter, $element); + } elseif ($element instanceof TextBreak) { + $this->_writeTextBreak($xmlWriter); + } elseif ($element instanceof Link) { + $this->writeUnsupportedElement($xmlWriter, 'Link'); + } elseif ($element instanceof Title) { + $this->writeUnsupportedElement($xmlWriter, 'Title'); + } elseif ($element instanceof PageBreak) { + $this->writeUnsupportedElement($xmlWriter, 'Page Break'); + } elseif ($element instanceof Table) { + $this->writeUnsupportedElement($xmlWriter, 'Table'); + } elseif ($element instanceof ListItem) { + $this->writeUnsupportedElement($xmlWriter, 'List Item'); + } elseif ($element instanceof Image || + $element instanceof MemoryImage) { + $this->writeUnsupportedElement($xmlWriter, 'Image'); + } elseif ($element instanceof Object) { + $this->writeUnsupportedElement($xmlWriter, 'Object'); + } elseif ($element instanceof TOC) { + $this->writeUnsupportedElement($xmlWriter, 'TOC'); + } else { + $this->writeUnsupportedElement($xmlWriter, 'Element'); + } + } + + if ($pSection == $countSections) { + $this->_writeEndSection($xmlWriter, $section); + } else { + $this->_writeSection($xmlWriter, $section); + } + } + } + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } + + /** + * Write text + * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Section\Text $text + * @param bool $withoutP + */ + protected function _writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false) + { + $styleFont = $text->getFontStyle(); + $styleParagraph = $text->getParagraphStyle(); + + // @todo Commented for TextRun. Should really checkout this value + // $SfIsObject = ($styleFont instanceof Font) ? true : false; + $SfIsObject = false; + + if ($SfIsObject) { + // Don't never be the case, because I browse all sections for cleaning all styles not declared + die('PhpWord : $SfIsObject wouldn\'t be an object'); + } else { + if (!$withoutP) { + $xmlWriter->startElement('text:p'); // text:p + } + if (empty($styleFont)) { + if (empty($styleParagraph)) { + $xmlWriter->writeAttribute('text:style-name', 'P1'); + } else { + $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); + } + $xmlWriter->writeRaw($text->getText()); + } else { + if (empty($styleParagraph)) { + $xmlWriter->writeAttribute('text:style-name', 'Standard'); + } else { + $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); + } + // text:span + $xmlWriter->startElement('text:span'); + $xmlWriter->writeAttribute('text:style-name', $styleFont); + $xmlWriter->writeRaw($text->getText()); + $xmlWriter->endElement(); + } + if (!$withoutP) { + $xmlWriter->endElement(); // text:p + } + } + } + + /** + * Write TextRun section + * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Section\TextRun $textrun + * @todo Enable all other section types + */ + protected function _writeTextRun(XMLWriter $xmlWriter, TextRun $textrun) + { + $elements = $textrun->getElements(); + $xmlWriter->startElement('text:p'); + if (count($elements) > 0) { + foreach ($elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element, true); + } + } + } + $xmlWriter->endElement(); + } + + /** + * Write TextBreak + */ + protected function _writeTextBreak(XMLWriter $xmlWriter = null) + { + $xmlWriter->startElement('text:p'); + $xmlWriter->writeAttribute('text:style-name', 'Standard'); + $xmlWriter->endElement(); + } + + // @codeCoverageIgnoreStart + private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null) + { + } + + private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null) + { + } + // @codeCoverageIgnoreEnd + + /** + * Write unsupported element + * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param string $element + */ + private function writeUnsupportedElement($xmlWriter, $element) + { + $xmlWriter->startElement('text:p'); + $xmlWriter->writeRaw($element); + $xmlWriter->endElement(); + } +} diff --git a/Classes/PHPWord/Writer/ODText/Manifest.php b/src/PhpWord/Writer/ODText/Manifest.php similarity index 53% rename from Classes/PHPWord/Writer/ODText/Manifest.php rename to src/PhpWord/Writer/ODText/Manifest.php index 0d627ec96c..ddc5cd9525 100755 --- a/Classes/PHPWord/Writer/ODText/Manifest.php +++ b/src/PhpWord/Writer/ODText/Manifest.php @@ -1,8 +1,8 @@ getParentWriter()->getUseDiskCaching()) { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header - $objWriter->startDocument('1.0', 'UTF-8'); + $xmlWriter->startDocument('1.0', 'UTF-8'); // manifest:manifest - $objWriter->startElement('manifest:manifest'); - $objWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'); - $objWriter->writeAttribute('manifest:version', '1.2'); + $xmlWriter->startElement('manifest:manifest'); + $xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'); + $xmlWriter->writeAttribute('manifest:version', '1.2'); // manifest:file-entry - $objWriter->startElement('manifest:file-entry'); - $objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text'); - $objWriter->writeAttribute('manifest:version', '1.2'); - $objWriter->writeAttribute('manifest:full-path', '/'); - $objWriter->endElement(); + $xmlWriter->startElement('manifest:file-entry'); + $xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text'); + $xmlWriter->writeAttribute('manifest:version', '1.2'); + $xmlWriter->writeAttribute('manifest:full-path', '/'); + $xmlWriter->endElement(); // manifest:file-entry - $objWriter->startElement('manifest:file-entry'); - $objWriter->writeAttribute('manifest:media-type', 'text/xml'); - $objWriter->writeAttribute('manifest:full-path', 'content.xml'); - $objWriter->endElement(); + $xmlWriter->startElement('manifest:file-entry'); + $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); + $xmlWriter->writeAttribute('manifest:full-path', 'content.xml'); + $xmlWriter->endElement(); // manifest:file-entry - $objWriter->startElement('manifest:file-entry'); - $objWriter->writeAttribute('manifest:media-type', 'text/xml'); - $objWriter->writeAttribute('manifest:full-path', 'meta.xml'); - $objWriter->endElement(); + $xmlWriter->startElement('manifest:file-entry'); + $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); + $xmlWriter->writeAttribute('manifest:full-path', 'meta.xml'); + $xmlWriter->endElement(); // manifest:file-entry - $objWriter->startElement('manifest:file-entry'); - $objWriter->writeAttribute('manifest:media-type', 'text/xml'); - $objWriter->writeAttribute('manifest:full-path', 'styles.xml'); - $objWriter->endElement(); + $xmlWriter->startElement('manifest:file-entry'); + $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); + $xmlWriter->writeAttribute('manifest:full-path', 'styles.xml'); + $xmlWriter->endElement(); // Not used yet. Legacy from PHPExcel // @codeCoverageIgnoreStart @@ -84,10 +85,10 @@ public function writeManifest(PHPWord $pPHPWord = null) $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension()); $mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath()); - $objWriter->startElement('manifest:file-entry'); - $objWriter->writeAttribute('manifest:media-type', $mimeType); - $objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename())); - $objWriter->endElement(); + $xmlWriter->startElement('manifest:file-entry'); + $xmlWriter->writeAttribute('manifest:media-type', $mimeType); + $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename())); + $xmlWriter->endElement(); } elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) { $extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType()); $extension = explode('/', $extension); @@ -95,32 +96,31 @@ public function writeManifest(PHPWord $pPHPWord = null) $mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType(); - $objWriter->startElement('manifest:file-entry'); - $objWriter->writeAttribute('manifest:media-type', $mimeType); - $objWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename())); - $objWriter->endElement(); + $xmlWriter->startElement('manifest:file-entry'); + $xmlWriter->writeAttribute('manifest:media-type', $mimeType); + $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename())); + $xmlWriter->endElement(); } } // @codeCoverageIgnoreEnd - $objWriter->endElement(); + $xmlWriter->endElement(); // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } /** * Get image mime type * - * @param string $pFile Filename - * @return string Mime Type - * @throws Exception - * @codeCoverageIgnore Image is not yet handled by ODText + * @param string $pFile Filename + * @return string Mime Type + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ private function _getImageMimeType($pFile = '') { - if (PHPWord_Shared_File::file_exists($pFile)) { + if (File::file_exists($pFile)) { $image = getimagesize($pFile); return image_type_to_mime_type($image[2]); } else { diff --git a/src/PhpWord/Writer/ODText/Meta.php b/src/PhpWord/Writer/ODText/Meta.php new file mode 100644 index 0000000000..16814cb3b1 --- /dev/null +++ b/src/PhpWord/Writer/ODText/Meta.php @@ -0,0 +1,93 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8'); + + // office:document-meta + $xmlWriter->startElement('office:document-meta'); + $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); + $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); + $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); + $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); + $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); + $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); + $xmlWriter->writeAttribute('office:version', '1.2'); + + // office:meta + $xmlWriter->startElement('office:meta'); + + // dc:creator + $xmlWriter->writeElement('dc:creator', $phpWord->getDocumentProperties()->getLastModifiedBy()); + // dc:date + $xmlWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $phpWord->getDocumentProperties()->getModified())); + // dc:description + $xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription()); + // dc:subject + $xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject()); + // dc:title + $xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle()); + // meta:creation-date + $xmlWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $phpWord->getDocumentProperties()->getCreated())); + // meta:initial-creator + $xmlWriter->writeElement('meta:initial-creator', $phpWord->getDocumentProperties()->getCreator()); + // meta:keyword + $xmlWriter->writeElement('meta:keyword', $phpWord->getDocumentProperties()->getKeywords()); + + // @todo : Where these properties are written ? + // $phpWord->getDocumentProperties()->getCategory() + // $phpWord->getDocumentProperties()->getCompany() + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } +} diff --git a/Classes/PHPWord/Writer/ODText/Mimetype.php b/src/PhpWord/Writer/ODText/Mimetype.php old mode 100755 new mode 100644 similarity index 69% rename from Classes/PHPWord/Writer/ODText/Mimetype.php rename to src/PhpWord/Writer/ODText/Mimetype.php index af3b33485b..77eb0a5a00 --- a/Classes/PHPWord/Writer/ODText/Mimetype.php +++ b/src/PhpWord/Writer/ODText/Mimetype.php @@ -1,8 +1,8 @@ getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8'); + + // Styles:Styles + $xmlWriter->startElement('office:document-styles'); + $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); + $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); + $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); + $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); + $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); + $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); + $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); + $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); + $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); + $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); + $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); + $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); + $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); + $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); + $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); + $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); + $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); + $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); + $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); + $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); + $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); + $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); + $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); + $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); + $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); + $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); + $xmlWriter->writeAttribute('office:version', '1.2'); + + + // office:font-face-decls + $xmlWriter->startElement('office:font-face-decls'); + $arrFonts = array(); + $styles = Style::getStyles(); + $numFonts = 0; + if (count($styles) > 0) { + foreach ($styles as $styleName => $style) { + // PhpOffice\PhpWord\Style\Font + if ($style instanceof Font) { + $numFonts++; + $name = $style->getName(); + if (!in_array($name, $arrFonts)) { + $arrFonts[] = $name; + + // style:font-face + $xmlWriter->startElement('style:font-face'); + $xmlWriter->writeAttribute('style:name', $name); + $xmlWriter->writeAttribute('svg:font-family', $name); + $xmlWriter->endElement(); + } + } + } + } + if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) { + $xmlWriter->startElement('style:font-face'); + $xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME); + $xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + + // office:styles + $xmlWriter->startElement('office:styles'); + + // style:default-style + $xmlWriter->startElement('style:default-style'); + $xmlWriter->writeAttribute('style:family', 'paragraph'); + + // style:paragraph-properties + $xmlWriter->startElement('style:paragraph-properties'); + $xmlWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit'); + $xmlWriter->writeAttribute('style:text-autospace', 'ideograph-alpha'); + $xmlWriter->writeAttribute('style:punctuation-wrap', 'hanging'); + $xmlWriter->writeAttribute('style:line-break', 'strict'); + $xmlWriter->writeAttribute('style:tab-stop-distance', '1.249cm'); + $xmlWriter->writeAttribute('style:writing-mode', 'page'); + $xmlWriter->endElement(); + + // style:text-properties + $xmlWriter->startElement('style:text-properties'); + $xmlWriter->writeAttribute('style:use-window-font-color', 'true'); + $xmlWriter->writeAttribute('style:font-name', PhpWord::DEFAULT_FONT_NAME); + $xmlWriter->writeAttribute('fo:font-size', PhpWord::DEFAULT_FONT_SIZE . 'pt'); + $xmlWriter->writeAttribute('fo:language', 'fr'); + $xmlWriter->writeAttribute('fo:country', 'FR'); + $xmlWriter->writeAttribute('style:letter-kerning', 'true'); + $xmlWriter->writeAttribute('style:font-name-asian', PhpWord::DEFAULT_FONT_NAME . '2'); + $xmlWriter->writeAttribute('style:font-size-asian', PhpWord::DEFAULT_FONT_SIZE . 'pt'); + $xmlWriter->writeAttribute('style:language-asian', 'zh'); + $xmlWriter->writeAttribute('style:country-asian', 'CN'); + $xmlWriter->writeAttribute('style:font-name-complex', PhpWord::DEFAULT_FONT_NAME . '2'); + $xmlWriter->writeAttribute('style:font-size-complex', PhpWord::DEFAULT_FONT_SIZE . 'pt'); + $xmlWriter->writeAttribute('style:language-complex', 'hi'); + $xmlWriter->writeAttribute('style:country-complex', 'IN'); + $xmlWriter->writeAttribute('fo:hyphenate', 'false'); + $xmlWriter->writeAttribute('fo:hyphenation-remain-char-count', '2'); + $xmlWriter->writeAttribute('fo:hyphenation-push-char-count', '2'); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + // Write Style Definitions + $styles = Style::getStyles(); + if (count($styles) > 0) { + foreach ($styles as $styleName => $style) { + if (preg_match('#^T[0-9]+$#', $styleName) == 0 + && preg_match('#^P[0-9]+$#', $styleName) == 0 + ) { + // PhpOffice\PhpWord\Style\Font + if ($style instanceof Font) { + // style:style + $xmlWriter->startElement('style:style'); + $xmlWriter->writeAttribute('style:name', $styleName); + $xmlWriter->writeAttribute('style:family', 'text'); + + // style:text-properties + $xmlWriter->startElement('style:text-properties'); + $xmlWriter->writeAttribute('fo:font-size', ($style->getSize()) . 'pt'); + $xmlWriter->writeAttribute('style:font-size-asian', ($style->getSize()) . 'pt'); + $xmlWriter->writeAttribute('style:font-size-complex', ($style->getSize()) . 'pt'); + if ($style->getItalic()) { + $xmlWriter->writeAttribute('fo:font-style', 'italic'); + $xmlWriter->writeAttribute('style:font-style-asian', 'italic'); + $xmlWriter->writeAttribute('style:font-style-complex', 'italic'); + } + if ($style->getBold()) { + $xmlWriter->writeAttribute('fo:font-weight', 'bold'); + $xmlWriter->writeAttribute('style:font-weight-asian', 'bold'); + } + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } elseif ($style instanceof Paragraph) { + // PhpOffice\PhpWord\Style\Paragraph + // style:style + $xmlWriter->startElement('style:style'); + $xmlWriter->writeAttribute('style:name', $styleName); + $xmlWriter->writeAttribute('style:family', 'paragraph'); + + //style:paragraph-properties + $xmlWriter->startElement('style:paragraph-properties'); + $xmlWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)) . 'cm'); + $xmlWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)) . 'cm'); + $xmlWriter->writeAttribute('fo:text-align', $style->getAlign()); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + } elseif ($style instanceof TableFull) { + // PhpOffice\PhpWord\Style\TableFull + } + } + } + } + $xmlWriter->endElement(); + + // office:automatic-styles + $xmlWriter->startElement('office:automatic-styles'); + // style:page-layout + $xmlWriter->startElement('style:page-layout'); + $xmlWriter->writeAttribute('style:name', 'Mpm1'); + // style:page-layout-properties + $xmlWriter->startElement('style:page-layout-properties'); + $xmlWriter->writeAttribute('fo:page-width', "21.001cm"); + $xmlWriter->writeAttribute('fo:page-height', '29.7cm'); + $xmlWriter->writeAttribute('style:num-format', '1'); + $xmlWriter->writeAttribute('style:print-orientation', 'portrait'); + $xmlWriter->writeAttribute('fo:margin-top', '2.501cm'); + $xmlWriter->writeAttribute('fo:margin-bottom', '2cm'); + $xmlWriter->writeAttribute('fo:margin-left', '2.501cm'); + $xmlWriter->writeAttribute('fo:margin-right', '2.501cm'); + $xmlWriter->writeAttribute('style:writing-mode', 'lr-tb'); + $xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0'); + $xmlWriter->writeAttribute('style:layout-grid-lines', '25199'); + $xmlWriter->writeAttribute('style:layout-grid-base-height', '0.423cm'); + $xmlWriter->writeAttribute('style:layout-grid-ruby-height', '0cm'); + $xmlWriter->writeAttribute('style:layout-grid-mode', 'none'); + $xmlWriter->writeAttribute('style:layout-grid-ruby-below', 'false'); + $xmlWriter->writeAttribute('style:layout-grid-print', 'false'); + $xmlWriter->writeAttribute('style:layout-grid-display', 'false'); + $xmlWriter->writeAttribute('style:layout-grid-base-width', '0.37cm'); + $xmlWriter->writeAttribute('style:layout-grid-snap-to', 'true'); + $xmlWriter->writeAttribute('style:footnote-max-height', '0cm'); + //style:footnote-sep + $xmlWriter->startElement('style:footnote-sep'); + $xmlWriter->writeAttribute('style:width', '0.018cm'); + $xmlWriter->writeAttribute('style:line-style', 'solid'); + $xmlWriter->writeAttribute('style:adjustment', 'left'); + $xmlWriter->writeAttribute('style:rel-width', '25%'); + $xmlWriter->writeAttribute('style:color', '#000000'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + // style:header-style + $xmlWriter->startElement('style:header-style'); + $xmlWriter->endElement(); + // style:footer-style + $xmlWriter->startElement('style:footer-style'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + // office:master-styles + $xmlWriter->startElement('office:master-styles'); + // style:master-page + $xmlWriter->startElement('style:master-page'); + $xmlWriter->writeAttribute('style:name', 'Standard'); + $xmlWriter->writeAttribute('style:page-layout-name', 'Mpm1'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } +} diff --git a/Classes/PHPWord/Writer/ODText/WriterPart.php b/src/PhpWord/Writer/ODText/WriterPart.php old mode 100755 new mode 100644 similarity index 69% rename from Classes/PHPWord/Writer/ODText/WriterPart.php rename to src/PhpWord/Writer/ODText/WriterPart.php index c65269a2c5..4c1de3c27e --- a/Classes/PHPWord/Writer/ODText/WriterPart.php +++ b/src/PhpWord/Writer/ODText/WriterPart.php @@ -1,8 +1,8 @@ _parentWriter = $pWriter; } @@ -51,15 +50,15 @@ public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null) /** * Get parent IWriter object * - * @return PHPWord_Writer_IWriter - * @throws Exception + * @return \PhpOffice\PhpWord\Writer\IWriter + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ public function getParentWriter() { if (!is_null($this->_parentWriter)) { return $this->_parentWriter; } else { - throw new Exception("No parent PHPWord_Writer_IWriter assigned."); + throw new Exception("No parent IWriter assigned."); } } } diff --git a/Classes/PHPWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php similarity index 68% rename from Classes/PHPWord/Writer/RTF.php rename to src/PhpWord/Writer/RTF.php index 03aee54222..1d6a2d9588 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -1,8 +1,8 @@ setPHPWord($pPHPWord); + // Assign PhpWord + $this->setPhpWord($phpWord); // Set HashTable variables - $this->_drawingHashTable = new PHPWord_HashTable(); + $this->_drawingHashTable = new HashTable(); } /** - * Save PHPWord to file + * Save PhpWord to file * - * @param string $pFilename - * @throws Exception + * @param string $pFileName + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ public function save($pFilename = null) { @@ -110,57 +108,46 @@ public function save($pFilename = null) } } else { - throw new Exception("PHPWord object unassigned."); + throw new Exception("PhpWord object unassigned."); } } /** - * Get PHPWord object - * - * @return PHPWord - * @throws Exception + * @return \PhpOffice\PhpWord\PhpWord + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ - public function getPHPWord() + public function getPhpWord() { if (!is_null($this->_document)) { return $this->_document; } else { - throw new Exception("No PHPWord assigned."); + throw new Exception("No PhpWord assigned."); } } /** - * Get PHPWord object - * - * @param PHPWord $pPHPWord PHPWord object - * @throws Exception - * @return PHPWord_Writer_RTF + * @param \PhpOffice\PhpWord\PhpWord $phpWord + * @return \PhpOffice\PhpWord\Writer\RTF */ - public function setPHPWord(PHPWord $pPHPWord = null) + public function setPhpWord(PhpWord $phpWord = null) { - $this->_document = $pPHPWord; + $this->_document = $phpWord; return $this; } /** * Get PHPWord_Worksheet_BaseDrawing HashTable * - * @return PHPWord_HashTable - * @codeCoverageIgnore + * @return \PhpOffice\PhpWord\HashTable */ public function getDrawingHashTable() { return $this->_drawingHashTable; } - /** - * Get document data - * - * @return string - */ private function getData() { - // PHPWord object : $this->_document + // PhpWord object : $this->_document $this->_fontTable = $this->getDataFont(); $this->_colorTable = $this->getDataColor(); @@ -171,22 +158,22 @@ private function getData() $sRTFContent .= '\deff0'; // Set the default tab size (720 twips) $sRTFContent .= '\deftab720'; - $sRTFContent .= PHP_EOL; + $sRTFContent .= \PHP_EOL; // Set the font tbl group $sRTFContent .= '{\fonttbl'; foreach ($this->_fontTable as $idx => $font) { $sRTFContent .= '{\f' . $idx . '\fnil\fcharset0 ' . $font . ';}'; } - $sRTFContent .= '}' . PHP_EOL; + $sRTFContent .= '}' . \PHP_EOL; // Set the color tbl group $sRTFContent .= '{\colortbl '; foreach ($this->_colorTable as $idx => $color) { - $arrColor = PHPWord_Shared_Drawing::htmlToRGB($color); + $arrColor = Drawing::htmlToRGB($color); $sRTFContent .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . ''; } - $sRTFContent .= ';}' . PHP_EOL; + $sRTFContent .= ';}' . \PHP_EOL; // Set the generator - $sRTFContent .= '{\*\generator PHPWord;}' . PHP_EOL; + $sRTFContent .= '{\*\generator PhpWord;}' . \PHP_EOL; // Set the view mode of the document $sRTFContent .= '\viewkind4'; // Set the numberof bytes that follows a unicode character @@ -200,8 +187,8 @@ private function getData() // Point size (in half-points) above which to kern character pairs $sRTFContent .= '\kerning1'; // Set the font size in half-points - $sRTFContent .= '\fs' . (PHPWord::DEFAULT_FONT_SIZE * 2); - $sRTFContent .= PHP_EOL; + $sRTFContent .= '\fs' . (PhpWord::DEFAULT_FONT_SIZE * 2); + $sRTFContent .= \PHP_EOL; // Body $sRTFContent .= $this->getDataContent(); @@ -211,27 +198,22 @@ private function getData() return $sRTFContent; } - /** - * Get font table - * - * @return array - */ private function getDataFont() { - $pPHPWord = $this->_document; + $phpWord = $this->_document; $arrFonts = array(); - // Default font : PHPWord::DEFAULT_FONT_NAME - $arrFonts[] = PHPWord::DEFAULT_FONT_NAME; - // PHPWord object : $this->_document + // Default font : PhpWord::DEFAULT_FONT_NAME + $arrFonts[] = PhpWord::DEFAULT_FONT_NAME; + // PhpWord object : $this->_document // Browse styles - $styles = PHPWord_Style::getStyles(); + $styles = Style::getStyles(); $numPStyles = 0; if (count($styles) > 0) { foreach ($styles as $styleName => $style) { - // PHPWord_Style_Font - if ($style instanceof PHPWord_Style_Font) { + // PhpOffice\PhpWord\Style\Font + if ($style instanceof Font) { if (in_array($style->getName(), $arrFonts) == false) { $arrFonts[] = $style->getName(); } @@ -240,7 +222,7 @@ private function getDataFont() } // Search all fonts used - $_sections = $pPHPWord->getSections(); + $_sections = $phpWord->getSections(); $countSections = count($_sections); if ($countSections > 0) { $pSection = 0; @@ -250,10 +232,10 @@ private function getDataFont() $_elements = $section->getElements(); foreach ($_elements as $element) { - if ($element instanceof PHPWord_Section_Text) { + if ($element instanceof Text) { $fStyle = $element->getFontStyle(); - if ($fStyle instanceof PHPWord_Style_Font) { + if ($fStyle instanceof Font) { if (in_array($fStyle->getName(), $arrFonts) == false) { $arrFonts[] = $fStyle->getName(); } @@ -266,31 +248,26 @@ private function getDataFont() return $arrFonts; } - /** - * Get color tables - * - * @return array - */ private function getDataColor() { - $pPHPWord = $this->_document; + $phpWord = $this->_document; $arrColors = array(); - // PHPWord object : $this->_document + // PhpWord object : $this->_document // Browse styles - $styles = PHPWord_Style::getStyles(); + $styles = Style::getStyles(); $numPStyles = 0; if (count($styles) > 0) { foreach ($styles as $styleName => $style) { - // PHPWord_Style_Font - if ($style instanceof PHPWord_Style_Font) { + // Font + if ($style instanceof Font) { $color = $style->getColor(); $fgcolor = $style->getFgColor(); - if (in_array($color, $arrColors) == false && $color != PHPWord::DEFAULT_FONT_COLOR && !empty($color)) { + if (in_array($color, $arrColors) == false && $color != PhpWord::DEFAULT_FONT_COLOR && !empty($color)) { $arrColors[] = $color; } - if (in_array($fgcolor, $arrColors) == false && $fgcolor != PHPWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) { + if (in_array($fgcolor, $arrColors) == false && $fgcolor != PhpWord::DEFAULT_FONT_COLOR && !empty($fgcolor)) { $arrColors[] = $fgcolor; } } @@ -298,7 +275,7 @@ private function getDataColor() } // Search all fonts used - $_sections = $pPHPWord->getSections(); + $_sections = $phpWord->getSections(); $countSections = count($_sections); if ($countSections > 0) { $pSection = 0; @@ -308,10 +285,10 @@ private function getDataColor() $_elements = $section->getElements(); foreach ($_elements as $element) { - if ($element instanceof PHPWord_Section_Text) { + if ($element instanceof Text) { $fStyle = $element->getFontStyle(); - if ($fStyle instanceof PHPWord_Style_Font) { + if ($fStyle instanceof Font) { if (in_array($fStyle->getColor(), $arrColors) == false) { $arrColors[] = $fStyle->getColor(); } @@ -327,17 +304,12 @@ private function getDataColor() return $arrColors; } - /** - * Get content - * - * @return string - */ private function getDataContent() { - $pPHPWord = $this->_document; + $phpWord = $this->_document; $sRTFBody = ''; - $_sections = $pPHPWord->getSections(); + $_sections = $phpWord->getSections(); $countSections = count($_sections); $pSection = 0; @@ -346,28 +318,28 @@ private function getDataContent() $pSection++; $_elements = $section->getElements(); foreach ($_elements as $element) { - if ($element instanceof PHPWord_Section_Text) { + if ($element instanceof Text) { $sRTFBody .= $this->getDataContentText($element); - } elseif ($element instanceof PHPWord_Section_TextBreak) { + } elseif ($element instanceof TextBreak) { $sRTFBody .= $this->getDataContentTextBreak(); - } elseif ($element instanceof PHPWord_Section_TextRun) { + } elseif ($element instanceof TextRun) { $sRTFBody .= $this->getDataContentTextRun($element); - } elseif ($element instanceof PHPWord_Section_Link) { + } elseif ($element instanceof Link) { $sRTFBody .= $this->getDataContentUnsupportedElement('Link'); - } elseif ($element instanceof PHPWord_Section_Title) { + } elseif ($element instanceof Title) { $sRTFBody .= $this->getDataContentUnsupportedElement('Title'); - } elseif ($element instanceof PHPWord_Section_PageBreak) { + } elseif ($element instanceof PageBreak) { $sRTFBody .= $this->getDataContentUnsupportedElement('Page Break'); - } elseif ($element instanceof PHPWord_Section_Table) { + } elseif ($element instanceof Table) { $sRTFBody .= $this->getDataContentUnsupportedElement('Table'); - } elseif ($element instanceof PHPWord_Section_ListItem) { + } elseif ($element instanceof ListItem) { $sRTFBody .= $this->getDataContentUnsupportedElement('List Item'); - } elseif ($element instanceof PHPWord_Section_Image || - $element instanceof PHPWord_Section_MemoryImage) { + } elseif ($element instanceof Image || + $element instanceof MemoryImage) { $sRTFBody .= $this->getDataContentUnsupportedElement('Image'); - } elseif ($element instanceof PHPWord_Section_Object) { + } elseif ($element instanceof Object) { $sRTFBody .= $this->getDataContentUnsupportedElement('Object'); - } elseif ($element instanceof PHPWord_TOC) { + } elseif ($element instanceof TOC) { $sRTFBody .= $this->getDataContentUnsupportedElement('TOC'); } else { $sRTFBody .= $this->getDataContentUnsupportedElement('Other'); @@ -378,27 +350,20 @@ private function getDataContent() return $sRTFBody; } - /** - * Get text - * - * @param PHPWord_Section_Text $text - * @param boolean $withoutP - * @return string - */ - private function getDataContentText(PHPWord_Section_Text $text, $withoutP = false) + private function getDataContentText(Text $text, $withoutP = false) { $sRTFText = ''; $styleFont = $text->getFontStyle(); - $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; + $SfIsObject = ($styleFont instanceof Font) ? true : false; if (!$SfIsObject) { - $styleFont = PHPWord_Style::getStyle($styleFont); + $styleFont = Style::getStyle($styleFont); } $styleParagraph = $text->getParagraphStyle(); - $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; if (!$SpIsObject) { - $styleParagraph = PHPWord_Style::getStyle($styleParagraph); + $styleParagraph = Style::getStyle($styleParagraph); } if ($styleParagraph && !$withoutP) { @@ -420,7 +385,7 @@ private function getDataContentText(PHPWord_Section_Text $text, $withoutP = fals $this->_lastParagraphStyle = ''; } - if ($styleFont instanceof PHPWord_Style_Font) { + if ($styleFont instanceof Font) { if ($styleFont->getColor() != null) { $idxColor = array_search($styleFont->getColor(), $this->_colorTable); if ($idxColor !== false) { @@ -452,7 +417,7 @@ private function getDataContentText(PHPWord_Section_Text $text, $withoutP = fals } $sRTFText .= $text->getText(); - if ($styleFont instanceof PHPWord_Style_Font) { + if ($styleFont instanceof Font) { $sRTFText .= '\cf0'; $sRTFText .= '\f0'; @@ -463,66 +428,52 @@ private function getDataContentText(PHPWord_Section_Text $text, $withoutP = fals $sRTFText .= '\i0'; } if ($styleFont->getSize()) { - $sRTFText .= '\fs' . (PHPWord::DEFAULT_FONT_SIZE * 2); + $sRTFText .= '\fs' . (PhpWord::DEFAULT_FONT_SIZE * 2); } } if (!$withoutP) { - $sRTFText .= '\par' . PHP_EOL; + $sRTFText .= '\par' . \PHP_EOL; } - return $sRTFText; } - /** - * Get text run content - * - * @param PHPWord_Section_TextRun $textrun - * @return string - */ - private function getDataContentTextRun(PHPWord_Section_TextRun $textrun) + private function getDataContentTextRun(TextRun $textrun) { $sRTFText = ''; $elements = $textrun->getElements(); if (count($elements) > 0) { - $sRTFText .= '\pard\nowidctlpar' . PHP_EOL; + $sRTFText .= '\pard\nowidctlpar' . \PHP_EOL; foreach ($elements as $element) { - if ($element instanceof PHPWord_Section_Text) { + if ($element instanceof Text) { $sRTFText .= '{'; $sRTFText .= $this->getDataContentText($element, true); - $sRTFText .= '}' . PHP_EOL; + $sRTFText .= '}' . \PHP_EOL; } } - $sRTFText .= '\par' . PHP_EOL; + $sRTFText .= '\par' . \PHP_EOL; } - return $sRTFText; } - /** - * Get text break - * - * @return string - */ private function getDataContentTextBreak() { $this->_lastParagraphStyle = ''; - return '\par' . PHP_EOL; + return '\par' . \PHP_EOL; } /** * Write unsupported element * * @param string $element - * @return string */ private function getDataContentUnsupportedElement($element) { $sRTFText = ''; - $sRTFText .= '\pard\nowidctlpar' . PHP_EOL; + $sRTFText .= '\pard\nowidctlpar' . \PHP_EOL; $sRTFText .= "{$element}"; - $sRTFText .= '\par' . PHP_EOL; + $sRTFText .= '\par' . \PHP_EOL; return $sRTFText; } diff --git a/Classes/PHPWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php similarity index 71% rename from Classes/PHPWord/Writer/Word2007.php rename to src/PhpWord/Writer/Word2007.php index 16d66c666f..61a8bc1269 100755 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -1,8 +1,8 @@ _document = $PHPWord; + $this->_document = $phpWord; $this->_diskCachingDirectory = './'; - $this->_writerParts['contenttypes'] = new PHPWord_Writer_Word2007_ContentTypes(); - $this->_writerParts['rels'] = new PHPWord_Writer_Word2007_Rels(); - $this->_writerParts['docprops'] = new PHPWord_Writer_Word2007_DocProps(); - $this->_writerParts['documentrels'] = new PHPWord_Writer_Word2007_DocumentRels(); - $this->_writerParts['document'] = new PHPWord_Writer_Word2007_Document(); - $this->_writerParts['styles'] = new PHPWord_Writer_Word2007_Styles(); - $this->_writerParts['header'] = new PHPWord_Writer_Word2007_Header(); - $this->_writerParts['footer'] = new PHPWord_Writer_Word2007_Footer(); - $this->_writerParts['footnotes'] = new PHPWord_Writer_Word2007_Footnotes(); - $this->_writerParts['footnotesrels'] = new PHPWord_Writer_Word2007_FootnotesRels(); + $this->_writerParts['contenttypes'] = new ContentTypes(); + $this->_writerParts['rels'] = new Rels(); + $this->_writerParts['docprops'] = new DocProps(); + $this->_writerParts['documentrels'] = new DocumentRels(); + $this->_writerParts['document'] = new Document(); + $this->_writerParts['styles'] = new Styles(); + $this->_writerParts['header'] = new Header(); + $this->_writerParts['footer'] = new Footer(); + $this->_writerParts['footnotes'] = new Footnotes(); + $this->_writerParts['footnotesrels'] = new FootnotesRels(); foreach ($this->_writerParts as $writer) { $writer->setParentWriter($this); } } - /** - * Save - * - * @param string $pFilename - */ public function save($pFilename = null) { if (!is_null($this->_document)) { @@ -120,18 +85,18 @@ public function save($pFilename = null) } // Create new ZIP file and open it for writing - $objZip = new ZipArchive(); + $objZip = new \ZipArchive(); // Try opening the ZIP file - if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) { - if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) { + if ($objZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) { + if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) { throw new Exception("Could not open " . $pFilename . " for writing."); } } $sectionElements = array(); - $_secElements = PHPWord_Media::getSectionMediaElements(); + $_secElements = Media::getSectionMediaElements(); foreach ($_secElements as $element) { // loop through section media elements if ($element['type'] != 'hyperlink') { $this->_addFileToPackage($objZip, $element); @@ -139,7 +104,7 @@ public function save($pFilename = null) $sectionElements[] = $element; } - $_hdrElements = PHPWord_Media::getHeaderMediaElements(); + $_hdrElements = Media::getHeaderMediaElements(); foreach ($_hdrElements as $_headerFile => $_hdrMedia) { // loop through headers if (count($_hdrMedia) > 0) { $objZip->addFromString('word/_rels/' . $_headerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_hdrMedia)); @@ -149,7 +114,7 @@ public function save($pFilename = null) } } - $_ftrElements = PHPWord_Media::getFooterMediaElements(); + $_ftrElements = Media::getFooterMediaElements(); foreach ($_ftrElements as $_footerFile => $_ftrMedia) { // loop through footers if (count($_ftrMedia) > 0) { $objZip->addFromString('word/_rels/' . $_footerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_ftrMedia)); @@ -160,7 +125,7 @@ public function save($pFilename = null) } $footnoteLinks = array(); - $_footnoteElements = PHPWord_Footnote::getFootnoteLinkElements(); + $_footnoteElements = Footnote::getFootnoteLinkElements(); // loop through footnote link elements foreach ($_footnoteElements as $element) { $footnoteLinks[] = $element; @@ -168,7 +133,7 @@ public function save($pFilename = null) $_cHdrs = 0; $_cFtrs = 0; - $rID = PHPWord_Media::countSectionMediaElements() + 6; + $rID = Media::countSectionMediaElements() + 6; $_sections = $this->_document->getSections(); $footers = array(); @@ -193,8 +158,8 @@ public function save($pFilename = null) } } - if (PHPWord_Footnote::countFootnoteElements() > 0) { - $_allFootnotesCollection = PHPWord_Footnote::getFootnoteElements(); + if (Footnote::countFootnoteElements() > 0) { + $_allFootnotesCollection = Footnote::getFootnoteElements(); $_footnoteFile = 'footnotes.xml'; $sectionElements[] = array('target'=>$_footnoteFile, 'type'=>'footnotes', 'rID'=>++$rID); $objZip->addFromString('word/'.$_footnoteFile, $this->getWriterPart('footnotes')->writeFootnotes($_allFootnotesCollection)); @@ -222,11 +187,11 @@ public function save($pFilename = null) $objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document)); // Write static files - $objZip->addFile(PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/numbering.xml', 'word/numbering.xml'); - $objZip->addFile(PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/settings.xml', 'word/settings.xml'); - $objZip->addFile(PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/theme1.xml', 'word/theme/theme1.xml'); - $objZip->addFile(PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/webSettings.xml', 'word/webSettings.xml'); - $objZip->addFile(PHPWORD_BASE_PATH . 'PHPWord/_staticDocParts/fontTable.xml', 'word/fontTable.xml'); + $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/numbering.xml', 'word/numbering.xml'); + $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/settings.xml', 'word/settings.xml'); + $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/theme1.xml', 'word/theme/theme1.xml'); + $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/webSettings.xml', 'word/webSettings.xml'); + $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/fontTable.xml', 'word/fontTable.xml'); // Close file @@ -242,13 +207,11 @@ public function save($pFilename = null) @unlink($pFilename); } } else { - throw new Exception("PHPWord object unassigned."); + throw new Exception("PhpWord object unassigned."); } } /** - * Check content types - * * @param string $src */ private function checkContentTypes($src) @@ -257,10 +220,21 @@ private function checkContentTypes($src) if (stripos(strrev($src), strrev('.php')) === 0) { $extension = 'php'; } 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'; + } } - if (isset($extension) && $extension) { + if (isset($extension)) { $imageData = getimagesize($src); $imageType = image_type_to_mime_type($imageData[2]); $imageExtension = str_replace('.', '', image_type_to_extension($imageData[2])); @@ -270,16 +244,13 @@ private function checkContentTypes($src) if (!in_array($imageType, $this->_imageTypes)) { $this->_imageTypes[$imageExtension] = $imageType; } - } elseif (!in_array($extension, $this->_objectTypes)) { - $this->_objectTypes[] = $extension; + } else { + if (!in_array($extension, $this->_objectTypes)) { + $this->_objectTypes[] = $extension; + } } } - /** - * Get writer part - * - * @param string $pPartName - */ public function getWriterPart($pPartName = '') { if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) { @@ -289,20 +260,11 @@ public function getWriterPart($pPartName = '') } } - /** - * Get use disk catching setting - */ public function getUseDiskCaching() { return $this->_useDiskCaching; } - /** - * Set use disk catching setting - * - * @param boolean $pValue - * @param string $pDirectory - */ public function setUseDiskCaching($pValue = false, $pDirectory = null) { $this->_useDiskCaching = $pValue; @@ -319,11 +281,13 @@ public function setUseDiskCaching($pValue = false, $pDirectory = null) } /** - * Add file to package - * - * @param mixed $objZip - * @param array $element + * @return string */ + public function getDiskCachingDirectory() + { + return $this->_diskCachingDirectory; + } + private function _addFileToPackage($objZip, $element) { if (isset($element['isMemImage']) && $element['isMemImage']) { @@ -341,14 +305,4 @@ private function _addFileToPackage($objZip, $element) $this->checkContentTypes($element['source']); } } - - /** - * Get disk caching directory - * - * @return string - */ - public function getDiskCachingDirectory() - { - return $this->_diskCachingDirectory; - } } diff --git a/src/PhpWord/Writer/Word2007/Base.php b/src/PhpWord/Writer/Word2007/Base.php new file mode 100644 index 0000000000..a18d57eae8 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Base.php @@ -0,0 +1,1001 @@ +getFontStyle(); + + $SfIsObject = ($styleFont instanceof Font) ? true : false; + + if (!$withoutP) { + $xmlWriter->startElement('w:p'); + + $styleParagraph = $text->getParagraphStyle(); + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; + + if ($SpIsObject) { + $this->_writeParagraphStyle($xmlWriter, $styleParagraph); + } elseif (!$SpIsObject && !is_null($styleParagraph)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleParagraph); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + } + + $strText = htmlspecialchars($text->getText()); + $strText = String::controlCharacterPHP2OOXML($strText); + + $xmlWriter->startElement('w:r'); + + if ($SfIsObject) { + $this->_writeTextStyle($xmlWriter, $styleFont); + } elseif (!$SfIsObject && !is_null($styleFont)) { + $xmlWriter->startElement('w:rPr'); + $xmlWriter->startElement('w:rStyle'); + $xmlWriter->writeAttribute('w:val', $styleFont); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:t'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text + $xmlWriter->writeRaw($strText); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); // w:r + + if (!$withoutP) { + $xmlWriter->endElement(); // w:p + } + } + + protected function _writeTextRun(XMLWriter $xmlWriter, TextRun $textrun) + { + $elements = $textrun->getElements(); + $styleParagraph = $textrun->getParagraphStyle(); + + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; + + $xmlWriter->startElement('w:p'); + + if ($SpIsObject) { + $this->_writeParagraphStyle($xmlWriter, $styleParagraph); + } elseif (!$SpIsObject && !is_null($styleParagraph)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleParagraph); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + if (count($elements) > 0) { + foreach ($elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element, true); + } elseif ($element instanceof Link) { + $this->_writeLink($xmlWriter, $element, true); + } elseif ($element instanceof Image) { + $this->_writeImage($xmlWriter, $element, true); + } elseif ($element instanceof Footnote) { + $this->_writeFootnoteReference($xmlWriter, $element, true); + } elseif ($element instanceof TextBreak) { + $xmlWriter->writeElement('w:br'); + } + } + } + + $xmlWriter->endElement(); + } + + /** + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Style\Paragraph $style + * @param bool $withoutPPR + * @return void + */ + protected function _writeParagraphStyle( + XMLWriter $xmlWriter, + Paragraph $style, + $withoutPPR = false + ) { + + $align = $style->getAlign(); + $spacing = $style->getSpacing(); + $spaceBefore = $style->getSpaceBefore(); + $spaceAfter = $style->getSpaceAfter(); + $indent = $style->getIndent(); + $hanging = $style->getHanging(); + $tabs = $style->getTabs(); + $widowControl = $style->getWidowControl(); + $keepNext = $style->getKeepNext(); + $keepLines = $style->getKeepLines(); + $pageBreakBefore = $style->getPageBreakBefore(); + + if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || + !is_null($spaceAfter) || !is_null($indent) || !is_null($hanging) || + !is_null($tabs) || !is_null($widowControl) || !is_null($keepNext) || + !is_null($keepLines) || !is_null($pageBreakBefore)) { + if (!$withoutPPR) { + $xmlWriter->startElement('w:pPr'); + } + + // Alignment + if (!is_null($align)) { + $xmlWriter->startElement('w:jc'); + $xmlWriter->writeAttribute('w:val', $align); + $xmlWriter->endElement(); + } + + // Indentation + if (!is_null($indent) || !is_null($hanging)) { + $xmlWriter->startElement('w:ind'); + $xmlWriter->writeAttribute('w:firstLine', 0); + if (!is_null($indent)) { + $xmlWriter->writeAttribute('w:left', $indent); + } + if (!is_null($hanging)) { + $xmlWriter->writeAttribute('w:hanging', $hanging); + } + $xmlWriter->endElement(); + } + + // Spacing + if (!is_null($spaceBefore) || !is_null($spaceAfter) || + !is_null($spacing)) { + $xmlWriter->startElement('w:spacing'); + if (!is_null($spaceBefore)) { + $xmlWriter->writeAttribute('w:before', $spaceBefore); + } + if (!is_null($spaceAfter)) { + $xmlWriter->writeAttribute('w:after', $spaceAfter); + } + if (!is_null($spacing)) { + $xmlWriter->writeAttribute('w:line', $spacing); + $xmlWriter->writeAttribute('w:lineRule', 'auto'); + } + $xmlWriter->endElement(); + } + + // Pagination + if (!$widowControl) { + $xmlWriter->startElement('w:widowControl'); + $xmlWriter->writeAttribute('w:val', '0'); + $xmlWriter->endElement(); + } + if ($keepNext) { + $xmlWriter->startElement('w:keepNext'); + $xmlWriter->writeAttribute('w:val', '1'); + $xmlWriter->endElement(); + } + if ($keepLines) { + $xmlWriter->startElement('w:keepLines'); + $xmlWriter->writeAttribute('w:val', '1'); + $xmlWriter->endElement(); + } + if ($pageBreakBefore) { + $xmlWriter->startElement('w:pageBreakBefore'); + $xmlWriter->writeAttribute('w:val', '1'); + $xmlWriter->endElement(); + } + + // Tabs + if (!is_null($tabs)) { + $tabs->toXml($xmlWriter); + } + + if (!$withoutPPR) { + $xmlWriter->endElement(); // w:pPr + } + } + } + + protected function _writeLink(XMLWriter $xmlWriter, Link $link, $withoutP = false) + { + $rID = $link->getRelationId(); + $linkName = $link->getLinkName(); + if (is_null($linkName)) { + $linkName = $link->getLinkSrc(); + } + + $styleFont = $link->getFontStyle(); + $SfIsObject = ($styleFont instanceof Font) ? true : false; + + if (!$withoutP) { + $xmlWriter->startElement('w:p'); + + $styleParagraph = $link->getParagraphStyle(); + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; + + if ($SpIsObject) { + $this->_writeParagraphStyle($xmlWriter, $styleParagraph); + } elseif (!$SpIsObject && !is_null($styleParagraph)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleParagraph); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + } + + $xmlWriter->startElement('w:hyperlink'); + $xmlWriter->writeAttribute('r:id', 'rId' . $rID); + $xmlWriter->writeAttribute('w:history', '1'); + + $xmlWriter->startElement('w:r'); + if ($SfIsObject) { + $this->_writeTextStyle($xmlWriter, $styleFont); + } elseif (!$SfIsObject && !is_null($styleFont)) { + $xmlWriter->startElement('w:rPr'); + $xmlWriter->startElement('w:rStyle'); + $xmlWriter->writeAttribute('w:val', $styleFont); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:t'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text + $xmlWriter->writeRaw($linkName); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + if (!$withoutP) { + $xmlWriter->endElement(); // w:p + } + } + + protected function _writePreserveText(XMLWriter $xmlWriter, PreserveText $textrun) + { + $styleFont = $textrun->getFontStyle(); + $styleParagraph = $textrun->getParagraphStyle(); + + $SfIsObject = ($styleFont instanceof Font) ? true : false; + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; + + $arrText = $textrun->getText(); + if (!is_array($arrText)) { + $arrText = array($arrText); + } + + $xmlWriter->startElement('w:p'); + + if ($SpIsObject) { + $this->_writeParagraphStyle($xmlWriter, $styleParagraph); + } elseif (!$SpIsObject && !is_null($styleParagraph)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleParagraph); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + foreach ($arrText as $text) { + + if (substr($text, 0, 1) == '{') { + $text = substr($text, 1, -1); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'begin'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + + if ($SfIsObject) { + $this->_writeTextStyle($xmlWriter, $styleFont); + } elseif (!$SfIsObject && !is_null($styleFont)) { + $xmlWriter->startElement('w:rPr'); + $xmlWriter->startElement('w:rStyle'); + $xmlWriter->writeAttribute('w:val', $styleFont); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:instrText'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); + $xmlWriter->writeRaw($text); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'separate'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'end'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } else { + $text = htmlspecialchars($text); + $text = String::controlCharacterPHP2OOXML($text); + + $xmlWriter->startElement('w:r'); + + if ($SfIsObject) { + $this->_writeTextStyle($xmlWriter, $styleFont); + } elseif (!$SfIsObject && !is_null($styleFont)) { + $xmlWriter->startElement('w:rPr'); + $xmlWriter->startElement('w:rStyle'); + $xmlWriter->writeAttribute('w:val', $styleFont); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:t'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); + $xmlWriter->writeRaw($text); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + } + + $xmlWriter->endElement(); // p + } + + protected function _writeTextStyle(XMLWriter $xmlWriter, Font $style) + { + $font = $style->getName(); + $bold = $style->getBold(); + $italic = $style->getItalic(); + $color = $style->getColor(); + $size = $style->getSize(); + $fgColor = $style->getFgColor(); + $strikethrough = $style->getStrikethrough(); + $underline = $style->getUnderline(); + $superscript = $style->getSuperScript(); + $subscript = $style->getSubScript(); + $hint = $style->getHint(); + + $xmlWriter->startElement('w:rPr'); + + // Font + if ($font != PhpWord::DEFAULT_FONT_NAME) { + $xmlWriter->startElement('w:rFonts'); + $xmlWriter->writeAttribute('w:ascii', $font); + $xmlWriter->writeAttribute('w:hAnsi', $font); + $xmlWriter->writeAttribute('w:eastAsia', $font); + $xmlWriter->writeAttribute('w:cs', $font); + //Font Content Type + if ($hint != PhpWord::DEFAULT_FONT_CONTENT_TYPE) { + $xmlWriter->writeAttribute('w:hint', $hint); + } + $xmlWriter->endElement(); + } + + + // Color + if ($color != PhpWord::DEFAULT_FONT_COLOR) { + $xmlWriter->startElement('w:color'); + $xmlWriter->writeAttribute('w:val', $color); + $xmlWriter->endElement(); + } + + // Size + if ($size != PhpWord::DEFAULT_FONT_SIZE) { + $xmlWriter->startElement('w:sz'); + $xmlWriter->writeAttribute('w:val', $size * 2); + $xmlWriter->endElement(); + $xmlWriter->startElement('w:szCs'); + $xmlWriter->writeAttribute('w:val', $size * 2); + $xmlWriter->endElement(); + } + + // Bold + if ($bold) { + $xmlWriter->writeElement('w:b', null); + } + + // Italic + if ($italic) { + $xmlWriter->writeElement('w:i', null); + $xmlWriter->writeElement('w:iCs', null); + } + + // Underline + if (!is_null($underline) && $underline != 'none') { + $xmlWriter->startElement('w:u'); + $xmlWriter->writeAttribute('w:val', $underline); + $xmlWriter->endElement(); + } + + // Strikethrough + if ($strikethrough) { + $xmlWriter->writeElement('w:strike', null); + } + + // Foreground-Color + if (!is_null($fgColor)) { + $xmlWriter->startElement('w:highlight'); + $xmlWriter->writeAttribute('w:val', $fgColor); + $xmlWriter->endElement(); + } + + // Superscript/subscript + if ($superscript || $subscript) { + $xmlWriter->startElement('w:vertAlign'); + $xmlWriter->writeAttribute('w:val', $superscript ? 'superscript' : 'subscript'); + $xmlWriter->endElement(); + } + + $xmlWriter->endElement(); + } + + /** + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Section\TextBreak $element + */ + protected function _writeTextBreak($xmlWriter, $element = null) + { + $hasStyle = false; + if (!is_null($element)) { + $fontStyle = $element->getFontStyle(); + $sfIsObject = ($fontStyle instanceof Font) ? true : false; + $paragraphStyle = $element->getParagraphStyle(); + $spIsObject = ($paragraphStyle instanceof Paragraph) ? true : false; + $hasStyle = !is_null($fontStyle) || !is_null($paragraphStyle); + } + if ($hasStyle) { + // Paragraph style + $xmlWriter->startElement('w:p'); + if ($spIsObject) { + $this->_writeParagraphStyle($xmlWriter, $paragraphStyle); + } elseif (!$spIsObject && !is_null($paragraphStyle)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $paragraphStyle); + $xmlWriter->endElement(); // w:pStyle + $xmlWriter->endElement(); // w:pPr + } + // Font style + if (!is_null($fontStyle)) { + $xmlWriter->startElement('w:pPr'); + if ($sfIsObject) { + $this->_writeTextStyle($xmlWriter, $fontStyle); + } elseif (!$sfIsObject && !is_null($fontStyle)) { + $xmlWriter->startElement('w:rPr'); + $xmlWriter->startElement('w:rStyle'); + $xmlWriter->writeAttribute('w:val', $fontStyle); + $xmlWriter->endElement(); // w:rStyle + $xmlWriter->endElement(); // w:rPr + } + $xmlWriter->endElement(); // w:pPr + } + $xmlWriter->endElement(); // w:p + } else { + // Null element. No paragraph nor font style + $xmlWriter->writeElement('w:p', null); + } + } + + protected function _writeTable(XMLWriter $xmlWriter, Table $table) + { + $_rows = $table->getRows(); + $_cRows = count($_rows); + + if ($_cRows > 0) { + $xmlWriter->startElement('w:tbl'); + $tblStyle = $table->getStyle(); + $tblWidth = $table->getWidth(); + if ($tblStyle instanceof PhpOffice\PhpWord\Style\Table) { + $this->_writeTableStyle($xmlWriter, $tblStyle); + } else { + if (!empty($tblStyle)) { + $xmlWriter->startElement('w:tblPr'); + $xmlWriter->startElement('w:tblStyle'); + $xmlWriter->writeAttribute('w:val', $tblStyle); + $xmlWriter->endElement(); + if (!is_null($tblWidth)) { + $xmlWriter->startElement('w:tblW'); + $xmlWriter->writeAttribute('w:w', $tblWidth); + $xmlWriter->writeAttribute('w:type', 'pct'); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + } + + for ($i = 0; $i < $_cRows; $i++) { + $row = $_rows[$i]; + $height = $row->getHeight(); + $rowStyle = $row->getStyle(); + $tblHeader = $rowStyle->getTblHeader(); + $cantSplit = $rowStyle->getCantSplit(); + + $xmlWriter->startElement('w:tr'); + + if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) { + $xmlWriter->startElement('w:trPr'); + if (!is_null($height)) { + $xmlWriter->startElement('w:trHeight'); + $xmlWriter->writeAttribute('w:val', $height); + $xmlWriter->endElement(); + } + if ($tblHeader) { + $xmlWriter->startElement('w:tblHeader'); + $xmlWriter->writeAttribute('w:val', '1'); + $xmlWriter->endElement(); + } + if ($cantSplit) { + $xmlWriter->startElement('w:cantSplit'); + $xmlWriter->writeAttribute('w:val', '1'); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + + foreach ($row->getCells() as $cell) { + $xmlWriter->startElement('w:tc'); + + $cellStyle = $cell->getStyle(); + $width = $cell->getWidth(); + + $xmlWriter->startElement('w:tcPr'); + $xmlWriter->startElement('w:tcW'); + $xmlWriter->writeAttribute('w:w', $width); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + + if ($cellStyle instanceof Cell) { + $this->_writeCellStyle($xmlWriter, $cellStyle); + } + + $xmlWriter->endElement(); + + $_elements = $cell->getElements(); + if (count($_elements) > 0) { + foreach ($_elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element); + } elseif ($element instanceof TextRun) { + $this->_writeTextRun($xmlWriter, $element); + } elseif ($element instanceof Link) { + $this->_writeLink($xmlWriter, $element); + } elseif ($element instanceof TextBreak) { + $this->_writeTextBreak($xmlWriter, $element); + } elseif ($element instanceof ListItem) { + $this->_writeListItem($xmlWriter, $element); + } elseif ($element instanceof Image || + $element instanceof MemoryImage + ) { + $this->_writeImage($xmlWriter, $element); + } elseif ($element instanceof Object) { + $this->_writeObject($xmlWriter, $element); + } elseif ($element instanceof PreserveText) { + $this->_writePreserveText($xmlWriter, $element); + } + } + } else { + $this->_writeTextBreak($xmlWriter); + } + + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + } + + protected function _writeTableStyle( + XMLWriter $xmlWriter, + \PhpOffice\PhpWord\Style\Table $style = null + ) { + $margins = $style->getCellMargin(); + $mTop = (!is_null($margins[0])) ? true : false; + $mLeft = (!is_null($margins[1])) ? true : false; + $mRight = (!is_null($margins[2])) ? true : false; + $mBottom = (!is_null($margins[3])) ? true : false; + + if ($mTop || $mLeft || $mRight || $mBottom) { + $xmlWriter->startElement('w:tblPr'); + $xmlWriter->startElement('w:tblCellMar'); + + if ($mTop) { + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:w', $margins[0]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + + if ($mLeft) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:w', $margins[1]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + + if ($mRight) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:w', $margins[2]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + + if ($mBottom) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:w', $margins[3]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + } + + protected function _writeCellStyle(XMLWriter $xmlWriter, Cell $style = null) + { + $bgColor = $style->getBgColor(); + $valign = $style->getVAlign(); + $textDir = $style->getTextDirection(); + $brdSz = $style->getBorderSize(); + $brdCol = $style->getBorderColor(); + + $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; + + $styles = (!is_null($bgColor) || !is_null($valign) || !is_null($textDir) || $borders) ? true : false; + + if ($styles) { + if (!is_null($textDir)) { + $xmlWriter->startElement('w:textDirection'); + $xmlWriter->writeAttribute('w:val', $textDir); + $xmlWriter->endElement(); + } + + if (!is_null($bgColor)) { + $xmlWriter->startElement('w:shd'); + $xmlWriter->writeAttribute('w:val', 'clear'); + $xmlWriter->writeAttribute('w:color', 'auto'); + $xmlWriter->writeAttribute('w:fill', $bgColor); + $xmlWriter->endElement(); + } + + if (!is_null($valign)) { + $xmlWriter->startElement('w:vAlign'); + $xmlWriter->writeAttribute('w:val', $valign); + $xmlWriter->endElement(); + } + + if ($borders) { + $_defaultColor = $style->getDefaultBorderColor(); + + $xmlWriter->startElement('w:tcBorders'); + if ($bTop) { + if (is_null($brdCol[0])) { + $brdCol[0] = $_defaultColor; + } + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[0]); + $xmlWriter->writeAttribute('w:color', $brdCol[0]); + $xmlWriter->endElement(); + } + + if ($bLeft) { + if (is_null($brdCol[1])) { + $brdCol[1] = $_defaultColor; + } + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[1]); + $xmlWriter->writeAttribute('w:color', $brdCol[1]); + $xmlWriter->endElement(); + } + + if ($bRight) { + if (is_null($brdCol[2])) { + $brdCol[2] = $_defaultColor; + } + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[2]); + $xmlWriter->writeAttribute('w:color', $brdCol[2]); + $xmlWriter->endElement(); + } + + if ($bBottom) { + if (is_null($brdCol[3])) { + $brdCol[3] = $_defaultColor; + } + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[3]); + $xmlWriter->writeAttribute('w:color', $brdCol[3]); + $xmlWriter->endElement(); + } + + $xmlWriter->endElement(); + } + } + $gridSpan = $style->getGridSpan(); + if (!is_null($gridSpan)) { + $xmlWriter->startElement('w:gridSpan'); + $xmlWriter->writeAttribute('w:val', $gridSpan); + $xmlWriter->endElement(); + } + + $vMerge = $style->getVMerge(); + if (!is_null($vMerge)) { + $xmlWriter->startElement('w:vMerge'); + $xmlWriter->writeAttribute('w:val', $vMerge); + $xmlWriter->endElement(); + } + } + + /** + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Section\Image|\PhpOffice\PhpWord\Section\MemoryImage $image + */ + protected function _writeImage(XMLWriter $xmlWriter, $image, $withoutP = false) + { + $rId = $image->getRelationId(); + + $style = $image->getStyle(); + $width = $style->getWidth(); + $height = $style->getHeight(); + $align = $style->getAlign(); + $marginTop = $style->getMarginTop(); + $marginLeft = $style->getMarginLeft(); + $wrappingStyle = $style->getWrappingStyle(); + + if (!$withoutP) { + $xmlWriter->startElement('w:p'); + + if (!is_null($align)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:jc'); + $xmlWriter->writeAttribute('w:val', $align); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + } + + $xmlWriter->startElement('w:r'); + + $xmlWriter->startElement('w:pict'); + + $xmlWriter->startElement('v:shape'); + $xmlWriter->writeAttribute('type', '#_x0000_t75'); + + $imgStyle = ''; + if (null !== $width) { + $imgStyle .= 'width:' . $width . 'px;'; + } + if (null !== $height) { + $imgStyle .= 'height:' . $height . 'px;'; + } + if (null !== $marginTop) { + $imgStyle .= 'margin-top:' . $marginTop . 'in;'; + } + if (null !== $marginLeft) { + $imgStyle .= 'margin-left:' . $marginLeft . 'in;'; + } + + switch ($wrappingStyle) { + case \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND: + $imgStyle .= 'position:absolute;z-index:-251658752;'; + break; + case \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE: + $imgStyle .= 'position:absolute;z-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; + break; + case \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_TIGHT: + $imgStyle .= 'position:absolute;z-index:251659264;mso-wrap-edited:f;mso-position-horizontal:absolute;mso-position-vertical:absolute'; + break; + case \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_INFRONT: + $imgStyle .= 'position:absolute;zz-index:251659264;mso-position-horizontal:absolute;mso-position-vertical:absolute;'; + break; + } + + $xmlWriter->writeAttribute('style', $imgStyle); + + $xmlWriter->startElement('v:imagedata'); + $xmlWriter->writeAttribute('r:id', 'rId' . $rId); + $xmlWriter->writeAttribute('o:title', ''); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + if (!$withoutP) { + $xmlWriter->endElement(); // w:p + } + } + + protected function _writeWatermark(XMLWriter $xmlWriter, $image) + { + $rId = $image->getRelationId(); + + $style = $image->getStyle(); + $width = $style->getWidth(); + $height = $style->getHeight(); + $marginLeft = $style->getMarginLeft(); + $marginTop = $style->getMarginTop(); + + $xmlWriter->startElement('w:p'); + + $xmlWriter->startElement('w:r'); + + $xmlWriter->startElement('w:pict'); + + $xmlWriter->startElement('v:shape'); + $xmlWriter->writeAttribute('type', '#_x0000_t75'); + + $strStyle = 'position:absolute;'; + $strStyle .= ' width:' . $width . 'px;'; + $strStyle .= ' height:' . $height . 'px;'; + if (!is_null($marginTop)) { + $strStyle .= ' margin-top:' . $marginTop . 'px;'; + } + if (!is_null($marginLeft)) { + $strStyle .= ' margin-left:' . $marginLeft . 'px;'; + } + + $xmlWriter->writeAttribute('style', $strStyle); + + $xmlWriter->startElement('v:imagedata'); + $xmlWriter->writeAttribute('r:id', 'rId' . $rId); + $xmlWriter->writeAttribute('o:title', ''); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + } + + protected function _writeTitle(XMLWriter $xmlWriter, Title $title) + { + $text = htmlspecialchars($title->getText()); + $text = String::controlCharacterPHP2OOXML($text); + $anchor = $title->getAnchor(); + $bookmarkId = $title->getBookmarkId(); + $style = $title->getStyle(); + + $xmlWriter->startElement('w:p'); + + if (!empty($style)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $style); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'end'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:bookmarkStart'); + $xmlWriter->writeAttribute('w:id', $bookmarkId); + $xmlWriter->writeAttribute('w:name', $anchor); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:t'); + $xmlWriter->writeRaw($text); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:bookmarkEnd'); + $xmlWriter->writeAttribute('w:id', $bookmarkId); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + } + + protected function _writeFootnote(XMLWriter $xmlWriter, Footnote $footnote) + { + $xmlWriter->startElement('w:footnote'); + $xmlWriter->writeAttribute('w:id', $footnote->getReferenceId()); + + $styleParagraph = $footnote->getParagraphStyle(); + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; + + $xmlWriter->startElement('w:p'); + + if ($SpIsObject) { + $this->_writeParagraphStyle($xmlWriter, $styleParagraph); + } elseif (!$SpIsObject && !is_null($styleParagraph)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleParagraph); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $elements = $footnote->getElements(); + if (count($elements) > 0) { + foreach ($elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element, true); + } elseif ($element instanceof Link) { + $this->_writeLink($xmlWriter, $element, true); + } + } + } + + $xmlWriter->endElement(); // w:p + $xmlWriter->endElement(); // w:footnote + } + + protected function _writeFootnoteReference(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false) + { + if (!$withoutP) { + $xmlWriter->startElement('w:p'); + } + + $xmlWriter->startElement('w:r'); + + $xmlWriter->startElement('w:footnoteReference'); + $xmlWriter->writeAttribute('w:id', $footnote->getReferenceId()); + $xmlWriter->endElement(); // w:footnoteReference + + $xmlWriter->endElement(); // w:r + + if (!$withoutP) { + $xmlWriter->endElement(); // w:p + } + } +} diff --git a/Classes/PHPWord/Writer/Word2007/ContentTypes.php b/src/PhpWord/Writer/Word2007/ContentTypes.php similarity index 65% rename from Classes/PHPWord/Writer/Word2007/ContentTypes.php rename to src/PhpWord/Writer/Word2007/ContentTypes.php index 26032ae169..be74594b67 100755 --- a/Classes/PHPWord/Writer/Word2007/ContentTypes.php +++ b/src/PhpWord/Writer/Word2007/ContentTypes.php @@ -1,8 +1,8 @@ getParentWriter()->getUseDiskCaching()) { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header - $objWriter->startDocument('1.0', 'UTF-8', 'yes'); + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); // Types - $objWriter->startElement('Types'); - $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types'); + $xmlWriter->startElement('Types'); + $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types'); // Rels $this->_writeDefaultContentType( - $objWriter, + $xmlWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml' ); // XML $this->_writeDefaultContentType( - $objWriter, + $xmlWriter, 'xml', 'application/xml' ); // Add media content-types foreach ($_imageTypes as $key => $value) { - $this->_writeDefaultContentType($objWriter, $key, $value); + $this->_writeDefaultContentType($xmlWriter, $key, $value); } // Add embedding content-types if (count($_objectTypes) > 0) { $this->_writeDefaultContentType( - $objWriter, + $xmlWriter, 'bin', 'application/vnd.openxmlformats-officedocument.oleObject' ); @@ -86,76 +78,76 @@ public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers // DocProps $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml' ); $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml' ); // Document $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/document.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml' ); // Styles $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/styles.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml' ); // Numbering $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml' ); // Settings $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/settings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml' ); // Theme1 $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml' ); // WebSettings $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/webSettings.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml' ); // Font Table $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/fontTable.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml' ); // Footnotes $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/footnotes.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml' ); for ($i = 1; $i <= $_cHdrs; $i++) { $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/header' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml' ); @@ -164,29 +156,30 @@ public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers for ($i = 1; $i <= count($footers); $i++) { if (!is_null($footers[$i])) { $this->_writeOverrideContentType( - $objWriter, + $xmlWriter, '/word/footer' . $i . '.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml' ); } } - $objWriter->endElement(); + + $xmlWriter->endElement(); // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } /** * Get image mime type * - * @param string $pFile Filename - * @return string Mime Type - * @throws Exception + * @param string $pFile Filename + * @return string Mime Type + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ private function _getImageMimeType($pFile = '') { - if (PHPWord_Shared_File::file_exists($pFile)) { + if (File::file_exists($pFile)) { $image = getimagesize($pFile); return image_type_to_mime_type($image[2]); } else { @@ -195,42 +188,38 @@ private function _getImageMimeType($pFile = '') } /** - * Write Default content type - * - * @param PHPWord_Shared_XMLWriter $objWriter XML Writer - * @param string $pPartname Part name - * @param string $pContentType Content type - * @throws Exception + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer + * @param string $pPartname Part name + * @param string $pContentType Content type + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ - private function _writeDefaultContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') + private function _writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '') { if ($pPartname != '' && $pContentType != '') { // Write content type - $objWriter->startElement('Default'); - $objWriter->writeAttribute('Extension', $pPartname); - $objWriter->writeAttribute('ContentType', $pContentType); - $objWriter->endElement(); + $xmlWriter->startElement('Default'); + $xmlWriter->writeAttribute('Extension', $pPartname); + $xmlWriter->writeAttribute('ContentType', $pContentType); + $xmlWriter->endElement(); } else { throw new Exception("Invalid parameters passed."); } } /** - * Write Override content type - * - * @param PHPWord_Shared_XMLWriter $objWriter XML Writer - * @param string $pPartname Part name - * @param string $pContentType Content type - * @throws Exception + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param string $pPartname Part name + * @param string $pContentType Content type + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ - private function _writeOverrideContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') + private function _writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '') { if ($pPartname != '' && $pContentType != '') { // Write content type - $objWriter->startElement('Override'); - $objWriter->writeAttribute('PartName', $pPartname); - $objWriter->writeAttribute('ContentType', $pContentType); - $objWriter->endElement(); + $xmlWriter->startElement('Override'); + $xmlWriter->writeAttribute('PartName', $pPartname); + $xmlWriter->writeAttribute('ContentType', $pContentType); + $xmlWriter->endElement(); } else { throw new Exception("Invalid parameters passed."); } diff --git a/src/PhpWord/Writer/Word2007/DocProps.php b/src/PhpWord/Writer/Word2007/DocProps.php new file mode 100644 index 0000000000..bbfc6523f8 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/DocProps.php @@ -0,0 +1,184 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); + + // Properties + $xmlWriter->startElement('Properties'); + $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'); + $xmlWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); + + // Application + $xmlWriter->writeElement('Application', 'Microsoft Office Word'); + + // ScaleCrop + $xmlWriter->writeElement('ScaleCrop', 'false'); + + // HeadingPairs + $xmlWriter->startElement('HeadingPairs'); + + // Vector + $xmlWriter->startElement('vt:vector'); + $xmlWriter->writeAttribute('size', '4'); + $xmlWriter->writeAttribute('baseType', 'variant'); + + // Variant + $xmlWriter->startElement('vt:variant'); + $xmlWriter->writeElement('vt:lpstr', 'Theme'); + $xmlWriter->endElement(); + + // Variant + $xmlWriter->startElement('vt:variant'); + $xmlWriter->writeElement('vt:i4', '1'); + $xmlWriter->endElement(); + + // Variant + $xmlWriter->startElement('vt:variant'); + $xmlWriter->writeElement('vt:lpstr', 'Slide Titles'); + $xmlWriter->endElement(); + + // Variant + $xmlWriter->startElement('vt:variant'); + $xmlWriter->writeElement('vt:i4', '1'); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + // TitlesOfParts + $xmlWriter->startElement('TitlesOfParts'); + + // Vector + $xmlWriter->startElement('vt:vector'); + $xmlWriter->writeAttribute('size', '1'); + $xmlWriter->writeAttribute('baseType', 'lpstr'); + + $xmlWriter->writeElement('vt:lpstr', 'Office Theme'); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + // Company + $xmlWriter->writeElement('Company', $phpWord->getDocumentProperties()->getCompany()); + + // LinksUpToDate + $xmlWriter->writeElement('LinksUpToDate', 'false'); + + // SharedDoc + $xmlWriter->writeElement('SharedDoc', 'false'); + + // HyperlinksChanged + $xmlWriter->writeElement('HyperlinksChanged', 'false'); + + // AppVersion + $xmlWriter->writeElement('AppVersion', '12.0000'); + + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } + + + public function writeDocPropsCore(PhpWord $phpWord = null) + { + // Create XML writer + $xmlWriter = null; + if ($this->getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); + + // cp:coreProperties + $xmlWriter->startElement('cp:coreProperties'); + $xmlWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'); + $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); + $xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); + $xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/'); + $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); + + // dc:creator + $xmlWriter->writeElement('dc:creator', $phpWord->getDocumentProperties()->getCreator()); + + // cp:lastModifiedBy + $xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocumentProperties()->getLastModifiedBy()); + + // dcterms:created + $xmlWriter->startElement('dcterms:created'); + $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); + $xmlWriter->writeRaw(date(DATE_W3C, $phpWord->getDocumentProperties()->getCreated())); + $xmlWriter->endElement(); + + // dcterms:modified + $xmlWriter->startElement('dcterms:modified'); + $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); + $xmlWriter->writeRaw(date(DATE_W3C, $phpWord->getDocumentProperties()->getModified())); + $xmlWriter->endElement(); + + // dc:title + $xmlWriter->writeElement('dc:title', $phpWord->getDocumentProperties()->getTitle()); + + // dc:description + $xmlWriter->writeElement('dc:description', $phpWord->getDocumentProperties()->getDescription()); + + // dc:subject + $xmlWriter->writeElement('dc:subject', $phpWord->getDocumentProperties()->getSubject()); + + // cp:keywords + $xmlWriter->writeElement('cp:keywords', $phpWord->getDocumentProperties()->getKeywords()); + + // cp:category + $xmlWriter->writeElement('cp:category', $phpWord->getDocumentProperties()->getCategory()); + + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } +} diff --git a/src/PhpWord/Writer/Word2007/Document.php b/src/PhpWord/Writer/Word2007/Document.php new file mode 100644 index 0000000000..09710ba6a4 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Document.php @@ -0,0 +1,505 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); + + // w:document + $xmlWriter->startElement('w:document'); + + $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); + $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); + $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); + $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); + $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); + $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); + $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); + $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); + $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); + + $xmlWriter->startElement('w:body'); + + $_sections = $phpWord->getSections(); + $countSections = count($_sections); + $pSection = 0; + + if ($countSections > 0) { + foreach ($_sections as $section) { + $pSection++; + + $_elements = $section->getElements(); + + foreach ($_elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element); + } elseif ($element instanceof TextRun) { + $this->_writeTextRun($xmlWriter, $element); + } elseif ($element instanceof Link) { + $this->_writeLink($xmlWriter, $element); + } elseif ($element instanceof Title) { + $this->_writeTitle($xmlWriter, $element); + } elseif ($element instanceof TextBreak) { + $this->_writeTextBreak($xmlWriter, $element); + } elseif ($element instanceof PageBreak) { + $this->_writePageBreak($xmlWriter); + } elseif ($element instanceof Table) { + $this->_writeTable($xmlWriter, $element); + } elseif ($element instanceof ListItem) { + $this->_writeListItem($xmlWriter, $element); + } elseif ($element instanceof Image || + $element instanceof MemoryImage + ) { + $this->_writeImage($xmlWriter, $element); + } elseif ($element instanceof Object) { + $this->_writeObject($xmlWriter, $element); + } elseif ($element instanceof TOC) { + $this->_writeTOC($xmlWriter); + } elseif ($element instanceof Footnote) { + $this->_writeFootnoteReference($xmlWriter, $element); + } + } + + if ($pSection == $countSections) { + $this->_writeEndSection($xmlWriter, $section); + } else { + $this->_writeSection($xmlWriter, $section); + } + } + } + + $xmlWriter->endElement(); // End w:body + $xmlWriter->endElement(); // End w:document + + // Return + return $xmlWriter->getData(); + } + + private function _writeSection(XMLWriter $xmlWriter, Section $section) + { + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:pPr'); + $this->_writeEndSection($xmlWriter, $section, 3); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + private function _writeEndSection(XMLWriter $xmlWriter, Section $section) + { + $settings = $section->getSettings(); + $_headers = $section->getHeaders(); + $_footer = $section->getFooter(); + $pgSzW = $settings->getPageSizeW(); + $pgSzH = $settings->getPageSizeH(); + $orientation = $settings->getOrientation(); + + $marginTop = $settings->getMarginTop(); + $marginLeft = $settings->getMarginLeft(); + $marginRight = $settings->getMarginRight(); + $marginBottom = $settings->getMarginBottom(); + + $headerHeight = $settings->getHeaderHeight(); + $footerHeight = $settings->getFooterHeight(); + + $borders = $settings->getBorderSize(); + + $colsNum = $settings->getColsNum(); + $colsSpace = $settings->getColsSpace(); + $breakType = $settings->getBreakType(); + + $xmlWriter->startElement('w:sectPr'); + + foreach ($_headers as &$_header) { + $rId = $_header->getRelationId(); + $xmlWriter->startElement('w:headerReference'); + $xmlWriter->writeAttribute('w:type', $_header->getType()); + $xmlWriter->writeAttribute('r:id', 'rId' . $rId); + $xmlWriter->endElement(); + } + + if ($section->hasDifferentFirstPage()) { + $xmlWriter->startElement('w:titlePg'); + $xmlWriter->endElement(); + } + + if (!is_null($breakType)) { + $xmlWriter->startElement('w:type'); + $xmlWriter->writeAttribute('w:val', $breakType); + $xmlWriter->endElement(); + } + + if (!is_null($_footer)) { + $rId = $_footer->getRelationId(); + $xmlWriter->startElement('w:footerReference'); + $xmlWriter->writeAttribute('w:type', 'default'); + $xmlWriter->writeAttribute('r:id', 'rId' . $rId); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:pgSz'); + $xmlWriter->writeAttribute('w:w', $pgSzW); + $xmlWriter->writeAttribute('w:h', $pgSzH); + + if (!is_null($orientation) && strtolower($orientation) != 'portrait') { + $xmlWriter->writeAttribute('w:orient', $orientation); + } + + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:pgMar'); + $xmlWriter->writeAttribute('w:top', $marginTop); + $xmlWriter->writeAttribute('w:right', $marginRight); + $xmlWriter->writeAttribute('w:bottom', $marginBottom); + $xmlWriter->writeAttribute('w:left', $marginLeft); + $xmlWriter->writeAttribute('w:header', $headerHeight); + $xmlWriter->writeAttribute('w:footer', $footerHeight); + $xmlWriter->writeAttribute('w:gutter', '0'); + $xmlWriter->endElement(); + + + if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) { + $borderColor = $settings->getBorderColor(); + + $xmlWriter->startElement('w:pgBorders'); + $xmlWriter->writeAttribute('w:offsetFrom', 'page'); + + if (!is_null($borders[0])) { + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[0]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[0]); + $xmlWriter->endElement(); + } + + if (!is_null($borders[1])) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[1]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[1]); + $xmlWriter->endElement(); + } + + if (!is_null($borders[2])) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[2]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[2]); + $xmlWriter->endElement(); + } + + if (!is_null($borders[3])) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[3]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[3]); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + + // Page numbering + if (null !== $settings->getPageNumberingStart()) { + $xmlWriter->startElement('w:pgNumType'); + $xmlWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart()); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:cols'); + $xmlWriter->writeAttribute('w:num', $colsNum); + $xmlWriter->writeAttribute('w:space', $colsSpace); + $xmlWriter->endElement(); + + + $xmlWriter->endElement(); + } + + private function _writePageBreak(XMLWriter $xmlWriter) + { + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:br'); + $xmlWriter->writeAttribute('w:type', 'page'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + public function _writeListItem(XMLWriter $xmlWriter, ListItem $listItem) + { + $textObject = $listItem->getTextObject(); + $text = $textObject->getText(); + $styleParagraph = $textObject->getParagraphStyle(); + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; + + $depth = $listItem->getDepth(); + $listType = $listItem->getStyle()->getListType(); + + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:pPr'); + + if ($SpIsObject) { + $this->_writeParagraphStyle($xmlWriter, $styleParagraph, true); + } elseif (!$SpIsObject && !is_null($styleParagraph)) { + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleParagraph); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:numPr'); + + $xmlWriter->startElement('w:ilvl'); + $xmlWriter->writeAttribute('w:val', $depth); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:numId'); + $xmlWriter->writeAttribute('w:val', $listType); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $this->_writeText($xmlWriter, $textObject, true); + + $xmlWriter->endElement(); + } + + protected function _writeObject(XMLWriter $xmlWriter, Object $object) + { + $rIdObject = $object->getRelationId(); + $rIdImage = $object->getImageRelationId(); + $shapeId = md5($rIdObject . '_' . $rIdImage); + + $objectId = $object->getObjectId(); + + $style = $object->getStyle(); + $width = $style->getWidth(); + $height = $style->getHeight(); + $align = $style->getAlign(); + + + $xmlWriter->startElement('w:p'); + + if (!is_null($align)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:jc'); + $xmlWriter->writeAttribute('w:val', $align); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:r'); + + $xmlWriter->startElement('w:object'); + $xmlWriter->writeAttribute('w:dxaOrig', '249'); + $xmlWriter->writeAttribute('w:dyaOrig', '160'); + + $xmlWriter->startElement('v:shape'); + $xmlWriter->writeAttribute('id', $shapeId); + $xmlWriter->writeAttribute('type', '#_x0000_t75'); + $xmlWriter->writeAttribute('style', 'width:104px;height:67px'); + $xmlWriter->writeAttribute('o:ole', ''); + + $xmlWriter->startElement('v:imagedata'); + $xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage); + $xmlWriter->writeAttribute('o:title', ''); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->startElement('o:OLEObject'); + $xmlWriter->writeAttribute('Type', 'Embed'); + $xmlWriter->writeAttribute('ProgID', 'Package'); + $xmlWriter->writeAttribute('ShapeID', $shapeId); + $xmlWriter->writeAttribute('DrawAspect', 'Icon'); + $xmlWriter->writeAttribute('ObjectID', '_' . $objectId); + $xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); // w:r + + $xmlWriter->endElement(); // w:p + } + + private function _writeTOC(XMLWriter $xmlWriter) + { + $titles = TOC::getTitles(); + $styleFont = TOC::getStyleFont(); + + $styleTOC = TOC::getStyleTOC(); + $fIndent = $styleTOC->getIndent(); + $tabLeader = $styleTOC->getTabLeader(); + $tabPos = $styleTOC->getTabPos(); + + $isObject = ($styleFont instanceof Font) ? true : false; + + for ($i = 0; $i < count($titles); $i++) { + $title = $titles[$i]; + $indent = ($title['depth'] - 1) * $fIndent; + + $xmlWriter->startElement('w:p'); + + $xmlWriter->startElement('w:pPr'); + + if ($isObject && !is_null($styleFont->getParagraphStyle())) { + $this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle()); + } + + if ($indent > 0) { + $xmlWriter->startElement('w:ind'); + $xmlWriter->writeAttribute('w:left', $indent); + $xmlWriter->endElement(); + } + + if (!empty($styleFont) && !$isObject) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleFont); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:tabs'); + $xmlWriter->startElement('w:tab'); + $xmlWriter->writeAttribute('w:val', 'right'); + if (!empty($tabLeader)) { + $xmlWriter->writeAttribute('w:leader', $tabLeader); + } + $xmlWriter->writeAttribute('w:pos', $tabPos); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); // w:pPr + + + if ($i == 0) { + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'begin'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:instrText'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); + $xmlWriter->writeRaw('TOC \o "1-9" \h \z \u'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'separate'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:hyperlink'); + $xmlWriter->writeAttribute('w:anchor', $title['anchor']); + $xmlWriter->writeAttribute('w:history', '1'); + + $xmlWriter->startElement('w:r'); + + if ($isObject) { + $this->_writeTextStyle($xmlWriter, $styleFont); + } + + $xmlWriter->startElement('w:t'); + $xmlWriter->writeRaw($title['text']); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->writeElement('w:tab', null); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'begin'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:instrText'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); + $xmlWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'end'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); // w:hyperlink + + $xmlWriter->endElement(); // w:p + } + + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'end'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } +} diff --git a/Classes/PHPWord/Writer/Word2007/DocumentRels.php b/src/PhpWord/Writer/Word2007/DocumentRels.php similarity index 63% rename from Classes/PHPWord/Writer/Word2007/DocumentRels.php rename to src/PhpWord/Writer/Word2007/DocumentRels.php index eda62c5e7f..79b7bfba36 100755 --- a/Classes/PHPWord/Writer/Word2007/DocumentRels.php +++ b/src/PhpWord/Writer/Word2007/DocumentRels.php @@ -1,8 +1,8 @@ getParentWriter()->getUseDiskCaching()) { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header - $objWriter->startDocument('1.0', 'UTF-8', 'yes'); + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); // Relationships - $objWriter->startElement('Relationships'); - $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); + $xmlWriter->startElement('Relationships'); + $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); // Relationship word/document.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles', 'styles.xml' @@ -63,7 +57,7 @@ public function writeDocumentRels($_relsCollection) // Relationship word/numbering.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, 2, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering', 'numbering.xml' @@ -71,7 +65,7 @@ public function writeDocumentRels($_relsCollection) // Relationship word/settings.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, 3, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings', 'settings.xml' @@ -79,7 +73,7 @@ public function writeDocumentRels($_relsCollection) // Relationship word/settings.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, 4, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', 'theme/theme1.xml' @@ -87,7 +81,7 @@ public function writeDocumentRels($_relsCollection) // Relationship word/settings.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, 5, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings', 'webSettings.xml' @@ -95,7 +89,7 @@ public function writeDocumentRels($_relsCollection) // Relationship word/settings.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, 6, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable', 'fontTable.xml' @@ -109,7 +103,7 @@ public function writeDocumentRels($_relsCollection) $targetMode = ($relationType == 'hyperlink') ? 'External' : ''; $this->_writeRelationship( - $objWriter, + $xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, @@ -118,34 +112,28 @@ public function writeDocumentRels($_relsCollection) } - $objWriter->endElement(); + $xmlWriter->endElement(); // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } - /** - * Write word/_rels/(header|footer)(\d).xml.rels - * - * @param array $_relsCollection - * @return string XML data - */ public function writeHeaderFooterRels($_relsCollection) { // Create XML writer - $objWriter = null; + $xmlWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header - $objWriter->startDocument('1.0', 'UTF-8', 'yes'); + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); // Relationships - $objWriter->startElement('Relationships'); - $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); + $xmlWriter->startElement('Relationships'); + $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); // Relationships to Images / Embeddings / Headers / Footers foreach ($_relsCollection as $relation) { @@ -154,29 +142,21 @@ public function writeHeaderFooterRels($_relsCollection) $relationId = $relation['rID']; $this->_writeRelationship( - $objWriter, + $xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName ); } - $objWriter->endElement(); + + $xmlWriter->endElement(); // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } - /** - * Write individual relations - * - * @param PHPWord_Shared_XMLWriter $objWriter - * @param int $pId - * @param string $pType - * @param string $pTarget - * @param string $pTargetMode - */ - private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') + private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if ($pType != '' && $pTarget != '') { if (strpos($pId, 'rId') === false) { @@ -184,16 +164,16 @@ private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, } // Write relationship - $objWriter->startElement('Relationship'); - $objWriter->writeAttribute('Id', $pId); - $objWriter->writeAttribute('Type', $pType); - $objWriter->writeAttribute('Target', $pTarget); + $xmlWriter->startElement('Relationship'); + $xmlWriter->writeAttribute('Id', $pId); + $xmlWriter->writeAttribute('Type', $pType); + $xmlWriter->writeAttribute('Target', $pTarget); if ($pTargetMode != '') { - $objWriter->writeAttribute('TargetMode', $pTargetMode); + $xmlWriter->writeAttribute('TargetMode', $pTargetMode); } - $objWriter->endElement(); + $xmlWriter->endElement(); } else { throw new Exception("Invalid parameters passed."); } diff --git a/src/PhpWord/Writer/Word2007/Footer.php b/src/PhpWord/Writer/Word2007/Footer.php new file mode 100644 index 0000000000..e10a7eff05 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Footer.php @@ -0,0 +1,88 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); + + $xmlWriter->startElement('w:ftr'); + $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); + $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); + $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); + $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); + $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); + $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); + $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); + $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); + $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); + + $_elements = $footer->getElements(); + + foreach ($_elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element); + } elseif ($element instanceof TextRun) { + $this->_writeTextRun($xmlWriter, $element); + } elseif ($element instanceof TextBreak) { + $this->_writeTextBreak($xmlWriter, $element); + } elseif ($element instanceof Table) { + $this->_writeTable($xmlWriter, $element); + } elseif ($element instanceof Image || + $element instanceof MemoryImage + ) { + $this->_writeImage($xmlWriter, $element); + } elseif ($element instanceof PreserveText) { + $this->_writePreserveText($xmlWriter, $element); + } + } + + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } +} diff --git a/src/PhpWord/Writer/Word2007/Footnotes.php b/src/PhpWord/Writer/Word2007/Footnotes.php new file mode 100644 index 0000000000..fa048c4623 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Footnotes.php @@ -0,0 +1,84 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); + + $xmlWriter->startElement('w:footnotes'); + $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); + $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); + + // write separator and continuation separator + $xmlWriter->startElement('w:footnote'); + $xmlWriter->writeAttribute('w:id', 0); + $xmlWriter->writeAttribute('w:type', 'separator'); + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:separator'); + $xmlWriter->endElement(); // w:separator + $xmlWriter->endElement(); // w:r + $xmlWriter->endElement(); // w:p + $xmlWriter->endElement(); // w:footnote + + $xmlWriter->startElement('w:footnote'); + $xmlWriter->writeAttribute('w:id', 1); + $xmlWriter->writeAttribute('w:type', 'continuationSeparator'); + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:continuationSeparator'); + $xmlWriter->endElement(); // w:continuationSeparator + $xmlWriter->endElement(); // w:r + $xmlWriter->endElement(); // w:p + $xmlWriter->endElement(); // w:footnote + + foreach ($allFootnotesCollection as $footnote) { + if ($footnote instanceof Footnote) { + $this->_writeFootnote($xmlWriter, $footnote); + } + } + + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } +} diff --git a/Classes/PHPWord/Writer/Word2007/FootnotesRels.php b/src/PhpWord/Writer/Word2007/FootnotesRels.php similarity index 54% rename from Classes/PHPWord/Writer/Word2007/FootnotesRels.php rename to src/PhpWord/Writer/Word2007/FootnotesRels.php index 487219855b..7f76c3cdef 100644 --- a/Classes/PHPWord/Writer/Word2007/FootnotesRels.php +++ b/src/PhpWord/Writer/Word2007/FootnotesRels.php @@ -1,8 +1,8 @@ getParentWriter()->getUseDiskCaching()) { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header - $objWriter->startDocument('1.0', 'UTF-8', 'yes'); + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); // Relationships - $objWriter->startElement('Relationships'); - $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); + $xmlWriter->startElement('Relationships'); + $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); // Relationships to Links foreach ($_relsCollection as $relation) { @@ -59,25 +54,16 @@ public function writeFootnotesRels($_relsCollection) $relationId = $relation['rID']; $targetMode = ($relationType == 'hyperlink') ? 'External' : ''; - $this->_writeRelationship($objWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode); + $this->_writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode); } - $objWriter->endElement(); + $xmlWriter->endElement(); // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } - /** - * Write individual relations - * - * @param PHPWord_Shared_XMLWriter $objWriter - * @param int $pId - * @param string $pType - * @param string $pTarget - * @param string $pTargetMode - */ - private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') + private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if ($pType != '' && $pTarget != '') { if (strpos($pId, 'rId') === false) { @@ -85,16 +71,16 @@ private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, } // Write relationship - $objWriter->startElement('Relationship'); - $objWriter->writeAttribute('Id', $pId); - $objWriter->writeAttribute('Type', $pType); - $objWriter->writeAttribute('Target', $pTarget); + $xmlWriter->startElement('Relationship'); + $xmlWriter->writeAttribute('Id', $pId); + $xmlWriter->writeAttribute('Type', $pType); + $xmlWriter->writeAttribute('Target', $pTarget); if ($pTargetMode != '') { - $objWriter->writeAttribute('TargetMode', $pTargetMode); + $xmlWriter->writeAttribute('TargetMode', $pTargetMode); } - $objWriter->endElement(); + $xmlWriter->endElement(); } else { throw new Exception("Invalid parameters passed."); } diff --git a/src/PhpWord/Writer/Word2007/Header.php b/src/PhpWord/Writer/Word2007/Header.php new file mode 100644 index 0000000000..b5695f8816 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Header.php @@ -0,0 +1,92 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); + + $xmlWriter->startElement('w:hdr'); + $xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006'); + $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); + $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); + $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math'); + $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); + $xmlWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'); + $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word'); + $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); + $xmlWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml'); + + + $_elements = $header->getElements(); + + foreach ($_elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element); + } elseif ($element instanceof TextRun) { + $this->_writeTextRun($xmlWriter, $element); + } elseif ($element instanceof TextBreak) { + $this->_writeTextBreak($xmlWriter, $element); + } elseif ($element instanceof Table) { + $this->_writeTable($xmlWriter, $element); + } elseif ($element instanceof Image || + $element instanceof MemoryImage + ) { + if (!$element->getIsWatermark()) { + $this->_writeImage($xmlWriter, $element); + } else { + $this->_writeWatermark($xmlWriter, $element); + } + } elseif ($element instanceof PreserveText) { + $this->_writePreserveText($xmlWriter, $element); + } + } + + $xmlWriter->endElement(); + + // Return + return $xmlWriter->getData(); + } +} diff --git a/Classes/PHPWord/Writer/Word2007/Rels.php b/src/PhpWord/Writer/Word2007/Rels.php similarity index 55% rename from Classes/PHPWord/Writer/Word2007/Rels.php rename to src/PhpWord/Writer/Word2007/Rels.php index 9304bda668..63e8c848eb 100755 --- a/Classes/PHPWord/Writer/Word2007/Rels.php +++ b/src/PhpWord/Writer/Word2007/Rels.php @@ -1,8 +1,8 @@ getParentWriter()->getUseDiskCaching()) { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { - $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); } // XML header - $objWriter->startDocument('1.0', 'UTF-8', 'yes'); + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); // Relationships - $objWriter->startElement('Relationships'); - $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); + $xmlWriter->startElement('Relationships'); + $xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); $relationId = 1; // Relationship word/document.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', 'word/document.xml' @@ -64,7 +60,7 @@ public function writeRelationships(PHPWord $pPHPWord = null) // Relationship docProps/core.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, ++$relationId, 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', 'docProps/core.xml' @@ -72,29 +68,28 @@ public function writeRelationships(PHPWord $pPHPWord = null) // Relationship docProps/app.xml $this->_writeRelationship( - $objWriter, + $xmlWriter, ++$relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', 'docProps/app.xml' ); - $objWriter->endElement(); + $xmlWriter->endElement(); - // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } /** * Write Override content type * - * @param PHPWord_Shared_XMLWriter $objWriter XML Writer - * @param int $pId Relationship ID. rId will be prepended! - * @param string $pType Relationship type - * @param string $pTarget Relationship target - * @param string $pTargetMode Relationship target mode - * @throws Exception + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param int $pId Relationship ID. rId will be prepended! + * @param string $pType Relationship type + * @param string $pTarget Relationship target + * @param string $pTargetMode Relationship target mode + * @throws \PhpOffice\PhpWord\Exceptions\Exception */ - private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') + private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if ($pType != '' && $pTarget != '') { if (strpos($pId, 'rId') === false) { @@ -102,16 +97,16 @@ private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, } // Write relationship - $objWriter->startElement('Relationship'); - $objWriter->writeAttribute('Id', $pId); - $objWriter->writeAttribute('Type', $pType); - $objWriter->writeAttribute('Target', $pTarget); + $xmlWriter->startElement('Relationship'); + $xmlWriter->writeAttribute('Id', $pId); + $xmlWriter->writeAttribute('Type', $pType); + $xmlWriter->writeAttribute('Target', $pTarget); if ($pTargetMode != '') { - $objWriter->writeAttribute('TargetMode', $pTargetMode); + $xmlWriter->writeAttribute('TargetMode', $pTargetMode); } - $objWriter->endElement(); + $xmlWriter->endElement(); } else { throw new Exception("Invalid parameters passed."); } diff --git a/src/PhpWord/Writer/Word2007/Styles.php b/src/PhpWord/Writer/Word2007/Styles.php new file mode 100644 index 0000000000..ff45c9a18b --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Styles.php @@ -0,0 +1,396 @@ +getParentWriter()->getUseDiskCaching()) { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); + } else { + $xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); + } + + $this->_document = $phpWord; + + // XML header + $xmlWriter->startDocument('1.0', 'UTF-8', 'yes'); + + $xmlWriter->startElement('w:styles'); + + $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); + $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'); + + // Write DocDefaults + $this->_writeDocDefaults($xmlWriter); + + + // Write Style Definitions + $styles = Style::getStyles(); + + // Write normal paragraph style + $normalStyle = null; + if (array_key_exists('Normal', $styles)) { + $normalStyle = $styles['Normal']; + } + $xmlWriter->startElement('w:style'); + $xmlWriter->writeAttribute('w:type', 'paragraph'); + $xmlWriter->writeAttribute('w:default', '1'); + $xmlWriter->writeAttribute('w:styleId', 'Normal'); + $xmlWriter->startElement('w:name'); + $xmlWriter->writeAttribute('w:val', 'Normal'); + $xmlWriter->endElement(); + if (!is_null($normalStyle)) { + $this->_writeParagraphStyle($xmlWriter, $normalStyle); + } + $xmlWriter->endElement(); + + // Write other styles + if (count($styles) > 0) { + foreach ($styles as $styleName => $style) { + if ($styleName == 'Normal') { + continue; + } + if ($style instanceof Font) { + + $paragraphStyle = $style->getParagraphStyle(); + $styleType = $style->getStyleType(); + + $type = ($styleType == 'title') ? 'paragraph' : 'character'; + + if (!is_null($paragraphStyle)) { + $type = 'paragraph'; + } + + $xmlWriter->startElement('w:style'); + $xmlWriter->writeAttribute('w:type', $type); + + if ($styleType == 'title') { + $arrStyle = explode('_', $styleName); + $styleId = 'Heading' . $arrStyle[1]; + $styleName = 'heading ' . $arrStyle[1]; + $styleLink = 'Heading' . $arrStyle[1] . 'Char'; + $xmlWriter->writeAttribute('w:styleId', $styleId); + + $xmlWriter->startElement('w:link'); + $xmlWriter->writeAttribute('w:val', $styleLink); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:name'); + $xmlWriter->writeAttribute('w:val', $styleName); + $xmlWriter->endElement(); + + if (!is_null($paragraphStyle)) { + // Point parent style to Normal + $xmlWriter->startElement('w:basedOn'); + $xmlWriter->writeAttribute('w:val', 'Normal'); + $xmlWriter->endElement(); + $this->_writeParagraphStyle($xmlWriter, $paragraphStyle); + } + + $this->_writeTextStyle($xmlWriter, $style); + + $xmlWriter->endElement(); + + } elseif ($style instanceof Paragraph) { + $xmlWriter->startElement('w:style'); + $xmlWriter->writeAttribute('w:type', 'paragraph'); + $xmlWriter->writeAttribute('w:customStyle', '1'); + $xmlWriter->writeAttribute('w:styleId', $styleName); + + $xmlWriter->startElement('w:name'); + $xmlWriter->writeAttribute('w:val', $styleName); + $xmlWriter->endElement(); + + // Parent style + $basedOn = $style->getBasedOn(); + if (!is_null($basedOn)) { + $xmlWriter->startElement('w:basedOn'); + $xmlWriter->writeAttribute('w:val', $basedOn); + $xmlWriter->endElement(); + } + + // Next paragraph style + $next = $style->getNext(); + if (!is_null($next)) { + $xmlWriter->startElement('w:next'); + $xmlWriter->writeAttribute('w:val', $next); + $xmlWriter->endElement(); + } + + $this->_writeParagraphStyle($xmlWriter, $style); + $xmlWriter->endElement(); + + } elseif ($style instanceof TableFull) { + $xmlWriter->startElement('w:style'); + $xmlWriter->writeAttribute('w:type', 'table'); + $xmlWriter->writeAttribute('w:customStyle', '1'); + $xmlWriter->writeAttribute('w:styleId', $styleName); + + $xmlWriter->startElement('w:name'); + $xmlWriter->writeAttribute('w:val', $styleName); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:uiPriority'); + $xmlWriter->writeAttribute('w:val', '99'); + $xmlWriter->endElement(); + + $this->_writeFullTableStyle($xmlWriter, $style); + + $xmlWriter->endElement(); + } + } + } + + $xmlWriter->endElement(); // w:styles + + // Return + return $xmlWriter->getData(); + } + + private function _writeFullTableStyle(XMLWriter $xmlWriter, TableFull $style) + { + + $brdSz = $style->getBorderSize(); + $brdCol = $style->getBorderColor(); + $bgColor = $style->getBgColor(); + $cellMargin = $style->getCellMargin(); + + $bTop = (!is_null($brdSz[0])) ? true : false; + $bLeft = (!is_null($brdSz[1])) ? true : false; + $bRight = (!is_null($brdSz[2])) ? true : false; + $bBottom = (!is_null($brdSz[3])) ? true : false; + $bInsH = (!is_null($brdSz[4])) ? true : false; + $bInsV = (!is_null($brdSz[5])) ? true : false; + $borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false; + + $mTop = (!is_null($cellMargin[0])) ? true : false; + $mLeft = (!is_null($cellMargin[1])) ? true : false; + $mRight = (!is_null($cellMargin[2])) ? true : false; + $mBottom = (!is_null($cellMargin[3])) ? true : false; + $margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false; + + $xmlWriter->startElement('w:tblPr'); + + if ($margins) { + $xmlWriter->startElement('w:tblCellMar'); + if ($mTop) { + echo $margins[0]; + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:w', $cellMargin[0]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + if ($mLeft) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:w', $cellMargin[1]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + if ($mRight) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:w', $cellMargin[2]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + if ($mBottom) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:w', $cellMargin[3]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + + if ($borders) { + $xmlWriter->startElement('w:tblBorders'); + if ($bTop) { + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[0]); + $xmlWriter->writeAttribute('w:color', $brdCol[0]); + $xmlWriter->endElement(); + } + if ($bLeft) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[1]); + $xmlWriter->writeAttribute('w:color', $brdCol[1]); + $xmlWriter->endElement(); + } + if ($bRight) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[2]); + $xmlWriter->writeAttribute('w:color', $brdCol[2]); + $xmlWriter->endElement(); + } + if ($bBottom) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[3]); + $xmlWriter->writeAttribute('w:color', $brdCol[3]); + $xmlWriter->endElement(); + } + if ($bInsH) { + $xmlWriter->startElement('w:insideH'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[4]); + $xmlWriter->writeAttribute('w:color', $brdCol[4]); + $xmlWriter->endElement(); + } + if ($bInsV) { + $xmlWriter->startElement('w:insideV'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[5]); + $xmlWriter->writeAttribute('w:color', $brdCol[5]); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + + $xmlWriter->endElement(); + + if (!is_null($bgColor)) { + $xmlWriter->startElement('w:tcPr'); + $xmlWriter->startElement('w:shd'); + $xmlWriter->writeAttribute('w:val', 'clear'); + $xmlWriter->writeAttribute('w:color', 'auto'); + $xmlWriter->writeAttribute('w:fill', $bgColor); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + // First Row + $firstRow = $style->getFirstRow(); + if (!is_null($firstRow)) { + $this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow); + } + } + + private function _writeRowStyle(XMLWriter $xmlWriter, $type, TableFull $style) + { + $brdSz = $style->getBorderSize(); + $brdCol = $style->getBorderColor(); + $bgColor = $style->getBgColor(); + + $bTop = (!is_null($brdSz[0])) ? true : false; + $bLeft = (!is_null($brdSz[1])) ? true : false; + $bRight = (!is_null($brdSz[2])) ? true : false; + $bBottom = (!is_null($brdSz[3])) ? true : false; + $borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false; + + $xmlWriter->startElement('w:tblStylePr'); + $xmlWriter->writeAttribute('w:type', $type); + + $xmlWriter->startElement('w:tcPr'); + if (!is_null($bgColor)) { + $xmlWriter->startElement('w:shd'); + $xmlWriter->writeAttribute('w:val', 'clear'); + $xmlWriter->writeAttribute('w:color', 'auto'); + $xmlWriter->writeAttribute('w:fill', $bgColor); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:tcBorders'); + if ($bTop) { + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[0]); + $xmlWriter->writeAttribute('w:color', $brdCol[0]); + $xmlWriter->endElement(); + } + if ($bLeft) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[1]); + $xmlWriter->writeAttribute('w:color', $brdCol[1]); + $xmlWriter->endElement(); + } + if ($bRight) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[2]); + $xmlWriter->writeAttribute('w:color', $brdCol[2]); + $xmlWriter->endElement(); + } + if ($bBottom) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[3]); + $xmlWriter->writeAttribute('w:color', $brdCol[3]); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + } + + + private function _writeDocDefaults(XMLWriter $xmlWriter) + { + $fontName = $this->_document->getDefaultFontName(); + $fontSize = $this->_document->getDefaultFontSize(); + + $xmlWriter->startElement('w:docDefaults'); + $xmlWriter->startElement('w:rPrDefault'); + $xmlWriter->startElement('w:rPr'); + + $xmlWriter->startElement('w:rFonts'); + $xmlWriter->writeAttribute('w:ascii', $fontName); + $xmlWriter->writeAttribute('w:hAnsi', $fontName); + $xmlWriter->writeAttribute('w:eastAsia', $fontName); + $xmlWriter->writeAttribute('w:cs', $fontName); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:sz'); + $xmlWriter->writeAttribute('w:val', $fontSize * 2); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:szCs'); + $xmlWriter->writeAttribute('w:val', $fontSize * 2); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } +} diff --git a/Classes/PHPWord/Writer/Word2007/WriterPart.php b/src/PhpWord/Writer/Word2007/WriterPart.php similarity index 63% rename from Classes/PHPWord/Writer/Word2007/WriterPart.php rename to src/PhpWord/Writer/Word2007/WriterPart.php index 35cf348f3a..d147996f8a 100755 --- a/Classes/PHPWord/Writer/Word2007/WriterPart.php +++ b/src/PhpWord/Writer/Word2007/WriterPart.php @@ -1,8 +1,8 @@ _parentWriter = $pWriter; } - /** - * Get parent writer - * - * @return PHPWord_Writer_IWriter - */ public function getParentWriter() { if (!is_null($this->_parentWriter)) { return $this->_parentWriter; } else { - throw new Exception("No parent PHPWord_Writer_IWriter assigned."); + throw new Exception("No parent IWriter assigned."); } } } diff --git a/Classes/PHPWord/_staticDocParts/_doc.png b/src/PhpWord/_staticDocParts/_doc.png similarity index 100% rename from Classes/PHPWord/_staticDocParts/_doc.png rename to src/PhpWord/_staticDocParts/_doc.png diff --git a/Classes/PHPWord/_staticDocParts/_ppt.png b/src/PhpWord/_staticDocParts/_ppt.png similarity index 100% rename from Classes/PHPWord/_staticDocParts/_ppt.png rename to src/PhpWord/_staticDocParts/_ppt.png diff --git a/Classes/PHPWord/_staticDocParts/_xls.png b/src/PhpWord/_staticDocParts/_xls.png similarity index 100% rename from Classes/PHPWord/_staticDocParts/_xls.png rename to src/PhpWord/_staticDocParts/_xls.png diff --git a/Classes/PHPWord/_staticDocParts/fontTable.xml b/src/PhpWord/_staticDocParts/fontTable.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/fontTable.xml rename to src/PhpWord/_staticDocParts/fontTable.xml diff --git a/Classes/PHPWord/_staticDocParts/numbering.xml b/src/PhpWord/_staticDocParts/numbering.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/numbering.xml rename to src/PhpWord/_staticDocParts/numbering.xml diff --git a/Classes/PHPWord/_staticDocParts/settings.xml b/src/PhpWord/_staticDocParts/settings.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/settings.xml rename to src/PhpWord/_staticDocParts/settings.xml diff --git a/Classes/PHPWord/_staticDocParts/theme1.xml b/src/PhpWord/_staticDocParts/theme1.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/theme1.xml rename to src/PhpWord/_staticDocParts/theme1.xml diff --git a/Classes/PHPWord/_staticDocParts/webSettings.xml b/src/PhpWord/_staticDocParts/webSettings.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/webSettings.xml rename to src/PhpWord/_staticDocParts/webSettings.xml diff --git a/tests/PHPWord/AutoloaderTest.php b/tests/PHPWord/AutoloaderTest.php new file mode 100644 index 0000000000..2a5e7cf970 --- /dev/null +++ b/tests/PHPWord/AutoloaderTest.php @@ -0,0 +1,36 @@ +assertContains( + array('PhpOffice\\PhpWord\\Autoloader', 'autoload'), + \spl_autoload_functions() + ); + } + + 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' + ); + } +} diff --git a/tests/PHPWord/IOFactoryTest.php b/tests/PHPWord/IOFactoryTest.php new file mode 100644 index 0000000000..1ac2a381b8 --- /dev/null +++ b/tests/PHPWord/IOFactoryTest.php @@ -0,0 +1,54 @@ +assertInstanceOf( + 'PhpOffice\\PhpWord\\Writer\\Word2007', + IOFactory::createWriter(new PhpWord(), 'Word2007') + ); + } + + /** + * @covers ::createWriter + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage Could not instantiate "Word2006" class. + */ + final public function testNonexistentWriterCanNotBeCreated() + { + IOFactory::createWriter(new PhpWord(), 'Word2006'); + } + + /** + * @covers ::createReader + */ + final public function testExistingReaderCanBeCreated() + { + $this->assertInstanceOf( + 'PhpOffice\\PhpWord\\Reader\\Word2007', + IOFactory::createReader('Word2007') + ); + } + + /** + * @covers ::createReader + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage Could not instantiate "Word2006" class. + */ + final public function testNonexistentReaderCanNotBeCreated() + { + IOFactory::createReader('Word2006'); + } +} diff --git a/tests/PHPWord/MediaTest.php b/tests/PHPWord/MediaTest.php new file mode 100644 index 0000000000..7969b442b9 --- /dev/null +++ b/tests/PHPWord/MediaTest.php @@ -0,0 +1,58 @@ +assertEquals(Media::getSectionMediaElements(), array()); + } + + public function testCountSectionMediaElementsWithNull() + { + $this->assertEquals(Media::countSectionMediaElements(), 0); + } + + public function testGetHeaderMediaElements() + { + $this->assertAttributeEquals( + Media::getHeaderMediaElements(), + '_headerMedia', + 'PhpOffice\\PhpWord\\Media' + ); + } + + public function testGetFooterMediaElements() + { + $this->assertAttributeEquals( + Media::getFooterMediaElements(), + '_footerMedia', + 'PhpOffice\\PhpWord\\Media' + ); + } + + /** + * Todo: add memory image to this test + * + * @covers \PhpOffice\PhpWord\Media::addSectionMediaElement + */ + public function testAddSectionMediaElement() + { + $section = new Section(0); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars_noext_jpg"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars.jpg"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/mario.gif"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/firefox.png"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/duke_nukem.bmp"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/angela_merkel.tif"); + + $elements = $section->getElements(); + $this->assertEquals(6, count($elements)); + foreach ($elements as $element) { + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); + } + } +} diff --git a/tests/PHPWord/PhpWordTest.php b/tests/PHPWord/PhpWordTest.php new file mode 100644 index 0000000000..d9896d18c8 --- /dev/null +++ b/tests/PHPWord/PhpWordTest.php @@ -0,0 +1,157 @@ +assertEquals(new DocumentProperties(), $phpWord->getDocumentProperties()); + $this->assertEquals(PhpWord::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName()); + $this->assertEquals(PhpWord::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize()); + } + + /** + * @covers ::setDocumentProperties + * @covers ::getDocumentProperties + */ + public function testSetGetDocumentProperties() + { + $phpWord = new PhpWord(); + $creator = 'PhpWord'; + $properties = $phpWord->getDocumentProperties(); + $properties->setCreator($creator); + $phpWord->setDocumentProperties($properties); + $this->assertEquals($creator, $phpWord->getDocumentProperties()->getCreator()); + } + + /** + * @covers ::createSection + * @covers ::getSections + */ + public function testCreateGetSections() + { + $phpWord = new PhpWord(); + $this->assertEquals(new Section(1), $phpWord->createSection()); + $phpWord->createSection(); + $this->assertEquals(2, \count($phpWord->getSections())); + } + + /** + * @covers ::setDefaultFontName + * @covers ::getDefaultFontName + */ + public function testSetGetDefaultFontName() + { + $phpWord = new PhpWord(); + $fontName = 'Times New Roman'; + $this->assertEquals(PhpWord::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName()); + $phpWord->setDefaultFontName($fontName); + $this->assertEquals($fontName, $phpWord->getDefaultFontName()); + } + + /** + * @covers ::setDefaultFontSize + * @covers ::getDefaultFontSize + */ + public function testSetGetDefaultFontSize() + { + $phpWord = new PhpWord(); + $fontSize = 16; + $this->assertEquals(PhpWord::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize()); + $phpWord->setDefaultFontSize($fontSize); + $this->assertEquals($fontSize, $phpWord->getDefaultFontSize()); + } + + /** + * @covers ::setDefaultParagraphStyle + * @covers ::loadTemplate + */ + public function testSetDefaultParagraphStyle() + { + $phpWord = new PhpWord(); + $phpWord->setDefaultParagraphStyle(array()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', Style::getStyle('Normal')); + } + + /** + * @covers ::addParagraphStyle + * @covers ::addFontStyle + * @covers ::addTableStyle + * @covers ::addLinkStyle + */ + public function testAddStyles() + { + $phpWord = new PhpWord(); + $styles = array( + 'Paragraph' => 'Paragraph', + 'Font' => 'Font', + 'Table' => 'TableFull', + 'Link' => 'Font', + ); + foreach ($styles as $key => $value) { + $method = "add{$key}Style"; + $styleId = "{$key} Style"; + $phpWord->$method($styleId, array()); + $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$value}", Style::getStyle($styleId)); + } + + } + + /** + * @covers ::addTitleStyle + */ + public function testAddTitleStyle() + { + $phpWord = new PhpWord(); + $titleLevel = 1; + $titleName = "Heading_{$titleLevel}"; + $phpWord->addTitleStyle($titleLevel, array()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', Style::getStyle($titleName)); + } + + /** + * @covers ::loadTemplate + */ + public function testLoadTemplate() + { + $templateFqfn = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'blank.docx') + ); + $phpWord = new PhpWord(); + $this->assertInstanceOf( + 'PhpOffice\\PhpWord\\Template', + $phpWord->loadTemplate($templateFqfn) + ); + } + + /** + * @covers ::loadTemplate + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + */ + public function testLoadTemplateException() + { + $templateFqfn = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'blanks.docx') + ); + $phpWord = new PhpWord(); + $phpWord->loadTemplate($templateFqfn); + } +} diff --git a/tests/PHPWord/Reader/Word2007Test.php b/tests/PHPWord/Reader/Word2007Test.php new file mode 100644 index 0000000000..ef25e8220e --- /dev/null +++ b/tests/PHPWord/Reader/Word2007Test.php @@ -0,0 +1,58 @@ +assertTrue($object->canRead($file)); + } + + /** + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + */ + public function testCanReadFailed() + { + $dir = join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents') + ); + $object = new Word2007; + $file = $dir . \DIRECTORY_SEPARATOR . 'foo.docx'; + $this->assertFalse($object->canRead($file)); + $object = IOFactory::load($file); + } + + /** + * Test load document + */ + public function testLoad() + { + $dir = join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents') + ); + $file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx'; + $object = IOFactory::load($file); + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object); + } +} diff --git a/tests/PHPWord/Section/ImageTest.php b/tests/PHPWord/Section/ImageTest.php new file mode 100644 index 0000000000..bfb38aea7c --- /dev/null +++ b/tests/PHPWord/Section/ImageTest.php @@ -0,0 +1,104 @@ +assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage); + $this->assertEquals($oImage->getSource(), $src); + $this->assertEquals($oImage->getMediaId(), md5($src)); + $this->assertEquals($oImage->getIsWatermark(), false); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); + } + + public function testConstructWithStyle() + { + $src = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'firefox.png') + ); + $oImage = new Image( + $src, + array('width' => 210, 'height' => 210, 'align' => 'center', + 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND) + ); + + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); + } + + /** + * @covers ::__construct + */ + public function testValidImageTypes() + { + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars_noext_jpg"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mars.jpg"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/mario.gif"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/firefox.png"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/duke_nukem.bmp"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/angela_merkel.tif"); + } + + /** + * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException + * @covers ::__construct + */ + public function testImageNotFound() + { + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/thisisnotarealimage"); + } + + /** + * @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException + * @covers ::__construct + */ + public function testInvalidImageTypes() + { + new Image(\PHPWORD_TESTS_BASE_DIR . "/data/images/alexz-johnson.pcx"); + } + + public function testStyle() + { + $oImage = new Image(\join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') + ), array('width' => 210, 'height' => 210, 'align' => 'center')); + + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); + } + + public function testRelationID() + { + $oImage = new Image(\join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') + )); + + $iVal = rand(1, 1000); + $oImage->setRelationId($iVal); + $this->assertEquals($oImage->getRelationId(), $iVal); + } + + public function testWatermark() + { + $oImage = new Image(\join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') + )); + + $oImage->setIsWatermark(true); + $this->assertEquals($oImage->getIsWatermark(), true); + } +} diff --git a/tests/PHPWord/Section/ListItemTest.php b/tests/PHPWord/Section/ListItemTest.php new file mode 100644 index 0000000000..aa6142ed2e --- /dev/null +++ b/tests/PHPWord/Section/ListItemTest.php @@ -0,0 +1,38 @@ +assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $oListItem->getTextObject()); + } + + public function testStyle() + { + $oListItem = new ListItem( + 'text', + 1, + null, + array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER) + ); + + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle()); + $this->assertEquals( + $oListItem->getStyle()->getListType(), + \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER + ); + } + + public function testDepth() + { + $iVal = rand(1, 1000); + $oListItem = new ListItem('text', $iVal); + + $this->assertEquals($oListItem->getDepth(), $iVal); + } +} diff --git a/tests/PHPWord/Section/TextTest.php b/tests/PHPWord/Section/TextTest.php new file mode 100644 index 0000000000..b14bcbf91e --- /dev/null +++ b/tests/PHPWord/Section/TextTest.php @@ -0,0 +1,42 @@ +assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $oText); + $this->assertEquals(null, $oText->getText()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); + } + + public function testText() + { + $oText = new Text('text'); + + $this->assertEquals($oText->getText(), 'text'); + } + + public function testFont() + { + $oText = new Text('text', 'fontStyle'); + $this->assertEquals($oText->getFontStyle(), 'fontStyle'); + + $oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle()); + } + + public function testParagraph() + { + $oText = new Text('text', 'fontStyle', 'paragraphStyle'); + $this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle'); + + $oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); + } +} diff --git a/tests/PHPWord/SettingsTest.php b/tests/PHPWord/SettingsTest.php new file mode 100644 index 0000000000..b07b3b155a --- /dev/null +++ b/tests/PHPWord/SettingsTest.php @@ -0,0 +1,23 @@ +assertTrue(Settings::getCompatibility()); + $this->assertTrue(Settings::setCompatibility(false)); + $this->assertFalse(Settings::getCompatibility()); + $this->assertFalse(Settings::setCompatibility('Non boolean')); + } +} diff --git a/tests/PHPWord/Shared/FileTest.php b/tests/PHPWord/Shared/FileTest.php new file mode 100644 index 0000000000..d3fd4869c5 --- /dev/null +++ b/tests/PHPWord/Shared/FileTest.php @@ -0,0 +1,42 @@ +assertTrue(File::file_exists('blank.docx')); + } + /** + * Test file_exists() + */ + public function testNoFileExists() + { + $dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates')); + chdir($dir); + $this->assertFalse(File::file_exists('404.docx')); + } + + /** + * Test realpath() + */ + public function testRealpath() + { + $dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates')); + chdir($dir); + $file = 'blank.docx'; + $expected = $dir . \DIRECTORY_SEPARATOR . $file; + $this->assertEquals($expected, File::realpath($file)); + } +} diff --git a/tests/PHPWord/Shared/StringTest.php b/tests/PHPWord/Shared/StringTest.php new file mode 100644 index 0000000000..cc21c2d2d2 --- /dev/null +++ b/tests/PHPWord/Shared/StringTest.php @@ -0,0 +1,30 @@ +assertTrue(String::isUTF8('')); + $this->assertTrue(String::isUTF8('éééé')); + $this->assertFalse(String::isUTF8(utf8_decode('éééé'))); + } + + public function testControlCharacterOOXML2PHP() + { + $this->assertEquals('', String::controlCharacterOOXML2PHP('')); + $this->assertEquals(chr(0x08), String::controlCharacterOOXML2PHP('_x0008_')); + } + + public function testControlCharacterPHP2OOXML() + { + $this->assertEquals('', String::controlCharacterPHP2OOXML('')); + $this->assertEquals('_x0008_', String::controlCharacterPHP2OOXML(chr(0x08))); + } +} diff --git a/tests/PHPWord/StyleTest.php b/tests/PHPWord/StyleTest.php new file mode 100644 index 0000000000..0a95bef22a --- /dev/null +++ b/tests/PHPWord/StyleTest.php @@ -0,0 +1,40 @@ + '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; + Style::addParagraphStyle('Paragraph', $paragraph); + Style::addFontStyle('Font', $font); + Style::addLinkStyle('Link', $font); + Style::addTableStyle('Table', $table); + Style::addTitleStyle(1, $font); + Style::setDefaultParagraphStyle($paragraph); + + $this->assertEquals($elementCount, count(Style::getStyles())); + foreach ($styles as $name => $style) { + $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$style}", Style::getStyle($name)); + } + $this->assertNull(Style::getStyle('Unknown')); + } +} diff --git a/Tests/PHPWord/Writer/ODText/WriterPartTest.php b/tests/PHPWord/Writer/ODText/WriterPartTest.php similarity index 56% rename from Tests/PHPWord/Writer/ODText/WriterPartTest.php rename to tests/PHPWord/Writer/ODText/WriterPartTest.php index f7b70ba2bc..58b0f4a78d 100644 --- a/Tests/PHPWord/Writer/ODText/WriterPartTest.php +++ b/tests/PHPWord/Writer/ODText/WriterPartTest.php @@ -1,15 +1,14 @@ getMockForAbstractClass( - 'PHPWord_Writer_Word2007_WriterPart' + 'PhpOffice\\PhpWord\\Writer\\ODText\\WriterPart' ); - $object->setParentWriter(new PHPWord_Writer_ODText()); + $object->setParentWriter(new ODText()); $this->assertEquals( - new PHPWord_Writer_ODText(), + new ODText(), $object->getParentWriter() ); } @@ -33,12 +32,12 @@ public function testSetGetParentWriter() /** * covers ::getParentWriter * @expectedException Exception - * @expectedExceptionMessage No parent PHPWord_Writer_IWriter assigned. + * @expectedExceptionMessage No parent IWriter assigned. */ public function testSetGetParentWriterNull() { $object = $this->getMockForAbstractClass( - 'PHPWord_Writer_Word2007_WriterPart' + 'PhpOffice\\PhpWord\\Writer\\ODText\\WriterPart' ); $object->getParentWriter(); } diff --git a/Tests/PHPWord/Writer/Word2007/FooterTest.php b/tests/PHPWord/Writer/Word2007/FooterTest.php similarity index 62% rename from Tests/PHPWord/Writer/Word2007/FooterTest.php rename to tests/PHPWord/Writer/Word2007/FooterTest.php index 1facc622e9..9ce5cf9719 100644 --- a/Tests/PHPWord/Writer/Word2007/FooterTest.php +++ b/tests/PHPWord/Writer/Word2007/FooterTest.php @@ -1,16 +1,15 @@ addText(''); $container->addPreserveText(''); $container->addTextBreak(); @@ -32,8 +31,8 @@ public function testWriteFooter() $container->addTable()->addRow()->addCell()->addText(''); $container->addImage($imageSrc); - $writer = new PHPWord_Writer_Word2007(); - $object = new PHPWord_Writer_Word2007_Footer(); + $writer = new Word2007(); + $object = new Footer(); $object->setParentWriter($writer); $object->writeFooter($container); $writer->setUseDiskCaching(true); diff --git a/Tests/PHPWord/Writer/Word2007/HeaderTest.php b/tests/PHPWord/Writer/Word2007/HeaderTest.php similarity index 63% rename from Tests/PHPWord/Writer/Word2007/HeaderTest.php rename to tests/PHPWord/Writer/Word2007/HeaderTest.php index f4972b7ce9..c562e2564d 100644 --- a/Tests/PHPWord/Writer/Word2007/HeaderTest.php +++ b/tests/PHPWord/Writer/Word2007/HeaderTest.php @@ -1,16 +1,15 @@ addText('Test'); $container->addPreserveText(''); $container->addTextBreak(); @@ -34,8 +33,8 @@ public function testWriteHeader() $container->addImage($imageSrc); $container->addWatermark($imageSrc); - $writer = new PHPWord_Writer_Word2007(); - $object = new PHPWord_Writer_Word2007_Header(); + $writer = new Word2007(); + $object = new Header(); $object->setParentWriter($writer); $object->writeHeader($container); $writer->setUseDiskCaching(true); diff --git a/Tests/PHPWord/Writer/Word2007/WriterPartTest.php b/tests/PHPWord/Writer/Word2007/WriterPartTest.php similarity index 55% rename from Tests/PHPWord/Writer/Word2007/WriterPartTest.php rename to tests/PHPWord/Writer/Word2007/WriterPartTest.php index 3d98317899..2b7f68a589 100644 --- a/Tests/PHPWord/Writer/Word2007/WriterPartTest.php +++ b/tests/PHPWord/Writer/Word2007/WriterPartTest.php @@ -1,15 +1,15 @@ getMockForAbstractClass( - 'PHPWord_Writer_Word2007_WriterPart' + 'PhpOffice\\PhpWord\\Writer\\Word2007\\WriterPart' ); - $object->setParentWriter(new PHPWord_Writer_Word2007()); + $object->setParentWriter(new Word2007()); $this->assertEquals( - new PHPWord_Writer_Word2007(), + new Word2007(), $object->getParentWriter() ); } @@ -33,12 +33,12 @@ public function testSetGetParentWriter() /** * covers ::getParentWriter * @expectedException Exception - * @expectedExceptionMessage No parent PHPWord_Writer_IWriter assigned. + * @expectedExceptionMessage No parent IWriter assigned. */ public function testSetGetParentWriterNull() { $object = $this->getMockForAbstractClass( - 'PHPWord_Writer_Word2007_WriterPart' + 'PhpOffice\\PhpWord\\Writer\\Word2007\\WriterPart' ); $object->getParentWriter(); } diff --git a/Tests/PHPWord/DocumentPropertiesTest.php b/tests/PhpWord/DocumentPropertiesTest.php similarity index 60% rename from Tests/PHPWord/DocumentPropertiesTest.php rename to tests/PhpWord/DocumentPropertiesTest.php index f98a9907b2..d1c0224b70 100644 --- a/Tests/PHPWord/DocumentPropertiesTest.php +++ b/tests/PhpWord/DocumentPropertiesTest.php @@ -1,20 +1,17 @@ setCreator(); $this->assertEquals('', $oProperties->getCreator()); @@ -24,7 +21,7 @@ public function testCreator() public function testLastModifiedBy() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setLastModifiedBy(); $this->assertEquals('', $oProperties->getLastModifiedBy()); @@ -34,7 +31,7 @@ public function testLastModifiedBy() public function testCreated() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setCreated(); $this->assertEquals(time(), $oProperties->getCreated()); @@ -45,7 +42,7 @@ public function testCreated() public function testModified() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setModified(); $this->assertEquals(time(), $oProperties->getModified()); @@ -56,7 +53,7 @@ public function testModified() public function testTitle() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setTitle(); $this->assertEquals('', $oProperties->getTitle()); @@ -66,7 +63,7 @@ public function testTitle() public function testDescription() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setDescription(); $this->assertEquals('', $oProperties->getDescription()); @@ -76,7 +73,7 @@ public function testDescription() public function testSubject() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setSubject(); $this->assertEquals('', $oProperties->getSubject()); @@ -86,7 +83,7 @@ public function testSubject() public function testKeywords() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setKeywords(); $this->assertEquals('', $oProperties->getKeywords()); @@ -96,7 +93,7 @@ public function testKeywords() public function testCategory() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setCategory(); $this->assertEquals('', $oProperties->getCategory()); @@ -106,7 +103,7 @@ public function testCategory() public function testCompany() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setCompany(); $this->assertEquals('', $oProperties->getCompany()); @@ -116,7 +113,7 @@ public function testCompany() public function testManager() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setManager(); $this->assertEquals('', $oProperties->getManager()); @@ -126,30 +123,30 @@ public function testManager() public function testCustomProperty() { - $oProperties = new PHPWord_DocumentProperties(); + $oProperties = new DocumentProperties(); $oProperties->setCustomProperty('key1', null); $oProperties->setCustomProperty('key2', true); $oProperties->setCustomProperty('key3', 3); $oProperties->setCustomProperty('key4', 4.4); $oProperties->setCustomProperty('key5', 'value5'); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, + DocumentProperties::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key1') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, + DocumentProperties::PROPERTY_TYPE_BOOLEAN, $oProperties->getCustomPropertyType('key2') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, + DocumentProperties::PROPERTY_TYPE_INTEGER, $oProperties->getCustomPropertyType('key3') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, + DocumentProperties::PROPERTY_TYPE_FLOAT, $oProperties->getCustomPropertyType('key4') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, + DocumentProperties::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key5') ); $this->assertEquals(null, $oProperties->getCustomPropertyType('key6')); @@ -172,50 +169,50 @@ public function testCustomProperty() public function testConvertProperty() { - $this->assertEquals('', PHPWord_DocumentProperties::convertProperty('a', 'empty')); - $this->assertEquals(null, PHPWord_DocumentProperties::convertProperty('a', 'null')); - $this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8', 'int')); - $this->assertEquals(8, PHPWord_DocumentProperties::convertProperty('8.3', 'uint')); - $this->assertEquals(8.3, PHPWord_DocumentProperties::convertProperty('8.3', 'decimal')); - $this->assertEquals('8.3', PHPWord_DocumentProperties::convertProperty('8.3', 'lpstr')); - $this->assertEquals(strtotime('10/11/2013'), PHPWord_DocumentProperties::convertProperty('10/11/2013', 'date')); - $this->assertEquals(true, PHPWord_DocumentProperties::convertProperty('true', 'bool')); - $this->assertEquals(false, PHPWord_DocumentProperties::convertProperty('1', 'bool')); - $this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', 'array')); - $this->assertEquals('1', PHPWord_DocumentProperties::convertProperty('1', '')); + $this->assertEquals('', DocumentProperties::convertProperty('a', 'empty')); + $this->assertEquals(null, DocumentProperties::convertProperty('a', 'null')); + $this->assertEquals(8, DocumentProperties::convertProperty('8', 'int')); + $this->assertEquals(8, DocumentProperties::convertProperty('8.3', 'uint')); + $this->assertEquals(8.3, DocumentProperties::convertProperty('8.3', 'decimal')); + $this->assertEquals('8.3', DocumentProperties::convertProperty('8.3', 'lpstr')); + $this->assertEquals(strtotime('10/11/2013'), DocumentProperties::convertProperty('10/11/2013', 'date')); + $this->assertEquals(true, DocumentProperties::convertProperty('true', 'bool')); + $this->assertEquals(false, DocumentProperties::convertProperty('1', 'bool')); + $this->assertEquals('1', DocumentProperties::convertProperty('1', 'array')); + $this->assertEquals('1', DocumentProperties::convertProperty('1', '')); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, - PHPWord_DocumentProperties::convertPropertyType('int') + DocumentProperties::PROPERTY_TYPE_INTEGER, + DocumentProperties::convertPropertyType('int') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_INTEGER, - PHPWord_DocumentProperties::convertPropertyType('uint') + DocumentProperties::PROPERTY_TYPE_INTEGER, + DocumentProperties::convertPropertyType('uint') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_FLOAT, - PHPWord_DocumentProperties::convertPropertyType('decimal') + DocumentProperties::PROPERTY_TYPE_FLOAT, + DocumentProperties::convertPropertyType('decimal') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_STRING, - PHPWord_DocumentProperties::convertPropertyType('lpstr') + DocumentProperties::PROPERTY_TYPE_STRING, + DocumentProperties::convertPropertyType('lpstr') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_DATE, - PHPWord_DocumentProperties::convertPropertyType('date') + DocumentProperties::PROPERTY_TYPE_DATE, + DocumentProperties::convertPropertyType('date') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_BOOLEAN, - PHPWord_DocumentProperties::convertPropertyType('bool') + DocumentProperties::PROPERTY_TYPE_BOOLEAN, + DocumentProperties::convertPropertyType('bool') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, - PHPWord_DocumentProperties::convertPropertyType('array') + DocumentProperties::PROPERTY_TYPE_UNKNOWN, + DocumentProperties::convertPropertyType('array') ); $this->assertEquals( - PHPWord_DocumentProperties::PROPERTY_TYPE_UNKNOWN, - PHPWord_DocumentProperties::convertPropertyType('') + DocumentProperties::PROPERTY_TYPE_UNKNOWN, + DocumentProperties::convertPropertyType('') ); } } diff --git a/Tests/PHPWord/Exceptions/ExceptionTest.php b/tests/PhpWord/Exceptions/ExceptionTest.php similarity index 72% rename from Tests/PHPWord/Exceptions/ExceptionTest.php rename to tests/PhpWord/Exceptions/ExceptionTest.php index a403aa28e6..2792f7165a 100644 --- a/Tests/PHPWord/Exceptions/ExceptionTest.php +++ b/tests/PhpWord/Exceptions/ExceptionTest.php @@ -1,5 +1,5 @@ assertInstanceOf('PHPWord_Section_Footer_PreserveText', $oPreserveText); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $oPreserveText); $this->assertEquals($oPreserveText->getText(), null); $this->assertEquals($oPreserveText->getFontStyle(), null); $this->assertEquals($oPreserveText->getParagraphStyle(), null); @@ -17,7 +17,7 @@ public function testConstruct() public function testConstructWithString() { - $oPreserveText = new PHPWord_Section_Footer_PreserveText('text', 'styleFont', 'styleParagraph'); + $oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph'); $this->assertEquals($oPreserveText->getText(), array('text')); $this->assertEquals($oPreserveText->getFontStyle(), 'styleFont'); $this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); @@ -25,12 +25,15 @@ public function testConstructWithString() public function testConstructWithArray() { - $oPreserveText = new PHPWord_Section_Footer_PreserveText( + $oPreserveText = new PreserveText( 'text', array('align' => 'center'), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); - $this->assertInstanceOf('PHPWord_Style_Font', $oPreserveText->getFontStyle()); - $this->assertInstanceOf('PHPWord_Style_Paragraph', $oPreserveText->getParagraphStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle()); + $this->assertInstanceOf( + 'PhpOffice\\PhpWord\\Style\\Paragraph', + $oPreserveText->getParagraphStyle() + ); } } diff --git a/Tests/PHPWord/Section/FooterTest.php b/tests/PhpWord/Section/FooterTest.php similarity index 62% rename from Tests/PHPWord/Section/FooterTest.php rename to tests/PhpWord/Section/FooterTest.php index 2f244911b0..18abf53a4b 100644 --- a/Tests/PHPWord/Section/FooterTest.php +++ b/tests/PhpWord/Section/FooterTest.php @@ -1,22 +1,22 @@ assertInstanceOf('PHPWord_Section_Footer', $oFooter); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer', $oFooter); $this->assertEquals($oFooter->getFooterCount(), $iVal); } public function testRelationID() { - $oFooter = new PHPWord_Section_Footer(0); + $oFooter = new Footer(0); $iVal = rand(1, 1000); $oFooter->setRelationId($iVal); @@ -25,27 +25,27 @@ public function testRelationID() public function testAddText() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->addText('text'); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); } public function testAddTextNotUTF8() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->addText(utf8_decode('ééé')); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); $this->assertEquals($element->getText(), 'ééé'); } public function testAddTextBreak() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $iVal = rand(1, 1000); $oFooter->addTextBreak($iVal); @@ -54,68 +54,68 @@ public function testAddTextBreak() public function testCreateTextRun() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->createTextRun(); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_TextRun', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element); } public function testAddTable() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->addTable(); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_Table', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element); } public function testAddImage() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->addImage($src); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_Image', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); } public function testAddMemoryImage() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->addMemoryImage( 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' ); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element); } public function testAddPreserveText() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->addPreserveText('text'); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element); } public function testAddPreserveTextNotUTF8() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $element = $oFooter->addPreserveText(utf8_decode('ééé')); $this->assertCount(1, $oFooter->getElements()); - $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element); $this->assertEquals($element->getText(), array('ééé')); } public function testGetElements() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $this->assertInternalType('array', $oFooter->getElements()); } diff --git a/Tests/PHPWord/Section/FootnoteTest.php b/tests/PhpWord/Section/FootnoteTest.php similarity index 58% rename from Tests/PHPWord/Section/FootnoteTest.php rename to tests/PhpWord/Section/FootnoteTest.php index bd991278ba..ca3be2cae2 100644 --- a/Tests/PHPWord/Section/FootnoteTest.php +++ b/tests/PhpWord/Section/FootnoteTest.php @@ -1,54 +1,57 @@ assertInstanceOf('PHPWord_Section_Footnote', $oFootnote); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footnote', $oFootnote); $this->assertCount(0, $oFootnote->getElements()); $this->assertEquals($oFootnote->getParagraphStyle(), null); } public function testConstructString() { - $oFootnote = new PHPWord_Section_Footnote('pStyle'); + $oFootnote = new Footnote('pStyle'); $this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle'); } public function testConstructArray() { - $oFootnote = new PHPWord_Section_Footnote(array('spacing' => 100)); + $oFootnote = new Footnote(array('spacing' => 100)); - $this->assertInstanceOf('PHPWord_Style_Paragraph', $oFootnote->getParagraphStyle()); + $this->assertInstanceOf( + 'PhpOffice\\PhpWord\\Style\\Paragraph', + $oFootnote->getParagraphStyle() + ); } public function testAddText() { - $oFootnote = new PHPWord_Section_Footnote(); + $oFootnote = new Footnote(); $element = $oFootnote->addText('text'); $this->assertCount(1, $oFootnote->getElements()); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); } public function testAddLink() { - $oFootnote = new PHPWord_Section_Footnote(); + $oFootnote = new Footnote(); $element = $oFootnote->addLink('http://www.google.fr'); $this->assertCount(1, $oFootnote->getElements()); - $this->assertInstanceOf('PHPWord_Section_Link', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element); } public function testReferenceId() { - $oFootnote = new PHPWord_Section_Footnote(); + $oFootnote = new Footnote(); $iVal = rand(1, 1000); $oFootnote->setReferenceId($iVal); @@ -57,7 +60,7 @@ public function testReferenceId() public function testGetElements() { - $oFootnote = new PHPWord_Section_Footnote(); + $oFootnote = new Footnote(); $this->assertInternalType('array', $oFootnote->getElements()); } } diff --git a/Tests/PHPWord/Section/HeaderTest.php b/tests/PhpWord/Section/HeaderTest.php similarity index 58% rename from Tests/PHPWord/Section/HeaderTest.php rename to tests/PhpWord/Section/HeaderTest.php index c08aec24c3..26e4087f4c 100644 --- a/Tests/PHPWord/Section/HeaderTest.php +++ b/tests/PhpWord/Section/HeaderTest.php @@ -1,50 +1,50 @@ assertInstanceOf('PHPWord_Section_Header', $oHeader); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Header', $oHeader); $this->assertEquals($oHeader->getHeaderCount(), $iVal); - $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO); + $this->assertEquals($oHeader->getType(), Header::AUTO); } public function testAddText() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addText('text'); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); $this->assertCount(1, $oHeader->getElements()); $this->assertEquals($element->getText(), 'text'); } public function testAddTextNotUTF8() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addText(utf8_decode('ééé')); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); $this->assertCount(1, $oHeader->getElements()); $this->assertEquals($element->getText(), 'ééé'); } public function testAddTextBreak() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $oHeader->addTextBreak(); $this->assertCount(1, $oHeader->getElements()); } public function testAddTextBreakWithParams() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $iVal = rand(1, 1000); $oHeader->addTextBreak($iVal); $this->assertCount($iVal, $oHeader->getElements()); @@ -52,17 +52,17 @@ public function testAddTextBreakWithParams() public function testCreateTextRun() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->createTextRun(); - $this->assertInstanceOf('PHPWord_Section_TextRun', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element); $this->assertCount(1, $oHeader->getElements()); } public function testAddTable() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addTable(); - $this->assertInstanceOf('PHPWord_Section_Table', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element); $this->assertCount(1, $oHeader->getElements()); } @@ -70,42 +70,42 @@ public function testAddImage() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addImage($src); $this->assertCount(1, $oHeader->getElements()); - $this->assertInstanceOf('PHPWord_Section_Image', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); } public function testAddMemoryImage() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addMemoryImage( 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' ); $this->assertCount(1, $oHeader->getElements()); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element); } public function testAddPreserveText() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addPreserveText('text'); $this->assertCount(1, $oHeader->getElements()); - $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element); } public function testAddPreserveTextNotUTF8() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addPreserveText(utf8_decode('ééé')); $this->assertCount(1, $oHeader->getElements()); - $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element); $this->assertEquals($element->getText(), array('ééé')); } @@ -113,25 +113,25 @@ public function testAddWatermark() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $element = $oHeader->addWatermark($src); $this->assertCount(1, $oHeader->getElements()); - $this->assertInstanceOf('PHPWord_Section_Image', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); } public function testGetElements() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $this->assertInternalType('array', $oHeader->getElements()); } public function testRelationId() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $iVal = rand(1, 1000); $oHeader->setRelationId($iVal); @@ -140,26 +140,26 @@ public function testRelationId() public function testResetType() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $oHeader->firstPage(); $oHeader->resetType(); - $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::AUTO); + $this->assertEquals($oHeader->getType(), Header::AUTO); } public function testFirstPage() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $oHeader->firstPage(); - $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::FIRST); + $this->assertEquals($oHeader->getType(), Header::FIRST); } public function testEvenPage() { - $oHeader = new PHPWord_Section_Header(1); + $oHeader = new Header(1); $oHeader->evenPage(); - $this->assertEquals($oHeader->getType(), PHPWord_Section_Header::EVEN); + $this->assertEquals($oHeader->getType(), Header::EVEN); } } diff --git a/Tests/PHPWord/Section/LinkTest.php b/tests/PhpWord/Section/LinkTest.php similarity index 60% rename from Tests/PHPWord/Section/LinkTest.php rename to tests/PhpWord/Section/LinkTest.php index 413b23fe95..0d20a6fa0c 100644 --- a/Tests/PHPWord/Section/LinkTest.php +++ b/tests/PhpWord/Section/LinkTest.php @@ -1,16 +1,16 @@ assertInstanceOf('PHPWord_Section_Link', $oLink); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $oLink); $this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com'); $this->assertEquals($oLink->getLinkName(), null); $this->assertEquals($oLink->getFontStyle(), null); @@ -19,23 +19,23 @@ public function testConstructDefault() public function testConstructWithParamsArray() { - $oLink = new PHPWord_Section_Link( + $oLink = new Link( 'http://www.google.com', 'Search Engine', - array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE), + array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); - $this->assertInstanceOf('PHPWord_Section_Link', $oLink); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $oLink); $this->assertEquals($oLink->getLinkSrc(), 'http://www.google.com'); $this->assertEquals($oLink->getLinkName(), 'Search Engine'); - $this->assertInstanceOf('PHPWord_Style_Font', $oLink->getFontStyle()); - $this->assertInstanceOf('PHPWord_Style_Paragraph', $oLink->getParagraphStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle()); } public function testConstructWithParamsString() { - $oLink = new PHPWord_Section_Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle'); + $oLink = new Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle'); $this->assertEquals($oLink->getFontStyle(), 'fontStyle'); $this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle'); @@ -43,7 +43,7 @@ public function testConstructWithParamsString() public function testRelationId() { - $oLink = new PHPWord_Section_Link('http://www.google.com'); + $oLink = new Link('http://www.google.com'); $iVal = rand(1, 1000); $oLink->setRelationId($iVal); diff --git a/Tests/PHPWord/Section/MemoryImageTest.php b/tests/PhpWord/Section/MemoryImageTest.php similarity index 65% rename from Tests/PHPWord/Section/MemoryImageTest.php rename to tests/PhpWord/Section/MemoryImageTest.php index 3bfb39e358..8869ad5b66 100644 --- a/Tests/PHPWord/Section/MemoryImageTest.php +++ b/tests/PhpWord/Section/MemoryImageTest.php @@ -1,7 +1,7 @@ assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng'); @@ -26,11 +26,11 @@ public function testGIF() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'mario.gif') ); - $oMemoryImage = new PHPWord_Section_MemoryImage($src); + $oMemoryImage = new MemoryImage($src); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif'); @@ -43,11 +43,11 @@ public function testJPG() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oMemoryImage = new PHPWord_Section_MemoryImage($src); + $oMemoryImage = new MemoryImage($src); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertEquals($oMemoryImage->getSource(), $src); $this->assertEquals($oMemoryImage->getMediaId(), md5($src)); $this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg'); @@ -58,12 +58,12 @@ public function testJPG() public function testBMP() { - $oMemoryImage = new PHPWord_Section_MemoryImage(\join( + $oMemoryImage = new MemoryImage(\join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'duke_nukem.bmp') )); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $oMemoryImage); $this->assertEquals($oMemoryImage->getImageCreateFunction(), null); $this->assertEquals($oMemoryImage->getImageFunction(), null); $this->assertEquals($oMemoryImage->getImageExtension(), null); @@ -72,19 +72,19 @@ public function testBMP() public function testStyle() { - $oMemoryImage = new PHPWord_Section_MemoryImage(\join( + $oMemoryImage = new MemoryImage(\join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ), array('width' => 210, 'height' => 210, 'align' => 'center')); - $this->assertInstanceOf('PHPWord_Style_Image', $oMemoryImage->getStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle()); } public function testRelationID() { - $oMemoryImage = new PHPWord_Section_MemoryImage(\join( + $oMemoryImage = new MemoryImage(\join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') )); $iVal = rand(1, 1000); diff --git a/Tests/PHPWord/Section/ObjectTest.php b/tests/PhpWord/Section/ObjectTest.php similarity index 54% rename from Tests/PHPWord/Section/ObjectTest.php rename to tests/PhpWord/Section/ObjectTest.php index b72f2484c8..22d713c283 100644 --- a/Tests/PHPWord/Section/ObjectTest.php +++ b/tests/PhpWord/Section/ObjectTest.php @@ -1,7 +1,7 @@ assertInstanceOf('PHPWord_Section_Object', $oObject); - $this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); $this->assertEquals($oObject->getSource(), $src); } @@ -22,11 +22,11 @@ public function testConstructWithNotSupportedFiles() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'passthrough.xsl') ); - $oObject = new PHPWord_Section_Object($src); + $oObject = new Object($src); - $this->assertInstanceOf('PHPWord_Section_Object', $oObject); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject); $this->assertEquals($oObject->getSource(), null); $this->assertEquals($oObject->getStyle(), null); } @@ -35,12 +35,12 @@ public function testConstructWithSupportedFilesAndStyle() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); - $oObject = new PHPWord_Section_Object($src, array('width' => '230px')); + $oObject = new Object($src, array('width' => '230px')); - $this->assertInstanceOf('PHPWord_Section_Object', $oObject); - $this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $oObject); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); $this->assertEquals($oObject->getSource(), $src); } @@ -48,9 +48,9 @@ public function testRelationId() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); - $oObject = new PHPWord_Section_Object($src); + $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setRelationId($iVal); @@ -61,9 +61,9 @@ public function testImageRelationId() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); - $oObject = new PHPWord_Section_Object($src); + $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setImageRelationId($iVal); @@ -74,9 +74,9 @@ public function testObjectId() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); - $oObject = new PHPWord_Section_Object($src); + $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setObjectId($iVal); diff --git a/Tests/PHPWord/Section/PageBreakTest.php b/tests/PhpWord/Section/PageBreakTest.php similarity index 50% rename from Tests/PHPWord/Section/PageBreakTest.php rename to tests/PhpWord/Section/PageBreakTest.php index 5efd0fe944..f01803ceba 100644 --- a/Tests/PHPWord/Section/PageBreakTest.php +++ b/tests/PhpWord/Section/PageBreakTest.php @@ -1,7 +1,7 @@ assertInstanceOf('PHPWord_Section_PageBreak', $oPageBreak); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\PageBreak', $oPageBreak); } } diff --git a/Tests/PHPWord/Section/SettingsTest.php b/tests/PhpWord/Section/SettingsTest.php similarity index 89% rename from Tests/PHPWord/Section/SettingsTest.php rename to tests/PhpWord/Section/SettingsTest.php index 92e8465434..b780316883 100644 --- a/Tests/PHPWord/Section/SettingsTest.php +++ b/tests/PhpWord/Section/SettingsTest.php @@ -1,7 +1,7 @@ setSettingValue('_orientation', 'landscape'); $this->assertEquals('landscape', $oSettings->getOrientation()); @@ -46,7 +46,7 @@ public function testSettingValue() public function testMargin() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $iVal = rand(1, 1000); $oSettings->setMarginTop($iVal); @@ -68,7 +68,7 @@ public function testMargin() public function testOrientationLandscape() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $oSettings->setLandscape(); $this->assertEquals('landscape', $oSettings->getOrientation()); @@ -79,7 +79,7 @@ public function testOrientationLandscape() public function testOrientationPortrait() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $oSettings->setPortrait(); $this->assertNull($oSettings->getOrientation()); @@ -90,7 +90,7 @@ public function testOrientationPortrait() public function testBorderSize() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $iVal = rand(1, 1000); $oSettings->setBorderSize($iVal); @@ -120,7 +120,7 @@ public function testBorderSize() public function testBorderColor() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $oSettings->setBorderColor('FF00AA'); $this->assertEquals(array('FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'), $oSettings->getBorderColor()); @@ -145,7 +145,7 @@ public function testBorderColor() public function testNumberingStart() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $this->assertNull($oSettings->getPageNumberingStart()); @@ -160,7 +160,7 @@ public function testNumberingStart() public function testHeader() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $this->assertEquals(720, $oSettings->getHeaderHeight()); @@ -175,7 +175,7 @@ public function testHeader() public function testFooter() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $this->assertEquals(720, $oSettings->getFooterHeight()); @@ -190,7 +190,7 @@ public function testFooter() public function testColumnsNum() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); // Default $this->assertEquals(1, $oSettings->getColsNum()); @@ -206,23 +206,23 @@ public function testColumnsNum() public function testColumnsSpace() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); // Default $this->assertEquals(720, $oSettings->getColsSpace()); $iVal = rand(1, 1000); - $this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace($iVal)); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Settings', $oSettings->setColsSpace($iVal)); $this->assertEquals($iVal, $oSettings->getColsSpace()); - $this->assertInstanceOf('PHPWord_Section_Settings', $oSettings->setColsSpace()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Settings', $oSettings->setColsSpace()); $this->assertEquals(720, $oSettings->getColsSpace()); } public function testBreakType() { // Section Settings - $oSettings = new PHPWord_Section_Settings(); + $oSettings = new Settings(); $this->assertNull($oSettings->getBreakType()); diff --git a/Tests/PHPWord/Section/Table/CellTest.php b/tests/PhpWord/Section/Table/CellTest.php similarity index 58% rename from Tests/PHPWord/Section/Table/CellTest.php rename to tests/PhpWord/Section/Table/CellTest.php index 3071e5f3ca..bca9a1b5b9 100644 --- a/Tests/PHPWord/Section/Table/CellTest.php +++ b/tests/PhpWord/Section/Table/CellTest.php @@ -1,67 +1,67 @@ assertInstanceOf('PHPWord_Section_Table_Cell', $oCell); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $oCell); $this->assertEquals($oCell->getWidth(), null); } public function testConstructWithStyleArray() { $iVal = rand(1, 1000); - $oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, array('valign' => 'center')); + $oCell = new Cell('section', $iVal, null, array('valign' => 'center')); - $this->assertInstanceOf('PHPWord_Style_Cell', $oCell->getStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Cell', $oCell->getStyle()); $this->assertEquals($oCell->getWidth(), null); } public function testConstructWithStyleString() { $iVal = rand(1, 1000); - $oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, 'cellStyle'); + $oCell = new Cell('section', $iVal, null, 'cellStyle'); $this->assertEquals($oCell->getStyle(), 'cellStyle'); } public function testAddText() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addText('text'); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); } public function testAddTextNotUTF8() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addText(utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); $this->assertEquals($element->getText(), 'ééé'); } public function testAddLink() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addLink('http://www.google.fr', 'Nom'); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Link', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element); } public function testAddTextBreak() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $oCell->addTextBreak(); $this->assertCount(1, $oCell->getElements()); @@ -69,21 +69,21 @@ public function testAddTextBreak() public function testAddListItem() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addListItem('text'); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_ListItem', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\ListItem', $element); $this->assertEquals($element->getTextObject()->getText(), 'text'); } public function testAddListItemNotUTF8() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addListItem(utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_ListItem', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\ListItem', $element); $this->assertEquals($element->getTextObject()->getText(), 'ééé'); } @@ -91,118 +91,118 @@ public function testAddImageSection() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addImage($src); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Image', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); } public function testAddImageHeader() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oCell = new PHPWord_Section_Table_Cell('header', 1); + $oCell = new Cell('header', 1); $element = $oCell->addImage($src); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Image', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); } public function testAddImageFooter() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oCell = new PHPWord_Section_Table_Cell('footer', 1); + $oCell = new Cell('footer', 1); $element = $oCell->addImage($src); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Image', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); } public function testAddMemoryImageSection() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addMemoryImage( 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' ); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element); } public function testAddMemoryImageHeader() { - $oCell = new PHPWord_Section_Table_Cell('header', 1); + $oCell = new Cell('header', 1); $element = $oCell->addMemoryImage( 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' ); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element); } public function testAddMemoryImageFooter() { - $oCell = new PHPWord_Section_Table_Cell('footer', 1); + $oCell = new Cell('footer', 1); $element = $oCell->addMemoryImage( 'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png' ); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_MemoryImage', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element); } public function testAddObjectXLS() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->addObject($src); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Object', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $element); } public function testAddPreserveText() { - $oCell = new PHPWord_Section_Table_Cell('header', 1); + $oCell = new Cell('header', 1); $element = $oCell->addPreserveText('text'); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element); } public function testAddPreserveTextNotUTF8() { - $oCell = new PHPWord_Section_Table_Cell('header', 1); + $oCell = new Cell('header', 1); $element = $oCell->addPreserveText(utf8_decode('ééé')); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element); $this->assertEquals($element->getText(), array('ééé')); } public function testCreateTextRun() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $element = $oCell->createTextRun(); $this->assertCount(1, $oCell->getElements()); - $this->assertInstanceOf('PHPWord_Section_TextRun', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element); } public function testGetElements() { - $oCell = new PHPWord_Section_Table_Cell('section', 1); + $oCell = new Cell('section', 1); $this->assertInternalType('array', $oCell->getElements()); } diff --git a/Tests/PHPWord/Section/Table/RowTest.php b/tests/PhpWord/Section/Table/RowTest.php similarity index 60% rename from Tests/PHPWord/Section/Table/RowTest.php rename to tests/PhpWord/Section/Table/RowTest.php index e62a5bd926..346c913e77 100644 --- a/Tests/PHPWord/Section/Table/RowTest.php +++ b/tests/PhpWord/Section/Table/RowTest.php @@ -1,27 +1,27 @@ assertInstanceOf('PHPWord_Section_Table_Row', $oRow); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Row', $oRow); $this->assertEquals($oRow->getHeight(), null); $this->assertInternalType('array', $oRow->getCells()); $this->assertCount(0, $oRow->getCells()); - $this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); } public function testConstructWithParams() { $iVal = rand(1, 1000); $iVal2 = rand(1, 1000); - $oRow = new PHPWord_Section_Table_Row( + $oRow = new Row( 'section', $iVal, $iVal2, @@ -29,15 +29,15 @@ public function testConstructWithParams() ); $this->assertEquals($oRow->getHeight(), $iVal2); - $this->assertInstanceOf('PHPWord_Style_Row', $oRow->getStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); } public function testAddCell() { - $oRow = new PHPWord_Section_Table_Row('section', 1); + $oRow = new Row('section', 1); $element = $oRow->addCell(); - $this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $element); $this->assertCount(1, $oRow->getCells()); } } diff --git a/Tests/PHPWord/Section/TableTest.php b/tests/PhpWord/Section/TableTest.php similarity index 59% rename from Tests/PHPWord/Section/TableTest.php rename to tests/PhpWord/Section/TableTest.php index 167f1190f0..bb48812610 100644 --- a/Tests/PHPWord/Section/TableTest.php +++ b/tests/PhpWord/Section/TableTest.php @@ -1,15 +1,15 @@ assertInstanceOf('PHPWord_Section_Table', $oTable); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $oTable); $this->assertEquals($oTable->getStyle(), null); $this->assertEquals($oTable->getWidth(), null); $this->assertEquals($oTable->getRows(), array()); @@ -18,25 +18,25 @@ public function testConstruct() public function testStyleText() { - $oTable = new PHPWord_Section_Table('section', 1, 'tableStyle'); + $oTable = new Table('section', 1, 'tableStyle'); $this->assertEquals($oTable->getStyle(), 'tableStyle'); } public function testStyleArray() { - $oTable = new PHPWord_Section_Table( + $oTable = new Table( 'section', 1, array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80) ); - $this->assertInstanceOf('PHPWord_Style_Table', $oTable->getStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle()); } public function testWidth() { - $oTable = new PHPWord_Section_Table('section', 1); + $oTable = new Table('section', 1); $iVal = rand(1, 1000); $oTable->setWidth($iVal); $this->assertEquals($oTable->getWidth(), $iVal); @@ -44,17 +44,17 @@ public function testWidth() public function testRow() { - $oTable = new PHPWord_Section_Table('section', 1); + $oTable = new Table('section', 1); $element = $oTable->addRow(); - $this->assertInstanceOf('PHPWord_Section_Table_Row', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Row', $element); $this->assertCount(1, $oTable->getRows()); } public function testCell() { - $oTable = new PHPWord_Section_Table('section', 1); + $oTable = new Table('section', 1); $oTable->addRow(); $element = $oTable->addCell(); - $this->assertInstanceOf('PHPWord_Section_Table_Cell', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table\\Cell', $element); } } diff --git a/Tests/PHPWord/Section/TextBreakTest.php b/tests/PhpWord/Section/TextBreakTest.php similarity index 59% rename from Tests/PHPWord/Section/TextBreakTest.php rename to tests/PhpWord/Section/TextBreakTest.php index 761c04a395..1176714f20 100644 --- a/Tests/PHPWord/Section/TextBreakTest.php +++ b/tests/PhpWord/Section/TextBreakTest.php @@ -1,13 +1,12 @@ assertNull($object->getFontStyle()); $this->assertNull($object->getParagraphStyle()); } @@ -27,9 +26,9 @@ public function testConstruct() */ public function testConstructWithStyleObject() { - $fStyle = new PHPWord_Style_Font(); - $pStyle = new PHPWord_Style_Paragraph(); - $object = new PHPWord_Section_TextBreak($fStyle, $pStyle); + $fStyle = new Font(); + $pStyle = new Paragraph(); + $object = new TextBreak($fStyle, $pStyle); $this->assertEquals($fStyle, $object->getFontStyle()); $this->assertEquals($pStyle, $object->getParagraphStyle()); } @@ -41,9 +40,9 @@ public function testConstructWithStyleArray() { $fStyle = array('size' => 12); $pStyle = array('spacing' => 240); - $object = new PHPWord_Section_TextBreak($fStyle, $pStyle); - $this->assertInstanceOf('PHPWord_Style_Font', $object->getFontStyle()); - $this->assertInstanceOf('PHPWord_Style_Paragraph', $object->getParagraphStyle()); + $object = new TextBreak($fStyle, $pStyle); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $object->getFontStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); } /** @@ -53,7 +52,7 @@ public function testConstructWithStyleName() { $fStyle = 'fStyle'; $pStyle = 'pStyle'; - $object = new PHPWord_Section_TextBreak($fStyle, $pStyle); + $object = new TextBreak($fStyle, $pStyle); $this->assertEquals($fStyle, $object->getFontStyle()); $this->assertEquals($pStyle, $object->getParagraphStyle()); } diff --git a/Tests/PHPWord/Section/TextRunTest.php b/tests/PhpWord/Section/TextRunTest.php similarity index 59% rename from Tests/PHPWord/Section/TextRunTest.php rename to tests/PhpWord/Section/TextRunTest.php index 81402476d0..6fce163487 100644 --- a/Tests/PHPWord/Section/TextRunTest.php +++ b/tests/PhpWord/Section/TextRunTest.php @@ -1,73 +1,73 @@ assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun); $this->assertCount(0, $oTextRun->getElements()); $this->assertEquals($oTextRun->getParagraphStyle(), null); } public function testConstructString() { - $oTextRun = new PHPWord_Section_TextRun('pStyle'); + $oTextRun = new TextRun('pStyle'); - $this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun); $this->assertCount(0, $oTextRun->getElements()); $this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle'); } public function testConstructArray() { - $oTextRun = new PHPWord_Section_TextRun(array('spacing' => 100)); + $oTextRun = new TextRun(array('spacing' => 100)); - $this->assertInstanceOf('PHPWord_Section_TextRun', $oTextRun); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $oTextRun); $this->assertCount(0, $oTextRun->getElements()); - $this->assertInstanceOf('PHPWord_Style_Paragraph', $oTextRun->getParagraphStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oTextRun->getParagraphStyle()); } public function testAddText() { - $oTextRun = new PHPWord_Section_TextRun(); + $oTextRun = new TextRun(); $element = $oTextRun->addText('text'); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); $this->assertEquals($element->getText(), 'text'); } public function testAddTextNotUTF8() { - $oTextRun = new PHPWord_Section_TextRun(); + $oTextRun = new TextRun(); $element = $oTextRun->addText(utf8_decode('ééé')); - $this->assertInstanceOf('PHPWord_Section_Text', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); $this->assertEquals($element->getText(), 'ééé'); } public function testAddLink() { - $oTextRun = new PHPWord_Section_TextRun(); + $oTextRun = new TextRun(); $element = $oTextRun->addLink('http://www.google.fr'); - $this->assertInstanceOf('PHPWord_Section_Link', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element); $this->assertCount(1, $oTextRun->getElements()); $this->assertEquals($element->getLinkSrc(), 'http://www.google.fr'); } public function testAddLinkWithName() { - $oTextRun = new PHPWord_Section_TextRun(); + $oTextRun = new TextRun(); $element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé')); - $this->assertInstanceOf('PHPWord_Section_Link', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element); $this->assertCount(1, $oTextRun->getElements()); $this->assertEquals($element->getLinkSrc(), 'http://www.google.fr'); $this->assertEquals($element->getLinkName(), 'ééé'); @@ -77,21 +77,21 @@ public function testAddImage() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $oTextRun = new PHPWord_Section_TextRun(); + $oTextRun = new TextRun(); $element = $oTextRun->addImage($src); - $this->assertInstanceOf('PHPWord_Section_Image', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); $this->assertCount(1, $oTextRun->getElements()); } public function testCreateFootnote() { - $oTextRun = new PHPWord_Section_TextRun(); + $oTextRun = new TextRun(); $element = $oTextRun->createFootnote(); - $this->assertInstanceOf('PHPWord_Section_Footnote', $element); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footnote', $element); $this->assertCount(1, $oTextRun->getElements()); } } diff --git a/Tests/PHPWord/Section/TitleTest.php b/tests/PhpWord/Section/TitleTest.php similarity index 64% rename from Tests/PHPWord/Section/TitleTest.php rename to tests/PhpWord/Section/TitleTest.php index 97ce5de66c..69a018375d 100644 --- a/Tests/PHPWord/Section/TitleTest.php +++ b/tests/PhpWord/Section/TitleTest.php @@ -1,35 +1,35 @@ assertInstanceOf('PHPWord_Section_Title', $oTitle); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Title', $oTitle); $this->assertEquals($oTitle->getText(), 'text'); } public function testStyleNull() { - $oTitle = new PHPWord_Section_Title('text'); + $oTitle = new Title('text'); $this->assertEquals($oTitle->getStyle(), null); } public function testStyleNotNull() { - $oTitle = new PHPWord_Section_Title('text', 1, 'style'); + $oTitle = new Title('text', 1, 'style'); $this->assertEquals($oTitle->getStyle(), 'style'); } public function testAnchor() { - $oTitle = new PHPWord_Section_Title('text'); + $oTitle = new Title('text'); $iVal = rand(1, 1000); $oTitle->setAnchor($iVal); @@ -38,7 +38,7 @@ public function testAnchor() public function testBookmarkID() { - $oTitle = new PHPWord_Section_Title('text'); + $oTitle = new Title('text'); $iVal = rand(1, 1000); $oTitle->setBookmarkId($iVal); diff --git a/Tests/PHPWord/SectionTest.php b/tests/PhpWord/SectionTest.php similarity index 52% rename from Tests/PHPWord/SectionTest.php rename to tests/PhpWord/SectionTest.php index ac540d06a8..950fc3eeb0 100644 --- a/Tests/PHPWord/SectionTest.php +++ b/tests/PhpWord/SectionTest.php @@ -1,92 +1,89 @@ assertAttributeEquals($oSection->getSettings(), '_settings', new PHPWord_Section(0)); + $oSection = new Section(0); + $this->assertAttributeEquals($oSection->getSettings(), '_settings', new Section(0)); } /** - * @covers PHPWord_Section::getElements + * @covers ::getElements */ public function testGetElements() { - $oSection = new PHPWord_Section(0); - $this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0)); + $oSection = new Section(0); + $this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new Section(0)); } /** - * @covers PHPWord_Section::getFooter + * @covers ::getFooter */ public function testGetFooter() { - $oSection = new PHPWord_Section(0); - $this->assertAttributeEquals($oSection->getFooter(), '_footer', new PHPWord_Section(0)); + $oSection = new Section(0); + $this->assertAttributeEquals($oSection->getFooter(), '_footer', new Section(0)); } /** - * @covers PHPWord_Section::getHeaders + * @covers ::getHeaders */ public function testGetHeaders() { - $oSection = new PHPWord_Section(0); - $this->assertAttributeEquals($oSection->getHeaders(), '_headers', new PHPWord_Section(0)); + $oSection = new Section(0); + $this->assertAttributeEquals($oSection->getHeaders(), '_headers', new Section(0)); } /** - * @covers PHPWord_Section::setSettings + * @covers ::setSettings */ public function testSetSettings() { $expected = 'landscape'; - $object = new PHPWord_Section(0); + $object = new Section(0); $object->setSettings(array('orientation' => $expected)); $this->assertEquals($expected, $object->getSettings()->getOrientation()); } /** - * @covers PHPWord_Section::addText - * @covers PHPWord_Section::addLink - * @covers PHPWord_Section::addTextBreak - * @covers PHPWord_Section::addPageBreak - * @covers PHPWord_Section::addTable - * @covers PHPWord_Section::addListItem - * @covers PHPWord_Section::addObject - * @covers PHPWord_Section::addImage - * @covers PHPWord_Section::addMemoryImage - * @covers PHPWord_Section::addTOC - * @covers PHPWord_Section::addTitle - * @covers PHPWord_Section::createTextRun - * @covers PHPWord_Section::createFootnote + * @covers ::addText + * @covers ::addLink + * @covers ::addTextBreak + * @covers ::addPageBreak + * @covers ::addTable + * @covers ::addListItem + * @covers ::addObject + * @covers ::addImage + * @covers ::addMemoryImage + * @covers ::addTOC + * @covers ::addTitle + * @covers ::createTextRun + * @covers ::createFootnote */ public function testAddElements() { $objectSource = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); $imageSource = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png') + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png') ); $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; - $section = new PHPWord_Section(0); + $section = new Section(0); $section->addText(utf8_decode('ä')); $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); $section->addTextBreak(); @@ -103,31 +100,28 @@ public function testAddElements() $elementCollection = $section->getElements(); $elementType = 'Link'; - $objectType = "PHPWord_Section_{$elementType}"; - $this->assertInstanceOf($objectType, $elementCollection[1]); + $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$elementType}", $elementCollection[1]); // $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', // 'Table', 'ListItem', 'Object', 'Image', 'MemoryImage', 'TOC', // 'Title', 'TextRun'); // $i = 0; // foreach ($elementTypes as $elementType) { - // $objectType = "PHPWord_Section_{$elementType}"; - // $this->assertInstanceOf($objectType, $elementCollection[$i]); + // $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$elementType}", $elementCollection[$i]); // $i++; // } } /** - * @covers PHPWord_Section::createHeader - * @covers PHPWord_Section::createFooter + * @covers ::createHeader + * @covers ::createFooter */ public function testCreateHeaderFooter() { - $object = new PHPWord_Section(0); + $object = new Section(0); $elements = array('Header', 'Footer'); foreach ($elements as $element) { - $objectType = "PHPWord_Section_{$element}"; $method = "create{$element}"; - $this->assertInstanceOf($objectType, $object->$method()); + $this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$element}", $object->$method()); } } } diff --git a/Tests/PHPWord/Shared/DrawingTest.php b/tests/PhpWord/Shared/DrawingTest.php similarity index 66% rename from Tests/PHPWord/Shared/DrawingTest.php rename to tests/PhpWord/Shared/DrawingTest.php index 550ee67c6b..21116291cf 100644 --- a/Tests/PHPWord/Shared/DrawingTest.php +++ b/tests/PhpWord/Shared/DrawingTest.php @@ -1,12 +1,9 @@ assertEquals(round($value * 9525), $result); - $result = PHPWord_Shared_Drawing::EMUToPixels($value); + $result = Drawing::EMUToPixels($value); $this->assertEquals(round($value / 9525), $result); - $result = PHPWord_Shared_Drawing::pixelsToPoints($value); + $result = Drawing::pixelsToPoints($value); $this->assertEquals($value * 0.67777777, $result); - $result = PHPWord_Shared_Drawing::pointsToPixels($value); + $result = Drawing::pointsToPixels($value); $this->assertEquals($value * 1.333333333, $result); - $result = PHPWord_Shared_Drawing::degreesToAngle($value); + $result = Drawing::degreesToAngle($value); $this->assertEquals((int)round($value * 60000), $result); - $result = PHPWord_Shared_Drawing::angleToDegrees($value); + $result = Drawing::angleToDegrees($value); $this->assertEquals(round($value / 60000), $result); - $result = PHPWord_Shared_Drawing::pixelsToCentimeters($value); + $result = Drawing::pixelsToCentimeters($value); $this->assertEquals($value * 0.028, $result); - $result = PHPWord_Shared_Drawing::centimetersToPixels($value); + $result = Drawing::centimetersToPixels($value); $this->assertEquals($value / 0.028, $result); } } @@ -59,7 +56,7 @@ public function testHtmlToRGB() $values[] = array('0F9D', false); // 4 characters // Conduct test foreach ($values as $value) { - $result = PHPWord_Shared_Drawing::htmlToRGB($value[0]); + $result = Drawing::htmlToRGB($value[0]); $this->assertEquals($value[1], $result); } } diff --git a/tests/PhpWord/Shared/FileTest.php b/tests/PhpWord/Shared/FileTest.php new file mode 100644 index 0000000000..d3fd4869c5 --- /dev/null +++ b/tests/PhpWord/Shared/FileTest.php @@ -0,0 +1,42 @@ +assertTrue(File::file_exists('blank.docx')); + } + /** + * Test file_exists() + */ + public function testNoFileExists() + { + $dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates')); + chdir($dir); + $this->assertFalse(File::file_exists('404.docx')); + } + + /** + * Test realpath() + */ + public function testRealpath() + { + $dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates')); + chdir($dir); + $file = 'blank.docx'; + $expected = $dir . \DIRECTORY_SEPARATOR . $file; + $this->assertEquals($expected, File::realpath($file)); + } +} diff --git a/Tests/PHPWord/Shared/FontTest.php b/tests/PhpWord/Shared/FontTest.php similarity index 50% rename from Tests/PHPWord/Shared/FontTest.php rename to tests/PhpWord/Shared/FontTest.php index 5a40e465c8..64d1c67d87 100644 --- a/Tests/PHPWord/Shared/FontTest.php +++ b/tests/PhpWord/Shared/FontTest.php @@ -1,13 +1,10 @@ assertEquals($original * 16 / 12, $result); - $result = PHPWord_Shared_Font::inchSizeToPixels($original); + $result = Font::inchSizeToPixels($original); $this->assertEquals($original * 96, $result); - $result = PHPWord_Shared_Font::centimeterSizeToPixels($original); + $result = Font::centimeterSizeToPixels($original); $this->assertEquals($original * 37.795275591, $result); - $result = PHPWord_Shared_Font::centimeterSizeToTwips($original); + $result = Font::centimeterSizeToTwips($original); $this->assertEquals($original * 565.217, $result); - $result = PHPWord_Shared_Font::inchSizeToTwips($original); + $result = Font::inchSizeToTwips($original); $this->assertEquals($original * 565.217 * 2.54, $result); - $result = PHPWord_Shared_Font::pixelSizeToTwips($original); + $result = Font::pixelSizeToTwips($original); $this->assertEquals($original * 565.217 / 37.795275591, $result); - $result = PHPWord_Shared_Font::pointSizeToTwips($original); + $result = Font::pointSizeToTwips($original); $this->assertEquals($original * 20, $result); } } diff --git a/Tests/PHPWord/Style/CellTest.php b/tests/PhpWord/Style/CellTest.php similarity index 85% rename from Tests/PHPWord/Style/CellTest.php rename to tests/PhpWord/Style/CellTest.php index 0d47095128..6e540e6395 100644 --- a/Tests/PHPWord/Style/CellTest.php +++ b/tests/PhpWord/Style/CellTest.php @@ -1,12 +1,9 @@ 'left', - 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR, + 'textDirection' => Cell::TEXT_DIR_BTLR, 'bgColor' => 'FFFF00', 'borderTopSize' => 120, 'borderTopColor' => 'FFFF00', @@ -46,7 +43,7 @@ public function testSetGetNormal() */ public function testBorderColor() { - $object = new PHPWord_Style_Cell(); + $object = new Cell(); $default = '000000'; $value = 'FF0000'; @@ -66,7 +63,7 @@ public function testBorderColor() */ public function testBorderSize() { - $object = new PHPWord_Style_Cell(); + $object = new Cell(); $value = 120; $expected = array($value, $value, $value, $value); diff --git a/Tests/PHPWord/Style/FontTest.php b/tests/PhpWord/Style/FontTest.php similarity index 74% rename from Tests/PHPWord/Style/FontTest.php rename to tests/PhpWord/Style/FontTest.php index 46cec029b2..4f0cbaa5f9 100644 --- a/Tests/PHPWord/Style/FontTest.php +++ b/tests/PhpWord/Style/FontTest.php @@ -1,14 +1,11 @@ 'both')); + $object = new Font('text', array('align' => 'both')); $this->assertEquals('text', $object->getStyleType()); - $this->assertInstanceOf('PHPWord_Style_Paragraph', $object->getParagraphStyle()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); } /** @@ -34,18 +31,18 @@ public function testInitiation() */ public function testSetStyleValueWithNullOrEmpty() { - $object = new PHPWord_Style_Font(); + $object = new Font(); $attributes = array( - 'name' => PHPWord::DEFAULT_FONT_NAME, - 'size' => PHPWord::DEFAULT_FONT_SIZE, + 'name' => PhpWord::DEFAULT_FONT_NAME, + 'size' => PhpWord::DEFAULT_FONT_SIZE, 'bold' => false, 'italic' => false, 'superScript' => false, 'subScript' => false, - 'underline' => PHPWord_Style_Font::UNDERLINE_NONE, + 'underline' => Font::UNDERLINE_NONE, 'strikethrough' => false, - 'color' => PHPWord::DEFAULT_FONT_COLOR, + 'color' => PhpWord::DEFAULT_FONT_COLOR, 'fgColor' => null, ); foreach ($attributes as $key => $default) { @@ -62,7 +59,7 @@ public function testSetStyleValueWithNullOrEmpty() */ public function testSetStyleValueNormal() { - $object = new PHPWord_Style_Font(); + $object = new Font(); $attributes = array( 'name' => 'Times New Roman', @@ -71,7 +68,7 @@ public function testSetStyleValueNormal() 'italic' => true, 'superScript' => true, 'subScript' => true, - 'underline' => PHPWord_Style_Font::UNDERLINE_HEAVY, + 'underline' => Font::UNDERLINE_HEAVY, 'strikethrough' => true, 'color' => '999999', 'fgColor' => '999999', @@ -85,15 +82,15 @@ public function testSetStyleValueNormal() public function testLineHeight() { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); // Test style array $text = $section->addText('This is a test', array( 'line-height' => 2.0 )); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); $lineHeight = $element->getAttribute('w:line'); @@ -104,7 +101,7 @@ public function testLineHeight() // Test setter $text->getFontStyle()->setLineHeight(3.0); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); $lineHeight = $element->getAttribute('w:line'); diff --git a/Tests/PHPWord/Style/ImageTest.php b/tests/PhpWord/Style/ImageTest.php similarity index 82% rename from Tests/PHPWord/Style/ImageTest.php rename to tests/PhpWord/Style/ImageTest.php index 7e7b38881a..9c75843e17 100644 --- a/Tests/PHPWord/Style/ImageTest.php +++ b/tests/PhpWord/Style/ImageTest.php @@ -1,12 +1,9 @@ 200, @@ -39,7 +36,7 @@ public function testSetGetNormal() */ public function testSetStyleValue() { - $object = new PHPWord_Style_Image(); + $object = new Image(); $properties = array( 'width' => 200, @@ -58,11 +55,11 @@ public function testSetStyleValue() /** * Test setWrappingStyle exception * - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testSetWrappingStyleException() { - $object = new PHPWord_Style_Image(); + $object = new Image(); $object->setWrappingStyle('foo'); } } diff --git a/Tests/PHPWord/Style/ListItemTest.php b/tests/PhpWord/Style/ListItemTest.php similarity index 60% rename from Tests/PHPWord/Style/ListItemTest.php rename to tests/PhpWord/Style/ListItemTest.php index 890f468347..94b1baa2f9 100644 --- a/Tests/PHPWord/Style/ListItemTest.php +++ b/tests/PhpWord/Style/ListItemTest.php @@ -1,12 +1,9 @@ assertEquals($value, $object->getListType()); } @@ -27,9 +24,9 @@ public function testConstruct() */ public function testSetStyleValue() { - $object = new PHPWord_Style_ListItem(); + $object = new ListItem(); - $value = PHPWord_Style_ListItem::TYPE_ALPHANUM; + $value = ListItem::TYPE_ALPHANUM; $object->setStyleValue('_listType', $value); $this->assertEquals($value, $object->getListType()); } @@ -39,9 +36,9 @@ public function testSetStyleValue() */ public function testListType() { - $object = new PHPWord_Style_ListItem(); + $object = new ListItem(); - $value = PHPWord_Style_ListItem::TYPE_ALPHANUM; + $value = ListItem::TYPE_ALPHANUM; $object->setListType($value); $this->assertEquals($value, $object->getListType()); } diff --git a/Tests/PHPWord/Style/ParagraphTest.php b/tests/PhpWord/Style/ParagraphTest.php similarity index 79% rename from Tests/PHPWord/Style/ParagraphTest.php rename to tests/PhpWord/Style/ParagraphTest.php index ff084a5716..35f04b5ebb 100644 --- a/Tests/PHPWord/Style/ParagraphTest.php +++ b/tests/PhpWord/Style/ParagraphTest.php @@ -1,15 +1,12 @@ null, @@ -47,7 +44,7 @@ public function testSetStyleValueWithNullOrEmpty() */ public function testSetStyleValueNormal() { - $object = new PHPWord_Style_Paragraph(); + $object = new Paragraph(); $attributes = array( 'align' => 'justify', @@ -84,25 +81,22 @@ public function testSetStyleValueNormal() */ public function testTabs() { - $object = new PHPWord_Style_Paragraph(); - $object->setTabs(array( - new PHPWord_Style_Tab('left', 1550), - new PHPWord_Style_Tab('right', 5300), - )); - $this->assertInstanceOf('PHPWord_Style_Tabs', $object->getTabs()); + $object = new Paragraph(); + $object->setTabs(array(new Tab('left', 1550), new Tab('right', 5300))); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Tabs', $object->getTabs()); } public function testLineHeight() { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); // Test style array $text = $section->addText('This is a test', array(), array( 'line-height' => 2.0 )); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); $lineHeight = $element->getAttribute('w:line'); @@ -113,7 +107,7 @@ public function testLineHeight() // Test setter $text->getParagraphStyle()->setLineHeight(3.0); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); $lineHeight = $element->getAttribute('w:line'); @@ -128,7 +122,7 @@ public function testLineHeight() */ public function testLineHeightValidation() { - $object = new PHPWord_Style_Paragraph(); + $object = new Paragraph(); $object->setLineHeight('12.5pt'); $this->assertEquals(12.5, $object->getLineHeight()); } diff --git a/Tests/PHPWord/Style/RowTest.php b/tests/PhpWord/Style/RowTest.php similarity index 85% rename from Tests/PHPWord/Style/RowTest.php rename to tests/PhpWord/Style/RowTest.php index cbbecfbc09..af30517ae7 100644 --- a/Tests/PHPWord/Style/RowTest.php +++ b/tests/PhpWord/Style/RowTest.php @@ -1,12 +1,9 @@ true, diff --git a/Tests/PHPWord/Style/TOCTest.php b/tests/PhpWord/Style/TOCTest.php similarity index 68% rename from Tests/PHPWord/Style/TOCTest.php rename to tests/PhpWord/Style/TOCTest.php index 4607ba37aa..4c6c631a63 100644 --- a/Tests/PHPWord/Style/TOCTest.php +++ b/tests/PhpWord/Style/TOCTest.php @@ -1,13 +1,10 @@ 9062, - 'tabLeader' => PHPWord_Style_TOC::TABLEADER_DOT, - 'indent' => 200, + 'tabPos' => 9062, + 'tabLeader' => TOC::TABLEADER_DOT, + 'indent' => 200, ); foreach ($properties as $key => $value) { // set/get diff --git a/Tests/PHPWord/Style/TableFullTest.php b/tests/PhpWord/Style/TableFullTest.php similarity index 88% rename from Tests/PHPWord/Style/TableFullTest.php rename to tests/PhpWord/Style/TableFullTest.php index 7f7b77324b..ad3324ca14 100644 --- a/Tests/PHPWord/Style/TableFullTest.php +++ b/tests/PhpWord/Style/TableFullTest.php @@ -1,12 +1,9 @@ 'FF0000'); $styleFirstRow = array('borderBottomSize' => 3); - $object = new PHPWord_Style_TableFull($styleTable, $styleFirstRow); + $object = new TableFull($styleTable, $styleFirstRow); $this->assertEquals('FF0000', $object->getBgColor()); $firstRow = $object->getFirstRow(); - $this->assertInstanceOf('PHPWord_Style_TableFull', $firstRow); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TableFull', $firstRow); $this->assertEquals(3, $firstRow->getBorderBottomSize()); } @@ -37,7 +34,7 @@ public function testConstruct() */ public function testSetGetNormal() { - $object = new PHPWord_Style_TableFull(); + $object = new TableFull(); $attributes = array( 'bgColor' => 'FF0000', @@ -74,7 +71,7 @@ public function testSetGetNormal() */ public function testBorderColor() { - $object = new PHPWord_Style_TableFull(); + $object = new TableFull(); $parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV'); $value = 'FF0000'; @@ -96,7 +93,7 @@ public function testBorderColor() */ public function testBorderSize() { - $object = new PHPWord_Style_TableFull(); + $object = new TableFull(); $parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV'); $value = 4; @@ -118,7 +115,7 @@ public function testBorderSize() */ public function testCellMargin() { - $object = new PHPWord_Style_TableFull(); + $object = new TableFull(); $parts = array('Top', 'Left', 'Right', 'Bottom'); $value = 240; diff --git a/Tests/PHPWord/Style/TableTest.php b/tests/PhpWord/Style/TableTest.php similarity index 86% rename from Tests/PHPWord/Style/TableTest.php rename to tests/PhpWord/Style/TableTest.php index 439aa5ae8b..965da9d7dc 100644 --- a/Tests/PHPWord/Style/TableTest.php +++ b/tests/PhpWord/Style/TableTest.php @@ -1,12 +1,9 @@ addParagraphStyle('tabbed', array( - 'tabs' => array( - new PHPWord_Style_Tab('left', 1440, 'dot'), - ) - )); - $doc = TestHelperDOCX::getDocument($PHPWord); + $phpWord = new PhpWord(); + $phpWord->addParagraphStyle('tabbed', array('tabs' => array(new Tab('left', 1440, 'dot')))); + $doc = TestHelperDOCX::getDocument($phpWord); $file = 'word/styles.xml'; $path = '/w:styles/w:style[@w:styleId="tabbed"]/w:pPr/w:tabs/w:tab[1]'; $element = $doc->getElement($path, $file); diff --git a/Tests/PHPWord/TOCTest.php b/tests/PhpWord/TOCTest.php similarity index 55% rename from Tests/PHPWord/TOCTest.php rename to tests/PhpWord/TOCTest.php index d4503da5fd..daa0b5fdce 100644 --- a/Tests/PHPWord/TOCTest.php +++ b/tests/PhpWord/TOCTest.php @@ -1,38 +1,31 @@ 9062, - 'tabLeader' => PHPWord_Style_TOC::TABLEADER_DOT, - 'indent' => 200, - ); - $object = new PHPWord_TOC( - array('size' => 11), - array('tabPos' => $expected['tabPos']) + 'tabPos' => 9062, + 'tabLeader' => \PhpOffice\PhpWord\Style\TOC::TABLEADER_DOT, + 'indent' => 200, ); + $object = new TOC(array('size' => 11), array('tabPos' => $expected['tabPos'])); $tocStyle = $object->getStyleTOC(); - $this->assertInstanceOf('PHPWord_Style_TOC', $tocStyle); - $this->assertInstanceOf('PHPWord_Style_Font', $object->getStyleFont()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TOC', $tocStyle); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $object->getStyleFont()); foreach ($expected as $key => $value) { $method = "get{$key}"; @@ -41,8 +34,8 @@ public function testConstruct() } /** - * @covers PHPWord_TOC::addTitle - * @covers PHPWord_TOC::getTitles + * @covers ::addTitle + * @covers ::getTitles */ public function testAddAndGetTitle() { @@ -56,16 +49,16 @@ public function testAddAndGetTitle() 'Heading 3' => 3, ); - // @covers PHPWord_TOC::addTitle + // @covers ::addTitle foreach ($titles as $text => $depth) { - $response = PHPWord_TOC::addTitle($text, $depth); + $response = TOC::addTitle($text, $depth); } $this->assertEquals($anchor, $response[0]); $this->assertEquals($bookmark, $response[1]); - // @covers PHPWord_TOC::getTitles + // @covers ::getTitles $i = 0; - $savedTitles = PHPWord_TOC::getTitles(); + $savedTitles = TOC::getTitles(); foreach ($titles as $text => $depth) { $this->assertEquals($text, $savedTitles[$i]['text']); $this->assertEquals($depth, $savedTitles[$i]['depth']); diff --git a/Tests/PHPWord/TemplateTest.php b/tests/PhpWord/TemplateTest.php similarity index 65% rename from Tests/PHPWord/TemplateTest.php rename to tests/PhpWord/TemplateTest.php index 1439cebce3..7d790e4942 100644 --- a/Tests/PHPWord/TemplateTest.php +++ b/tests/PhpWord/TemplateTest.php @@ -1,11 +1,11 @@ load( \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'remove_tables_by_needle.xsl') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'remove_tables_by_needle.xsl') ) ); foreach (array('${employee.', '${scoreboard.') as $needle) { @@ -65,7 +65,7 @@ final public function testXslStyleSheetCanBeApplied($actualDocumentFqfn) { $expectedDocumentFqfn = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'without_table_macros.docx') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'without_table_macros.docx') ); $actualDocumentZip = new \ZipArchive(); @@ -87,16 +87,16 @@ final public function testXslStyleSheetCanBeApplied($actualDocumentFqfn) /** * @covers ::applyXslStyleSheet - * @expectedException Exception + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception * @expectedExceptionMessage Could not set values for the given XSL style sheet parameters. * @test */ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue() { - $template = new PHPWord_Template( + $template = new Template( \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'blank.docx') ) ); @@ -104,12 +104,12 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParamete $xslDOMDocument->load( \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'passthrough.xsl') ) ); /* - * We have to use error control below, because XSLTProcessor::setParameter omits warning on failure. + * We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure. * This warning fails the test. */ @$template->applyXslStyleSheet($xslDOMDocument, array(1 => 'somevalue')); @@ -117,16 +117,16 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParamete /** * @covers ::applyXslStyleSheet - * @expectedException Exception + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception * @expectedExceptionMessage Could not load XML from the given template. * @test */ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate() { - $template = new PHPWord_Template( + $template = new Template( \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'corrupted_main_document_part.docx') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'corrupted_main_document_part.docx') ) ); @@ -134,60 +134,34 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromT $xslDOMDocument->load( \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'xsl', 'passthrough.xsl') ) ); /* - * We have to use error control below, because DOMDocument::loadXML omits warning on failure. + * We have to use error control below, because \DOMDocument::loadXML omits warning on failure. * This warning fails the test. */ @$template->applyXslStyleSheet($xslDOMDocument); } - /** - * @covers PHPWord_Template - */ - public function testConstruct() - { - $template = \join( - \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-row.docx') - ); - $expectedVar = array('tableHeader', 'userId', 'userName'); - $document = new PHPWord_Template($template); - $actualVar = $document->getVariables(); - $document->cloneRow('userId', 9); - $document->setValue('userId#1', utf8_decode('ééé')); - $document->setValue('userId#2', 'a'); - $document->setValue('userId#3', 'a'); - $document->setValue('userId#3', 'a'); - $document->setValue('userId#4', 'a'); - $document->setValue('userId#5', 'a'); - $document->setValue('userId#6', 'a'); - $document->setValue('userId#7', 'a'); - $document->setValue('userId#8', 'a'); - $document->cloneRow('userId#9', 'a'); - $this->assertEquals($expectedVar, $actualVar); - } - /** * @covers ::setValue * @covers ::getVariables * @covers ::cloneRow * @covers ::saveAs */ - public function testCloneMergedRow() + public function testCloneRow() { $template = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-merge.docx') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'clone-merge.docx') ); $expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation'); $docName = 'clone-test-result.docx'; - $PHPWord = new PHPWord(); - $document = $PHPWord->loadTemplate($template); + $phpWord = new PhpWord(); + $document = $phpWord->loadTemplate($template); $actualVar = $document->getVariables(); $document->cloneRow('userId', 1); $document->setValue('userId#1', 'Test'); diff --git a/Tests/PHPWord/Writer/ODText/ContentTest.php b/tests/PhpWord/Writer/ODText/ContentTest.php similarity index 63% rename from Tests/PHPWord/Writer/ODText/ContentTest.php rename to tests/PhpWord/Writer/ODText/ContentTest.php index 63b84d7553..e1f6aa2be9 100644 --- a/Tests/PHPWord/Writer/ODText/ContentTest.php +++ b/tests/PhpWord/Writer/ODText/ContentTest.php @@ -1,15 +1,11 @@ + * covers ::writeContent + * covers */ public function testWriteContent() { $imageSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png') ); $objectSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); $expected = 'Expected'; - $PHPWord = new PHPWord(); - $PHPWord->setDefaultFontName('Verdana'); - $PHPWord->addFontStyle('Font', array('size' => 11)); - $PHPWord->addParagraphStyle('Paragraph', array('align' => 'center')); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $phpWord->setDefaultFontName('Verdana'); + $phpWord->addFontStyle('Font', array('size' => 11)); + $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $section = $phpWord->createSection(); $section->addText($expected); $section->addText('Test font style', 'Font'); $section->addText('Test paragraph style', null, 'Paragraph'); @@ -57,7 +53,7 @@ public function testWriteContent() $section->addTOC(); $textrun = $section->createTextRun(); $textrun->addText('Test text run'); - $doc = TestHelperDOCX::getDocument($PHPWord, 'ODText'); + $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); $element = "/office:document-content/office:body/office:text/text:p"; $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue); diff --git a/Tests/PHPWord/Writer/ODTextTest.php b/tests/PhpWord/Writer/ODTextTest.php similarity index 50% rename from Tests/PHPWord/Writer/ODTextTest.php rename to tests/PhpWord/Writer/ODTextTest.php index 7cc49fbaa8..3b6b8e61ff 100644 --- a/Tests/PHPWord/Writer/ODTextTest.php +++ b/tests/PhpWord/Writer/ODTextTest.php @@ -1,14 +1,11 @@ assertInstanceOf('PHPWord', $object->getPHPWord()); - $this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable()); $this->assertEquals('./', $object->getDiskCachingDirectory()); - $writerParts = array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles'); - foreach ($writerParts as $part) { + foreach (array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles') as $part) { $this->assertInstanceOf( - "PHPWord_Writer_ODText_{$part}", + "PhpOffice\\PhpWord\\Writer\\ODText\\{$part}", $object->getWriterPart($part) ); $this->assertInstanceOf( - "PHPWord_Writer_ODText", + 'PhpOffice\\PhpWord\\Writer\\ODText', $object->getWriterPart($part)->getParentWriter() ); } } /** - * @covers ::getPHPWord - * @expectedException Exception - * @expectedExceptionMessage No PHPWord assigned. + * @covers ::getPhpWord + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage No PhpWord assigned. */ public function testConstructWithNull() { - $object = new PHPWord_Writer_ODText(); - $object->getPHPWord(); + $object = new ODText(); + $object->getPhpWord(); } /** - * @covers ::save + * @covers ::save */ public function testSave() { $imageSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png') ); $objectSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); $file = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'temp.odt') ); - $phpWord = new PHPWord(); + $phpWord = new PhpWord(); $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->createSection(); @@ -84,7 +80,7 @@ public function testSave() $section = $phpWord->createSection(); $textrun = $section->createTextRun(); $textrun->addText('Test 3'); - $writer = new PHPWord_Writer_ODText($phpWord); + $writer = new ODText($phpWord); $writer->save($file); $this->assertTrue(file_exists($file)); @@ -93,49 +89,62 @@ public function testSave() } /** - * @covers ::save - * @expectedException Exception - * @expectedExceptionMessage PHPWord object unassigned. + * @covers ::save + * @todo Haven't got any method to test this + */ + public function testSavePhpOutput() + { + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); + $section->addText('Test'); + $writer = new ODText($phpWord); + $writer->save('php://output'); + } + + /** + * @covers ::save + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage PhpWord object unassigned. */ public function testSaveException() { - $writer = new PHPWord_Writer_ODText(); + $writer = new ODText(); $writer->save(); } /** - * @covers ::getWriterPart + * @covers ::getWriterPart */ public function testGetWriterPartNull() { - $object = new PHPWord_Writer_ODText(); + $object = new ODText(); $this->assertNull($object->getWriterPart('foo')); } /** - * @covers ::setUseDiskCaching - * @covers ::getUseDiskCaching + * @covers ::setUseDiskCaching + * @covers ::getUseDiskCaching */ public function testSetGetUseDiskCaching() { - $object = new PHPWord_Writer_ODText(); - $object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT); + $object = new ODText(); + $object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR); $this->assertTrue($object->getUseDiskCaching()); - $this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory()); + $this->assertEquals(\PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory()); } /** - * @covers ::setUseDiskCaching - * @expectedException Exception + * @covers ::setUseDiskCaching + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception */ public function testSetUseDiskCachingException() { $dir = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, 'foo') + array(\PHPWORD_TESTS_BASE_DIR, 'foo') ); - $object = new PHPWord_Writer_ODText($phpWord); + $object = new ODText($phpWord); $object->setUseDiskCaching(true, $dir); } } diff --git a/tests/PhpWord/Writer/RTFTest.php b/tests/PhpWord/Writer/RTFTest.php new file mode 100644 index 0000000000..17bcd1f10c --- /dev/null +++ b/tests/PhpWord/Writer/RTFTest.php @@ -0,0 +1,104 @@ +assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable()); + } + + /** + * covers ::__construct + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage No PhpWord assigned. + */ + public function testConstructWithNull() + { + $object = new RTF(); + $object->getPhpWord(); + } + + /** + * @covers ::save + * @todo Haven't got any method to test this + */ + public function testSavePhpOutput() + { + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); + $section->addText('Test'); + $writer = new RTF($phpWord); + $writer->save('php://output'); + } + + /** + * @covers ::save + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage PhpWord object unassigned. + */ + public function testSaveException() + { + $writer = new RTF(); + $writer->save(); + } + + /** + * @covers ::save + * @covers :: + */ + public function testSave() + { + $imageSrc = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'PhpWord.png') + ); + $objectSrc = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') + ); + $file = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'temp.rtf') + ); + + $phpWord = new PhpWord(); + $phpWord->addFontStyle('Font', array('size' => 11)); + $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $section = $phpWord->createSection(); + $section->addText('Test 1', 'Font'); + $section->addTextBreak(); + $section->addText('Test 2', null, 'Paragraph'); + $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 RTF($phpWord); + $writer->save($file); + + $this->assertTrue(file_exists($file)); + + unlink($file); + } +} diff --git a/Tests/PHPWord/Writer/Word2007/BaseTest.php b/tests/PhpWord/Writer/Word2007/BaseTest.php similarity index 71% rename from Tests/PHPWord/Writer/Word2007/BaseTest.php rename to tests/PhpWord/Writer/Word2007/BaseTest.php index fde6e30b20..a1d19435a3 100644 --- a/Tests/PHPWord/Writer/Word2007/BaseTest.php +++ b/tests/PhpWord/Writer/Word2007/BaseTest.php @@ -1,15 +1,11 @@ addFontStyle($rStyle, array('bold' => true)); - $PHPWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $phpWord->addFontStyle($rStyle, array('bold' => true)); + $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); + $section = $phpWord->createSection(); $section->addText('Test', $rStyle, $pStyle); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = "/w:document/w:body/w:p/w:r/w:rPr/w:rStyle"; $this->assertEquals($rStyle, $doc->getElementAttribute($element, 'w:val')); @@ -44,68 +40,69 @@ public function testWriteText() } /** - * covers ::_writeTextRun + * covers ::_writeTextRun */ public function testWriteTextRun() { $pStyle = 'pStyle'; $aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120); $imageSrc = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $PHPWord = new PHPWord(); - $PHPWord->addParagraphStyle($pStyle, $aStyle); - $section = $PHPWord->createSection('Test'); + $phpWord = new PhpWord(); + $phpWord->addParagraphStyle($pStyle, $aStyle); + $section = $phpWord->createSection('Test'); $textrun = $section->createTextRun($pStyle); $textrun->addText('Test'); $textrun->addTextBreak(); $textrun = $section->createTextRun($aStyle); $textrun->addLink('http://test.com'); $textrun->addImage($imageSrc); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $parent = "/w:document/w:body/w:p"; $this->assertTrue($doc->elementExists("{$parent}/w:pPr/w:pStyle[@w:val='{$pStyle}']")); } /** - * covers ::_writeLink + * covers ::_writeLink */ public function testWriteLink() { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); - $expected = 'PHPWord'; + $expected = 'PhpWord'; $section->addLink('http://github.com/phpoffice/phpword', $expected); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); $this->assertEquals($expected, $element->nodeValue); } /** - * covers ::_writePreserveText + * covers ::_writePreserveText */ public function testWritePreserveText() { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $footer = $section->createFooter(); $footer->addPreserveText('{PAGE}'); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml'); $this->assertEquals('PAGE', $preserve->nodeValue); $this->assertEquals('preserve', $preserve->getAttribute('xml:space')); } + /** - * covers ::_writeTextBreak + * covers ::_writeTextBreak */ public function testWriteTextBreak() { @@ -114,14 +111,14 @@ public function testWriteTextBreak() $fName = 'fStyle'; $pName = 'pStyle'; - $PHPWord = new PHPWord(); - $PHPWord->addFontStyle($fName, $fArray); - $PHPWord->addParagraphStyle($pName, $pArray); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $phpWord->addFontStyle($fName, $fArray); + $phpWord->addParagraphStyle($pName, $pArray); + $section = $phpWord->createSection(); $section->addTextBreak(); $section->addTextBreak(1, $fArray, $pArray); $section->addTextBreak(1, $fName, $pName); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:rPr/w:rStyle'); $this->assertEquals($fName, $element->getAttribute('w:val')); @@ -130,29 +127,29 @@ public function testWriteTextBreak() } /** - * covers ::_writeParagraphStyle + * covers ::_writeParagraphStyle */ public function testWriteParagraphStyleAlign() { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $section->addText('This is my text', null, array('align' => 'right')); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:jc'); $this->assertEquals('right', $element->getAttribute('w:val')); } /** - * covers ::_writeParagraphStyle + * covers ::_writeParagraphStyle */ public function testWriteParagraphStylePagination() { // Create the doc - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $attributes = array( 'widowControl' => false, 'keepNext' => true, @@ -162,7 +159,7 @@ public function testWriteParagraphStylePagination() foreach ($attributes as $attribute => $value) { $section->addText('Test', null, array($attribute => $value)); } - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); // Test the attributes $i = 0; @@ -176,11 +173,11 @@ public function testWriteParagraphStylePagination() } /** - * covers ::_writeTextStyle + * covers ::_writeTextStyle */ public function testWriteFontStyle() { - $PHPWord = new PHPWord(); + $phpWord = new PhpWord(); $styles['name'] = 'Verdana'; $styles['size'] = 14; $styles['bold'] = true; @@ -191,9 +188,9 @@ public function testWriteFontStyle() $styles['color'] = 'FF0000'; $styles['fgColor'] = 'yellow'; - $section = $PHPWord->createSection(); + $section = $phpWord->createSection(); $section->addText('Test', $styles); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $parent = '/w:document/w:body/w:p/w:r/w:rPr'; $this->assertEquals($styles['name'], $doc->getElementAttribute("{$parent}/w:rFonts", 'w:ascii')); @@ -208,11 +205,11 @@ public function testWriteFontStyle() } /** - * covers ::_writeTableStyle + * covers ::_writeTableStyle */ public function testWriteTableStyle() { - $PHPWord = new PHPWord(); + $phpWord = new PhpWord(); $tWidth = 120; $rHeight = 120; $cWidth = 120; @@ -234,7 +231,7 @@ public function testWriteTableStyle() $cStyles["borderLeftColor"] = 'FF0000'; $cStyles["borderRightColor"] = 'FF0000'; - $section = $PHPWord->createSection(); + $section = $phpWord->createSection(); $table = $section->addTable($tStyles); $table->setWidth = 100; $table->addRow($rHeight, $rStyles); @@ -246,13 +243,13 @@ public function testWriteTableStyle() $textrun = $cell->createTextRun(); $textrun->addText('Test'); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $parent = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellMar'; - $this->assertEquals($tStyles['cellMarginTop'], $doc->getElementAttribute("{$parent}/w:top", 'w:w')); - $this->assertEquals($tStyles['cellMarginRight'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); - $this->assertEquals($tStyles['cellMarginBottom'], $doc->getElementAttribute("{$parent}/w:bottom", 'w:w')); - $this->assertEquals($tStyles['cellMarginLeft'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); + // $this->assertEquals($tStyles['cellMarginTop'], $doc->getElementAttribute("{$parent}/w:top", 'w:w')); + // $this->assertEquals($tStyles['cellMarginRight'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); + // $this->assertEquals($tStyles['cellMarginBottom'], $doc->getElementAttribute("{$parent}/w:bottom", 'w:w')); + // $this->assertEquals($tStyles['cellMarginLeft'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); $parent = '/w:document/w:body/w:tbl/w:tr/w:trPr'; $this->assertEquals($rHeight, $doc->getElementAttribute("{$parent}/w:trHeight", 'w:val')); @@ -266,12 +263,12 @@ public function testWriteTableStyle() } /** - * covers ::_writeCellStyle + * covers ::_writeCellStyle */ public function testWriteCellStyleCellGridSpan() { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $table = $section->addTable(); @@ -286,21 +283,21 @@ public function testWriteCellStyleCellGridSpan() $table->addCell(40); $table->addCell(40); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan'); $this->assertEquals(5, $element->getAttribute('w:val')); } /** - * covers ::_writeImage + * covers ::_writeImage */ public function testWriteImagePosition() { - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $section->addImage( - PHPWORD_TESTS_DIR_ROOT . '/_files/images/earth.jpg', + \PHPWORD_TESTS_BASE_DIR . '/data/images/earth.jpg', array( 'marginTop' => -1, 'marginLeft' => -1, @@ -308,7 +305,7 @@ public function testWriteImagePosition() ) ); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:r/w:pict/v:shape'); $style = $element->getAttribute('style'); @@ -318,34 +315,34 @@ public function testWriteImagePosition() } /** - * covers ::_writeWatermark + * covers ::_writeWatermark */ public function testWriteWatermark() { $imageSrc = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'images', 'earth.jpg') ); - $PHPWord = new PHPWord(); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $header = $section->createHeader(); $header->addWatermark($imageSrc); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference"); $this->assertStringStartsWith("rId", $element->getAttribute('r:id')); } /** - * covers ::_writeTitle + * covers ::_writeTitle */ public function testWriteTitle() { - $PHPWord = new PHPWord(); - $PHPWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); - $PHPWord->createSection()->addTitle('Test', 1); - $doc = TestHelperDOCX::getDocument($PHPWord); + $phpWord = new PhpWord(); + $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); + $phpWord->createSection()->addTitle('Test', 1); + $doc = TestHelperDOCX::getDocument($phpWord); $element = "/w:document/w:body/w:p/w:pPr/w:pStyle"; $this->assertEquals('Heading1', $doc->getElementAttribute($element, 'w:val')); diff --git a/Tests/PHPWord/Writer/Word2007/DocumentTest.php b/tests/PhpWord/Writer/Word2007/DocumentTest.php similarity index 68% rename from Tests/PHPWord/Writer/Word2007/DocumentTest.php rename to tests/PhpWord/Writer/Word2007/DocumentTest.php index 5bc11b5aa3..ef03b1c9f4 100644 --- a/Tests/PHPWord/Writer/Word2007/DocumentTest.php +++ b/tests/PhpWord/Writer/Word2007/DocumentTest.php @@ -1,14 +1,10 @@ createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $section->getSettings()->setPageNumberingStart(2); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType'); $this->assertEquals(2, $element->getAttribute('w:start')); } /** - * covers ::_writeTOC - * covers ::_writePageBreak - * covers ::_writeListItem - * covers ::_writeTitle - * covers ::_writeObject + * covers ::_writeTOC + * covers ::_writePageBreak + * covers ::_writeListItem + * covers ::_writeTitle + * covers ::_writeObject */ public function testElements() { $objectSrc = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'documents', 'sheet.xls') ); - $PHPWord = new PHPWord(); - $PHPWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); - $PHPWord->addTitleStyle(2, array('color'=>'666666')); - $section = $PHPWord->createSection(); + $phpWord = new PhpWord(); + $phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); + $phpWord->addTitleStyle(2, array('color'=>'666666')); + $section = $phpWord->createSection(); $section->addTOC(); $section->addPageBreak(); $section->addTitle('Title 1', 1); $section->addListItem('List Item 1', 0); $section->addListItem('List Item 2', 0); $section->addListItem('List Item 3', 0); - $section = $PHPWord->createSection(); + $section = $phpWord->createSection(); $section->addTitle('Title 2', 2); $section->addObject($objectSrc); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); // TOC $element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:tabs/w:tab'); @@ -84,4 +80,4 @@ public function testElements() $element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject'); $this->assertEquals('Embed', $element->getAttribute('Type')); } -} \ No newline at end of file +} diff --git a/Tests/PHPWord/Writer/Word2007/FootnotesTest.php b/tests/PhpWord/Writer/Word2007/FootnotesTest.php similarity index 66% rename from Tests/PHPWord/Writer/Word2007/FootnotesTest.php rename to tests/PhpWord/Writer/Word2007/FootnotesTest.php index ea49bd6726..066c089b07 100644 --- a/Tests/PHPWord/Writer/Word2007/FootnotesTest.php +++ b/tests/PhpWord/Writer/Word2007/FootnotesTest.php @@ -1,12 +1,10 @@ createSection(); + $phpWord = new PhpWord(); + $section = $phpWord->createSection(); $section->addText('Text'); $footnote = $section->createFootnote(); $footnote->addText('Footnote'); $footnote->addLink('http://google.com'); - $doc = TestHelperDOCX::getDocument($PHPWord); + $doc = TestHelperDOCX::getDocument($phpWord); $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference")); } diff --git a/Tests/PHPWord/Writer/Word2007/StylesTest.php b/tests/PhpWord/Writer/Word2007/StylesTest.php similarity index 74% rename from Tests/PHPWord/Writer/Word2007/StylesTest.php rename to tests/PhpWord/Writer/Word2007/StylesTest.php index bcdc4b815d..6ed05f673d 100644 --- a/Tests/PHPWord/Writer/Word2007/StylesTest.php +++ b/tests/PhpWord/Writer/Word2007/StylesTest.php @@ -1,12 +1,10 @@ 'both'); $pBase = array('basedOn' => 'Normal'); @@ -43,13 +41,13 @@ public function testWriteStyles() 'borderInsideHSize' => 120, 'borderInsideVSize' => 120, ); - $PHPWord->setDefaultParagraphStyle($pStyle); - $PHPWord->addParagraphStyle('Base Style', $pBase); - $PHPWord->addParagraphStyle('New Style', $pNew); - $PHPWord->addFontStyle('New Style', $rStyle, $pStyle); - $PHPWord->addTableStyle('Table Style', $tStyle, $tStyle); - $PHPWord->addTitleStyle(1, $rStyle, $pStyle); - $doc = TestHelperDOCX::getDocument($PHPWord); + $phpWord->setDefaultParagraphStyle($pStyle); + $phpWord->addParagraphStyle('Base Style', $pBase); + $phpWord->addParagraphStyle('New Style', $pNew); + $phpWord->addFontStyle('New Style', $rStyle, $pStyle); + $phpWord->addTableStyle('Table Style', $tStyle, $tStyle); + $phpWord->addTitleStyle(1, $rStyle, $pStyle); + $doc = TestHelperDOCX::getDocument($phpWord); $file = 'word/styles.xml'; diff --git a/Tests/PHPWord/Writer/Word2007Test.php b/tests/PhpWord/Writer/Word2007Test.php similarity index 53% rename from Tests/PHPWord/Writer/Word2007Test.php rename to tests/PhpWord/Writer/Word2007Test.php index ca1d7d8236..feeee723a6 100644 --- a/Tests/PHPWord/Writer/Word2007Test.php +++ b/tests/PhpWord/Writer/Word2007Test.php @@ -1,15 +1,12 @@ assertInstanceOf( - "PHPWord_Writer_Word2007_{$part}", + "PhpOffice\\PhpWord\\Writer\\Word2007\\{$part}", $object->getWriterPart($part) ); $this->assertInstanceOf( - "PHPWord_Writer_Word2007", + 'PhpOffice\\PhpWord\\Writer\\Word2007', $object->getWriterPart($part)->getParentWriter() ); } } /** - * @covers ::save + * @covers ::save */ public function testSave() { - $phpWord = new PHPWord(); + $phpWord = new PhpWord(); $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->createSection(); @@ -57,10 +63,10 @@ public function testSave() $textrun = $section->createTextRun(); $textrun->addText('Test 3'); - $writer = new PHPWord_Writer_Word2007($phpWord); + $writer = new Word2007($phpWord); $file = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.docx') + array(\PHPWORD_TESTS_BASE_DIR, 'data', 'temp.docx') ); $writer->save($file); $this->assertTrue(file_exists($file)); @@ -68,27 +74,7 @@ public function testSave() } /** - * @covers ::save - * @expectedException Exception - * @expectedExceptionMessage PHPWord object unassigned. - */ - public function testSaveException() - { - $writer = new PHPWord_Writer_Word2007(); - $writer->save(); - } - - /** - * @covers ::getWriterPart - */ - public function testGetWriterPartNull() - { - $object = new PHPWord_Writer_Word2007(); - $this->assertNull($object->getWriterPart('foo')); - } - - /** - * @covers ::checkContentTypes + * @covers ::checkContentTypes */ public function testCheckContentTypes() { @@ -100,10 +86,10 @@ public function testCheckContentTypes() 'duke_nukem.bmp' => '5.bmp', 'angela_merkel.tif' => '6.tif', ); - $phpWord = new PHPWord(); + $phpWord = new PhpWord(); $section = $phpWord->createSection(); foreach ($images as $source => $target) { - $section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/data/images/{$source}"); } $doc = TestHelperDOCX::getDocument($phpWord); @@ -111,37 +97,36 @@ public function testCheckContentTypes() foreach ($images as $source => $target) { $this->assertFileEquals( - PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}", + \PHPWORD_TESTS_BASE_DIR . "/data/images/{$source}", $mediaPath . "/section_image{$target}" ); } } /** - * @covers ::setUseDiskCaching - * @covers ::getUseDiskCaching - * @covers ::getDiskCachingDirectory + * @covers ::setUseDiskCaching + * @covers ::getUseDiskCaching */ public function testSetGetUseDiskCaching() { - $object = new PHPWord_Writer_Word2007(); - $object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT); + $object = new Word2007(); + $object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR); + $this->assertTrue($object->getUseDiskCaching()); - $this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory()); } /** - * @covers ::setUseDiskCaching - * @expectedException Exception + * @covers ::setUseDiskCaching + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception */ public function testSetUseDiskCachingException() { $dir = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, 'foo') + array(\PHPWORD_TESTS_BASE_DIR, 'foo') ); - $object = new PHPWord_Writer_Word2007(); + $object = new Word2007(); $object->setUseDiskCaching(true, $dir); } } diff --git a/Tests/_inc/TestHelperDOCX.php b/tests/common/TestHelperDOCX.php similarity index 52% rename from Tests/_inc/TestHelperDOCX.php rename to tests/common/TestHelperDOCX.php index ba5dcf07f6..bd3d4f8caf 100644 --- a/Tests/_inc/TestHelperDOCX.php +++ b/tests/common/TestHelperDOCX.php @@ -1,38 +1,36 @@ save(self::$file); + $xmlWriter = IOFactory::createWriter($phpWord, $writerName); + $xmlWriter->save(self::$file); $zip = new \ZipArchive; $res = $zip->open(self::$file); if ($res === true) { - $zip->extractTo(sys_get_temp_dir() . '/PHPWord_Unit_Test/'); + $zip->extractTo(sys_get_temp_dir() . '/PhpWord_Unit_Test/'); $zip->close(); } - return new XmlDocument(sys_get_temp_dir() . '/PHPWord_Unit_Test/'); + return new XmlDocument(sys_get_temp_dir() . '/PhpWord_Unit_Test/'); } public static function clear() @@ -40,8 +38,8 @@ public static function clear() if (file_exists(self::$file)) { unlink(self::$file); } - if (is_dir(sys_get_temp_dir() . '/PHPWord_Unit_Test/')) { - self::deleteDir(sys_get_temp_dir() . '/PHPWord_Unit_Test/'); + if (is_dir(sys_get_temp_dir() . '/PhpWord_Unit_Test/')) { + self::deleteDir(sys_get_temp_dir() . '/PhpWord_Unit_Test/'); } } @@ -70,4 +68,4 @@ public static function getFile() { return self::$file; } -} \ No newline at end of file +} diff --git a/Tests/_inc/XmlDocument.php b/tests/common/XmlDocument.php similarity index 96% rename from Tests/_inc/XmlDocument.php rename to tests/common/XmlDocument.php index 4d3d00347d..deee806bac 100644 --- a/Tests/_inc/XmlDocument.php +++ b/tests/common/XmlDocument.php @@ -1,7 +1,5 @@ file = $file; $file = $this->path . '/' . $file; - $this->dom = new DOMDocument(); + $this->dom = new \DOMDocument(); $this->dom->load($file); return $this->dom; } diff --git a/tests/common/bootstrap.php b/tests/common/bootstrap.php new file mode 100755 index 0000000000..e8192d6b58 --- /dev/null +++ b/tests/common/bootstrap.php @@ -0,0 +1,14 @@ +