diff --git a/.travis.yml b/.travis.yml index 5613304904..2de1aa7cec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - 5.3.3 - 5.3 - 5.4 - 5.5 diff --git a/Classes/PHPWord.php b/Classes/PHPWord.php deleted file mode 100755 index d591b94ecf..0000000000 --- a/Classes/PHPWord.php +++ /dev/null @@ -1,276 +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 $styleName string - * @param $styles array - */ - public function addParagraphStyle($styleName, $styles) - { - PHPWord_Style::addParagraphStyle($styleName, $styles); - } - - /** - * Adds a font style definition to styles.xml - * - * @param $styleName string - * @param $styles array - */ - public function addFontStyle($styleName, $styleFont, $styleParagraph = null) - { - PHPWord_Style::addFontStyle($styleName, $styleFont, $styleParagraph); - } - - /** - * Adds a table style definition to styles.xml - * - * @param $styleName string - * @param $styles array - */ - public function addTableStyle($styleName, $styleTable, $styleFirstRow = null) - { - PHPWord_Style::addTableStyle($styleName, $styleTable, $styleFirstRow); - } - - /** - * Adds a heading style definition to styles.xml - * - * @param $titleCount int - * @param $styles array - */ - public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null) - { - PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph); - } - - /** - * Adds a hyperlink style to styles.xml - * - * @param $styleName string - * @param $styles array - */ - public function addLinkStyle($styleName, $styles) - { - PHPWord_Style::addLinkStyle($styleName, $styles); - } - - /** - * Get sections - * @return PHPWord_Section[] - */ - public function getSections() - { - return $this->_sectionCollection; - } - - /** - * 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 aa36efc88b..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/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php deleted file mode 100755 index 0899990b16..0000000000 --- a/Classes/PHPWord/Writer/ODText/Content.php +++ /dev/null @@ -1,397 +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 - */ - protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) - { - $objWriter->startElement('text:p'); - $objWriter->writeAttribute('text:style-name', 'Standard'); - $objWriter->endElement(); - } - - // @codeCoverageIgnoreStart - private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null) - { - } - - 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 e9249120e5..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ /dev/null @@ -1,1025 +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 - */ - 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(); - } - } - - /** - * @param \PHPWord_Shared_XMLWriter $objWriter - * @param \PHPWord_Section_Image|\PHPWord_Section_MemoryImage $image - */ - 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 - */ - 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 - */ - 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 2e8f8b5a63..0000000000 --- a/Classes/PHPWord/Writer/Word2007/DocProps.php +++ /dev/null @@ -1,185 +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(); - } - - - 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 abdd92cc75..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ /dev/null @@ -1,491 +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(); - } - - private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) - { - $objWriter->startElement('w:p'); - $objWriter->startElement('w:pPr'); - $this->_writeEndSection($objWriter, $section, 3); - $objWriter->endElement(); - $objWriter->endElement(); - } - - private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) - { - $settings = $section->getSettings(); - $_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(); - } - - 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(); - } - - 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(); - } - - 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 - } - - 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 6ee18d66c7..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Footer.php +++ /dev/null @@ -1,83 +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 28d087c7d2..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Footnotes.php +++ /dev/null @@ -1,83 +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 59eebd9178..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Header.php +++ /dev/null @@ -1,87 +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 3724323e10..0000000000 --- a/Classes/PHPWord/Writer/Word2007/Styles.php +++ /dev/null @@ -1,394 +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(); - } - - 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); - } - } - - private function _writeRowStyle(PHPWord_Shared_XMLWriter $objWriter = null, $type, PHPWord_Style_TableFull $style) - { - $brdSz = $style->getBorderSize(); - $brdCol = $style->getBorderColor(); - $bgColor = $style->getBgColor(); - - $bTop = (!is_null($brdSz[0])) ? true : false; - $bLeft = (!is_null($brdSz[1])) ? true : false; - $bRight = (!is_null($brdSz[2])) ? true : false; - $bBottom = (!is_null($brdSz[3])) ? true : false; - $borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false; - - $objWriter->startElement('w:tblStylePr'); - $objWriter->writeAttribute('w:type', $type); - - $objWriter->startElement('w:tcPr'); - if (!is_null($bgColor)) { - $objWriter->startElement('w:shd'); - $objWriter->writeAttribute('w:val', 'clear'); - $objWriter->writeAttribute('w:color', 'auto'); - $objWriter->writeAttribute('w:fill', $bgColor); - $objWriter->endElement(); - } - - $objWriter->startElement('w:tcBorders'); - if ($bTop) { - $objWriter->startElement('w:top'); - $objWriter->writeAttribute('w:val', 'single'); - $objWriter->writeAttribute('w:sz', $brdSz[0]); - $objWriter->writeAttribute('w:color', $brdCol[0]); - $objWriter->endElement(); - } - if ($bLeft) { - $objWriter->startElement('w:left'); - $objWriter->writeAttribute('w:val', 'single'); - $objWriter->writeAttribute('w:sz', $brdSz[1]); - $objWriter->writeAttribute('w:color', $brdCol[1]); - $objWriter->endElement(); - } - if ($bRight) { - $objWriter->startElement('w:right'); - $objWriter->writeAttribute('w:val', 'single'); - $objWriter->writeAttribute('w:sz', $brdSz[2]); - $objWriter->writeAttribute('w:color', $brdCol[2]); - $objWriter->endElement(); - } - if ($bBottom) { - $objWriter->startElement('w:bottom'); - $objWriter->writeAttribute('w:val', 'single'); - $objWriter->writeAttribute('w:sz', $brdSz[3]); - $objWriter->writeAttribute('w:color', $brdCol[3]); - $objWriter->endElement(); - } - $objWriter->endElement(); - - $objWriter->endElement(); - - $objWriter->endElement(); - } - - - private function _writeDocDefaults(PHPWord_Shared_XMLWriter $objWriter = null) - { - $fontName = $this->_document->getDefaultFontName(); - $fontSize = $this->_document->getDefaultFontSize(); - - $objWriter->startElement('w:docDefaults'); - $objWriter->startElement('w:rPrDefault'); - $objWriter->startElement('w:rPr'); - - $objWriter->startElement('w:rFonts'); - $objWriter->writeAttribute('w:ascii', $fontName); - $objWriter->writeAttribute('w:hAnsi', $fontName); - $objWriter->writeAttribute('w:eastAsia', $fontName); - $objWriter->writeAttribute('w:cs', $fontName); - $objWriter->endElement(); - - $objWriter->startElement('w:sz'); - $objWriter->writeAttribute('w:val', $fontSize * 2); - $objWriter->endElement(); - - $objWriter->startElement('w:szCs'); - $objWriter->writeAttribute('w:val', $fontSize * 2); - $objWriter->endElement(); - - $objWriter->endElement(); - $objWriter->endElement(); - $objWriter->endElement(); - } -} diff --git a/README.md b/README.md index d35603d048..9b11d116af 100755 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ -# PHPWord +# PhpWord -[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.png?branch=master)](https://travis-ci.org/PHPOffice/PHPWord) +[![Build Status](https://travis-ci.org/PhpOffice/PhpWord.png?branch=master)](https://travis-ci.org/PhpOffice/PhpWord) [![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword) [![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword) [![Latest Unstable Version](https://poser.pugx.org/phpoffice/phpword/v/unstable.png)](https://packagist.org/packages/phpoffice/phpword) [![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword) __OpenXML - Read, Write and Create Word documents in PHP.__ -PHPWord is a library written in pure PHP and providing a set of classes that allow you to write to and read from different document file formats, like Word (.docx), WordPad (.rtf), Libre/OpenOffice Writer (.odt). +PhpWord is a library written in pure PHP and providing a set of classes that allow you to write to and read from different document file formats, like Word (.docx), WordPad (.rtf), Libre/OpenOffice Writer (.odt). No Windows operating system is needed for usage because the resulting DOCX, ODT, or RTF files can be opened by all major [word processing softwares](http://en.wikipedia.org/wiki/List_of_word_processors). -PHPWord is an open source project licensed under [LGPL](license.md). PHPWord is unit tested to make sure that the released versions are stable. +PhpWord is an open source project licensed under [LGPL](license.md). PhpWord is unit tested to make sure that the released versions are stable. __Want to contribute?__ Fork us! @@ -34,7 +34,7 @@ __Want to contribute?__ Fork us! * ... and many more features on progress ## Requirements -* PHP 5.3+ +* PHP 5.3.3+ * PHP [Zip](http://php.net/manual/en/book.zip.php) extension * PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension @@ -45,7 +45,7 @@ __Want to contribute?__ Fork us! ## Installation -It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add +It is recommended that you install the PhpWord library [through composer](http://getcomposer.org/). To do so, add the following lines to your ``composer.json``. ```json @@ -58,7 +58,7 @@ the following lines to your ``composer.json``. ## Documentation -We're reorganizing our documentation. Below are some of the most important things that you needed to get PHPWord creates document for you in no time. +We're reorganizing our documentation. Below are some of the most important things that you needed to get PhpWord creates document for you in no time. ### Table of contents @@ -79,14 +79,14 @@ We're reorganizing our documentation. Below are some of the most important thing #### Basic usage -The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/). +The following is a basic example of the PhpWord library. More examples are provided in the [samples folder](samples/). ```php -$PHPWord = new PHPWord(); +$phpWord = new PhpOffice\PhpWord\PhpWord(); // Every element you want to append to the word document is placed in a section. // To create a basic section: -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); // After creating a section, you can append elements: $section->addText('Hello world!'); @@ -97,13 +97,13 @@ $section->addText('Hello world! I am formatted.', // If you often need the same style again you can create a user defined style // to the word document and give the addText function the name of the style: -$PHPWord->addFontStyle('myOwnStyle', +$phpWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); $section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); // You can also put the appended element to local object like this: -$fontStyle = new PHPWord_Style_Font(); +$fontStyle = new \PhpOffice\PhpWord\Style\Font(); $fontStyle->setBold(true); $fontStyle->setName('Verdana'); $fontStyle->setSize(22); @@ -111,8 +111,8 @@ $myTextElement = $section->addText('Hello World!'); $myTextElement->setFontStyle($fontStyle); // Finally, write the document: -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); -$objWriter->save('helloWorld.docx'); +$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); +$xmlWriter->save('helloWorld.docx'); ``` @@ -120,20 +120,20 @@ $objWriter->save('helloWorld.docx'); The base length unit in Open Office XML is twip. Twip means "TWentieth of an Inch Point", i.e. 1 twip = 1/1440 inch. -You can use PHPWord helper functions to convert inches, centimeters, or points to twips. +You can use PhpWord helper functions to convert inches, centimeters, or points to twips. ```php // Paragraph with 6 points space after -$PHPWord->addParagraphStyle('My Style', array( - 'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(6)) +$phpWord->addParagraphStyle('My Style', array( + 'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6)) ); -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); $sectionStyle = $section->getSettings(); // half inch left margin -$sectionStyle->setMarginLeft(PHPWord_Shared_Font::inchSizeToTwips(.5)); +$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5)); // 2 cm right margin -$sectionStyle->setMarginRight(PHPWord_Shared_Font::centimeterSizeToTwips(2)); +$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2)); ``` @@ -142,7 +142,7 @@ $sectionStyle->setMarginRight(PHPWord_Shared_Font::centimeterSizeToTwips(2)); Every visible element in word is placed inside of a section. To create a section, use the following code: ```php -$section = $PHPWord->createSection($sectionSettings); +$section = $phpWord->createSection($sectionSettings); ``` The `$sectionSettings` is an optional associative array that sets the section. Example: @@ -188,7 +188,7 @@ The following two settings are automatically set by the use of the `orientation` You can change a section page numbering. ```php -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); $section->getSettings()->setPageNumberingStart(1); ``` @@ -271,7 +271,7 @@ $cell->getStyle()->setGridSpan(5); You can add images easily using the following example. ```php -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); $section->addImage('mars.jpg'); ``` 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 a5ac348f67..0000000000 --- a/Tests/PHPWord/Shared/FileTest.php +++ /dev/null @@ -1,57 +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)); - } -} 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/PHPWordTest.php b/Tests/PHPWordTest.php deleted file mode 100644 index 15106af6bb..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 PHPWord_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/PhpWord/AutoloaderTest.php b/Tests/PhpWord/AutoloaderTest.php new file mode 100644 index 0000000000..8c3d50f9eb --- /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' + ); + } +} \ No newline at end of file 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..f6e6ba3c16 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('') ); } -} +} \ No newline at end of file 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..bea725c963 100644 --- a/Tests/PHPWord/Exceptions/ExceptionTest.php +++ b/Tests/PhpWord/Exceptions/ExceptionTest.php @@ -1,5 +1,5 @@ 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'); + } +} \ No newline at end of file diff --git a/Tests/PhpWord/MediaTest.php b/Tests/PhpWord/MediaTest.php new file mode 100644 index 0000000000..179fbc020d --- /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 . "/_files/images/mars_noext_jpg"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars.jpg"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mario.gif"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/firefox.png"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/duke_nukem.bmp"); + $section->addImage(\PHPWORD_TESTS_BASE_DIR . "/_files/images/angela_merkel.tif"); + + $elements = $section->getElements(); + $this->assertEquals(6, count($elements)); + foreach ($elements as $element) { + $this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element); + } + } +} \ No newline at end of file diff --git a/Tests/PhpWord/Reader/Word2007Test.php b/Tests/PhpWord/Reader/Word2007Test.php new file mode 100644 index 0000000000..63f771d2e4 --- /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, '_files', '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, '_files', 'documents') + ); + $file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx'; + $object = IOFactory::load($file); + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object); + } +} \ No newline at end of file diff --git a/Tests/PHPWord/Section/Footer/PreserveTextTest.php b/Tests/PhpWord/Section/Footer/PreserveTextTest.php similarity index 57% rename from Tests/PHPWord/Section/Footer/PreserveTextTest.php rename to Tests/PhpWord/Section/Footer/PreserveTextTest.php index 61f84ee56a..3e355b4200 100644 --- a/Tests/PHPWord/Section/Footer/PreserveTextTest.php +++ b/Tests/PhpWord/Section/Footer/PreserveTextTest.php @@ -1,15 +1,15 @@ 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(), '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() + ); } -} +} \ No newline at end of file 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 10751d0e7e..9b6682e824 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,69 +54,69 @@ 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, '_files', '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(), 'ééé'); } public function testGetElements() { - $oFooter = new PHPWord_Section_Footer(1); + $oFooter = new Footer(1); $this->assertInternalType('array', $oFooter->getElements()); } -} +} \ No newline at end of file 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..c349b42cad 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()); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Section/HeaderTest.php b/Tests/PhpWord/Section/HeaderTest.php similarity index 59% rename from Tests/PHPWord/Section/HeaderTest.php rename to Tests/PhpWord/Section/HeaderTest.php index 527ad3ee4c..270fd71cea 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, '_files', '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(), 'ééé'); } @@ -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, '_files', '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); } -} +} \ No newline at end of file diff --git a/Tests/PhpWord/Section/ImageTest.php b/Tests/PhpWord/Section/ImageTest.php new file mode 100644 index 0000000000..d341a8ed1a --- /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, '_files', '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 . "/_files/images/mars_noext_jpg"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mars.jpg"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/mario.gif"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/firefox.png"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/duke_nukem.bmp"); + new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/angela_merkel.tif"); + } + + /** + * @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException + * @covers ::__construct + */ + public function testImageNotFound() + { + new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/thisisnotarealimage"); + } + + /** + * @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException + * @covers ::__construct + */ + public function testInvalidImageTypes() + { + new Image(\PHPWORD_TESTS_BASE_DIR . "/_files/images/alexz-johnson.pcx"); + } + + public function testStyle() + { + $oImage = new Image(\join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, '_files', '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, '_files', '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, '_files', 'images', 'earth.jpg') + )); + + $oImage->setIsWatermark(true); + $this->assertEquals($oImage->getIsWatermark(), true); + } +} \ No newline at end of file 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..b1723abfbb 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,10 +43,10 @@ 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); $this->assertEquals($oLink->getRelationId(), $iVal); } -} +} \ No newline at end of file diff --git a/Tests/PhpWord/Section/ListItemTest.php b/Tests/PhpWord/Section/ListItemTest.php new file mode 100644 index 0000000000..ff65bfb89c --- /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); + } +} \ No newline at end of file diff --git a/Tests/PHPWord/Section/MemoryImageTest.php b/Tests/PhpWord/Section/MemoryImageTest.php similarity index 67% rename from Tests/PHPWord/Section/MemoryImageTest.php rename to Tests/PhpWord/Section/MemoryImageTest.php index 3bfb39e358..4476baddc6 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, '_files', '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, '_files', '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, '_files', '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,23 +72,23 @@ 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, '_files', '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, '_files', 'images', 'earth.jpg') )); $iVal = rand(1, 1000); $oMemoryImage->setRelationId($iVal); $this->assertEquals($oMemoryImage->getRelationId(), $iVal); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Section/ObjectTest.php b/Tests/PhpWord/Section/ObjectTest.php similarity index 57% rename from Tests/PHPWord/Section/ObjectTest.php rename to Tests/PhpWord/Section/ObjectTest.php index b72f2484c8..cae33458ea 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, '_files', '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, '_files', '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, '_files', '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, '_files', 'documents', 'sheet.xls') ); - $oObject = new PHPWord_Section_Object($src); + $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setImageRelationId($iVal); @@ -74,12 +74,12 @@ public function testObjectId() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls') ); - $oObject = new PHPWord_Section_Object($src); + $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setObjectId($iVal); $this->assertEquals($oObject->getObjectId(), $iVal); } -} +} \ No newline at end of file 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..452c378054 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); } -} +} \ No newline at end of file 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..81f22cebf7 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()); @@ -232,4 +232,4 @@ public function testBreakType() $oSettings->setBreakType(); $this->assertNull($oSettings->getBreakType()); } -} +} \ No newline at end of file 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 30a7fcdb7a..a328a2a8e1 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,119 +91,119 @@ public function testAddImageSection() { $src = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg') + array(\PHPWORD_TESTS_BASE_DIR, '_files', '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, '_files', '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, '_files', '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, '_files', '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(), 'ééé'); } 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()); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Section/Table/RowTest.php b/Tests/PhpWord/Section/Table/RowTest.php similarity index 59% rename from Tests/PHPWord/Section/Table/RowTest.php rename to Tests/PhpWord/Section/Table/RowTest.php index e62a5bd926..e91ea3887e 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()); } -} +} \ No newline at end of file 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..9ab1cfb22c 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); } -} +} \ No newline at end of file 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..ceb0ea94d4 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,8 +52,8 @@ 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()); } -} +} \ No newline at end of file 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..a5579cded3 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, '_files', '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()); } -} +} \ No newline at end of file diff --git a/Tests/PhpWord/Section/TextTest.php b/Tests/PhpWord/Section/TextTest.php new file mode 100644 index 0000000000..a2f259bcc1 --- /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()); + } +} \ No newline at end of file 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..ac47dd301f 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,10 +38,10 @@ public function testAnchor() public function testBookmarkID() { - $oTitle = new PHPWord_Section_Title('text'); + $oTitle = new Title('text'); $iVal = rand(1, 1000); $oTitle->setBookmarkId($iVal); $this->assertEquals($oTitle->getBookmarkId(), $iVal); } -} +} \ No newline at end of file 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..55d649e1f8 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, '_files', 'documents', 'sheet.xls') ); $imageSource = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png') + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_BASE_DIR, '_files', '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()); } } -} +} \ No newline at end of file diff --git a/Tests/PhpWord/SettingsTest.php b/Tests/PhpWord/SettingsTest.php new file mode 100644 index 0000000000..bd33cb61f3 --- /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')); + } +} \ No newline at end of file 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..5c7001ed47 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,8 +56,8 @@ 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); } } -} +} \ No newline at end of file diff --git a/Tests/PhpWord/Shared/FileTest.php b/Tests/PhpWord/Shared/FileTest.php new file mode 100644 index 0000000000..579f266200 --- /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, '_files', 'templates')); + chdir($dir); + $this->assertFalse(File::file_exists('404.docx')); + } + + /** + * Test realpath() + */ + public function testRealpath() + { + $dir = join(\DIRECTORY_SEPARATOR, array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates')); + chdir($dir); + $file = 'blank.docx'; + $expected = $dir . \DIRECTORY_SEPARATOR . $file; + $this->assertEquals($expected, File::realpath($file)); + } +} \ No newline at end of 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..1ba4831024 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); } -} +} \ No newline at end of file diff --git a/Tests/PhpWord/Shared/StringTest.php b/Tests/PhpWord/Shared/StringTest.php new file mode 100644 index 0000000000..9da8502d1f --- /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))); + } +} \ No newline at end of file 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..ee79ec3b56 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,11 +63,11 @@ public function testBorderColor() */ public function testBorderSize() { - $object = new PHPWord_Style_Cell(); + $object = new Cell(); $value = 120; $expected = array($value, $value, $value, $value); $object->setStyleValue('_borderSize', $value); $this->assertEquals($expected, $object->getBorderSize()); } -} +} \ No newline at end of file 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..5bef23b19b 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'); @@ -113,4 +110,4 @@ public function testLineHeight() $this->assertEquals(720, $lineHeight); $this->assertEquals('auto', $lineRule); } -} +} \ No newline at end of file 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..3b8cd96f7b 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'); } -} +} \ No newline at end of file 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..5c7a3332ce 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,10 +36,10 @@ 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()); } -} +} \ No newline at end of file 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..05eabbb357 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,8 +122,8 @@ public function testLineHeight() */ public function testLineHeightValidation() { - $object = new PHPWord_Style_Paragraph(); + $object = new Paragraph(); $object->setLineHeight('12.5pt'); $this->assertEquals(12.5, $object->getLineHeight()); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Style/RowTest.php b/Tests/PhpWord/Style/RowTest.php similarity index 84% rename from Tests/PHPWord/Style/RowTest.php rename to Tests/PhpWord/Style/RowTest.php index cbbecfbc09..b83f2e5ff8 100644 --- a/Tests/PHPWord/Style/RowTest.php +++ b/Tests/PhpWord/Style/RowTest.php @@ -1,12 +1,9 @@ true, @@ -37,4 +34,4 @@ public function testProperties() $this->assertEquals($expected, $object->$get()); } } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Style/TOCTest.php b/Tests/PhpWord/Style/TOCTest.php similarity index 67% rename from Tests/PHPWord/Style/TOCTest.php rename to Tests/PhpWord/Style/TOCTest.php index 4607ba37aa..6f2520738f 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 @@ -36,4 +33,4 @@ public function testProperties() $this->assertEquals(null, $object->$get()); } } -} +} \ No newline at end of file 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..e84191e08e 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; @@ -130,4 +127,4 @@ public function testCellMargin() } $this->assertEquals($values, $object->getCellMargin()); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Style/TableTest.php b/Tests/PhpWord/Style/TableTest.php similarity index 85% rename from Tests/PHPWord/Style/TableTest.php rename to Tests/PhpWord/Style/TableTest.php index 439aa5ae8b..c9ea73018f 100644 --- a/Tests/PHPWord/Style/TableTest.php +++ b/Tests/PhpWord/Style/TableTest.php @@ -1,12 +1,9 @@ assertEquals($values, $object->getCellMargin()); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Style/TabsTest.php b/Tests/PhpWord/Style/TabsTest.php similarity index 62% rename from Tests/PHPWord/Style/TabsTest.php rename to Tests/PhpWord/Style/TabsTest.php index 7579ae6de0..dcecdf938d 100644 --- a/Tests/PHPWord/Style/TabsTest.php +++ b/Tests/PhpWord/Style/TabsTest.php @@ -1,15 +1,11 @@ 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); @@ -41,4 +33,4 @@ public function testTabsStyle() $this->assertEquals(1440, $element->getAttribute('w:pos')); $this->assertEquals('dot', $element->getAttribute('w:leader')); } -} +} \ No newline at end of file diff --git a/Tests/PhpWord/StyleTest.php b/Tests/PhpWord/StyleTest.php new file mode 100644 index 0000000000..bd24188fb3 --- /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')); + } +} \ No newline at end of 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..7007e03b41 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,20 +49,20 @@ 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']); $i++; } } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/TemplateTest.php b/Tests/PhpWord/TemplateTest.php similarity index 79% rename from Tests/PHPWord/TemplateTest.php rename to Tests/PhpWord/TemplateTest.php index 872ab182e4..ebb0c6659b 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, '_files', '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, '_files', '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, '_files', '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, '_files', '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, '_files', 'templates', 'corrupted_main_document_part.docx') ) ); @@ -134,12 +134,12 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromT $xslDOMDocument->load( \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl') + array(\PHPWORD_TESTS_BASE_DIR, '_files', '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); @@ -155,13 +155,13 @@ public function testCloneRow() { $template = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-row.docx') + array(\PHPWORD_TESTS_BASE_DIR, '_files', 'templates', 'clone-row.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..64f224ca88 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, '_files', 'images', 'PhpWord.png') ); $objectSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, '_files', '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,9 +53,9 @@ 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); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Writer/ODTextTest.php b/Tests/PhpWord/Writer/ODTextTest.php similarity index 54% rename from Tests/PHPWord/Writer/ODTextTest.php rename to Tests/PhpWord/Writer/ODTextTest.php index ef92d249fd..631360d8b4 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, '_files', 'images', 'PhpWord.png') ); $objectSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls') ); $file = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt') + array(\PHPWORD_TESTS_BASE_DIR, '_files', '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,62 +89,62 @@ public function testSave() } /** - * @covers ::save - * @todo Haven't got any method to test this + * @covers ::save + * @todo Haven't got any method to test this */ public function testSavePhpOutput() { - $phpWord = new PHPWord(); + $phpWord = new PhpWord(); $section = $phpWord->createSection(); $section->addText('Test'); - $writer = new PHPWord_Writer_ODText($phpWord); + $writer = new ODText($phpWord); $writer->save('php://output'); } /** - * @covers ::save - * @expectedException Exception - * @expectedExceptionMessage PHPWord object unassigned. + * @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); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Writer/RTFTest.php b/Tests/PhpWord/Writer/RTFTest.php similarity index 55% rename from Tests/PHPWord/Writer/RTFTest.php rename to Tests/PhpWord/Writer/RTFTest.php index d071def78f..656f6d4710 100644 --- a/Tests/PHPWord/Writer/RTFTest.php +++ b/Tests/PhpWord/Writer/RTFTest.php @@ -1,84 +1,81 @@ assertInstanceOf('PHPWord', $object->getPHPWord()); - $this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object->getPhpWord()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\HashTable', $object->getDrawingHashTable()); } /** - * covers ::__construct - * @expectedException Exception - * @expectedExceptionMessage No PHPWord assigned. + * covers ::__construct + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage No PhpWord assigned. */ public function testConstructWithNull() { - $object = new PHPWord_Writer_RTF(); - $object->getPHPWord(); + $object = new RTF(); + $object->getPhpWord(); } /** - * @covers ::save - * @todo Haven't got any method to test this + * @covers ::save + * @todo Haven't got any method to test this */ public function testSavePhpOutput() { - $phpWord = new PHPWord(); + $phpWord = new PhpWord(); $section = $phpWord->createSection(); $section->addText('Test'); - $writer = new PHPWord_Writer_RTF($phpWord); + $writer = new RTF($phpWord); $writer->save('php://output'); } /** - * @covers ::save - * @expectedException Exception - * @expectedExceptionMessage PHPWord object unassigned. + * @covers ::save + * @expectedException \PhpOffice\PhpWord\Exceptions\Exception + * @expectedExceptionMessage PhpWord object unassigned. */ public function testSaveException() { - $writer = new PHPWord_Writer_RTF(); + $writer = new RTF(); $writer->save(); } /** - * @covers ::save - * @covers :: + * @covers ::save + * @covers :: */ public function testSave() { $imageSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png') + array(\PHPWORD_TESTS_BASE_DIR, '_files', 'images', 'PhpWord.png') ); $objectSrc = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls') + array(\PHPWORD_TESTS_BASE_DIR, '_files', 'documents', 'sheet.xls') ); $file = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf') + array(\PHPWORD_TESTS_BASE_DIR, '_files', 'temp.rtf') ); - $phpWord = new PHPWord(); + $phpWord = new PhpWord(); $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->createSection(); @@ -97,11 +94,11 @@ public function testSave() $textrun = $section->createTextRun(); $textrun->addText('Test 3'); $textrun->addTextBreak(); - $writer = new PHPWord_Writer_RTF($phpWord); + $writer = new RTF($phpWord); $writer->save($file); $this->assertTrue(file_exists($file)); unlink($file); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Writer/Word2007/BaseTest.php b/Tests/PhpWord/Writer/Word2007/BaseTest.php similarity index 75% rename from Tests/PHPWord/Writer/Word2007/BaseTest.php rename to Tests/PhpWord/Writer/Word2007/BaseTest.php index fde6e30b20..ea44e9f19f 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, '_files', '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,7 +243,7 @@ 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')); @@ -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 . '/_files/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,38 +315,38 @@ 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, '_files', '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')); $element = "/w:document/w:body/w:p/w:r/w:fldChar"; $this->assertEquals('end', $doc->getElementAttribute($element, 'w:fldCharType')); } -} +} \ No newline at end of file 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 fe854feebe..e3eb847053 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, '_files', '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 65% rename from Tests/PHPWord/Writer/Word2007/FootnotesTest.php rename to Tests/PhpWord/Writer/Word2007/FootnotesTest.php index ea49bd6726..3913ff2c62 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")); } -} +} \ No newline at end of file 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..5de21c7d52 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'; @@ -68,4 +66,4 @@ public function testWriteStyles() $element = $doc->getElement($path, $file); $this->assertEquals('Normal', $element->getAttribute('w:val')); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Writer/Word2007Test.php b/Tests/PhpWord/Writer/Word2007Test.php similarity index 61% rename from Tests/PHPWord/Writer/Word2007Test.php rename to Tests/PhpWord/Writer/Word2007Test.php index 95abee8363..9bdf74a286 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, '_files', 'temp.docx') ); $writer->save($file); $this->assertTrue(file_exists($file)); @@ -68,7 +74,7 @@ public function testSave() } /** - * @covers ::checkContentTypes + * @covers ::checkContentTypes */ public function testCheckContentTypes() { @@ -80,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 . "/_files/images/{$source}"); } $doc = TestHelperDOCX::getDocument($phpWord); @@ -91,36 +97,36 @@ public function testCheckContentTypes() foreach ($images as $source => $target) { $this->assertFileEquals( - PHPWORD_TESTS_DIR_ROOT . "/_files/images/{$source}", + \PHPWORD_TESTS_BASE_DIR . "/_files/images/{$source}", $mediaPath . "/section_image{$target}" ); } } /** - * @covers ::setUseDiskCaching - * @covers ::getUseDiskCaching + * @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()); } /** - * @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); } -} +} \ No newline at end of file diff --git a/Tests/PhpWordTest.php b/Tests/PhpWordTest.php new file mode 100644 index 0000000000..cc51755f27 --- /dev/null +++ b/Tests/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, '_files', '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, '_files', 'templates', 'blanks.docx') + ); + $phpWord = new PhpWord(); + $phpWord->loadTemplate($templateFqfn); + } +} \ No newline at end of file diff --git a/Tests/_files/images/PHPWord.png b/Tests/_files/images/PhpWord.png similarity index 100% rename from Tests/_files/images/PHPWord.png rename to Tests/_files/images/PhpWord.png diff --git a/Tests/_inc/TestHelperDOCX.php b/Tests/_inc/TestHelperDOCX.php index dec1f0776f..bd3d4f8caf 100644 --- a/Tests/_inc/TestHelperDOCX.php +++ b/Tests/_inc/TestHelperDOCX.php @@ -1,7 +1,8 @@ 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() @@ -37,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/'); } } diff --git a/Tests/_inc/XmlDocument.php b/Tests/_inc/XmlDocument.php index 4d3d00347d..c6b1e83e20 100644 --- a/Tests/_inc/XmlDocument.php +++ b/Tests/_inc/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; } @@ -112,4 +110,4 @@ public function elementExists($path, $file = 'word/document.xml') $nodeList = $this->getNodeList($path, $file); return !($nodeList->length == 0); } -} +} \ No newline at end of file diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 1066a0d42c..dd261c3b77 100755 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,15 +1,14 @@ =5.3.0", + "php": ">=5.3.3", "ext-xml": "*", "ext-zip": "*" }, @@ -35,8 +39,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/index.rst b/docs/index.rst index a419d14dda..ac51d2fd64 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,9 +1,9 @@ -.. PHPWord documentation master file, created by +.. PhpWord documentation master file, created by sphinx-quickstart on Fri Mar 14 23:09:26 2014. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -Welcome to PHPWord's documentation! +Welcome to PhpWord's documentation! =================================== Contents: diff --git a/docs/intro.rst b/docs/intro.rst index 37bc01c1ad..d7cc648a4e 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -3,15 +3,15 @@ Introduction ============ -PHPWord is a library written in pure PHP and providing a set of classes that allow you to write to and read from different document file formats, like Word (.docx), WordPad (.rtf), Libre/OpenOffice Writer (.odt). +PhpWord is a library written in pure PHP and providing a set of classes that allow you to write to and read from different document file formats, like Word (.docx), WordPad (.rtf), Libre/OpenOffice Writer (.odt). No Windows operating system is needed for usage because the resulting DOCX, ODT, or RTF files can be opened by all major word processing softwares. -PHPWord is an open source project licensed under LGPL. PHPWord is unit tested to make sure that the released versions are stable. +PhpWord is an open source project licensed under LGPL. PhpWord is unit tested to make sure that the released versions are stable. Supported features ------------------ -Currently PHPWord can: +Currently PhpWord can: * Set document properties, e.g. title, subject, and creator. * Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering diff --git a/docs/setup.rst b/docs/setup.rst index 5557e27bba..cedc003577 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -3,7 +3,7 @@ Installation ============ -It is recommended that you install the PHPWord library through composer. To do so, add the following lines to your composer.json. +It is recommended that you install the PhpWord library through composer. To do so, add the following lines to your composer.json. .. code-block:: json { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 908304adea..8394be21ab 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,13 +9,13 @@ stopOnFailure="false" syntaxCheck="false"> - - ./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 10f129dbfa..a2fe9e9b3b 100755 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -1,21 +1,21 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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 @@ -51,12 +51,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; \ No newline at end of file diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php index e9e2d84bcb..24f47678f8 100755 --- a/samples/Sample_02_TabStops.php +++ b/samples/Sample_02_TabStops.php @@ -1,34 +1,34 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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'); @@ -39,12 +39,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php index 1e49629e9c..e3c1057c41 100755 --- a/samples/Sample_03_Sections.php +++ b/samples/Sample_03_Sections.php @@ -1,29 +1,29 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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'); @@ -32,12 +32,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index b30db7a56f..0d984dfe2b 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -1,22 +1,21 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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'); @@ -39,12 +38,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php index 3877defeff..2b630d2727 100644 --- a/samples/Sample_05_Multicolumn.php +++ b/samples/Sample_05_Multicolumn.php @@ -1,53 +1,53 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php index daaa6b4636..fd495afbf5 100755 --- a/samples/Sample_06_Footnote.php +++ b/samples/Sample_06_Footnote.php @@ -1,21 +1,21 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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'); @@ -40,12 +40,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php index f797b986e5..3dc92a06a3 100755 --- a/samples/Sample_07_TemplateCloneRow.php +++ b/samples/Sample_07_TemplateCloneRow.php @@ -1,14 +1,14 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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); @@ -57,10 +57,10 @@ $document->setValue('userPhone#3', '+1 428 889 775'); $name = 'Sample_07_TemplateCloneRow_result.docx'; -echo date('H:i:s'), " Write to Word2007 format", EOL; +echo date('H:i:s'), " Write to Word2007 format", \EOL; $document->saveAs($name); rename($name, "results/{$name}"); // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php index edd1992c43..e0d646cd2f 100644 --- a/samples/Sample_08_ParagraphPagination.php +++ b/samples/Sample_08_ParagraphPagination.php @@ -1,20 +1,20 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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 ' . @@ -52,12 +52,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php index 96e411a020..a43b98d81f 100644 --- a/samples/Sample_09_Tables.php +++ b/samples/Sample_09_Tables.php @@ -1,13 +1,13 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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 @@ -32,9 +32,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); @@ -64,7 +64,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); @@ -80,12 +80,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php index 8be721091c..6770d1ff6f 100644 --- a/samples/Sample_10_EastAsianFontStyle.php +++ b/samples/Sample_10_EastAsianFontStyle.php @@ -1,13 +1,13 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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')); @@ -16,12 +16,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_11_ReadWord2007.php b/samples/Sample_11_ReadWord2007.php index d96e92644c..980b1d4f3e 100644 --- a/samples/Sample_11_ReadWord2007.php +++ b/samples/Sample_11_ReadWord2007.php @@ -1,24 +1,24 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // Read contents $name = basename(__FILE__, '.php'); $source = "resources/{$name}.docx"; -echo date('H:i:s'), " Reading contents from `{$source}`", EOL; -$PHPWord = PHPWord_IOFactory::load($source); +echo date('H:i:s'), " Reading contents from `{$source}`", \EOL; +$phpWord = \PhpOffice\PhpWord\IOFactory::load($source); // (Re)write contents $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf'); foreach ($writers as $writer => $extension) { - echo date('H:i:s'), " Write to {$writer} format", EOL; - $objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer); - $objWriter->save("{$name}.{$extension}"); + echo date('H:i:s'), " Write to {$writer} format", \EOL; + $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer); + $xmlWriter->save("{$name}.{$extension}"); rename("{$name}.{$extension}", "results/{$name}.{$extension}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php index b0d0e13792..dd1b24d94b 100644 --- a/samples/Sample_12_HeaderFooter.php +++ b/samples/Sample_12_HeaderFooter.php @@ -1,15 +1,15 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.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(); @@ -18,7 +18,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') ); @@ -49,7 +49,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!"); @@ -63,12 +63,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php index 0f64cb7bb8..e64f638639 100644 --- a/samples/Sample_13_Images.php +++ b/samples/Sample_13_Images.php @@ -4,16 +4,16 @@ */ // Init -error_reporting(E_ALL); -define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); +echo date('H:i:s'), " Create new PhpWord object", \EOL; +$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); $section->addText('Local image without any styles:'); $section->addImage('resources/_mars.jpg'); $section->addTextBreak(2); @@ -31,12 +31,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php index fa64878407..7b23fb05ed 100644 --- a/samples/Sample_14_ListItem.php +++ b/samples/Sample_14_ListItem.php @@ -4,16 +4,16 @@ */ // Init -error_reporting(E_ALL); -define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); +echo date('H:i:s'), " Create new PhpWord object", \EOL; +$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); // Add listitem elements $section->addListItem('List Item 1', 0); @@ -31,16 +31,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'); @@ -55,12 +55,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php index ef631906d9..34519e8b86 100644 --- a/samples/Sample_15_Link.php +++ b/samples/Sample_15_Link.php @@ -4,22 +4,22 @@ */ // Init -error_reporting(E_ALL); -define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); +echo date('H:i:s'), " Create new PhpWord object", \EOL; +$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); // Add hyperlink elements -$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE)); +$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)); $section->addTextBreak(2); -$PHPWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000')); +$phpWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000')); $section->addLink('http://www.bing.com', null, 'myOwnLinkStyle'); $section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle'); @@ -29,12 +29,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php index e04c49e54d..1d2a51cb24 100644 --- a/samples/Sample_16_Object.php +++ b/samples/Sample_16_Object.php @@ -4,16 +4,16 @@ */ // Init -error_reporting(E_ALL); -define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '
'); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); +echo date('H:i:s'), " Create new PhpWord object", \EOL; +$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); $section->addText('You can open this OLE object by double clicking on the icon:'); $section->addTextBreak(2); $section->addObject('resources/_sheet.xls'); @@ -24,12 +24,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php index efa756e4df..7cc89e14fe 100644 --- a/samples/Sample_17_TitleTOC.php +++ b/samples/Sample_17_TitleTOC.php @@ -1,26 +1,26 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); +echo date('H:i:s'), " Create new PhpWord object", \EOL; +$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); // Define the TOC font style $fontStyle = array('spaceAfter'=>60, 'size'=>12); // Add title styles -$PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true)); -$PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666')); +$phpWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true)); +$phpWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666')); // Add text elements $section->addText('Table of contents:'); @@ -49,19 +49,19 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php index 8332bd0330..60f735da39 100644 --- a/samples/Sample_18_Watermark.php +++ b/samples/Sample_18_Watermark.php @@ -1,20 +1,20 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); +echo date('H:i:s'), " Create new PhpWord object", \EOL; +$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); $header = $section->createHeader(); $header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); $section->addText('The header reference to the current section includes a watermark image.'); @@ -25,12 +25,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php index 17299601c6..7fffed6d3d 100644 --- a/samples/Sample_19_TextBreak.php +++ b/samples/Sample_19_TextBreak.php @@ -1,25 +1,25 @@ '); -require_once '../Classes/PHPWord.php'; +error_reporting(\E_ALL); +define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '
'); +require_once '../src/PhpWord.php'; // New Word document -echo date('H:i:s'), " Create new PHPWord object", EOL; -$PHPWord = new PHPWord(); +echo date('H:i:s'), " Create new PhpWord object", \EOL; +$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code $fontStyle = array('size' => 24); $paragraphStyle = array('spacing' => 240, 'size' => 24); -$PHPWord->addFontStyle('fontStyle', array('size' => 9)); -$PHPWord->addParagraphStyle('paragraphStyle', array('spacing' => 480)); +$phpWord->addFontStyle('fontStyle', array('size' => 9)); +$phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480)); $fontStyle = array('size' => 24); -$section = $PHPWord->createSection(); +$section = $phpWord->createSection(); $section->addText('Text break with no style:'); $section->addTextBreak(); $section->addText('Text break with defined font style:'); @@ -38,12 +38,12 @@ $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}"); } // Done -echo date('H:i:s'), " Done writing file(s)", EOL; -echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL; +echo date('H:i:s'), " Done writing file(s)", \EOL; +echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL; diff --git a/samples/resources/PHPWord.png b/samples/resources/PhpWord.png similarity index 100% rename from samples/resources/PHPWord.png rename to samples/resources/PhpWord.png diff --git a/src/Autoloader.php b/src/Autoloader.php new file mode 100644 index 0000000000..cc82d23640 --- /dev/null +++ b/src/Autoloader.php @@ -0,0 +1,62 @@ +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() { @@ -220,4 +203,4 @@ public function __clone() } } } -} +} \ No newline at end of file diff --git a/src/IOFactory.php b/src/IOFactory.php new file mode 100644 index 0000000000..ffe825a09d --- /dev/null +++ b/src/IOFactory.php @@ -0,0 +1,77 @@ +load($filename); + } +} \ No newline at end of file diff --git a/Classes/PHPWord/Media.php b/src/Media.php old mode 100755 new mode 100644 similarity index 88% rename from Classes/PHPWord/Media.php rename to src/Media.php index 0332818460..f7954df3d3 --- a/Classes/PHPWord/Media.php +++ b/src/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,7 +91,7 @@ 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) { @@ -102,15 +101,15 @@ public static function addSectionMediaElement($src, $type, PHPWord_Section_Memor $media['imagefunction'] = $memoryImage->getImageFunction(); } else { $imageType = exif_imagetype($src); - if ($imageType === IMAGETYPE_JPEG) { + if ($imageType === \IMAGETYPE_JPEG) { $extension = 'jpg'; - } elseif ($imageType === IMAGETYPE_GIF) { + } elseif ($imageType === \IMAGETYPE_GIF) { $extension = 'gif'; - } elseif ($imageType === IMAGETYPE_PNG) { + } elseif ($imageType === \IMAGETYPE_PNG) { $extension = 'png'; - } elseif ($imageType === IMAGETYPE_BMP) { + } elseif ($imageType === \IMAGETYPE_BMP) { $extension = 'bmp'; - } elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) { + } elseif ($imageType === \IMAGETYPE_TIFF_II || $imageType === \IMAGETYPE_TIFF_MM) { $extension = 'tif'; } } @@ -203,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; @@ -275,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.php b/src/PhpWord.php new file mode 100644 index 0000000000..c2adbe874c --- /dev/null +++ b/src/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."); + } + } +} \ No newline at end of file diff --git a/Classes/PHPWord/Reader/Abstract.php b/src/Reader/AbstractReader.php similarity index 85% rename from Classes/PHPWord/Reader/Abstract.php rename to src/Reader/AbstractReader.php index ba7f6565c1..0d68e3138f 100644 --- a/Classes/PHPWord/Reader/Abstract.php +++ b/src/Reader/AbstractReader.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 diff --git a/Classes/PHPWord/Section.php b/src/Section.php old mode 100755 new mode 100644 similarity index 68% rename from Classes/PHPWord/Section.php rename to src/Section.php index a9402dab72..7fabb0b901 --- a/Classes/PHPWord/Section.php +++ b/src/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,12 +436,12 @@ 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; diff --git a/Classes/PHPWord/Section/Footer.php b/src/Section/Footer.php old mode 100755 new mode 100644 similarity index 73% rename from Classes/PHPWord/Section/Footer.php rename to src/Section/Footer.php index 238bae1b07..085bcd0769 --- a/Classes/PHPWord/Section/Footer.php +++ b/src/Section/Footer.php @@ -1,8 +1,8 @@ _elementCollection[] = $text; return $text; } @@ -81,25 +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 * - * @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; } @@ -108,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; } @@ -122,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; @@ -144,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; @@ -166,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/Section/Footer/PreserveText.php old mode 100755 new mode 100644 similarity index 80% rename from Classes/PHPWord/Section/Footer/PreserveText.php rename to src/Section/Footer/PreserveText.php index 7244374386..635af9f21d --- a/Classes/PHPWord/Section/Footer/PreserveText.php +++ b/src/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) != '_') { @@ -77,7 +76,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) != '_') { @@ -89,7 +88,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[0]; } @@ -100,7 +99,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() { @@ -110,7 +109,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/Section/Footnote.php similarity index 81% rename from Classes/PHPWord/Section/Footnote.php rename to src/Section/Footnote.php index 652a3873f3..2a9eacaf31 100644 --- a/Classes/PHPWord/Section/Footnote.php +++ b/src/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,12 +78,12 @@ public function __construct($styleParagraph = null) * * @var string $text * @var mixed $styleFont - * @return PHPWord_Section_Text + * @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; } @@ -96,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; @@ -120,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/Section/Header.php old mode 100755 new mode 100644 similarity index 75% rename from Classes/PHPWord/Section/Header.php rename to src/Section/Header.php index 5e1c6bfe73..d9d3eed1ed --- a/Classes/PHPWord/Section/Header.php +++ b/src/Section/Header.php @@ -1,8 +1,8 @@ _elementCollection[] = $text; return $text; } @@ -110,25 +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 * - * @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; } @@ -137,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; } @@ -151,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; @@ -173,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; @@ -195,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; } @@ -212,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; @@ -276,7 +277,7 @@ public function getType() */ public function resetType() { - return $this->_type = PHPWord_Section_Header::AUTO; + return $this->_type = self::AUTO; } /** @@ -284,7 +285,7 @@ public function resetType() */ public function firstPage() { - return $this->_type = PHPWord_Section_Header::FIRST; + return $this->_type = self::FIRST; } /** @@ -292,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/Section/Image.php old mode 100755 new mode 100644 similarity index 86% rename from Classes/PHPWord/Section/Image.php rename to src/Section/Image.php index fcaa1cc9ab..2c04125396 --- a/Classes/PHPWord/Section/Image.php +++ b/src/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) { @@ -109,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/Section/Link.php old mode 100755 new mode 100644 similarity index 86% rename from Classes/PHPWord/Section/Link.php rename to src/Section/Link.php index 620b08a1bf..c3c14466d6 --- a/Classes/PHPWord/Section/Link.php +++ b/src/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/Section/ListItem.php old mode 100755 new mode 100644 similarity index 83% rename from Classes/PHPWord/Section/ListItem.php rename to src/Section/ListItem.php index 83384a9490..7760e87dbd --- a/Classes/PHPWord/Section/ListItem.php +++ b/src/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/Section/MemoryImage.php old mode 100755 new mode 100644 similarity index 93% rename from Classes/PHPWord/Section/MemoryImage.php rename to src/Section/MemoryImage.php index 9d4ed97c0e..62de8317ae --- a/Classes/PHPWord/Section/MemoryImage.php +++ b/src/Section/MemoryImage.php @@ -1,8 +1,8 @@ _imageType, $_supportedImageTypes)) { $this->_src = $src; - $this->_style = new PHPWord_Style_Image(); + $this->_style = new Image(); if (!is_null($style) && is_array($style)) { foreach ($style as $key => $value) { @@ -143,7 +142,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/Section/Object.php old mode 100755 new mode 100644 similarity index 91% rename from Classes/PHPWord/Section/Object.php rename to src/Section/Object.php index 33d8cad9bc..a7cbdfc187 --- a/Classes/PHPWord/Section/Object.php +++ b/src/Section/Object.php @@ -1,8 +1,8 @@ _src = $src; - $this->_style = new PHPWord_Style_Image(); + $this->_style = new Image(); if (!is_null($style) && is_array($style)) { foreach ($style as $key => $value) { @@ -100,7 +98,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/Section/PageBreak.php old mode 100755 new mode 100644 similarity index 77% rename from Classes/PHPWord/Section/PageBreak.php rename to src/Section/PageBreak.php index 76536304cb..a164b32853 --- a/Classes/PHPWord/Section/PageBreak.php +++ b/src/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) != '_') { @@ -102,7 +100,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; } @@ -112,7 +110,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) { @@ -134,7 +132,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/Section/Table/Cell.php old mode 100755 new mode 100644 similarity index 71% rename from Classes/PHPWord/Section/Table/Cell.php rename to src/Section/Table/Cell.php index f8d6d3400b..21ae054fff --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/src/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)) { @@ -101,14 +110,14 @@ public function __construct($insideOf, $pCount, $width = null, $style = null) * * @param string $text * @param mixed $style - * @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; } @@ -119,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; @@ -148,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); } } @@ -166,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; } @@ -183,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); @@ -211,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); @@ -238,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); @@ -251,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]; @@ -280,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 { @@ -299,11 +308,11 @@ public function addPreserveText($text, $styleFont = null, $styleParagraph = null /** * Create a new TextRun * - * @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; } @@ -321,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/Section/Table/Row.php similarity index 85% rename from Classes/PHPWord/Section/Table/Row.php rename to src/Section/Table/Row.php index dd8ea65c12..b9092295b3 100644 --- a/Classes/PHPWord/Section/Table/Row.php +++ b/src/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/Section/Text.php old mode 100755 new mode 100644 similarity index 71% rename from Classes/PHPWord/Section/Text.php rename to src/Section/Text.php index 8631b66e1a..50dfdc8930 --- a/Classes/PHPWord/Section/Text.php +++ b/src/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/Section/TextBreak.php old mode 100755 new mode 100644 similarity index 73% rename from Classes/PHPWord/Section/TextBreak.php rename to src/Section/TextBreak.php index 85f53edc9d..938f66c2a5 --- a/Classes/PHPWord/Section/TextBreak.php +++ b/src/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; @@ -82,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() { @@ -92,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; @@ -111,10 +111,10 @@ public function setParagraphStyle($style = null) /** * Get Paragraph style * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->paragraphStyle; } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Section/TextRun.php b/src/Section/TextRun.php old mode 100755 new mode 100644 similarity index 72% rename from Classes/PHPWord/Section/TextRun.php rename to src/Section/TextRun.php index fcb2bd482b..0911b5dc61 --- a/Classes/PHPWord/Section/TextRun.php +++ b/src/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,14 +75,14 @@ public function __construct($styleParagraph = null) * * @var string $text * @var mixed $styleFont - * @return PHPWord_Section_Text + * @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; } @@ -92,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) { @@ -101,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; @@ -114,14 +115,14 @@ public function addLink($linkSrc, $linkName = null, $styleFont = null) * * @param string $imageSrc * @param mixed $styleFont - * @return PHPWord_Section_Image + * @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; @@ -134,14 +135,14 @@ public function addImage($imageSrc, $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); } } @@ -149,12 +150,12 @@ public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = nu * Create a new Footnote Element * * @param string $text - * @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 = \PhpOffice\PhpWord\Footnote::addFootnoteElement($footnote); $footnote->setReferenceId($refID); $this->_elementCollection[] = $footnote; return $footnote; @@ -173,10 +174,10 @@ public function getElements() /** * Get Paragraph style * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { return $this->_styleParagraph; } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Section/Title.php b/src/Section/Title.php old mode 100755 new mode 100644 similarity index 92% rename from Classes/PHPWord/Section/Title.php rename to src/Section/Title.php index 067370f2f2..1c3546aee9 --- a/Classes/PHPWord/Section/Title.php +++ b/src/Section/Title.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/Shared/ZipStreamWrapper.php old mode 100755 new mode 100644 similarity index 92% rename from Classes/PHPWord/Shared/ZipStreamWrapper.php rename to src/Shared/ZipStreamWrapper.php index fe4ff372d3..55b2fec650 --- a/Classes/PHPWord/Shared/ZipStreamWrapper.php +++ b/src/Shared/ZipStreamWrapper.php @@ -1,8 +1,8 @@ _archive = new ZipArchive(); + $this->_archive = new \ZipArchive(); $this->_archive->open($url['host']); $this->_fileNameInArchive = $url['fragment']; @@ -149,7 +149,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; @@ -158,7 +158,7 @@ public function stream_seek($offset, $whence) } break; - case SEEK_CUR: + case \SEEK_CUR: if ($offset >= 0) { $this->_position += $offset; return true; @@ -167,7 +167,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; @@ -180,4 +180,4 @@ public function stream_seek($offset, $whence) return false; } } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Style.php b/src/Style.php old mode 100755 new mode 100644 similarity index 80% rename from Classes/PHPWord/Style.php rename to src/Style.php index 8366b6583b..d765db691a --- a/Classes/PHPWord/Style.php +++ b/src/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,23 +94,19 @@ public static function addLinkStyle($styleName, $styles) } /** - * Add a table style - * * @param string $styleName * @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 string $styleName * @param array $styleFont * @param array $styleParagraph @@ -128,7 +115,7 @@ public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = { $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; @@ -141,9 +128,7 @@ public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = } /** - * Set default paragraph style - * - * @param array $styles Paragraph style definition + * @param array $styles Paragraph style definition */ public static function setDefaultParagraphStyle($styles) { @@ -153,7 +138,7 @@ public static function setDefaultParagraphStyle($styles) /** * Get all styles * - * @return PHPWord_Style_Font[] + * @return \PhpOffice\PhpWord\Style\Font[] */ public static function getStyles() { @@ -161,10 +146,7 @@ public static function getStyles() } /** - * Get style - * * @param string - * @return PHPWord_Style */ public static function getStyle($styleName) { @@ -174,4 +156,4 @@ public static function getStyle($styleName) return null; } } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Style/Cell.php b/src/Style/Cell.php old mode 100755 new mode 100644 similarity index 97% rename from Classes/PHPWord/Style/Cell.php rename to src/Style/Cell.php index b07eb4c237..99b7e8c550 --- a/Classes/PHPWord/Style/Cell.php +++ b/src/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; @@ -204,10 +186,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) { @@ -220,7 +200,7 @@ public function setStyleValue($key, $value) /** * Get font name * - * @return bool + * @return bool */ public function getName() { @@ -230,13 +210,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; @@ -256,22 +236,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() { @@ -279,10 +257,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) { @@ -294,9 +270,7 @@ public function setBold($pValue = false) } /** - * Get italics - * - * @return bool + * @return bool */ public function getItalic() { @@ -304,10 +278,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) { @@ -319,9 +291,7 @@ public function setItalic($pValue = false) } /** - * Get superscript - * - * @return bool + * @return bool */ public function getSuperScript() { @@ -329,10 +299,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) { @@ -345,9 +313,7 @@ public function setSuperScript($pValue = false) } /** - * Get superscript - * - * @return bool + * @return bool */ public function getSubScript() { @@ -355,10 +321,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) { @@ -371,9 +335,7 @@ public function setSubScript($pValue = false) } /** - * Get underline - * - * @return string + * @return string */ public function getUnderline() { @@ -381,24 +343,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() { @@ -406,10 +364,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) { @@ -423,7 +379,7 @@ public function setStrikethrough($pValue = false) /** * Get font color * - * @return string + * @return string */ public function getColor() { @@ -431,15 +387,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; @@ -448,7 +402,7 @@ public function setColor($pValue = PHPWord::DEFAULT_FONT_COLOR) /** * Get foreground/highlight color * - * @return bool + * @return bool */ public function getFgColor() { @@ -458,8 +412,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) { @@ -468,8 +422,6 @@ public function setFgColor($pValue = null) } /** - * Get style type - * * @return string */ public function getStyleType() @@ -478,9 +430,7 @@ public function getStyleType() } /** - * Get paragraph style - * - * @return PHPWord_Style_Paragraph + * @return \PhpOffice\PhpWord\Style\Paragraph */ public function getParagraphStyle() { @@ -488,11 +438,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) { @@ -530,15 +478,15 @@ 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; } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Style/Image.php b/src/Style/Image.php old mode 100755 new mode 100644 similarity index 91% rename from Classes/PHPWord/Style/Image.php rename to src/Style/Image.php index 9bec4d5bd7..a2390126ba --- a/Classes/PHPWord/Style/Image.php +++ b/src/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/Style/ListItem.php old mode 100755 new mode 100644 similarity index 82% rename from Classes/PHPWord/Style/ListItem.php rename to src/Style/ListItem.php index 5fbff0d6fb..d0d6c75086 --- a/Classes/PHPWord/Style/ListItem.php +++ b/src/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/Style/Paragraph.php old mode 100755 new mode 100644 similarity index 90% rename from Classes/PHPWord/Style/Paragraph.php rename to src/Style/Paragraph.php index 32a44929bf..b4d9006f67 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/src/Style/Paragraph.php @@ -1,8 +1,8 @@ _tabs = new PHPWord_Style_Tabs($pValue); + $this->_tabs = new Tabs($pValue); } return $this; } @@ -347,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') { @@ -369,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) { @@ -391,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) { @@ -416,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) { @@ -441,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) { @@ -466,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) { @@ -482,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) { diff --git a/Classes/PHPWord/Style/Row.php b/src/Style/Row.php similarity index 91% rename from Classes/PHPWord/Style/Row.php rename to src/Style/Row.php index 93b5f86265..237241e58f 100644 --- a/Classes/PHPWord/Style/Row.php +++ b/src/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/Style/Tab.php old mode 100755 new mode 100644 similarity index 82% rename from Classes/PHPWord/Style/Tab.php rename to src/Style/Tab.php index 8db7abae17..d55e914abb --- a/Classes/PHPWord/Style/Tab.php +++ b/src/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/Style/Table.php old mode 100755 new mode 100644 similarity index 92% rename from Classes/PHPWord/Style/Table.php rename to src/Style/Table.php index c3ef2e0140..15c766d21b --- a/Classes/PHPWord/Style/Table.php +++ b/src/Style/Table.php @@ -1,8 +1,8 @@ _firstRow = clone $this; @@ -196,8 +153,6 @@ public function __construct($styleTable = null, $styleFirstRow = null, $styleLas } /** - * Set style value - * * @param string $key * @param mixed $value */ @@ -217,7 +172,7 @@ public function setStyleValue($key, $value) /** * Get First Row Style * - * @return PHPWord_Style_TableFull + * @return \PhpOffice\PhpWord\Style\TableFull */ public function getFirstRow() { @@ -227,7 +182,7 @@ public function getFirstRow() /** * Get Last Row Style * - * @return PHPWord_Style_TableFull + * @return \PhpOffice\PhpWord\Style\TableFull */ public function getLastRow() { @@ -483,4 +438,4 @@ public function getCellMargin() { return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom); } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Style/Tabs.php b/src/Style/Tabs.php old mode 100755 new mode 100644 similarity index 71% rename from Classes/PHPWord/Style/Tabs.php rename to src/Style/Tabs.php index a5e1a8bba1..f836532f32 --- a/Classes/PHPWord/Style/Tabs.php +++ b/src/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/TOC.php old mode 100755 new mode 100644 similarity index 89% rename from Classes/PHPWord/TOC.php rename to src/TOC.php index c81fca228e..17df13b1ef --- a/Classes/PHPWord/TOC.php +++ b/src/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) != '_') { @@ -136,7 +134,7 @@ public static function getTitles() /** * Get TOC Style * - * @return PHPWord_Style_TOC + * @return \PhpOffice\PhpWord\Style\TOC */ public static function getStyleTOC() { @@ -146,7 +144,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/Template.php old mode 100755 new mode 100644 similarity index 91% rename from Classes/PHPWord/Template.php rename to src/Template.php index 752fa79222..65d0c989c9 --- a/Classes/PHPWord/Template.php +++ b/src/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) diff --git a/Classes/PHPWord/Writer/IWriter.php b/src/Writer/IWriter.php old mode 100755 new mode 100644 similarity index 75% rename from Classes/PHPWord/Writer/IWriter.php rename to src/Writer/IWriter.php index f5ca82992b..697aaa9e14 --- a/Classes/PHPWord/Writer/IWriter.php +++ b/src/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,42 +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 + * @return \PhpOffice\PhpWord\HashTable */ public function getDrawingHashTable() { @@ -233,10 +226,8 @@ public function getDrawingHashTable() } /** - * Get writer part - * - * @param string $pPartName Writer part name - * @return PHPWord_Writer_ODText_WriterPart + * @param string $pPartName Writer part name + * @return \PhpOffice\PhpWord\Writer\ODText\WriterPart */ public function getWriterPart($pPartName = '') { @@ -260,10 +251,10 @@ public function getUseDiskCaching() /** * Set use disk caching where possible? * - * @param boolean $pValue - * @param string $pDirectory Disk caching directory - * @throws Exception Exception when directory does not exist - * @return PHPWord_Writer_ODText + * @param boolean $pValue + * @param string $pDirectory Disk caching directory + * @throws \PhpOffice\PhpWord\Exceptions\Exception Exception when directory does not exist + * @return \PhpOffice\PhpWord\Writer\ODText */ public function setUseDiskCaching($pValue = false, $pDirectory = null) { @@ -281,12 +272,10 @@ public function setUseDiskCaching($pValue = false, $pDirectory = null) } /** - * Get disk caching directory - * * @return string */ public function getDiskCachingDirectory() { return $this->_diskCachingDirectory; } -} +} \ No newline at end of file diff --git a/src/Writer/ODText/Content.php b/src/Writer/ODText/Content.php new file mode 100644 index 0000000000..c73c6cf8b4 --- /dev/null +++ b/src/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 = null, Text $text, $withoutP = false) + { + $styleFont = $text->getFontStyle(); + $styleParagraph = $text->getParagraphStyle(); + + // @todo Commented for TextRun. Should really checkout this value + // $SfIsObject = ($styleFont instanceof Font) ? true : false; + $SfIsObject = false; + + if ($SfIsObject) { + // Don't never be the case, because I browse all sections for cleaning all styles not declared + die('PhpWord : $SfIsObject wouldn\'t be an object'); + } else { + if (!$withoutP) { + $xmlWriter->startElement('text:p'); // text:p + } + if (empty($styleFont)) { + if (empty($styleParagraph)) { + $xmlWriter->writeAttribute('text:style-name', 'P1'); + } else { + $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); + } + $xmlWriter->writeRaw($text->getText()); + } else { + if (empty($styleParagraph)) { + $xmlWriter->writeAttribute('text:style-name', 'Standard'); + } else { + $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); + } + // text:span + $xmlWriter->startElement('text:span'); + $xmlWriter->writeAttribute('text:style-name', $styleFont); + $xmlWriter->writeRaw($text->getText()); + $xmlWriter->endElement(); + } + if (!$withoutP) { + $xmlWriter->endElement(); // text:p + } + } + } + + /** + * Write TextRun section + * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Section\TextRun $textrun + * @todo Enable all other section types + */ + protected function _writeTextRun(XMLWriter $xmlWriter = null, TextRun $textrun) + { + $elements = $textrun->getElements(); + $xmlWriter->startElement('text:p'); + if (count($elements) > 0) { + foreach ($elements as $element) { + if ($element instanceof Text) { + $this->_writeText($xmlWriter, $element, true); + } + } + } + $xmlWriter->endElement(); + } + + /** + * Write TextBreak + */ + protected function _writeTextBreak(XMLWriter $xmlWriter = null) + { + $xmlWriter->startElement('text:p'); + $xmlWriter->writeAttribute('text:style-name', 'Standard'); + $xmlWriter->endElement(); + } + + // @codeCoverageIgnoreStart + private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null) + { + } + + private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null) + { + } + // @codeCoverageIgnoreEnd + + /** + * Write unsupported element + * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param string $element + */ + private function writeUnsupportedElement($xmlWriter, $element) + { + $xmlWriter->startElement('text:p'); + $xmlWriter->writeRaw($element); + $xmlWriter->endElement(); + } +} \ No newline at end of file diff --git a/Classes/PHPWord/Writer/ODText/Manifest.php b/src/Writer/ODText/Manifest.php old mode 100755 new mode 100644 similarity index 53% rename from Classes/PHPWord/Writer/ODText/Manifest.php rename to src/Writer/ODText/Manifest.php index 89e802dc61..48b230e947 --- a/Classes/PHPWord/Writer/ODText/Manifest.php +++ b/src/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,35 +96,35 @@ 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 + * @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 { throw new Exception("File $pFile does not exist"); } } -} +} \ No newline at end of file diff --git a/src/Writer/ODText/Meta.php b/src/Writer/ODText/Meta.php new file mode 100644 index 0000000000..16814cb3b1 --- /dev/null +++ b/src/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/Writer/ODText/Mimetype.php old mode 100755 new mode 100644 similarity index 69% rename from Classes/PHPWord/Writer/ODText/Mimetype.php rename to src/Writer/ODText/Mimetype.php index af3b33485b..6e0638dedb --- a/Classes/PHPWord/Writer/ODText/Mimetype.php +++ b/src/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/Writer/ODText/WriterPart.php old mode 100755 new mode 100644 similarity index 69% rename from Classes/PHPWord/Writer/ODText/WriterPart.php rename to src/Writer/ODText/WriterPart.php index c65269a2c5..a08b25c276 --- a/Classes/PHPWord/Writer/ODText/WriterPart.php +++ b/src/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."); } } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Writer/RTF.php b/src/Writer/RTF.php old mode 100755 new mode 100644 similarity index 70% rename from Classes/PHPWord/Writer/RTF.php rename to src/Writer/RTF.php index a090fb175c..263dce0e17 --- a/Classes/PHPWord/Writer/RTF.php +++ b/src/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) { @@ -93,42 +108,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_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 + * @return \PhpOffice\PhpWord\HashTable */ public function getDrawingHashTable() { @@ -137,7 +147,7 @@ public function getDrawingHashTable() private function getData() { - // PHPWord object : $this->_document + // PhpWord object : $this->_document $this->_fontTable = $this->getDataFont(); $this->_colorTable = $this->getDataColor(); @@ -148,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 @@ -177,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(); @@ -190,20 +200,20 @@ private function getData() 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(); } @@ -212,7 +222,7 @@ private function getDataFont() } // Search all fonts used - $_sections = $pPHPWord->getSections(); + $_sections = $phpWord->getSections(); $countSections = count($_sections); if ($countSections > 0) { $pSection = 0; @@ -222,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(); } @@ -240,24 +250,24 @@ private function getDataFont() 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; } } @@ -265,7 +275,7 @@ private function getDataColor() } // Search all fonts used - $_sections = $pPHPWord->getSections(); + $_sections = $phpWord->getSections(); $countSections = count($_sections); if ($countSections > 0) { $pSection = 0; @@ -275,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(); } @@ -296,10 +306,10 @@ private function getDataColor() private function getDataContent() { - $pPHPWord = $this->_document; + $phpWord = $this->_document; $sRTFBody = ''; - $_sections = $pPHPWord->getSections(); + $_sections = $phpWord->getSections(); $countSections = count($_sections); $pSection = 0; @@ -308,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'); @@ -340,23 +350,20 @@ private function getDataContent() return $sRTFBody; } - /** - * Get text - */ - 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) { @@ -378,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) { @@ -410,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'; @@ -421,33 +428,30 @@ 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 - */ - 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; } @@ -456,7 +460,7 @@ private function getDataContentTextBreak() { $this->_lastParagraphStyle = ''; - return '\par' . PHP_EOL; + return '\par' . \PHP_EOL; } /** @@ -467,10 +471,10 @@ private function getDataContentTextBreak() 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; } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/Writer/Word2007.php b/src/Writer/Word2007.php old mode 100755 new mode 100644 similarity index 76% rename from Classes/PHPWord/Writer/Word2007.php rename to src/Writer/Word2007.php index e62341bf9a..a8c2dacc11 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/src/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); @@ -77,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); @@ -96,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)); @@ -106,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)); @@ -117,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; @@ -125,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(); @@ -150,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)); @@ -179,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 @@ -199,7 +207,7 @@ public function save($pFilename = null) @unlink($pFilename); } } else { - throw new Exception("PHPWord object unassigned."); + throw new Exception("PhpWord object unassigned."); } } @@ -213,15 +221,15 @@ private function checkContentTypes($src) $extension = 'php'; } else { $imageType = exif_imagetype($src); - if ($imageType === IMAGETYPE_JPEG) { + if ($imageType === \IMAGETYPE_JPEG) { $extension = 'jpg'; - } elseif ($imageType === IMAGETYPE_GIF) { + } elseif ($imageType === \IMAGETYPE_GIF) { $extension = 'gif'; - } elseif ($imageType === IMAGETYPE_PNG) { + } elseif ($imageType === \IMAGETYPE_PNG) { $extension = 'png'; - } elseif ($imageType === IMAGETYPE_BMP) { + } elseif ($imageType === \IMAGETYPE_BMP) { $extension = 'bmp'; - } elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) { + } elseif ($imageType === \IMAGETYPE_TIFF_II || $imageType === \IMAGETYPE_TIFF_MM) { $extension = 'tif'; } } diff --git a/src/Writer/Word2007/Base.php b/src/Writer/Word2007/Base.php new file mode 100644 index 0000000000..a7090d1e65 --- /dev/null +++ b/src/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 = null, 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 = null, + 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 = null, 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 = null, 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 = null, 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 = null, 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 = null, + \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 = null, 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 = 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) { + $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 = null, $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 = null, 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 = null, 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 = null, 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/Writer/Word2007/ContentTypes.php old mode 100755 new mode 100644 similarity index 66% rename from Classes/PHPWord/Writer/Word2007/ContentTypes.php rename to src/Writer/Word2007/ContentTypes.php index 8a6e39ef85..787eb5ad68 --- a/Classes/PHPWord/Writer/Word2007/ContentTypes.php +++ b/src/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' ); @@ -78,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' ); @@ -156,7 +156,7 @@ 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' ); @@ -164,22 +164,22 @@ public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers } - $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 { @@ -188,44 +188,40 @@ 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."); } } -} +} \ No newline at end of file diff --git a/src/Writer/Word2007/DocProps.php b/src/Writer/Word2007/DocProps.php new file mode 100644 index 0000000000..bbfc6523f8 --- /dev/null +++ b/src/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/Writer/Word2007/Document.php b/src/Writer/Word2007/Document.php new file mode 100644 index 0000000000..142fa252fb --- /dev/null +++ b/src/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 = null, Section $section) + { + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:pPr'); + $this->_writeEndSection($xmlWriter, $section, 3); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section) + { + $settings = $section->getSettings(); + $_headers = $section->getHeaders(); + $_footer = $section->getFooter(); + $pgSzW = $settings->getPageSizeW(); + $pgSzH = $settings->getPageSizeH(); + $orientation = $settings->getOrientation(); + + $marginTop = $settings->getMarginTop(); + $marginLeft = $settings->getMarginLeft(); + $marginRight = $settings->getMarginRight(); + $marginBottom = $settings->getMarginBottom(); + + $headerHeight = $settings->getHeaderHeight(); + $footerHeight = $settings->getFooterHeight(); + + $borders = $settings->getBorderSize(); + + $colsNum = $settings->getColsNum(); + $colsSpace = $settings->getColsSpace(); + $breakType = $settings->getBreakType(); + + $xmlWriter->startElement('w:sectPr'); + + foreach ($_headers as &$_header) { + $rId = $_header->getRelationId(); + $xmlWriter->startElement('w:headerReference'); + $xmlWriter->writeAttribute('w:type', $_header->getType()); + $xmlWriter->writeAttribute('r:id', 'rId' . $rId); + $xmlWriter->endElement(); + } + + if ($section->hasDifferentFirstPage()) { + $xmlWriter->startElement('w:titlePg'); + $xmlWriter->endElement(); + } + + if (!is_null($breakType)) { + $xmlWriter->startElement('w:type'); + $xmlWriter->writeAttribute('w:val', $breakType); + $xmlWriter->endElement(); + } + + if (!is_null($_footer)) { + $rId = $_footer->getRelationId(); + $xmlWriter->startElement('w:footerReference'); + $xmlWriter->writeAttribute('w:type', 'default'); + $xmlWriter->writeAttribute('r:id', 'rId' . $rId); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:pgSz'); + $xmlWriter->writeAttribute('w:w', $pgSzW); + $xmlWriter->writeAttribute('w:h', $pgSzH); + + if (!is_null($orientation) && strtolower($orientation) != 'portrait') { + $xmlWriter->writeAttribute('w:orient', $orientation); + } + + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:pgMar'); + $xmlWriter->writeAttribute('w:top', $marginTop); + $xmlWriter->writeAttribute('w:right', $marginRight); + $xmlWriter->writeAttribute('w:bottom', $marginBottom); + $xmlWriter->writeAttribute('w:left', $marginLeft); + $xmlWriter->writeAttribute('w:header', $headerHeight); + $xmlWriter->writeAttribute('w:footer', $footerHeight); + $xmlWriter->writeAttribute('w:gutter', '0'); + $xmlWriter->endElement(); + + + if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) { + $borderColor = $settings->getBorderColor(); + + $xmlWriter->startElement('w:pgBorders'); + $xmlWriter->writeAttribute('w:offsetFrom', 'page'); + + if (!is_null($borders[0])) { + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[0]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[0]); + $xmlWriter->endElement(); + } + + if (!is_null($borders[1])) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[1]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[1]); + $xmlWriter->endElement(); + } + + if (!is_null($borders[2])) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[2]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[2]); + $xmlWriter->endElement(); + } + + if (!is_null($borders[3])) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $borders[3]); + $xmlWriter->writeAttribute('w:space', '24'); + $xmlWriter->writeAttribute('w:color', $borderColor[3]); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + + // Page numbering + if (null !== $settings->getPageNumberingStart()) { + $xmlWriter->startElement('w:pgNumType'); + $xmlWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart()); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:cols'); + $xmlWriter->writeAttribute('w:num', $colsNum); + $xmlWriter->writeAttribute('w:space', $colsSpace); + $xmlWriter->endElement(); + + + $xmlWriter->endElement(); + } + + private function _writePageBreak(XMLWriter $xmlWriter = null) + { + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:br'); + $xmlWriter->writeAttribute('w:type', 'page'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + public function _writeListItem(XMLWriter $xmlWriter = null, ListItem $listItem) + { + $textObject = $listItem->getTextObject(); + $text = $textObject->getText(); + $styleParagraph = $textObject->getParagraphStyle(); + $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; + + $depth = $listItem->getDepth(); + $listType = $listItem->getStyle()->getListType(); + + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:pPr'); + + if ($SpIsObject) { + $this->_writeParagraphStyle($xmlWriter, $styleParagraph, true); + } elseif (!$SpIsObject && !is_null($styleParagraph)) { + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleParagraph); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:numPr'); + + $xmlWriter->startElement('w:ilvl'); + $xmlWriter->writeAttribute('w:val', $depth); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:numId'); + $xmlWriter->writeAttribute('w:val', $listType); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $this->_writeText($xmlWriter, $textObject, true); + + $xmlWriter->endElement(); + } + + protected function _writeObject(XMLWriter $xmlWriter = null, Object $object) + { + $rIdObject = $object->getRelationId(); + $rIdImage = $object->getImageRelationId(); + $shapeId = md5($rIdObject . '_' . $rIdImage); + + $objectId = $object->getObjectId(); + + $style = $object->getStyle(); + $width = $style->getWidth(); + $height = $style->getHeight(); + $align = $style->getAlign(); + + + $xmlWriter->startElement('w:p'); + + if (!is_null($align)) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:jc'); + $xmlWriter->writeAttribute('w:val', $align); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:r'); + + $xmlWriter->startElement('w:object'); + $xmlWriter->writeAttribute('w:dxaOrig', '249'); + $xmlWriter->writeAttribute('w:dyaOrig', '160'); + + $xmlWriter->startElement('v:shape'); + $xmlWriter->writeAttribute('id', $shapeId); + $xmlWriter->writeAttribute('type', '#_x0000_t75'); + $xmlWriter->writeAttribute('style', 'width:104px;height:67px'); + $xmlWriter->writeAttribute('o:ole', ''); + + $xmlWriter->startElement('v:imagedata'); + $xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage); + $xmlWriter->writeAttribute('o:title', ''); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->startElement('o:OLEObject'); + $xmlWriter->writeAttribute('Type', 'Embed'); + $xmlWriter->writeAttribute('ProgID', 'Package'); + $xmlWriter->writeAttribute('ShapeID', $shapeId); + $xmlWriter->writeAttribute('DrawAspect', 'Icon'); + $xmlWriter->writeAttribute('ObjectID', '_' . $objectId); + $xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); // w:r + + $xmlWriter->endElement(); // w:p + } + + private function _writeTOC(XMLWriter $xmlWriter = null) + { + $titles = TOC::getTitles(); + $styleFont = TOC::getStyleFont(); + + $styleTOC = TOC::getStyleTOC(); + $fIndent = $styleTOC->getIndent(); + $tabLeader = $styleTOC->getTabLeader(); + $tabPos = $styleTOC->getTabPos(); + + $isObject = ($styleFont instanceof Font) ? true : false; + + for ($i = 0; $i < count($titles); $i++) { + $title = $titles[$i]; + $indent = ($title['depth'] - 1) * $fIndent; + + $xmlWriter->startElement('w:p'); + + $xmlWriter->startElement('w:pPr'); + + if ($isObject && !is_null($styleFont->getParagraphStyle())) { + $this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle()); + } + + if ($indent > 0) { + $xmlWriter->startElement('w:ind'); + $xmlWriter->writeAttribute('w:left', $indent); + $xmlWriter->endElement(); + } + + if (!empty($styleFont) && !$isObject) { + $xmlWriter->startElement('w:pPr'); + $xmlWriter->startElement('w:pStyle'); + $xmlWriter->writeAttribute('w:val', $styleFont); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:tabs'); + $xmlWriter->startElement('w:tab'); + $xmlWriter->writeAttribute('w:val', 'right'); + if (!empty($tabLeader)) { + $xmlWriter->writeAttribute('w:leader', $tabLeader); + } + $xmlWriter->writeAttribute('w:pos', $tabPos); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); // w:pPr + + + if ($i == 0) { + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'begin'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:instrText'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); + $xmlWriter->writeRaw('TOC \o "1-9" \h \z \u'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'separate'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:hyperlink'); + $xmlWriter->writeAttribute('w:anchor', $title['anchor']); + $xmlWriter->writeAttribute('w:history', '1'); + + $xmlWriter->startElement('w:r'); + + if ($isObject) { + $this->_writeTextStyle($xmlWriter, $styleFont); + } + + $xmlWriter->startElement('w:t'); + $xmlWriter->writeRaw($title['text']); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->writeElement('w:tab', null); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'begin'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:instrText'); + $xmlWriter->writeAttribute('xml:space', 'preserve'); + $xmlWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'end'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); // w:hyperlink + + $xmlWriter->endElement(); // w:p + } + + $xmlWriter->startElement('w:p'); + $xmlWriter->startElement('w:r'); + $xmlWriter->startElement('w:fldChar'); + $xmlWriter->writeAttribute('w:fldCharType', 'end'); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } +} diff --git a/Classes/PHPWord/Writer/Word2007/DocumentRels.php b/src/Writer/Word2007/DocumentRels.php old mode 100755 new mode 100644 similarity index 68% rename from Classes/PHPWord/Writer/Word2007/DocumentRels.php rename to src/Writer/Word2007/DocumentRels.php index 9817a31fa9..02071666ec --- a/Classes/PHPWord/Writer/Word2007/DocumentRels.php +++ b/src/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' @@ -58,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' @@ -66,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' @@ -74,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' @@ -82,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' @@ -90,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' @@ -104,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, @@ -113,28 +112,28 @@ public function writeDocumentRels($_relsCollection) } - $objWriter->endElement(); + $xmlWriter->endElement(); // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } 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) { @@ -143,7 +142,7 @@ public function writeHeaderFooterRels($_relsCollection) $relationId = $relation['rID']; $this->_writeRelationship( - $objWriter, + $xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName @@ -151,13 +150,13 @@ public function writeHeaderFooterRels($_relsCollection) } - $objWriter->endElement(); + $xmlWriter->endElement(); // Return - return $objWriter->getData(); + return $xmlWriter->getData(); } - 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) { @@ -165,18 +164,18 @@ 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."); } } -} +} \ No newline at end of file diff --git a/src/Writer/Word2007/Footer.php b/src/Writer/Word2007/Footer.php new file mode 100644 index 0000000000..e10a7eff05 --- /dev/null +++ b/src/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/Writer/Word2007/Footnotes.php b/src/Writer/Word2007/Footnotes.php new file mode 100644 index 0000000000..fa048c4623 --- /dev/null +++ b/src/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/Writer/Word2007/FootnotesRels.php similarity index 60% rename from Classes/PHPWord/Writer/Word2007/FootnotesRels.php rename to src/Writer/Word2007/FootnotesRels.php index 0e562b593a..6b2b56026f 100644 --- a/Classes/PHPWord/Writer/Word2007/FootnotesRels.php +++ b/src/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) { @@ -52,16 +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(); } - 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) { @@ -69,18 +71,18 @@ 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."); } } -} +} \ No newline at end of file diff --git a/src/Writer/Word2007/Header.php b/src/Writer/Word2007/Header.php new file mode 100644 index 0000000000..b5695f8816 --- /dev/null +++ b/src/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/Writer/Word2007/Rels.php old mode 100755 new mode 100644 similarity index 56% rename from Classes/PHPWord/Writer/Word2007/Rels.php rename to src/Writer/Word2007/Rels.php index 06eb59cc9f..db817f9cbc --- a/Classes/PHPWord/Writer/Word2007/Rels.php +++ b/src/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' @@ -60,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' @@ -68,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) { @@ -98,18 +97,18 @@ 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."); } } -} +} \ No newline at end of file diff --git a/src/Writer/Word2007/Styles.php b/src/Writer/Word2007/Styles.php new file mode 100644 index 0000000000..b90f4eb31c --- /dev/null +++ b/src/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 = null, TableFull $style) + { + + $brdSz = $style->getBorderSize(); + $brdCol = $style->getBorderColor(); + $bgColor = $style->getBgColor(); + $cellMargin = $style->getCellMargin(); + + $bTop = (!is_null($brdSz[0])) ? true : false; + $bLeft = (!is_null($brdSz[1])) ? true : false; + $bRight = (!is_null($brdSz[2])) ? true : false; + $bBottom = (!is_null($brdSz[3])) ? true : false; + $bInsH = (!is_null($brdSz[4])) ? true : false; + $bInsV = (!is_null($brdSz[5])) ? true : false; + $borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false; + + $mTop = (!is_null($cellMargin[0])) ? true : false; + $mLeft = (!is_null($cellMargin[1])) ? true : false; + $mRight = (!is_null($cellMargin[2])) ? true : false; + $mBottom = (!is_null($cellMargin[3])) ? true : false; + $margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false; + + $xmlWriter->startElement('w:tblPr'); + + if ($margins) { + $xmlWriter->startElement('w:tblCellMar'); + if ($mTop) { + echo $margins[0]; + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:w', $cellMargin[0]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + if ($mLeft) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:w', $cellMargin[1]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + if ($mRight) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:w', $cellMargin[2]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + if ($mBottom) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:w', $cellMargin[3]); + $xmlWriter->writeAttribute('w:type', 'dxa'); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + + if ($borders) { + $xmlWriter->startElement('w:tblBorders'); + if ($bTop) { + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[0]); + $xmlWriter->writeAttribute('w:color', $brdCol[0]); + $xmlWriter->endElement(); + } + if ($bLeft) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[1]); + $xmlWriter->writeAttribute('w:color', $brdCol[1]); + $xmlWriter->endElement(); + } + if ($bRight) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[2]); + $xmlWriter->writeAttribute('w:color', $brdCol[2]); + $xmlWriter->endElement(); + } + if ($bBottom) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[3]); + $xmlWriter->writeAttribute('w:color', $brdCol[3]); + $xmlWriter->endElement(); + } + if ($bInsH) { + $xmlWriter->startElement('w:insideH'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[4]); + $xmlWriter->writeAttribute('w:color', $brdCol[4]); + $xmlWriter->endElement(); + } + if ($bInsV) { + $xmlWriter->startElement('w:insideV'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[5]); + $xmlWriter->writeAttribute('w:color', $brdCol[5]); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + } + + $xmlWriter->endElement(); + + if (!is_null($bgColor)) { + $xmlWriter->startElement('w:tcPr'); + $xmlWriter->startElement('w:shd'); + $xmlWriter->writeAttribute('w:val', 'clear'); + $xmlWriter->writeAttribute('w:color', 'auto'); + $xmlWriter->writeAttribute('w:fill', $bgColor); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } + + // First Row + $firstRow = $style->getFirstRow(); + if (!is_null($firstRow)) { + $this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow); + } + } + + private function _writeRowStyle(XMLWriter $xmlWriter = null, $type, TableFull $style) + { + $brdSz = $style->getBorderSize(); + $brdCol = $style->getBorderColor(); + $bgColor = $style->getBgColor(); + + $bTop = (!is_null($brdSz[0])) ? true : false; + $bLeft = (!is_null($brdSz[1])) ? true : false; + $bRight = (!is_null($brdSz[2])) ? true : false; + $bBottom = (!is_null($brdSz[3])) ? true : false; + $borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false; + + $xmlWriter->startElement('w:tblStylePr'); + $xmlWriter->writeAttribute('w:type', $type); + + $xmlWriter->startElement('w:tcPr'); + if (!is_null($bgColor)) { + $xmlWriter->startElement('w:shd'); + $xmlWriter->writeAttribute('w:val', 'clear'); + $xmlWriter->writeAttribute('w:color', 'auto'); + $xmlWriter->writeAttribute('w:fill', $bgColor); + $xmlWriter->endElement(); + } + + $xmlWriter->startElement('w:tcBorders'); + if ($bTop) { + $xmlWriter->startElement('w:top'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[0]); + $xmlWriter->writeAttribute('w:color', $brdCol[0]); + $xmlWriter->endElement(); + } + if ($bLeft) { + $xmlWriter->startElement('w:left'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[1]); + $xmlWriter->writeAttribute('w:color', $brdCol[1]); + $xmlWriter->endElement(); + } + if ($bRight) { + $xmlWriter->startElement('w:right'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[2]); + $xmlWriter->writeAttribute('w:color', $brdCol[2]); + $xmlWriter->endElement(); + } + if ($bBottom) { + $xmlWriter->startElement('w:bottom'); + $xmlWriter->writeAttribute('w:val', 'single'); + $xmlWriter->writeAttribute('w:sz', $brdSz[3]); + $xmlWriter->writeAttribute('w:color', $brdCol[3]); + $xmlWriter->endElement(); + } + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + } + + + private function _writeDocDefaults(XMLWriter $xmlWriter = null) + { + $fontName = $this->_document->getDefaultFontName(); + $fontSize = $this->_document->getDefaultFontSize(); + + $xmlWriter->startElement('w:docDefaults'); + $xmlWriter->startElement('w:rPrDefault'); + $xmlWriter->startElement('w:rPr'); + + $xmlWriter->startElement('w:rFonts'); + $xmlWriter->writeAttribute('w:ascii', $fontName); + $xmlWriter->writeAttribute('w:hAnsi', $fontName); + $xmlWriter->writeAttribute('w:eastAsia', $fontName); + $xmlWriter->writeAttribute('w:cs', $fontName); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:sz'); + $xmlWriter->writeAttribute('w:val', $fontSize * 2); + $xmlWriter->endElement(); + + $xmlWriter->startElement('w:szCs'); + $xmlWriter->writeAttribute('w:val', $fontSize * 2); + $xmlWriter->endElement(); + + $xmlWriter->endElement(); + $xmlWriter->endElement(); + $xmlWriter->endElement(); + } +} \ No newline at end of file diff --git a/Classes/PHPWord/Writer/Word2007/WriterPart.php b/src/Writer/Word2007/WriterPart.php old mode 100755 new mode 100644 similarity index 73% rename from Classes/PHPWord/Writer/Word2007/WriterPart.php rename to src/Writer/Word2007/WriterPart.php index cc004254f3..38bead77ff --- a/Classes/PHPWord/Writer/Word2007/WriterPart.php +++ b/src/Writer/Word2007/WriterPart.php @@ -1,8 +1,8 @@ _parentWriter = $pWriter; } @@ -42,7 +42,7 @@ 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."); } } -} +} \ No newline at end of file diff --git a/Classes/PHPWord/_staticDocParts/_doc.png b/src/_staticDocParts/_doc.png similarity index 100% rename from Classes/PHPWord/_staticDocParts/_doc.png rename to src/_staticDocParts/_doc.png diff --git a/Classes/PHPWord/_staticDocParts/_ppt.png b/src/_staticDocParts/_ppt.png similarity index 100% rename from Classes/PHPWord/_staticDocParts/_ppt.png rename to src/_staticDocParts/_ppt.png diff --git a/Classes/PHPWord/_staticDocParts/_xls.png b/src/_staticDocParts/_xls.png similarity index 100% rename from Classes/PHPWord/_staticDocParts/_xls.png rename to src/_staticDocParts/_xls.png diff --git a/Classes/PHPWord/_staticDocParts/fontTable.xml b/src/_staticDocParts/fontTable.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/fontTable.xml rename to src/_staticDocParts/fontTable.xml diff --git a/Classes/PHPWord/_staticDocParts/numbering.xml b/src/_staticDocParts/numbering.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/numbering.xml rename to src/_staticDocParts/numbering.xml diff --git a/Classes/PHPWord/_staticDocParts/settings.xml b/src/_staticDocParts/settings.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/settings.xml rename to src/_staticDocParts/settings.xml diff --git a/Classes/PHPWord/_staticDocParts/theme1.xml b/src/_staticDocParts/theme1.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/theme1.xml rename to src/_staticDocParts/theme1.xml diff --git a/Classes/PHPWord/_staticDocParts/webSettings.xml b/src/_staticDocParts/webSettings.xml similarity index 100% rename from Classes/PHPWord/_staticDocParts/webSettings.xml rename to src/_staticDocParts/webSettings.xml