diff --git a/.travis.yml b/.travis.yml index da52a1746f..0712f73461 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,12 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm matrix: allow_failures: + - php: 7.0 - php: hhvm env: @@ -31,8 +33,6 @@ before_script: script: ## PHP_CodeSniffer - ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip - ## PHP Copy/Paste Detector - - ./vendor/bin/phpcpd src/ tests/ --verbose ## PHP Mess Detector - ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php ## PHPUnit @@ -47,4 +47,4 @@ after_script: - bash .travis_shell_after_success.sh ## Scrutinizer - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml \ No newline at end of file + - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 89bfc104d0..66f38ddaca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,26 +1,72 @@ -CHANGELOG -========= +Change Log +========== +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). -This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub. - -0.12.1 (30 August 2015) +v0.13.0 (31 July 2016) ------------------- +This release brings several improvements in `TemplateProcessor`, automatic output escaping feature for OOXML, ODF, HTML, and RTF (turned off, by default). +It also introduces constants for horizontal alignment options, and resolves some issues with PHP 7. +Manual installation feature has been dropped since the release. Please, use [Composer](https://getcomposer.org/) to install PHPWord. + +### Added +- Introduced the `\PhpOffice\PhpWord\SimpleType\Jc` simple type. - @RomanSyroeshko +- Introduced the `\PhpOffice\PhpWord\SimpleType\JcTable` simple type. - @RomanSyroeshko +- Introduced writer for the "Paragraph Alignment" element (see `\PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment`). - @RomanSyroeshko +- Introduced writer for the "Table Alignment" element (see `\PhpOffice\PhpWord\Writer\Word2007\Element\TableAlignment`). - @RomanSyroeshko +- Supported indexed arrays in arguments of `TemplateProcessor::setValue()`. - @RomanSyroeshko #618 +- Introduced automatic output escaping for OOXML, ODF, HTML, and RTF. To turn the feature on use `phpword.ini` or `\PhpOffice\PhpWord\Settings`. - @RomanSyroeshko #483 +- Supported processing of headers and footers in `TemplateProcessor::applyXslStyleSheet()`. - @RomanSyroeshko #335 + +### Changed +- Improved error message for the case when `autoload.php` is not found. - @RomanSyroeshko #371 +- Renamed the `align` option of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles into `alignment`. - @RomanSyroeshko +- Improved performance of `TemplateProcessor::setValue()`. - @kazitanvirahsan #614, #617 -Maintenance release. This release is focused primarily on ``TemplateProcessor``. +### Deprecated +- `getAlign` and `setAlign` methods of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles. +Use the correspondent `getAlignment` and `setAlignment` methods instead. - @RomanSyroeshko +- `left`, `right`, and `justify` alignment options for paragraphs (now are mapped to `Jc::START`, `Jc::END`, and `Jc::BOTH`). - @RomanSyroeshko +- `left`, `right`, and `justify` alignment options for tables (now are mapped to `Jc::START`, `Jc::END`, and `Jc::CENTER`). - @RomanSyroeshko +- `TCPDF` due to its limited HTML support. Use `DomPDF` or `MPDF` writer instead. - @RomanSyroeshko #399 + +### Removed +- `\PhpOffice\PhpWord\Style\Alignment`. Style properties, which previously stored instances of this class, now deal with strings. +In each case set of available string values is defined by the correspondent simple type. - @RomanSyroeshko +- Manual installation support. Since the release we have dependencies on third party libraries, +so installation via ZIP-archive download is not an option anymore. To install PHPWord use [Composer](https://getcomposer.org/). + We also removed `\PhpOffice\PhpWord\Autoloader`, because the latter change made it completely useless. + Autoloaders provided by Composer are in use now (see `bootstrap.php`). - @RomanSyroeshko +- `\PhpOffice\PhpWord\Shared\Drawing` replaced by `\PhpOffice\Common\Drawing`. - @Progi1984 #658 +- `\PhpOffice\PhpWord\Shared\Font`. - @Progi1984 #658 +- `\PhpOffice\PhpWord\Shared\String` replaced by `\PhpOffice\Common\Text`. - @Progi1984 @RomanSyroeshko #658 +- `\PhpOffice\PhpWord\Shared\XMLReader` replaced by `\PhpOffice\Common\XMLReader`. - @Progi1984 #658 +- `\PhpOffice\PhpWord\Shared\XMLWriter` replaced by `\PhpOffice\Common\XMLWriter`. - @Progi1984 @RomanSyroeshko #658 +- `AbstractContainer::addMemoryImage()`. Use `AbstractContainer::addImage()` instead. + +### Fixed +- `Undefined property` error while reading MS-DOC documents. - @jaberu #610 +- Corrupted OOXML template issue in case when its names is broken immediately after `$` sign. +That case wasn't taken into account in implementation of `TemplateProcessor::fixBrokenMacros()`. - @RomanSyroeshko @d-damien #548 + + + +v0.12.1 (30 August 2015) +----------------------- +Maintenance release. This release is focused primarily on `TemplateProcessor`. ### Changes -- Changed visibility of all private properties and methods of ``TemplateProcessor`` to ``protected``. - @RomanSyroeshko #498 -- Improved performance of ``TemplateProcessor::setValue()``. - @RomanSyroeshko @nicoSWD #513 +- Changed visibility of all private properties and methods of `TemplateProcessor` to `protected`. - @RomanSyroeshko #498 +- Improved performance of `TemplateProcessor::setValue()`. - @RomanSyroeshko @nicoSWD #513 ### Bugfixes -- Fixed issue with "Access denied" message while opening ``Sample_07_TemplateCloneRow.docx`` and ``Sample_23_TemplateBlock.docx`` result files on Windows platform. - @RomanSyroeshko @AshSat #532 -- Fixed ``PreserveText`` element alignment in footer (see ``Sample_12_HeaderFooter.php``). - @RomanSyroeshko @SSchwaiger #495 +- Fixed issue with "Access denied" message while opening `Sample_07_TemplateCloneRow.docx` and `Sample_23_TemplateBlock.docx` result files on Windows platform. - @RomanSyroeshko @AshSat #532 +- Fixed `PreserveText` element alignment in footer (see `Sample_12_HeaderFooter.php`). - @RomanSyroeshko @SSchwaiger #495 -0.12.0 (3 January 2015) +v0.12.0 (3 January 2015) ----------------------- - This release added form fields (textinput, checkbox, and dropdown), drawing shapes (arc, curve, line, polyline, rect, oval), and basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) elements along with some new styles. Basic MsDoc reader is introduced. ### Features @@ -78,18 +124,16 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap -0.11.1 (2 June 2014) +v0.11.1 (2 June 2014) -------------------- - This is an immediate bugfix release for HTML reader. - HTML Reader: `

` and header tags puts no output - @canyildiz @ivanlanin #257 -0.11.0 (1 June 2014) +v0.11.0 (1 June 2014) -------------------- - This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Four new elements were added: TextBox, ListItemRun, Field, and Line. Relative and absolute positioning for images and textboxes were added. Writer classes were refactored into parts, elements, and styles. ODT and RTF features were enhanced. Ability to add elements to PHPWord object via HTML were implemented. RTF and HTML reader were initiated. ### Features @@ -152,18 +196,16 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Four -0.10.1 (21 May 2014) +v0.10.1 (21 May 2014) -------------------- - This is a bugfix release for `php-zip` requirement in Composer. - Change Composer requirements for php-zip from `require` to `suggest` - @bskrtich #246 -0.10.0 (4 May 2014) +v0.10.0 (4 May 2014) ------------------- - This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML and PDF writing support is enabled. Basic ODText reader is introduced. ### Features @@ -246,18 +288,16 @@ This release marked heavy refactorings on internal code structure with the creat -0.9.1 (27 Mar 2014) +v0.9.1 (27 Mar 2014) ------------------- - This is a bugfix release for PSR-4 compatibility. - Fixed PSR-4 composer autoloader - @AntonTyutin -0.9.0 (26 Mar 2014) +v0.9.0 (26 Mar 2014) ------------------- - This release marked the transformation to namespaces (PHP 5.3+). ### Features @@ -278,18 +318,16 @@ This release marked the transformation to namespaces (PHP 5.3+). -0.8.1 (17 Mar 2014) +v0.8.1 (17 Mar 2014) ------------------- - This is a bugfix release for image detection functionality. - Added fallback for computers that do not have exif_imagetype - @bskrtich, @gabrielbull -0.8.0 (15 Mar 2014) +v0.8.0 (15 Mar 2014) ------------------- - This release merged a lot of improvements from the community. Unit tests introduced in this release and has reached 90% code coverage. ### Features @@ -336,9 +374,8 @@ This release merged a lot of improvements from the community. Unit tests introdu -0.7.0 (28 Jan 2014) +v0.7.0 (28 Jan 2014) ------------------- - This is the first release after a long development hiatus in [CodePlex](https://phpword.codeplex.com/). This release initialized ODT and RTF Writer, along with some other new features for the existing Word2007 Writer, e.g. tab, multiple header, rowspan and colspan. [Composer](https://packagist.org/packages/phpoffice/phpword) and [Travis](https://travis-ci.org/PHPOffice/PHPWord) were added. ### Features @@ -362,4 +399,4 @@ This is the first release after a long development hiatus in [CodePlex](https:// - Basic CI with Travis - @Progi1984 - Added PHPWord_Exception and exception when could not copy the template - @Progi1984 - IMPROVED: Moved examples out of Classes directory - @Progi1984 -- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49) +- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49) \ No newline at end of file diff --git a/LICENSE b/LICENSE index 3f6a8c3865..8a1acaeaba 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ PHPWord, a pure PHP library for reading and writing word processing documents. -Copyright (c) 2010-2014 PHPWord. +Copyright (c) 2010-2016 PHPWord. PHPWord is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 as published by diff --git a/README.md b/README.md index 8f499a8ebb..949238a79b 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Code Coverage](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/badges/coverage.png?s=742a98745725c562955440edc8d2c39d7ff5ae25)](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/) [![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword) [![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword) +[![Join the chat at https://gitter.im/PHPOffice/PHPWord](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/PHPOffice/PHPWord) PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF), HTML, and PDF. @@ -23,7 +24,7 @@ Read more about PHPWord: ## Features -With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library: +With PHPWord, you can create OOXML, ODF, or RTF documents dynamically using your PHP 5.3.3+ scripts. Below are some of the things that you can do with PHPWord library: - Set document properties, e.g. title, subject, and creator. - Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering @@ -44,50 +45,46 @@ With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your - Insert charts (pie, doughnut, bar, line, area, scatter, radar) - Insert form fields (textinput, checkbox, and dropdown) - Create document from templates -- Use XSL 1.0 style sheets to transform main document part of OOXML template +- Use XSL 1.0 style sheets to transform headers, main document part, and footers of an OOXML template - ... and many more features on progress ## Requirements PHPWord requires the following: -- PHP 5.3+ -- [Zip extension](http://php.net/manual/en/book.zip.php) +- PHP 5.3.3+ - [XML Parser extension](http://www.php.net/manual/en/xml.installation.php) +- [Zend\Escaper component](http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html) +- Zend\Stdlib component +- [Zend\Validator component](http://framework.zend.com/manual/current/en/modules/zend.validator.html) +- [Zip extension](http://php.net/manual/en/book.zip.php) (optional, used to write OOXML and ODF) - [GD extension](http://php.net/manual/en/book.image.php) (optional, used to add images) -- [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write DOCX and ODT) +- [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write OOXML and ODF) - [XSL extension](http://php.net/manual/en/book.xsl.php) (optional, used to apply XSL style sheet to template ) -- [dompdf](https://github.com/dompdf/dompdf) (optional, used to write PDF) +- [dompdf library](https://github.com/dompdf/dompdf) (optional, used to write PDF) ## Installation -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``. +PHPWord is installed via [Composer](https://getcomposer.org/). +You just need to [add dependency](https://getcomposer.org/doc/04-schema.md#package-links>) on PHPWord into your package. + +Example: ```json { "require": { - "phpoffice/phpword": "dev-master" + "phpoffice/phpword": "v0.13.*" } } ``` -Alternatively, you can download the latest release from the [releases page](https://github.com/PHPOffice/PHPWord/releases). -In this case, you will have to register the autoloader. - -```php -require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php'; -\PhpOffice\PhpWord\Autoloader::register(); -``` - ## Getting started The following is a basic usage example of the PHPWord library. ```php addSection(); // Adding Text element to the Section having font styled by default... $section->addText( - htmlspecialchars( - '"Learn from yesterday, live for today, hope for tomorrow. ' - . 'The important thing is not to stop questioning." ' - . '(Albert Einstein)' - ) + '"Learn from yesterday, live for today, hope for tomorrow. ' + . 'The important thing is not to stop questioning." ' + . '(Albert Einstein)' ); /* @@ -114,11 +109,9 @@ $section->addText( // Adding Text element with font customized inline... $section->addText( - htmlspecialchars( - '"Great achievement is usually born of great sacrifice, ' - . 'and is never the result of selfishness." ' - . '(Napoleon Hill)' - ), + '"Great achievement is usually born of great sacrifice, ' + . 'and is never the result of selfishness." ' + . '(Napoleon Hill)', array('name' => 'Tahoma', 'size' => 10) ); @@ -129,11 +122,9 @@ $phpWord->addFontStyle( array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true) ); $section->addText( - htmlspecialchars( - '"The greatest accomplishment is not in never falling, ' - . 'but in rising again after you fall." ' - . '(Vince Lombardi)' - ), + '"The greatest accomplishment is not in never falling, ' + . 'but in rising again after you fall." ' + . '(Vince Lombardi)', $fontStyleName ); @@ -142,9 +133,7 @@ $fontStyle = new \PhpOffice\PhpWord\Style\Font(); $fontStyle->setBold(true); $fontStyle->setName('Tahoma'); $fontStyle->setSize(13); -$myTextElement = $section->addText( - htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)') -); +$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)'); $myTextElement->setFontStyle($fontStyle); // Saving the document as OOXML file... @@ -162,7 +151,6 @@ $objWriter->save('helloWorld.html'); /* Note: we skip RTF, because it's not XML-based and requires a different example. */ /* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */ ``` -:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken. More examples are provided in the [samples folder](samples/). You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/) for more detail. diff --git a/VERSION b/VERSION index aac2dacab4..51de3305bb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.12.1 \ No newline at end of file +0.13.0 \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000000..11939feefd --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,28 @@ +=5.3.3", - "ext-xml": "*" + "ext-xml": "*", + "zendframework/zend-escaper": "2.4.*", + "zendframework/zend-stdlib": "2.4.*", + "zendframework/zend-validator": "2.4.*", + "phpoffice/common": "0.2.*" }, "require-dev": { "phpunit/phpunit": "3.7.*", "phpdocumentor/phpdocumentor":"2.*", "squizlabs/php_codesniffer": "1.*", "phpmd/phpmd": "2.*", - "sebastian/phpcpd": "2.*", "phploc/phploc": "2.*", "dompdf/dompdf":"0.6.*", - "tecnick.com/tcpdf": "6.*", + "tecnickcom/tcpdf": "6.*", "mpdf/mpdf": "5.*" }, "suggest": { - "ext-zip": "Used to write DOCX and ODT", - "ext-gd2": "Used to add images", - "ext-xmlwriter": "Used to write DOCX and ODT", - "ext-xsl": "Used to apply XSL style sheet to main document part of OOXML template", - "dompdf/dompdf": "Used to write PDF" + "ext-zip": "Allows writing OOXML and ODF", + "ext-gd2": "Allows adding images", + "ext-xmlwriter": "Allows writing OOXML and ODF", + "ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template", + "dompdf/dompdf": "Allows writing PDF" }, "autoload": { "psr-4": { diff --git a/docs/Makefile b/docs/Makefile index 5631b06028..bd38cd5d9d 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 de645350d0..e9b1c59e45 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -40,15 +40,15 @@ master_doc = 'index' # General information about the project. -project = u'PhpWord' -copyright = u'2014, PHPWord Contributors' +project = u'PHPWord' +copyright = u'2014-2015, PHPWord Contributors' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '0.12.0' +version = '0.13.0' # The full version, including alpha/beta/rc tags. release = version @@ -164,7 +164,7 @@ #html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'PhpWorddoc' +htmlhelp_basename = 'PHPWorddoc' # -- Options for LaTeX output -------------------------------------------------- @@ -183,8 +183,8 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'PhpWord.tex', u'PhpWord Documentation', - u'The PhpWord Team', 'manual'), + ('index', 'PHPWord.tex', u'PHPWord Documentation', + u'The PHPWord Team', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -213,8 +213,8 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'PhpWord', u'PhpWord Documentation', - [u'The PhpWord Team'], 1) + ('index', 'PHPWord', u'PHPWord Documentation', + [u'The PHPWord Team'], 1) ] # If true, show URL addresses after external links. @@ -227,8 +227,8 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'PhpWord', u'PhpWord Documentation', - u'The PhpWord Team', 'PhpWord', 'One line description of project.', + ('index', 'PHPWord', u'PHPWord Documentation', + u'The PHPWord Team', 'PHPWord', 'One line description of project.', 'Miscellaneous'), ] @@ -244,9 +244,9 @@ # -- Options for Epub output --------------------------------------------------- # Bibliographic Dublin Core info. -epub_title = u'PhpWord' -epub_author = u'The PhpWord Team' -epub_publisher = u'The PhpWord Team' +epub_title = u'PHPWord' +epub_author = u'The PHPWord Team' +epub_publisher = u'The PHPWord Team' epub_copyright = copyright # The language of the text. It defaults to the language option diff --git a/docs/elements.rst b/docs/elements.rst index eb70f9ad9b..d68ee035dc 100644 --- a/docs/elements.rst +++ b/docs/elements.rst @@ -50,115 +50,48 @@ column shows the containers while the rows lists the elements. Legend: -- ``v`` Available -- ``v*`` Available only when inside header/footer -- ``v**`` Available only when inside section -- ``-`` Not available -- ``?`` Should be available +- ``v``. Available. +- ``v*``. Available only when inside header/footer. +- ``v**``. Available only when inside section. +- ``-``. Not available. +- ``?``. Should be available. Texts ----- Text can be added by using ``addText`` and ``addTextRun`` method. -``addText`` is used for creating simple paragraphs that only contain -texts with the same style. ``addTextRun`` is used for creating complex -paragraphs that contain text with different style (some bold, other -italics, etc) or other elements, e.g. images or links. The syntaxes are -as follow: +``addText`` is used for creating simple paragraphs that only contain texts with the same style. +``addTextRun`` is used for creating complex paragraphs that contain text with different style (some bold, other +italics, etc) or other elements, e.g. images or links. The syntaxes are as follow: .. code-block:: php $section->addText($text, [$fontStyle], [$paragraphStyle]); $textrun = $section->addTextRun([$paragraphStyle]); -Text styles -~~~~~~~~~~~ - -You can use the ``$fontStyle`` and ``$paragraphStyle`` variable to -define text formatting. There are 2 options to style the inserted text -elements, i.e. inline style by using array or defined style by adding -style definition. - -Inline style examples: - -.. code-block:: php - - $fontStyle = array('name' => 'Times New Roman', 'size' => 9); - $paragraphStyle = array('align' => 'both'); - $section->addText('I am simple paragraph', $fontStyle, $paragraphStyle); +- ``$text``. Text to be displayed in the document. +- ``$fontStyle``. See :ref:`font-style`. +- ``$paragraphStyle``. See :ref:`paragraph-style`. - $textrun = $section->addTextRun(); - $textrun->addText('I am bold', array('bold' => true)); - $textrun->addText('I am italic', array('italic' => true)); - $textrun->addText('I am colored', array('color' => 'AACC00')); - -Defined style examples: - -.. code-block:: php - - $fontStyle = array('color' => '006699', 'size' => 18, 'bold' => true); - $phpWord->addFontStyle('fStyle', $fontStyle); - $text = $section->addText('Hello world!', 'fStyle'); - - $paragraphStyle = array('align' => 'center'); - $phpWord->addParagraphStyle('pStyle', $paragraphStyle); - $text = $section->addText('Hello world!', 'pStyle'); - -Font style -^^^^^^^^^^ - -Available font styles: - -- ``name`` Font name, e.g. *Arial* -- ``size`` Font size, e.g. *20*, *22*, -- ``hint`` Font content type, *default*, *eastAsia*, or *cs* -- ``bold`` Bold, *true* or *false* -- ``italic`` Italic, *true* or *false* -- ``superScript`` Superscript, *true* or *false* -- ``subScript`` Subscript, *true* or *false* -- ``underline`` Underline, *dash*, *dotted*, etc. -- ``strikethrough`` Strikethrough, *true* or *false* -- ``doubleStrikethrough`` Double strikethrough, *true* or *false* -- ``color`` Font color, e.g. *FF0000* -- ``fgColor`` Font highlight color, e.g. *yellow*, *green*, *blue* -- ``bgColor`` Font background color, e.g. *FF0000* -- ``smallCaps`` Small caps, *true* or *false* -- ``allCaps`` All caps, *true* or *false* - -Paragraph style -^^^^^^^^^^^^^^^ - -Available paragraph styles: - -- ``align`` Paragraph alignment, *left*, *right* or *center* -- ``spaceBefore`` Space before paragraph -- ``spaceAfter`` Space after paragraph -- ``indent`` Indent by how much -- ``hanging`` Hanging by how much -- ``basedOn`` Parent style -- ``next`` Style for next paragraph -- ``widowControl`` Allow first/last line to display on a separate page, - *true* or *false* -- ``keepNext`` Keep paragraph with next paragraph, *true* or *false* -- ``keepLines`` Keep all lines on one page, *true* or *false* -- ``pageBreakBefore`` Start paragraph on next page, *true* or *false* -- ``lineHeight`` text line height, e.g. *1.0*, *1.5*, ect... -- ``tabs`` Set of custom tab stops +For available styling options see :ref:`font-style` and :ref:`paragraph-style`. Titles ~~~~~~ -If you want to structure your document or build table of contents, you -need titles or headings. To add a title to the document, use the -``addTitleStyle`` and ``addTitle`` method. +If you want to structure your document or build table of contents, you need titles or headings. +To add a title to the document, use the ``addTitleStyle`` and ``addTitle`` method. .. code-block:: php $phpWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]); $section->addTitle($text, [$depth]); -Its necessary to add a title style to your document because otherwise -the title won't be detected as a real title. +- ``depth``. +- ``$fontStyle``. See :ref:`font-style`. +- ``$paragraphStyle``. See :ref:`paragraph-style`. +- ``$text``. Text to be displayed in the document. + +It's necessary to add a title style to your document because otherwise the title won't be detected as a real title. Links ~~~~~ @@ -169,16 +102,15 @@ You can add Hyperlinks to the document by using the function addLink: $section->addLink($linkSrc, [$linkName], [$fontStyle], [$paragraphStyle]); -- ``$linkSrc`` The URL of the link. -- ``$linkName`` Placeholder of the URL that appears in the document. -- ``$fontStyle`` See "Font style" section. -- ``$paragraphStyle`` See "Paragraph style" section. +- ``$linkSrc``. The URL of the link. +- ``$linkName``. Placeholder of the URL that appears in the document. +- ``$fontStyle``. See :ref:`font-style`. +- ``$paragraphStyle``. See :ref:`paragraph-style`. Preserve texts ~~~~~~~~~~~~~~ -The ``addPreserveText`` method is used to add a page number or page -count to headers or footers. +The ``addPreserveText`` method is used to add a page number or page count to headers or footers. .. code-block:: php @@ -190,16 +122,15 @@ Breaks Text breaks ~~~~~~~~~~~ -Text breaks are empty new lines. To add text breaks, use the following -syntax. All paramaters are optional. +Text breaks are empty new lines. To add text breaks, use the following syntax. All parameters are optional. .. code-block:: php $section->addTextBreak([$breakCount], [$fontStyle], [$paragraphStyle]); -- ``$breakCount`` How many lines -- ``$fontStyle`` See "Font style" section. -- ``$paragraphStyle`` See "Paragraph style" section. +- ``$breakCount``. How many lines. +- ``$fontStyle``. See :ref:`font-style`. +- ``$paragraphStyle``. See :ref:`paragraph-style`. Page breaks ~~~~~~~~~~~ @@ -224,56 +155,40 @@ Basic usage: Parameters: -- ``$text`` Text that appears in the document. -- ``$depth`` Depth of list item. -- ``$fontStyle`` See "Font style" section. -- ``$listStyle`` List style of the current element TYPE\_NUMBER, - TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in - PHPWord\_Style\_ListItem. -- ``$paragraphStyle`` See "Paragraph style" section. +- ``$text``. Text that appears in the document. +- ``$depth``. Depth of list item. +- ``$fontStyle``. See :ref:`font-style`. +- ``$listStyle``. List style of the current element TYPE\_NUMBER, + TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in PHPWord\_Style\_ListItem. +- ``$paragraphStyle``. See :ref:`paragraph-style`. Advanced usage: -You can also create your own numbering style by changing the -``$listStyle`` parameter with the name of your numbering style. +You can also create your own numbering style by changing the ``$listStyle`` parameter with the name of your numbering style. .. code-block:: php $phpWord->addNumberingStyle( 'multilevel', - array('type' => 'multilevel', 'levels' => array( - array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360), - array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720), + array( + 'type' => 'multilevel', + 'levels' => array( + array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360), + array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720), ) - ) + ) ); $section->addListItem('List Item I', 0, null, 'multilevel'); $section->addListItem('List Item I.a', 1, null, 'multilevel'); $section->addListItem('List Item I.b', 1, null, 'multilevel'); $section->addListItem('List Item II', 0, null, 'multilevel'); -Level styles: - -- ``start`` Starting value -- ``format`` Numbering format - bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter -- ``restart`` Restart numbering level symbol -- ``suffix`` Content between numbering symbol and paragraph text - tab\|space\|nothing -- ``text`` Numbering level text e.g. %1 for nonbullet or bullet - character -- ``align`` Numbering symbol align left\|center\|right\|both -- ``left`` See paragraph style -- ``hanging`` See paragraph style -- ``tabPos`` See paragraph style -- ``font`` Font name -- ``hint`` See font style +For available styling options see :ref:`numbering-level-style`. Tables ------ -To add tables, rows, and cells, use the ``addTable``, ``addRow``, and -``addCell`` methods: +To add tables, rows, and cells, use the ``addTable``, ``addRow``, and ``addCell`` methods: .. code-block:: php @@ -287,46 +202,19 @@ Table style can be defined with ``addTableStyle``: $tableStyle = array( 'borderColor' => '006699', - 'borderSize' => 6, - 'cellMargin' => 50 + 'borderSize' => 6, + 'cellMargin' => 50 ); $firstRowStyle = array('bgColor' => '66BBFF'); $phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle); $table = $section->addTable('myTable'); -Table, row, and cell styles -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Table styles: - -- ``width`` Table width in percent -- ``bgColor`` Background color, e.g. '9966CC' -- ``border(Top|Right|Bottom|Left)Size`` Border size in twips -- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC' -- ``cellMargin(Top|Right|Bottom|Left)`` Cell margin in twips - -Row styles: - -- ``tblHeader`` Repeat table row on every new page, *true* or *false* -- ``cantSplit`` Table row cannot break across pages, *true* or *false* -- ``exactHeight`` Row height is exact or at least - -Cell styles: - -- ``width`` Cell width in twips -- ``valign`` Vertical alignment, *top*, *center*, *both*, *bottom* -- ``textDirection`` Direction of text -- ``bgColor`` Background color, e.g. '9966CC' -- ``border(Top|Right|Bottom|Left)Size`` Border size in twips -- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC' -- ``gridSpan`` Number of columns spanned -- ``vMerge`` *restart* or *continue* +For available styling options see :ref:`table-style`. Cell span ~~~~~~~~~ -You can span a cell on multiple columns by using ``gridSpan`` or -multiple rows by using ``vMerge``. +You can span a cell on multiple columns by using ``gridSpan`` or multiple rows by using ``vMerge``. .. code-block:: php @@ -338,15 +226,14 @@ See ``Sample_09_Tables.php`` for more code sample. Images ------ -To add an image, use the ``addImage`` method to sections, headers, -footers, textruns, or table cells. +To add an image, use the ``addImage`` method to sections, headers, footers, textruns, or table cells. .. code-block:: php $section->addImage($src, [$style]); -- source String path to a local image or URL of a remote image -- styles Array fo styles for the image. See below. +- ``$src``. String path to a local image or URL of a remote image. +- ``$style``. See :ref:`image-style`. Examples: @@ -356,10 +243,10 @@ Examples: $section->addImage( 'mars.jpg', array( - 'width' => 100, - 'height' => 100, - 'marginTop' => -1, - 'marginLeft' => -1, + 'width' => 100, + 'height' => 100, + 'marginTop' => -1, + 'marginLeft' => -1, 'wrappingStyle' => 'behind' ) ); @@ -368,19 +255,6 @@ Examples: $textrun = $section->addTextRun(); $textrun->addImage('http://php.net/logo.jpg'); -Image styles -~~~~~~~~~~~~ - -Available image styles: - -- ``width`` Width in pixels -- ``height`` Height in pixels -- ``align`` Image alignment, *left*, *right*, or *center* -- ``marginTop`` Top margin in inches, can be negative -- ``marginLeft`` Left margin in inches, can be negative -- ``wrappingStyle`` Wrapping style, *inline*, *square*, *tight*, - *behind*, or *infront* - Watermarks ~~~~~~~~~~ @@ -408,25 +282,22 @@ Table of contents ----------------- To add a table of contents (TOC), you can use the ``addTOC`` method. -Your TOC can only be generated if you have add at least one title (See -"Titles"). +Your TOC can only be generated if you have add at least one title (See "Titles"). .. code-block:: php $section->addTOC([$fontStyle], [$tocStyle], [$minDepth], [$maxDepth]); -- ``$fontStyle``: See font style section -- ``$tocStyle``: See available options below -- ``$minDepth``: Minimum depth of header to be shown. Default 1 -- ``$maxDepth``: Maximum depth of header to be shown. Default 9 +- ``$fontStyle``. See font style section. +- ``$tocStyle``. See available options below. +- ``$minDepth``. Minimum depth of header to be shown. Default 1. +- ``$maxDepth``. Maximum depth of header to be shown. Default 9. Options for ``$tocStyle``: -- ``tabLeader`` Fill type between the title text and the page number. - Use the defined constants in PHPWord\_Style\_TOC. -- ``tabPos`` The position of the tab where the page number appears in - twips. -- ``indent`` The indent factor of the titles in twips. +- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in PHPWord\_Style\_TOC. +- ``tabPos``. The position of the tab where the page number appears in twips. +- ``indent``. The indent factor of the titles in twips. Footnotes & endnotes -------------------- @@ -468,17 +339,16 @@ redefine by ``addFontStyle`` method. Default value for this style is Checkboxes ---------- -Checkbox elements can be added to sections or table cells by using -``addCheckBox``. +Checkbox elements can be added to sections or table cells by using ``addCheckBox``. .. code-block:: php $section->addCheckBox($name, $text, [$fontStyle], [$paragraphStyle]) -- ``$name`` Name of the check box. -- ``$text`` Text following the check box -- ``$fontStyle`` See "Font style" section. -- ``$paragraphStyle`` See "Paragraph style" section. +- ``$name``. Name of the check box. +- ``$text``. Text to be displayed in the document. +- ``$fontStyle``. See :ref:`font-style`. +- ``$paragraphStyle``. See :ref:`paragraph-style`. Textboxes --------- @@ -502,11 +372,11 @@ Line elements can be added to sections by using ``addLine``. Available line style attributes: -- ``weight`` Line width in twips -- ``color`` Defines the color of stroke -- ``dash`` Line types: dash, rounddot, squaredot, dashdot, longdash, longdashdot, longdashdotdot -- ``beginArrow`` Start type of arrow: block, open, classic, diamond, oval -- ``endArrow`` End type of arrow: block, open, classic, diamond, ovel -- ``width`` Line-object width in pt -- ``height`` Line-object height in pt -- ``flip`` Flip the line element: true, false +- ``weight``. Line width in twips. +- ``color``. Defines the color of stroke. +- ``dash``. Line types: dash, rounddot, squaredot, dashdot, longdash, longdashdot, longdashdotdot. +- ``beginArrow``. Start type of arrow: block, open, classic, diamond, oval. +- ``endArrow``. End type of arrow: block, open, classic, diamond, oval. +- ``width``. Line-object width in pt. +- ``height``. Line-object height in pt. +- ``flip``. Flip the line element: true, false. \ No newline at end of file diff --git a/docs/faq.rst b/docs/faq.rst index 79652ae025..19fca1057f 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -3,11 +3,9 @@ Frequently asked questions ========================== -How contribute to PHPWord ? ---------------------------- - -- Improve the documentation (`Sphinx Format `__) - +How contribute to PHPWord? +-------------------------- +- Improve the documentation (`Sphinx Format `__) Is this the same with PHPWord that I found in CodePlex? ------------------------------------------------------- diff --git a/docs/general.rst b/docs/general.rst index 34d3af2477..27d0448abd 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -13,8 +13,7 @@ folder `__. .. code-block:: php `__. $section = $phpWord->addSection(); // Adding Text element to the Section having font styled by default... $section->addText( - htmlspecialchars( - '"Learn from yesterday, live for today, hope for tomorrow. ' - . 'The important thing is not to stop questioning." ' - . '(Albert Einstein)' - ) + '"Learn from yesterday, live for today, hope for tomorrow. ' + . 'The important thing is not to stop questioning." ' + . '(Albert Einstein)' ); /* @@ -41,11 +38,9 @@ folder `__. // Adding Text element with font customized inline... $section->addText( - htmlspecialchars( - '"Great achievement is usually born of great sacrifice, ' - . 'and is never the result of selfishness." ' - . '(Napoleon Hill)' - ), + '"Great achievement is usually born of great sacrifice, ' + . 'and is never the result of selfishness." ' + . '(Napoleon Hill)', array('name' => 'Tahoma', 'size' => 10) ); @@ -56,11 +51,9 @@ folder `__. array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true) ); $section->addText( - htmlspecialchars( - '"The greatest accomplishment is not in never falling, ' - . 'but in rising again after you fall." ' - . '(Vince Lombardi)' - ), + '"The greatest accomplishment is not in never falling, ' + . 'but in rising again after you fall." ' + . '(Vince Lombardi)', $fontStyleName ); @@ -69,9 +62,7 @@ folder `__. $fontStyle->setBold(true); $fontStyle->setName('Tahoma'); $fontStyle->setSize(13); - $myTextElement = $section->addText( - htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)') - ); + $myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)'); $myTextElement->setFontStyle($fontStyle); // Saving the document as OOXML file... @@ -125,8 +116,22 @@ included with PHPWord. \PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP); +Output escaping +~~~~~~~~~~~~~~~ + +Writing documents of some formats, especially XML-based, requires correct output escaping. +Without it your document may become broken when you put special characters like ampersand, quotes, and others in it. + +Escaping can be performed in two ways: outside of the library by a software developer and inside of the library by built-in mechanism. +By default, the built-in mechanism is disabled for backward compatibility with versions prior to v0.13.0. +To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord configuration file or use the following instruction at runtime: + +.. code-block:: php + + \PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); + Default font ------------- +~~~~~~~~~~~~ By default, every text appears in Arial 10 point. You can alter the default font by using the following two functions: @@ -178,4 +183,3 @@ points to twips. $sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5)); // 2 cm right margin $sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2)); - diff --git a/docs/installing.rst b/docs/installing.rst index 6599590460..9593484a55 100644 --- a/docs/installing.rst +++ b/docs/installing.rst @@ -8,41 +8,40 @@ Requirements Mandatory: -- PHP 5.3+ -- PHP `Zip `__ extension -- PHP `XML - Parser `__ - extension +- PHP 5.3.3+ +- `XML Parser `__ extension +- `Zend\\Escaper `__ component +- Zend\\Stdlib component +- `Zend\\Validator `__ component -Optional PHP extensions: +Optional: -- `GD `__ -- `XMLWriter `__ -- `XSL `__ +- `Zip `__ extension +- `GD `__ extension +- `XMLWriter `__ extension +- `XSL `__ extension +- `dompdf `__ library Installation ------------ -There are two ways to install PHPWord, i.e. via -`Composer `__ or manually by downloading the -library. +PHPWord is installed via `Composer `__. +You just need to `add dependency `__ on PHPWord into your package. -Using Composer -~~~~~~~~~~~~~~ - -To install via Composer, add the following lines to your -``composer.json``: +Example: .. code-block:: json { "require": { - "phpoffice/phpword": "dev-master" + "phpoffice/phpword": "v0.13.*" } } If you are a developer or if you want to help us with testing then fetch the latest branch for developers. -Notice: All contributions must be done against the developer branch. +Notice: all contributions must be done against the developer branch. + +Example: .. code-block:: json @@ -53,28 +52,6 @@ Notice: All contributions must be done against the developer branch. } -Manual install -~~~~~~~~~~~~~~ - -To install manually, you change to the webserver directory of your file system . -Then you have 2 possibilities. - - 1. `download PHPWord package from github `__. - Extract the package and put the contents to your machine. - 2. Alternatively you can use Git to install it: - .. code-block:: console - - git clone https://github.com/PHPOffice/PHPWord.git - -To use the library, include ``src/PhpWord/Autoloader.php`` in your PHP script and -invoke ``Autoloader::register``. - -.. code-block:: php - - require_once '/path/to/src/PhpWord/Autoloader.php'; - \PhpOffice\PhpWord\Autoloader::register(); - - Using samples ------------- diff --git a/docs/intro.rst b/docs/intro.rst index d2decd7c94..d1c791cf67 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -24,35 +24,34 @@ Documentation `__. Features -------- -- Set document properties, e.g. title, subject, and creator. -- Create document sections with different settings, e.g. - portrait/landscape, page size, and page numbering -- Create header and footer for each sections -- Set default font type, font size, and paragraph style -- Use UTF-8 and East Asia fonts/characters -- Define custom font styles (e.g. bold, italic, color) and paragraph - styles (e.g. centered, multicolumns, spacing) either as named style - or inline in text -- Insert paragraphs, either as a simple text or complex one (a text - run) that contains other elements -- Insert titles (headers) and table of contents -- Insert text breaks and page breaks -- Insert right-to-left text -- Insert and format images, either local, remote, or as page watermarks -- Insert binary OLE Objects such as Excel or Visio -- Insert and format table with customized properties for each rows - (e.g. repeat as header row) and cells (e.g. background color, - rowspan, colspan) -- Insert list items as bulleted, numbered, or multilevel -- Insert hyperlinks -- Insert footnotes and endnotes -- Insert drawing shapes (arc, curve, line, polyline, rect, oval) -- Insert charts (pie, doughnut, bar, line, area, scatter, radar) -- Insert form fields (textinput, checkbox, and dropdown) -- Create document from templates -- Use XSL 1.0 style sheets to transform main document part of OOXML - template -- ... and many more features on progress +- Set document properties, e.g. title, subject, and creator. +- Create document sections with different settings, e.g. + portrait/landscape, page size, and page numbering +- Create header and footer for each sections +- Set default font type, font size, and paragraph style +- Use UTF-8 and East Asia fonts/characters +- Define custom font styles (e.g. bold, italic, color) and paragraph + styles (e.g. centered, multicolumns, spacing) either as named style + or inline in text +- Insert paragraphs, either as a simple text or complex one (a text + run) that contains other elements +- Insert titles (headers) and table of contents +- Insert text breaks and page breaks +- Insert right-to-left text +- Insert and format images, either local, remote, or as page watermarks +- Insert binary OLE Objects such as Excel or Visio +- Insert and format table with customized properties for each rows + (e.g. repeat as header row) and cells (e.g. background color, + rowspan, colspan) +- Insert list items as bulleted, numbered, or multilevel +- Insert hyperlinks +- Insert footnotes and endnotes +- Insert drawing shapes (arc, curve, line, polyline, rect, oval) +- Insert charts (pie, doughnut, bar, line, area, scatter, radar) +- Insert form fields (textinput, checkbox, and dropdown) +- Create document from templates +- Use XSL 1.0 style sheets to transform headers, main document part, and footers of an OOXML template +- ... and many more features on progress File formats ------------ @@ -63,7 +62,7 @@ Writers ~~~~~~~ +---------------------------+----------------------+--------+-------+-------+--------+-------+ -| Features | | DOCX | ODT | RTF | HTML | PDF | +| Features | | OOXML | ODF | RTF | HTML | PDF | +===========================+======================+========+=======+=======+========+=======+ | **Document Properties** | Standard | ✓ | ✓ | ✓ | ✓ | ✓ | +---------------------------+----------------------+--------+-------+-------+--------+-------+ @@ -122,7 +121,7 @@ Readers ~~~~~~~ +---------------------------+----------------------+--------+-------+-------+-------+-------+ -| Features | | DOCX | DOC | ODT | RTF | HTML | +| Features | | OOXML | DOC | ODF | RTF | HTML | +===========================+======================+========+=======+=======+=======+=======+ | **Document Properties** | Standard | ✓ | | | | | +---------------------------+----------------------+--------+-------+-------+-------+-------+ @@ -183,13 +182,13 @@ Contributing We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute. -- Read `our contributing - guide `__. -- `Fork us `__ and `request - a pull `__ to the - `develop `__ - branch. -- Submit `bug reports or feature - requests `__ to GitHub. -- Follow `@PHPWord `__ and - `@PHPOffice `__ on Twitter. +- Read `our contributing + guide `__. +- `Fork us `__ and `request + a pull `__ to the + `develop `__ + branch. +- Submit `bug reports or feature + requests `__ to GitHub. +- Follow `@PHPWord `__ and + `@PHPOffice `__ on Twitter. diff --git a/docs/recipes.rst b/docs/recipes.rst index 0be6b4e06a..5042cdedc6 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -6,8 +6,7 @@ Recipes Create float left image ----------------------- -Use absolute positioning relative to margin horizontally and to line -vertically. +Use absolute positioning relative to margin horizontally and to line vertically. .. code-block:: php diff --git a/docs/references.rst b/docs/references.rst index 20aa1ed061..9c4e06a809 100644 --- a/docs/references.rst +++ b/docs/references.rst @@ -6,25 +6,23 @@ References ISO/IEC 29500, Third edition, 2012-09-01 --------------------- -- `Part 1: Fundamentals and Markup Language Reference - `__ -- `Part 2: Open Packaging Conventions - `__ -- `Part 3: Markup Compatibility and Extensibility - `__ -- `Part 4: Transitional Migration Features - `__ +- `Part 1: Fundamentals and Markup Language Reference + `__ +- `Part 2: Open Packaging Conventions + `__ +- `Part 3: Markup Compatibility and Extensibility + `__ +- `Part 4: Transitional Migration Features + `__ Formal specifications --------------------- -- `Oasis OpenDocument Standard Version - 1.2 `__ -- `Rich Text Format (RTF) Specification, version - 1.9.1 `__ +- `Oasis OpenDocument Standard Version 1.2 `__ +- `Rich Text Format (RTF) Specification, version 1.9.1 `__ Other resources --------------- -- `DocumentFormat.OpenXml.Wordprocessing Namespace on - MSDN `__ +- `DocumentFormat.OpenXml.Wordprocessing Namespace on + MSDN `__ diff --git a/docs/src/documentation.md b/docs/src/documentation.md deleted file mode 100644 index 1a59e94230..0000000000 --- a/docs/src/documentation.md +++ /dev/null @@ -1,1134 +0,0 @@ - -# Contents - -- [Introduction](#introduction) - - [Features](#features) - - [File formats](#file-formats) -- [Installing/configuring](#installing-configuring) - - [Requirements](#requirements) - - [Installation](#installation) - - [Using samples](#using-samples) -- [General usage](#general-usage) - - [Basic example](#basic-example) - - [Settings](#settings) - - [Default font](#default-font) - - [Document properties](#document-properties) - - [Measurement units](#measurement-units) -- [Containers](#containers) - - [Sections](#sections) - - [Headers](#headers) - - [Footers](#footers) - - [Other containers](#other-containers) -- [Elements](#elements) - - [Texts](#texts) - - [Breaks](#breaks) - - [Lists](#lists) - - [Tables](#tables) - - [Images](#images) - - [Objects](#objects) - - [Table of contents](#table-of-contents) - - [Footnotes & endnotes](#footnotes-endnotes) - - [Checkboxes](#checkboxes) - - [Textboxes](#textboxes) - - [Fields](#fields) - - [Lines](#lines) - - [Shapes](#shapes) - - [Charts](#charts) - - [FormFields](#form-fields) -- [Styles](#styles) - - [Section](#section) - - [Font](#font) - - [Paragraph](#paragraph) - - [Table](#table) -- [Templates processing](#templates-processing) -- [Writers & readers](#writers-readers) - - [OOXML](#ooxml) - - [OpenDocument](#opendocument) - - [RTF](#rtf) - - [HTML](#html) - - [PDF](#pdf) -- [Recipes](#recipes) -- [Frequently asked questions](#frequently-asked-questions) -- [References](#references) - -# Introduction - -PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF). - -PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading this Developers' Documentation and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/). - -## Features - -- Set document properties, e.g. title, subject, and creator. -- Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering -- Create header and footer for each sections -- Set default font type, font size, and paragraph style -- Use UTF-8 and East Asia fonts/characters -- Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text -- Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements -- Insert titles (headers) and table of contents -- Insert text breaks and page breaks -- Insert and format images, either local, remote, or as page watermarks -- Insert binary OLE Objects such as Excel or Visio -- Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan) -- Insert list items as bulleted, numbered, or multilevel -- Insert hyperlinks -- Insert footnotes and endnotes -- Insert drawing shapes (arc, curve, line, polyline, rect, oval) -- Insert charts (pie, doughnut, bar, line, area, scatter, radar) -- Insert form fields (textinput, checkbox, and dropdown) -- Create document from templates -- Use XSL 1.0 style sheets to transform main document part of OOXML template -- ... and many more features on progress - -## File formats - -Below are the supported features for each file formats. - -### Writers - -| Features | | DOCX | ODT | RTF | HTML | PDF | -|-------------------------|--------------------|------|-----|-----|------|-----| -| **Document Properties** | Standard | ✓ | ✓ | ✓ | ✓ | | -| | Custom | ✓ | ✓ | | | | -| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ | -| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ | -| | Title | ✓ | ✓ | | ✓ | ✓ | -| | Link | ✓ | ✓ | ✓ | ✓ | ✓ | -| | Preserve Text | ✓ | | | | | -| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ | -| | Page Break | ✓ | | ✓ | | | -| | List | ✓ | | | | | -| | Table | ✓ | ✓ | ✓ | ✓ | ✓ | -| | Image | ✓ | ✓ | ✓ | ✓ | | -| | Object | ✓ | | | | | -| | Watermark | ✓ | | | | | -| | Table of Contents | ✓ | | | | | -| | Header | ✓ | | | | | -| | Footer | ✓ | | | | | -| | Footnote | ✓ | | | ✓ | | -| | Endnote | ✓ | | | ✓ | | -| **Graphs** | 2D basic graphs | ✓ | | | | | -| | 2D advanced graphs | | | | | | -| | 3D graphs | ✓ | | | | | -| **Math** | OMML support | | | | | | -| | MathML support | | | | | | -| **Bonus** | Encryption | | | | | | -| | Protection | | | | | | - -### Readers - -| Features | | DOCX | ODT | RTF | HTML| -|-------------------------|--------------------|------|-----|-----|-----| -| **Document Properties** | Standard | ✓ | | | | -| | Custom | ✓ | | | | -| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | -| | Text Run | ✓ | | | | -| | Title | ✓ | ✓ | | | -| | Link | ✓ | | | | -| | Preserve Text | ✓ | | | | -| | Text Break | ✓ | | | | -| | Page Break | ✓ | | | | -| | List | ✓ | ✓ | | ✓ | -| | Table | ✓ | | | ✓ | -| | Image | ✓ | | | | -| | Object | | | | | -| | Watermark | | | | | -| | Table of Contents | | | | | -| | Header | ✓ | | | | -| | Footer | ✓ | | | | -| | Footnote | ✓ | | | | -| | Endnote | ✓ | | | | -| **Graphs** | 2D basic graphs | | | | | -| | 2D advanced graphs | | | | | -| | 3D graphs | | | | | -| **Math** | OMML support | | | | | -| | MathML support | | | | | -| **Bonus** | Encryption | | | | | -| | Protection | | | | | - -## Contributing - -We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute: - -- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md) -- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch -- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub -- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter - -# Installing/configuring - -## Requirements - -Mandatory: - -- PHP 5.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 - -Optional PHP extensions: - -- [GD](http://php.net/manual/en/book.image.php) -- [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) -- [XSL](http://php.net/manual/en/book.xsl.php) - -## Installation - -There are two ways to install PHPWord, i.e. via [Composer](http://getcomposer.org/) or manually by downloading the library. - -### Using Composer - -To install via Composer, add the following lines to your `composer.json`: - -```json -{ - "require": { - "phpoffice/phpword": "dev-master" - } -} -``` - -### Manual install - -To install manually, [download PHPWord package from github](https://github.com/PHPOffice/PHPWord/archive/master.zip). Extract the package and put the contents to your machine. To use the library, include `src/PhpWord/Autoloader.php` in your script and invoke `Autoloader::register`. - -```php -require_once '/path/to/src/PhpWord/Autoloader.php'; -\PhpOffice\PhpWord\Autoloader::register(); -``` - -## Using samples - -After installation, you can browse and use the samples that we've provided, either by command line or using browser. If you can access your PHPWord library folder using browser, point your browser to the `samples` folder, e.g. `http://localhost/PhpWord/samples/`. - -# General usage - -## Basic example - -The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](https://github.com/PHPOffice/PHPWord/tree/master/samples/). - -```php -addSection(); -// Adding Text element to the Section having font styled by default... -$section->addText( - htmlspecialchars( - '"Learn from yesterday, live for today, hope for tomorrow. ' - . 'The important thing is not to stop questioning." ' - . '(Albert Einstein)' - ) -); - -/* - * Note: it's possible to customize font style of the Text element you add in three ways: - * - inline; - * - using named font style (new font style object will be implicitly created); - * - using explicitly created font style object. - */ - -// Adding Text element with font customized inline... -$section->addText( - htmlspecialchars( - '"Great achievement is usually born of great sacrifice, ' - . 'and is never the result of selfishness." ' - . '(Napoleon Hill)' - ), - array('name' => 'Tahoma', 'size' => 10) -); - -// Adding Text element with font customized using named font style... -$fontStyleName = 'oneUserDefinedStyle'; -$phpWord->addFontStyle( - $fontStyleName, - array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true) -); -$section->addText( - htmlspecialchars( - '"The greatest accomplishment is not in never falling, ' - . 'but in rising again after you fall." ' - . '(Vince Lombardi)' - ), - $fontStyleName -); - -// Adding Text element with font customized using explicitly created font style object... -$fontStyle = new \PhpOffice\PhpWord\Style\Font(); -$fontStyle->setBold(true); -$fontStyle->setName('Tahoma'); -$fontStyle->setSize(13); -$myTextElement = $section->addText( - htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)') -); -$myTextElement->setFontStyle($fontStyle); - -// Saving the document as OOXML file... -$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); -$objWriter->save('helloWorld.docx'); - -// Saving the document as ODF file... -$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText'); -$objWriter->save('helloWorld.odt'); - -// Saving the document as HTML file... -$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML'); -$objWriter->save('helloWorld.html'); - -/* Note: we skip RTF, because it's not XML-based and requires a different example. */ -/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */ -``` - -## Settings - -The `PhpOffice\PhpWord\Settings` class provides some options that will affect the behavior of PHPWord. Below are the options. - -### XML Writer compatibility - -This option sets [XMLWriter::setIndent](http://www.php.net/manual/en/function.xmlwriter-set-indent.php) and [XMLWriter::setIndentString](http://www.php.net/manual/en/function.xmlwriter-set-indent-string.php). The default value of this option is `true` (compatible), which is [required for OpenOffice](https://github.com/PHPOffice/PHPWord/issues/103) to render OOXML document correctly. You can set this option to `false` during development to make the resulting XML file easier to read. - -```php -\PhpOffice\PhpWord\Settings::setCompatibility(false); -``` - -### Zip class - -By default, PHPWord uses PHP [ZipArchive](http://php.net/manual/en/book.zip.php) to read or write ZIP compressed archive and the files inside them. If you can't have ZipArchive installed on your server, you can use pure PHP library alternative, [PCLZip](http://www.phpconcept.net/pclzip/), which included with PHPWord. - -```php -\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP); -``` - -## Default font - -By default, every text appears in Arial 10 point. You can alter the default font by using the following two functions: - -```php -$phpWord->setDefaultFontName('Times New Roman'); -$phpWord->setDefaultFontSize(12); -``` - -## Document information - -You can set the document information such as title, creator, and company name. Use the following functions: - -```php -$properties = $phpWord->getDocInfo(); -$properties->setCreator('My name'); -$properties->setCompany('My factory'); -$properties->setTitle('My title'); -$properties->setDescription('My description'); -$properties->setCategory('My category'); -$properties->setLastModifiedBy('My name'); -$properties->setCreated(mktime(0, 0, 0, 3, 12, 2014)); -$properties->setModified(mktime(0, 0, 0, 3, 14, 2014)); -$properties->setSubject('My subject'); -$properties->setKeywords('my, key, word'); -``` - -## Measurement units - -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. - -```php -// Paragraph with 6 points space after -$phpWord->addParagraphStyle('My Style', array( - 'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(6)) -); - -$section = $phpWord->addSection(); -$sectionStyle = $section->getStyle(); -// half inch left margin -$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5)); -// 2 cm right margin -$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2)); -``` - -# Containers - -Containers are objects where you can put elements (texts, lists, tables, etc). There are 3 main containers, i.e. sections, headers, and footers. There are 3 elements that can also act as containers, i.e. textruns, table cells, and footnotes. - -## Sections - -Every visible element in word is placed inside of a section. To create a section, use the following code: - -```php -$section = $phpWord->addSection($sectionStyle); -``` - -The `$sectionStyle` is an optional associative array that sets the section. Example: - -```php -$sectionStyle = array( - 'orientation' => 'landscape', - 'marginTop' => 600, - 'colsNum' => 2, -); -``` - - -### Page number - -You can change a section page number by using the `pageNumberingStart` style of the section. - -```php -// Method 1 -$section = $phpWord->addSection(array('pageNumberingStart' => 1)); - -// Method 2 -$section = $phpWord->addSection(); -$section->getStyle()->setPageNumberingStart(1); -``` - -### Multicolumn - -You can change a section layout to multicolumn (like in a newspaper) by using the `breakType` and `colsNum` style of the section. - -```php -// Method 1 -$section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2)); - -// Method 2 -$section = $phpWord->addSection(); -$section->getStyle()->setBreakType('continuous'); -$section->getStyle()->setColsNum(2); -``` - -### Line numbering - -You can apply line numbering to a section by using the `lineNumbering` style of the section. - -```php -// Method 1 -$section = $phpWord->addSection(array('lineNumbering' => array())); - -// Method 2 -$section = $phpWord->addSection(); -$section->getStyle()->setLineNumbering(array()); -``` - -Below are the properties of the line numbering style. - -- `start` Line numbering starting value -- `increment` Line number increments -- `distance` Distance between text and line numbering in twip -- `restart` Line numbering restart setting continuous|newPage|newSection - -## Headers - -Each section can have its own header reference. To create a header use the `addHeader` method: - -```php -$header = $section->addHeader(); -``` - -Be sure to save the result in a local object. You can use all elements that are available for the footer. See "Footer" section for detail. Additionally, only inside of the header reference you can add watermarks or background pictures. See "Watermarks" section. - -## Footers - -Each section can have its own footer reference. To create a footer, use the `addFooter` method: - -```php -$footer = $section->addFooter(); -``` - -Be sure to save the result in a local object to add elements to a footer. You can add the following elements to footers: - -- Texts `addText` and `createTextrun` -- Text breaks -- Images -- Tables -- Preserve text - -See the "Elements" section for the detail of each elements. - -## Other containers - -Textruns, table cells, and footnotes are elements that can also act as containers. See the corresponding "Elements" section for the detail of each elements. - -# Elements - -Below are the matrix of element availability in each container. The column shows the containers while the rows lists the elements. - -| Num | Element | Section | Header | Footer | Cell | Text Run | Footnote | -|-----|---------------|---------|--------|--------|------|----------|----------| -| 1 | Text | v | v | v | v | v | v | -| 2 | Text Run | v | v | v | v | - | - | -| 3 | Link | v | v | v | v | v | v | -| 4 | Title | v | ? | ? | ? | ? | ? | -| 5 | Preserve Text | ? | v | v | v* | - | - | -| 6 | Text Break | v | v | v | v | v | v | -| 7 | Page Break | v | - | - | - | - | - | -| 8 | List | v | v | v | v | - | - | -| 9 | Table | v | v | v | v | - | - | -| 10 | Image | v | v | v | v | v | v | -| 11 | Watermark | - | v | - | - | - | - | -| 12 | Object | v | v | v | v | v | v | -| 13 | TOC | v | - | - | - | - | - | -| 14 | Footnote | v | - | - | v** | v** | - | -| 15 | Endnote | v | - | - | v** | v** | - | -| 16 | CheckBox | v | v | v | v | - | - | -| 17 | TextBox | v | v | v | v | - | - | -| 18 | Field | v | v | v | v | v | v | -| 19 | Line | v | v | v | v | v | v | -| 20 | Shape | v | v | v | v | v | v | -| 21 | Chart | v | - | - | - | - | - | -| 22 | Form Fields | v | v | v | v | v | v | - -Legend: - -- `v` Available -- `v*` Available only when inside header/footer -- `v**` Available only when inside section -- `-` Not available -- `?` Should be available - -## Texts - -Text can be added by using `addText` and `addTextRun` method. `addText` is used for creating simple paragraphs that only contain texts with the same style. `addTextRun` is used for creating complex paragraphs that contain text with different style (some bold, other italics, etc) or other elements, e.g. images or links. The syntaxes are as follow: - -```php -$section->addText($text, [$fontStyle], [$paragraphStyle]); -$textrun = $section->addTextRun([$paragraphStyle]); -``` - -You can use the `$fontStyle` and `$paragraphStyle` variable to define text formatting. There are 2 options to style the inserted text elements, i.e. inline style by using array or defined style by adding style definition. - -Inline style examples: - -```php -$fontStyle = array('name' => 'Times New Roman', 'size' => 9); -$paragraphStyle = array('align' => 'both'); -$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle); - -$textrun = $section->addTextRun(); -$textrun->addText('I am bold', array('bold' => true)); -$textrun->addText('I am italic', array('italic' => true)); -$textrun->addText('I am colored', array('color' => 'AACC00')); -``` - -Defined style examples: - -```php -$fontStyle = array('color' => '006699', 'size' => 18, 'bold' => true); -$phpWord->addFontStyle('fStyle', $fontStyle); -$text = $section->addText('Hello world!', 'fStyle'); - -$paragraphStyle = array('align' => 'center'); -$phpWord->addParagraphStyle('pStyle', $paragraphStyle); -$text = $section->addText('Hello world!', 'pStyle'); -``` - -### Titles - -If you want to structure your document or build table of contents, you need titles or headings. To add a title to the document, use the `addTitleStyle` and `addTitle` method. - -```php -$phpWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]); -$section->addTitle($text, [$depth]); -``` - -Its necessary to add a title style to your document because otherwise the title won't be detected as a real title. - -### Links - -You can add Hyperlinks to the document by using the function addLink: - -```php -$section->addLink($linkSrc, [$linkName], [$fontStyle], [$paragraphStyle]); -``` - -- `$linkSrc` The URL of the link. -- `$linkName` Placeholder of the URL that appears in the document. -- `$fontStyle` See "Font style" section. -- `$paragraphStyle` See "Paragraph style" section. - -### Preserve texts - -The `addPreserveText` method is used to add a page number or page count to headers or footers. - -```php -$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.'); -``` - -## Breaks - -### Text breaks - -Text breaks are empty new lines. To add text breaks, use the following syntax. All paramaters are optional. - -```php -$section->addTextBreak([$breakCount], [$fontStyle], [$paragraphStyle]); -``` - -- `$breakCount` How many lines -- `$fontStyle` See "Font style" section. -- `$paragraphStyle` See "Paragraph style" section. - -### Page breaks - -There are two ways to insert a page breaks, using the `addPageBreak` method or using the `pageBreakBefore` style of paragraph. - -```php -$section->addPageBreak(); -``` - -## Lists - -To add a list item use the function `addListItem`. - -Basic usage: - -```php -$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]); -``` - -Parameters: - -- `$text` Text that appears in the document. -- `$depth` Depth of list item. -- `$fontStyle` See "Font style" section. -- `$listStyle` List style of the current element TYPE\_NUMBER, TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in PHPWord\_Style\_ListItem. -- `$paragraphStyle` See "Paragraph style" section. - -Advanced usage: - -You can also create your own numbering style by changing the `$listStyle` parameter with the name of your numbering style. - -```php -$phpWord->addNumberingStyle( - 'multilevel', - array('type' => 'multilevel', 'levels' => array( - array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360), - array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720), - ) - ) -); -$section->addListItem('List Item I', 0, null, 'multilevel'); -$section->addListItem('List Item I.a', 1, null, 'multilevel'); -$section->addListItem('List Item I.b', 1, null, 'multilevel'); -$section->addListItem('List Item II', 0, null, 'multilevel'); -``` - -## Tables - -To add tables, rows, and cells, use the `addTable`, `addRow`, and `addCell` methods: - -```php -$table = $section->addTable([$tableStyle]); -$table->addRow([$height], [$rowStyle]); -$cell = $table->addCell($width, [$cellStyle]); -``` - -Table style can be defined with `addTableStyle`: - -```php -$tableStyle = array( - 'borderColor' => '006699', - 'borderSize' => 6, - 'cellMargin' => 50 -); -$firstRowStyle = array('bgColor' => '66BBFF'); -$phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle); -$table = $section->addTable('myTable'); -``` - -### Cell span - -You can span a cell on multiple columns by using `gridSpan` or multiple rows by using `vMerge`. - -```php -$cell = $table->addCell(200); -$cell->getStyle()->setGridSpan(5); -``` - -See `Sample_09_Tables.php` for more code sample. - -## Images - -To add an image, use the `addImage` method to sections, headers, footers, textruns, or table cells. - -```php -$section->addImage($src, [$style]); -``` - -- source String path to a local image or URL of a remote image -- styles Array fo styles for the image. See below. - -Examples: - -```php -$section = $phpWord->addSection(); -$section->addImage( - 'mars.jpg', - array( - 'width' => 100, - 'height' => 100, - 'marginTop' => -1, - 'marginLeft' => -1, - 'wrappingStyle' => 'behind' - ) -); -$footer = $section->addFooter(); -$footer->addImage('http://example.com/image.php'); -$textrun = $section->addTextRun(); -$textrun->addImage('http://php.net/logo.jpg'); -``` - -### Watermarks - -To add a watermark (or page background image), your section needs a header reference. After creating a header, you can use the `addWatermark` method to add a watermark. - -```php -$section = $phpWord->addSection(); -$header = $section->addHeader(); -$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); -``` - -## Objects - -You can add OLE embeddings, such as Excel spreadsheets or PowerPoint presentations to the document by using `addObject` method. - -```php -$section->addObject($src, [$style]); -``` - -## Table of contents - -To add a table of contents (TOC), you can use the `addTOC` method. Your TOC can only be generated if you have add at least one title (See "Titles"). - -```php -$section->addTOC([$fontStyle], [$tocStyle], [$minDepth], [$maxDepth]); -``` - -- `$fontStyle`: See font style section -- `$tocStyle`: See available options below -- `$minDepth`: Minimum depth of header to be shown. Default 1 -- `$maxDepth`: Maximum depth of header to be shown. Default 9 - -Options for `$tocStyle`: - -- `tabLeader` Fill type between the title text and the page number. Use the defined constants in PHPWord\_Style\_TOC. -- `tabPos` The position of the tab where the page number appears in twips. -- `indent` The indent factor of the titles in twips. - -## Footnotes & endnotes - -You can create footnotes with `addFootnote` and endnotes with `addEndnote` in texts or textruns, but it's recommended to use textrun to have better layout. You can use `addText`, `addLink`, `addTextBreak`, `addImage`, `addObject` on footnotes and endnotes. - -On textrun: - -```php -$textrun = $section->addTextRun(); -$textrun->addText('Lead text.'); -$footnote = $textrun->addFootnote(); -$footnote->addText('Footnote text can have '); -$footnote->addLink('http://test.com', 'links'); -$footnote->addText('.'); -$footnote->addTextBreak(); -$footnote->addText('And text break.'); -$textrun->addText('Trailing text.'); -$endnote = $textrun->addEndnote(); -$endnote->addText('Endnote put at the end'); -``` - -On text: - -```php -$section->addText('Lead text.'); -$footnote = $section->addFootnote(); -$footnote->addText('Footnote text.'); -``` - -The footnote reference number will be displayed with decimal number starting from 1. This number use `FooterReference` style which you can redefine by `addFontStyle` method. Default value for this style is `array('superScript' => true)`; - -## Checkboxes - -Checkbox elements can be added to sections or table cells by using `addCheckBox`. - -```php -$section->addCheckBox($name, $text, [$fontStyle], [$paragraphStyle]) -``` - -- `$name` Name of the check box. -- `$text` Text following the check box -- `$fontStyle` See "Font style" section. -- `$paragraphStyle` See "Paragraph style" section. - -## Textboxes - -To be completed. - -## Fields - -To be completed. - -## Lines - -To be completed. - -## Shapes - -To be completed. - -## Charts - -To be completed. - -## Form fields - -To be completed. - -# Styles - -## Section - -Below are the available styles for section: - -- `orientation` Page orientation, i.e. 'portrait' (default) or 'landscape' -- `marginTop` Page margin top in twips -- `marginLeft` Page margin left in twips -- `marginRight` Page margin right in twips -- `marginBottom` Page margin bottom in twips -- `borderTopSize` Border top size in twips -- `borderTopColor` Border top color -- `borderLeftSize` Border left size in twips -- `borderLeftColor` Border left color -- `borderRightSize` Border right size in twips -- `borderRightColor` Border right color -- `borderBottomSize` Border bottom size in twips -- `borderBottomColor` Border bottom color -- `headerHeight` Spacing to top of header -- `footerHeight` Spacing to bottom of footer -- `gutter` Page gutter spacing -- `colsNum` Number of columns -- `colsSpace` Spacing between columns -- `breakType` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage) - -The following two styles are automatically set by the use of the `orientation` style. You can alter them but that's not recommended. - -- `pageSizeW` Page width in twips -- `pageSizeH` Page height in twips - -## Font - -Available font styles: - -- `name` Font name, e.g. *Arial* -- `size` Font size, e.g. *20*, *22*, -- `hint` Font content type, *default*, *eastAsia*, or *cs* -- `bold` Bold, *true* or *false* -- `italic` Italic, *true* or *false* -- `superScript` Superscript, *true* or *false* -- `subScript` Subscript, *true* or *false* -- `underline` Underline, *dash*, *dotted*, etc. -- `strikethrough` Strikethrough, *true* or *false* -- `doubleStrikethrough` Double strikethrough, *true* or *false* -- `color` Font color, e.g. *FF0000* -- `fgColor` Font highlight color, e.g. *yellow*, *green*, *blue* -- `bgColor` Font background color, e.g. *FF0000* -- `smallCaps` Small caps, *true* or *false* -- `allCaps` All caps, *true* or *false* - -## Paragraph - -Available paragraph styles: - -- `align` Paragraph alignment, *left*, *right* or *center* -- `spaceBefore` Space before paragraph -- `spaceAfter` Space after paragraph -- `indent` Indent by how much -- `hanging` Hanging by how much -- `basedOn` Parent style -- `next` Style for next paragraph -- `widowControl` Allow first/last line to display on a separate page, *true* or *false* -- `keepNext` Keep paragraph with next paragraph, *true* or *false* -- `keepLines` Keep all lines on one page, *true* or *false* -- `pageBreakBefore` Start paragraph on next page, *true* or *false* -- `lineHeight` text line height, e.g. *1.0*, *1.5*, ect... -- `tabs` Set of custom tab stops - -## Table - -Table styles: - -- `width` Table width in percent -- `bgColor` Background color, e.g. '9966CC' -- `border(Top|Right|Bottom|Left)Size` Border size in twips -- `border(Top|Right|Bottom|Left)Color` Border color, e.g. '9966CC' -- `cellMargin(Top|Right|Bottom|Left)` Cell margin in twips - -Row styles: - -- `tblHeader` Repeat table row on every new page, *true* or *false* -- `cantSplit` Table row cannot break across pages, *true* or *false* -- `exactHeight` Row height is exact or at least - -Cell styles: - -- `width` Cell width in twips -- `valign` Vertical alignment, *top*, *center*, *both*, *bottom* -- `textDirection` Direction of text -- `bgColor` Background color, e.g. '9966CC' -- `border(Top|Right|Bottom|Left)Size` Border size in twips -- `border(Top|Right|Bottom|Left)Color` Border color, e.g. '9966CC' -- `gridSpan` Number of columns spanned -- `vMerge` *restart* or *continue* - -## Image - -Available image styles: - -- `width` Width in pixels -- `height` Height in pixels -- `align` Image alignment, *left*, *right*, or *center* -- `marginTop` Top margin in inches, can be negative -- `marginLeft` Left margin in inches, can be negative -- `wrappingStyle` Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront* - -## Numbering level - -- `start` Starting value -- `format` Numbering format bullet|decimal|upperRoman|lowerRoman|upperLetter|lowerLetter -- `restart` Restart numbering level symbol -- `suffix` Content between numbering symbol and paragraph text tab|space|nothing -- `text` Numbering level text e.g. %1 for nonbullet or bullet character -- `align` Numbering symbol align left|center|right|both -- `left` See paragraph style -- `hanging` See paragraph style -- `tabPos` See paragraph style -- `font` Font name -- `hint` See font style - -# Templates processing - -You can create a .docx document template with included search-patterns which can be replaced by any value you wish. Only single-line values can be replaced. - -To deal with a template file, use `new TemplateProcessor` statement. After TemplateProcessor instance creation the document template is copied into the temporary directory. Then you can use `TemplateProcessor::setValue` method to change the value of a search pattern. The search-pattern model is: `${search-pattern}`. - -Example: - -```php -$templateProcessor = new TemplateProcessor('Template.docx'); -$templateProcessor->setValue('Name', 'Somebody someone'); -$templateProcessor->setValue('Street', 'Coming-Undone-Street 32'); -``` - -It is not possible to directly add new OOXML elements to the template file being processed, but it is possible to transform main document part of the template using XSLT (see `TemplateProcessor::applyXslStyleSheet`). - -See `Sample_07_TemplateCloneRow.php` for example on how to create multirow from a single row in a template by using `TemplateProcessor::cloneRow`. - -See `Sample_23_TemplateBlock.php` for example on how to clone a block of text using `TemplateProcessor::cloneBlock` and delete a block of text using `TemplateProcessor::deleteBlock`. - -# Writers & readers - -## OOXML - -The package of OOXML document consists of the following files. - -- _rels/ - - .rels -- docProps/ - - app.xml - - core.xml - - custom.xml -- word/ - - rels/ - - document.rels.xml - - media/ - - theme/ - - theme1.xml - - document.xml - - fontTable.xml - - numbering.xml - - settings.xml - - styles.xml - - webSettings.xml -- [Content_Types].xml - -## OpenDocument - -### Package - -The package of OpenDocument document consists of the following files. - -- META-INF/ - - manifest.xml -- Pictures/ -- content.xml -- meta.xml -- styles.xml - -### content.xml - -The structure of `content.xml` is described below. - -- office:document-content - - office:font-facedecls - - office:automatic-styles - - office:body - - office:text - - draw:* - - office:forms - - table:table - - text:list - - text:numbered-paragraph - - text:p - - text:table-of-contents - - text:section - - office:chart - - office:image - - office:drawing - -### styles.xml - -The structure of `styles.xml` is described below. - -- office:document-styles - - office:styles - - office:automatic-styles - - office:master-styles - - office:master-page - -## RTF - -To be completed. - -## HTML - -To be completed. - -## PDF - -To be completed. - -# Recipes - -## Create float left image - -Use absolute positioning relative to margin horizontally and to line vertically. - -```php -$imageStyle = array( - 'width' => 40, - 'height' => 40 - 'wrappingStyle' => 'square', - 'positioning' => 'absolute', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'line', -); -$textrun->addImage('resources/_earth.jpg', $imageStyle); -$textrun->addText($lipsumText); -``` - -## Download the produced file automatically - -Use `php://output` as the filename. - -```php -$phpWord = new \PhpOffice\PhpWord\PhpWord(); -$section = $phpWord->createSection(); -$section->addText('Hello World!'); -$file = 'HelloWorld.docx'; -header("Content-Description: File Transfer"); -header('Content-Disposition: attachment; filename="' . $file . '"'); -header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); -header('Content-Transfer-Encoding: binary'); -header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); -header('Expires: 0'); -$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); -$xmlWriter->save("php://output"); -``` - -## Create numbered headings - -Define a numbering style and title styles, and match the two styles (with `pStyle` and `numStyle`) like below. - -```php -$phpWord->addNumberingStyle( - 'hNum', - array('type' => 'multilevel', 'levels' => array( - array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'), - array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'), - array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'), - ) - ) -); -$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'hNum', 'numLevel' => 0)); -$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'hNum', 'numLevel' => 1)); -$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'hNum', 'numLevel' => 2)); - -$section->addTitle('Heading 1', 1); -$section->addTitle('Heading 2', 2); -$section->addTitle('Heading 3', 3); -``` - -## Add a link within a title - -Apply 'HeadingN' paragraph style to TextRun or Link. Sample code: - -```php -$phpWord = new \PhpOffice\PhpWord\PhpWord(); -$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true)); -$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true)); -$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single')); - -$section = $phpWord->addSection(); - -// Textrun -$textrun = $section->addTextRun('Heading1'); -$textrun->addText('The '); -$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link'); - -// Link -$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2'); -``` - -## Remove [Compatibility Mode] text in the MS Word title bar - -Use the `Metadata\Compatibility\setOoxmlVersion(n)` method with `n` is the version of Office (14 = Office 2010, 15 = Office 2013). - -```php -$phpWord->getCompatibility()->setOoxmlVersion(15); -``` - -# Frequently asked questions - -## Is this the same with PHPWord that I found in CodePlex? - -No. This one is much better with tons of new features that you can’t find in PHPWord 0.6.3. The development in CodePlex is halted and switched to GitHub to allow more participation from the crowd. The more the merrier, right? - -## I’ve been running PHPWord from CodePlex flawlessly, but I can’t use the latest PHPWord from GitHub. Why? - -PHPWord requires PHP 5.3+ since 0.8, while PHPWord 0.6.3 from CodePlex can run with PHP 5.2. There’s a lot of new features that we can get from PHP 5.3 and it’s been around since 2009! You should upgrade your PHP version to use PHPWord 0.8+. - -# References - -## ISO/IEC 29500, Third edition, 2012-09-01 - -- [Part 1: Fundamentals and Markup Language Reference](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061750_ISO_IEC_29500-1_2012.zip) -- [Part 2: Open Packaging Conventions](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061796_ISO_IEC_29500-2_2012.zip) -- [Part 3: Markup Compatibility and Extensibility](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061797_ISO_IEC_29500-3_2012.zip) -- [Part 4: Transitional Migration Features](http://standards.iso.org/ittf/PubliclyAvailableStandards/c061798_ISO_IEC_29500-4_2012.zip) - -## Formal specifications - -- [Oasis OpenDocument Standard Version 1.2](http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os.html) -- [Rich Text Format (RTF) Specification, version 1.9.1](http://www.microsoft.com/en-us/download/details.aspx?id=10725) - -## Other resources - -- [DocumentFormat.OpenXml.Wordprocessing Namespace on MSDN](http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing%28v=office.14%29.aspx) diff --git a/docs/styles.rst b/docs/styles.rst index f4c1e8ebd4..b71059a69a 100644 --- a/docs/styles.rst +++ b/docs/styles.rst @@ -3,132 +3,143 @@ Styles ====== +.. _section-style: + Section ------- -Below are the available styles for section: - -- ``pageSizeW`` Page width in twips (the default is 11906/A4 size) -- ``pageSizeH`` Page height in twips (the default is 16838/A4 size) -- ``orientation`` Page orientation, i.e. 'portrait' (default) or - 'landscape' -- ``marginTop`` Page margin top in twips -- ``marginLeft`` Page margin left in twips -- ``marginRight`` Page margin right in twips -- ``marginBottom`` Page margin bottom in twips -- ``borderTopSize`` Border top size in twips -- ``borderTopColor`` Border top color -- ``borderLeftSize`` Border left size in twips -- ``borderLeftColor`` Border left color -- ``borderRightSize`` Border right size in twips -- ``borderRightColor`` Border right color -- ``borderBottomSize`` Border bottom size in twips -- ``borderBottomColor`` Border bottom color -- ``headerHeight`` Spacing to top of header -- ``footerHeight`` Spacing to bottom of footer -- ``gutter`` Page gutter spacing -- ``colsNum`` Number of columns -- ``colsSpace`` Spacing between columns -- ``breakType`` Section break type (nextPage, nextColumn, continuous, - evenPage, oddPage) +Available Section style options: + +- ``borderBottomColor``. Border bottom color. +- ``borderBottomSize``. Border bottom size (in twips). +- ``borderLeftColor``. Border left color. +- ``borderLeftSize``. Border left size (in twips). +- ``borderRightColor``. Border right color. +- ``borderRightSize``. Border right size (in twips). +- ``borderTopColor``. Border top color. +- ``borderTopSize``. Border top size (in twips). +- ``breakType``. Section break type (nextPage, nextColumn, continuous, evenPage, oddPage). +- ``colsNum``. Number of columns. +- ``colsSpace``. Spacing between columns. +- ``footerHeight``. Spacing to bottom of footer. +- ``gutter``. Page gutter spacing. +- ``headerHeight``. Spacing to top of header. +- ``marginTop``. Page margin top (in twips). +- ``marginLeft``. Page margin left (in twips). +- ``marginRight``. Page margin right (in twips). +- ``marginBottom``. Page margin bottom (in twips). +- ``orientation``. Page orientation (``portrait``, which is default, or ``landscape``). +- ``pageSizeH``. Page height (in twips). Implicitly defined by ``orientation`` option. Any changes are discouraged. +- ``pageSizeW``. Page width (in twips). Implicitly defined by ``orientation`` option. Any changes are discouraged. + +.. _font-style: Font ---- -Available font styles: - -- ``name`` Font name, e.g. *Arial* -- ``size`` Font size, e.g. *20*, *22*, -- ``hint`` Font content type, *default*, *eastAsia*, or *cs* -- ``bold`` Bold, *true* or *false* -- ``italic`` Italic, *true* or *false* -- ``superScript`` Superscript, *true* or *false* -- ``subScript`` Subscript, *true* or *false* -- ``underline`` Underline, *dash*, *dotted*, etc. -- ``strikethrough`` Strikethrough, *true* or *false* -- ``doubleStrikethrough`` Double strikethrough, *true* or *false* -- ``color`` Font color, e.g. *FF0000* -- ``fgColor`` Font highlight color, e.g. *yellow*, *green*, *blue* -- ``bgColor`` Font background color, e.g. *FF0000* -- ``smallCaps`` Small caps, *true* or *false* -- ``allCaps`` All caps, *true* or *false* -- ``rtl`` Right to Left language, *true* or *false* +Available Font style options: + +- ``allCaps``. All caps, *true* or *false*. +- ``bgColor``. Font background color, e.g. *FF0000*. +- ``bold``. Bold, *true* or *false*. +- ``color``. Font color, e.g. *FF0000*. +- ``doubleStrikethrough``. Double strikethrough, *true* or *false*. +- ``fgColor``. Font highlight color, e.g. *yellow*, *green*, *blue*. +- ``hint``. Font content type, *default*, *eastAsia*, or *cs*. +- ``italic``. Italic, *true* or *false*. +- ``name``. Font name, e.g. *Arial*. +- ``rtl``. Right to Left language, *true* or *false*. +- ``size``. Font size, e.g. *20*, *22*. +- ``smallCaps``. Small caps, *true* or *false*. +- ``strikethrough``. Strikethrough, *true* or *false*. +- ``subScript``. Subscript, *true* or *false*. +- ``superScript``. Superscript, *true* or *false*. +- ``underline``. Underline, *dash*, *dotted*, etc. + +.. _paragraph-style: Paragraph --------- -Available paragraph styles: - -- ``align`` Paragraph alignment, *left*, *right* or *center* -- ``spaceBefore`` Space before paragraph -- ``spaceAfter`` Space after paragraph -- ``indent`` Indent by how much -- ``hanging`` Hanging by how much -- ``basedOn`` Parent style -- ``next`` Style for next paragraph -- ``widowControl`` Allow first/last line to display on a separate page, - *true* or *false* -- ``keepNext`` Keep paragraph with next paragraph, *true* or *false* -- ``keepLines`` Keep all lines on one page, *true* or *false* -- ``pageBreakBefore`` Start paragraph on next page, *true* or *false* -- ``lineHeight`` text line height, e.g. *1.0*, *1.5*, ect... -- ``tabs`` Set of custom tab stops +Available Paragraph style options: + +- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012. +See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details. +- ``basedOn``. Parent style. +- ``hanging``. Hanging by how much. +- ``indent``. Indent by how much. +- ``keepLines``. Keep all lines on one page, *true* or *false*. +- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*. +- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc. +- ``next``. Style for next paragraph. +- ``pageBreakBefore``. Start paragraph on next page, *true* or *false*. +- ``spaceBefore``. Space before paragraph. +- ``spaceAfter``. Space after paragraph. +- ``tabs``. Set of custom tab stops. +- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*. + +.. _table-style: Table ----- -Table styles: +Available Table style options: + +- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012. +See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` classes for the details. +- ``bgColor``. Background color, e.g. '9966CC'. +- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'. +- ``border(Top|Right|Bottom|Left)Size``. Border size in twips. +- ``cellMargin(Top|Right|Bottom|Left)``. Cell margin in twips. +- ``width``. Table width in percent. -- ``width`` Table width in percent -- ``bgColor`` Background color, e.g. '9966CC' -- ``border(Top|Right|Bottom|Left)Size`` Border size in twips -- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC' -- ``cellMargin(Top|Right|Bottom|Left)`` Cell margin in twips +Available Row style options: -Row styles: +- ``cantSplit``. Table row cannot break across pages, *true* or *false*. +- ``exactHeight``. Row height is exact or at least. +- ``tblHeader``. Repeat table row on every new page, *true* or *false*. -- ``tblHeader`` Repeat table row on every new page, *true* or *false* -- ``cantSplit`` Table row cannot break across pages, *true* or *false* -- ``exactHeight`` Row height is exact or at least +Available Cell style options: -Cell styles: +- ``bgColor``. Background color, e.g. '9966CC'. +- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'. +- ``border(Top|Right|Bottom|Left)Size``. Border size in twips. +- ``gridSpan``. Number of columns spanned. +- ``textDirection(btLr|tbRl)``. Direction of text. You can use constants ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR`` and ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_TBRL`` +- ``valign``. Vertical alignment, *top*, *center*, *both*, *bottom*. +- ``vMerge``. *restart* or *continue*. +- ``width``. Cell width in twips. -- ``width`` Cell width in twips -- ``valign`` Vertical alignment, *top*, *center*, *both*, *bottom* -- ``textDirection`` Direction of text -- ``bgColor`` Background color, e.g. '9966CC' -- ``border(Top|Right|Bottom|Left)Size`` Border size in twips -- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC' -- ``gridSpan`` Number of columns spanned -- ``vMerge`` *restart* or *continue* +.. _image-style: Image ----- -Available image styles: +Available Image style options: + +- ``alignment``. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details. +- ``height``. Height in pixels. +- ``marginLeft``. Left margin in inches, can be negative. +- ``marginTop``. Top margin in inches, can be negative. +- ``width``. Width in pixels. +- ``wrappingStyle``. Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*. -- ``width`` Width in pixels -- ``height`` Height in pixels -- ``align`` Image alignment, *left*, *right*, or *center* -- ``marginTop`` Top margin in inches, can be negative -- ``marginLeft`` Left margin in inches, can be negative -- ``wrappingStyle`` Wrapping style, *inline*, *square*, *tight*, - *behind*, or *infront* +.. _numbering-level-style: Numbering level --------------- -- ``start`` Starting value -- ``format`` Numbering format - bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter -- ``restart`` Restart numbering level symbol -- ``suffix`` Content between numbering symbol and paragraph text - tab\|space\|nothing -- ``text`` Numbering level text e.g. %1 for nonbullet or bullet - character -- ``align`` Numbering symbol align left\|center\|right\|both -- ``left`` See paragraph style -- ``hanging`` See paragraph style -- ``tabPos`` See paragraph style -- ``font`` Font name -- ``hint`` See font style +Available NumberingLevel style options: + +- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012. +See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details. +- ``font``. Font name. +- ``format``. Numbering format bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter. +- ``hanging``. See paragraph style. +- ``hint``. See font style. +- ``left``. See paragraph style. +- ``restart``. Restart numbering level symbol. +- ``start``. Starting value. +- ``suffix``. Content between numbering symbol and paragraph text tab\|space\|nothing. +- ``tabPos``. See paragraph style. +- ``text``. Numbering level text e.g. %1 for nonbullet or bullet character. diff --git a/docs/templates-processing.rst b/docs/templates-processing.rst index 6a65ea0d57..af03b24586 100644 --- a/docs/templates-processing.rst +++ b/docs/templates-processing.rst @@ -3,7 +3,7 @@ Templates processing ==================== -You can create a .docx document template with included search-patterns which can be replaced by any value you wish. Only single-line values can be replaced. +You can create an OOXML document template with included search-patterns (macros) which can be replaced by any value you wish. Only single-line values can be replaced. To deal with a template file, use ``new TemplateProcessor`` statement. After TemplateProcessor instance creation the document template is copied into the temporary directory. Then you can use ``TemplateProcessor::setValue`` method to change the value of a search pattern. The search-pattern model is: ``${search-pattern}``. @@ -12,10 +12,10 @@ Example: .. code-block:: php $templateProcessor = new TemplateProcessor('Template.docx'); - $templateProcessor->setValue('Name', 'Somebody someone'); - $templateProcessor->setValue('Street', 'Coming-Undone-Street 32'); + $templateProcessor->setValue('Name', 'John Doe'); + $templateProcessor->setValue(array('City', 'Street'), array('Detroit', '12th Street')); -It is not possible to directly add new OOXML elements to the template file being processed, but it is possible to transform main document part of the template using XSLT (see ``TemplateProcessor::applyXslStyleSheet``). +It is not possible to directly add new OOXML elements to the template file being processed, but it is possible to transform headers, main document part, and footers of the template using XSLT (see ``TemplateProcessor::applyXslStyleSheet``). See ``Sample_07_TemplateCloneRow.php`` for example on how to create multirow from a single row in a template by using ``TemplateProcessor::cloneRow``. diff --git a/docs/writersreaders.rst b/docs/writersreaders.rst index 34a0805a8c..33aacc72af 100644 --- a/docs/writersreaders.rst +++ b/docs/writersreaders.rst @@ -8,35 +8,35 @@ OOXML The package of OOXML document consists of the following files. -- \_rels/ +- \_rels/ - - .rels + - .rels -- docProps/ +- docProps/ - - app.xml - - core.xml - - custom.xml + - app.xml + - core.xml + - custom.xml -- word/ +- word/ - - rels/ + - rels/ - - document.rels.xml + - document.rels.xml - - media/ - - theme/ + - media/ + - theme/ - - theme1.xml + - theme1.xml - - document.xml - - fontTable.xml - - numbering.xml - - settings.xml - - styles.xml - - webSettings.xml + - document.xml + - fontTable.xml + - numbering.xml + - settings.xml + - styles.xml + - webSettings.xml -- [Content\_Types].xml +- [Content\_Types].xml OpenDocument ------------ @@ -46,53 +46,53 @@ Package The package of OpenDocument document consists of the following files. -- META-INF/ +- META-INF/ - - manifest.xml + - manifest.xml -- Pictures/ -- content.xml -- meta.xml -- styles.xml +- Pictures/ +- content.xml +- meta.xml +- styles.xml content.xml ~~~~~~~~~~~ The structure of ``content.xml`` is described below. -- office:document-content +- office:document-content - - office:font-facedecls - - office:automatic-styles - - office:body + - office:font-facedecls + - office:automatic-styles + - office:body - - office:text + - office:text - - draw:\* - - office:forms - - table:table - - text:list - - text:numbered-paragraph - - text:p - - text:table-of-contents - - text:section + - draw:\* + - office:forms + - table:table + - text:list + - text:numbered-paragraph + - text:p + - text:table-of-contents + - text:section - - office:chart - - office:image - - office:drawing + - office:chart + - office:image + - office:drawing styles.xml ~~~~~~~~~~ The structure of ``styles.xml`` is described below. -- office:document-styles +- office:document-styles - - office:styles - - office:automatic-styles - - office:master-styles + - office:styles + - office:automatic-styles + - office:master-styles - - office:master-page + - office:master-page RTF --- diff --git a/phpmd.xml.dist b/phpmd.xml.dist index 5eb348ecfe..44b3efdf66 100644 --- a/phpmd.xml.dist +++ b/phpmd.xml.dist @@ -4,7 +4,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> - + + + + + + + + diff --git a/phpword.ini.dist b/phpword.ini.dist index f8eafb6a78..0f4cc358df 100644 --- a/phpword.ini.dist +++ b/phpword.ini.dist @@ -3,11 +3,12 @@ [General] -compatibility = true -zipClass = ZipArchive -pdfRendererName = DomPDF -pdfRendererPath = -; tempDir = "C:\PhpWordTemp" +compatibility = true +zipClass = ZipArchive +pdfRendererName = DomPDF +pdfRendererPath = +; tempDir = "C:\PhpWordTemp" +outputEscapingEnabled = false [Font] diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index f7aaece30a..1e51b2c072 100644 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -4,24 +4,29 @@ // New Word Document 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, 'allCaps' => true, 'doubleStrikethrough' => true)); -$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); + +$fontStyleName = 'rStyle'; +$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); + +$paragraphStyleName = 'pStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100)); + $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); // New portrait section $section = $phpWord->addSection(); // Simple text -$section->addTitle(htmlspecialchars('Welcome to PhpWord'), 1); -$section->addText(htmlspecialchars('Hello World!')); +$section->addTitle('Welcome to PhpWord', 1); +$section->addText('Hello World!'); // Two text break $section->addTextBreak(2); -// Defined style -$section->addText(htmlspecialchars('I am styled by a font style definition.'), 'rStyle'); -$section->addText(htmlspecialchars('I am styled by a paragraph style definition.'), null, 'pStyle'); -$section->addText(htmlspecialchars('I am styled by both font and paragraph style.'), 'rStyle', 'pStyle'); +// Define styles +$section->addText('I am styled by a font style definition.', $fontStyleName); +$section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName); +$section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName); $section->addTextBreak(); @@ -30,39 +35,39 @@ $fontStyle['size'] = 20; $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('I am inline styled '), $fontStyle); -$textrun->addText(htmlspecialchars('with ')); -$textrun->addText(htmlspecialchars('color'), array('color' => '996699')); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('bold'), array('bold' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('italic'), array('italic' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('underline'), array('underline' => 'dash')); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('strikethrough'), array('strikethrough' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('doubleStrikethrough'), array('doubleStrikethrough' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('superScript'), array('superScript' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('subScript'), array('subScript' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('smallCaps'), array('smallCaps' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('allCaps'), array('allCaps' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('fgColor'), array('fgColor' => 'yellow')); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('scale'), array('scale' => 200)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('spacing'), array('spacing' => 120)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('kerning'), array('kerning' => 10)); -$textrun->addText(htmlspecialchars('. ')); +$textrun->addText('I am inline styled ', $fontStyle); +$textrun->addText('with '); +$textrun->addText('color', array('color' => '996699')); +$textrun->addText(', '); +$textrun->addText('bold', array('bold' => true)); +$textrun->addText(', '); +$textrun->addText('italic', array('italic' => true)); +$textrun->addText(', '); +$textrun->addText('underline', array('underline' => 'dash')); +$textrun->addText(', '); +$textrun->addText('strikethrough', array('strikethrough' => true)); +$textrun->addText(', '); +$textrun->addText('doubleStrikethrough', array('doubleStrikethrough' => true)); +$textrun->addText(', '); +$textrun->addText('superScript', array('superScript' => true)); +$textrun->addText(', '); +$textrun->addText('subScript', array('subScript' => true)); +$textrun->addText(', '); +$textrun->addText('smallCaps', array('smallCaps' => true)); +$textrun->addText(', '); +$textrun->addText('allCaps', array('allCaps' => true)); +$textrun->addText(', '); +$textrun->addText('fgColor', array('fgColor' => 'yellow')); +$textrun->addText(', '); +$textrun->addText('scale', array('scale' => 200)); +$textrun->addText(', '); +$textrun->addText('spacing', array('spacing' => 120)); +$textrun->addText(', '); +$textrun->addText('kerning', array('kerning' => 10)); +$textrun->addText('. '); // Link -$section->addLink('http://www.google.com', htmlspecialchars('Google')); +$section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $section->addTextBreak(); // Image diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php index 46d91cec34..1702198751 100644 --- a/samples/Sample_02_TabStops.php +++ b/samples/Sample_02_TabStops.php @@ -5,9 +5,10 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Ads styles +// Define styles +$multipleTabsStyleName = 'multipleTab'; $phpWord->addParagraphStyle( - 'multipleTab', + $multipleTabsStyleName, array( 'tabs' => array( new \PhpOffice\PhpWord\Style\Tab('left', 1550), @@ -16,22 +17,20 @@ ) ) ); -$phpWord->addParagraphStyle( - 'rightTab', - array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090))) -); -$phpWord->addParagraphStyle( - 'centerTab', - array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680))) -); + +$rightTabStyleName = 'rightTab'; +$phpWord->addParagraphStyle($rightTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)))); + +$leftTabStyleName = 'centerTab'; +$phpWord->addParagraphStyle($leftTabStyleName, array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680)))); // New portrait section $section = $phpWord->addSection(); // Add listitem elements -$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree"), null, 'multipleTab'); -$section->addText(htmlspecialchars("Left Aligned\tRight Aligned"), null, 'rightTab'); -$section->addText(htmlspecialchars("\tCenter Aligned"), null, 'centerTab'); +$section->addText("Multiple Tabs:\tOne\tTwo\tThree", null, $multipleTabsStyleName); +$section->addText("Left Aligned\tRight Aligned", null, $rightTabStyleName); +$section->addText("\tCenter Aligned", null, $leftTabStyleName); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php index a95b15d644..a7b5b13d6d 100644 --- a/samples/Sample_03_Sections.php +++ b/samples/Sample_03_Sections.php @@ -7,15 +7,11 @@ // New portrait section $section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12)); -$section->addText(htmlspecialchars('I am placed on a default section.')); +$section->addText('I am placed on a default section.'); // New landscape section $section = $phpWord->addSection(array('orientation' => 'landscape')); -$section->addText( - htmlspecialchars( - 'I am placed on a landscape section. Every page starting from this section will be landscape style.' - ) -); +$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.'); $section->addPageBreak(); $section->addPageBreak(); @@ -23,7 +19,7 @@ $section = $phpWord->addSection( array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); -$section->addText(htmlspecialchars('This section uses other margins with folio papersize.')); +$section->addText('This section uses other margins with folio papersize.'); // New portrait section with Header & Footer $section = $phpWord->addSection( @@ -36,9 +32,9 @@ 'footerHeight' => 50, ) ); -$section->addText(htmlspecialchars('This section and we play with header/footer height.')); -$section->addHeader()->addText(htmlspecialchars('Header')); -$section->addFooter()->addText(htmlspecialchars('Footer')); +$section->addText('This section and we play with header/footer height.'); +$section->addHeader()->addText('Header'); +$section->addFooter()->addText('Footer'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index 7ebf6e3365..48978dd36b 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -5,39 +5,39 @@ 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', 'bgColor' => 'FFFFCC')); -$phpWord->addLinkStyle( - 'NLink', - array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) -); +// Define styles +$paragraphStyleName = 'pStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 100)); + +$boldFontStyleName = 'BoldText'; +$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); + +$coloredFontStyleName = 'ColoredText'; +$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC')); + +$linkFontStyleName = 'NLink'; +$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)); // New portrait section $section = $phpWord->addSection(); // Add text run -$textrun = $section->addTextRun('pStyle'); - -$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.')); -$textrun->addText(htmlspecialchars(' No break is placed after adding an element.'), 'BoldText'); -$textrun->addText(htmlspecialchars(' Both ')); -$textrun->addText(htmlspecialchars('superscript'), array('superScript' => true)); -$textrun->addText(htmlspecialchars(' and ')); -$textrun->addText(htmlspecialchars('subscript'), array('subScript' => true)); -$textrun->addText(htmlspecialchars(' are also available.')); -$textrun->addText( - htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.'), - 'ColoredText' -); -$textrun->addText(htmlspecialchars(' Sample Link: ')); -$textrun->addLink('http://www.google.com', null, 'NLink'); -$textrun->addText(htmlspecialchars(' Sample Image: ')); +$textrun = $section->addTextRun($paragraphStyleName); +$textrun->addText('Each textrun can contain native text, link elements or an image.'); +$textrun->addText(' No break is placed after adding an element.', $boldFontStyleName); +$textrun->addText(' Both '); +$textrun->addText('superscript', array('superScript' => true)); +$textrun->addText(' and '); +$textrun->addText('subscript', array('subScript' => true)); +$textrun->addText(' are also available.'); +$textrun->addText(' All elements are placed inside a paragraph with the optionally given paragraph style.', $coloredFontStyleName); +$textrun->addText(' Sample Link: '); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName); +$textrun->addText(' Sample Image: '); $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$textrun->addText(htmlspecialchars(' Sample Object: ')); +$textrun->addText(' Sample Object: '); $textrun->addObject('resources/_sheet.xls'); -$textrun->addText(htmlspecialchars(' Here is some more text. ')); +$textrun->addText(' Here is some more text. '); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php index b93ab344c1..f7cefa58d3 100644 --- a/samples/Sample_05_Multicolumn.php +++ b/samples/Sample_05_Multicolumn.php @@ -11,7 +11,7 @@ // Normal $section = $phpWord->addSection(); -$section->addText(htmlspecialchars("Normal paragraph. {$filler}")); +$section->addText("Normal paragraph. {$filler}"); // Two columns $section = $phpWord->addSection( @@ -21,11 +21,11 @@ 'breakType' => 'continuous', ) ); -$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}")); +$section->addText("Two columns, one inch (1440 twips) spacing. {$filler}"); // Normal $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addText(htmlspecialchars("Normal paragraph again. {$filler}")); +$section->addText("Normal paragraph again. {$filler}"); // Three columns $section = $phpWord->addSection( @@ -35,11 +35,11 @@ 'breakType' => 'continuous', ) ); -$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}")); +$section->addText("Three columns, half inch (720 twips) spacing. {$filler}"); // Normal $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addText(htmlspecialchars('Normal paragraph again.')); +$section->addText("Normal paragraph again. {$filler}"); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php index c7f3d8c0bc..30afcf815b 100644 --- a/samples/Sample_06_Footnote.php +++ b/samples/Sample_06_Footnote.php @@ -6,44 +6,46 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); \PhpOffice\PhpWord\Settings::setCompatibility(false); +// Define styles +$paragraphStyleName = 'pStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 100)); + +$boldFontStyleName = 'BoldText'; +$phpWord->addFontStyle($boldFontStyleName, array('bold' => true)); + +$coloredFontStyleName = 'ColoredText'; +$phpWord->addFontStyle($coloredFontStyleName, array('color' => 'FF8080', 'bgColor' => 'FFFFCC')); + +$linkFontStyleName = 'NLink'; +$phpWord->addLinkStyle($linkFontStyleName, array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)); + // New portrait section $section = $phpWord->addSection(); -// 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' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) -); - // Add text elements -$textrun = $section->addTextRun('pStyle'); -$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. '), 'pStyle'); +$textrun = $section->addTextRun($paragraphStyleName); +$textrun->addText('This is some lead text in a paragraph with a following footnote. ', $paragraphStyleName); $footnote = $textrun->addFootnote(); -$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ')); -$footnote->addText(htmlspecialchars('No break is placed after adding an element. '), 'BoldText'); -$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. '), 'ColoredText'); +$footnote->addText('Just like a textrun, a footnote can contain native texts. '); +$footnote->addText('No break is placed after adding an element. ', $boldFontStyleName); +$footnote->addText('All elements are placed inside a paragraph. ', $coloredFontStyleName); $footnote->addTextBreak(); -$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ')); -$footnote->addText(htmlspecialchars('links like ')); -$footnote->addLink('http://www.google.com', null, 'NLink'); -$footnote->addText(htmlspecialchars(', image like ')); +$footnote->addText('But you can insert a manual text break like above, '); +$footnote->addText('links like '); +$footnote->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub', $linkFontStyleName); +$footnote->addText(', image like '); $footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$footnote->addText(htmlspecialchars(', or object like ')); +$footnote->addText(', or object like '); $footnote->addObject('resources/_sheet.xls'); -$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.')); +$footnote->addText('But you can only put footnote in section, not in header or footer.'); $section->addText( - htmlspecialchars( - 'You can also create the footnote directly from the section making it wrap in a paragraph ' - . 'like the footnote below this paragraph. But is is best used from within a textrun.' - ) + 'You can also create the footnote directly from the section making it wrap in a paragraph ' + . 'like the footnote below this paragraph. But is is best used from within a textrun.' ); $footnote = $section->addFootnote(); -$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line')); +$footnote->addText('The reference for this is wrapped in its own line'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php index 60edacb5a7..22a68537c6 100644 --- a/samples/Sample_07_TemplateCloneRow.php +++ b/samples/Sample_07_TemplateCloneRow.php @@ -6,52 +6,52 @@ $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx'); // Variables on different parts of document -$templateProcessor->setValue('weekday', htmlspecialchars(date('l'))); // On section/content -$templateProcessor->setValue('time', htmlspecialchars(date('H:i'))); // On footer -$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__))); // On header +$templateProcessor->setValue('weekday', date('l')); // On section/content +$templateProcessor->setValue('time', date('H:i')); // On footer +$templateProcessor->setValue('serverName', realpath(__DIR__)); // On header // Simple table $templateProcessor->cloneRow('rowValue', 10); -$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun')); -$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury')); -$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus')); -$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth')); -$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars')); -$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter')); -$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn')); -$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus')); -$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun')); -$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto')); - -$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1')); -$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2')); -$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3')); -$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4')); -$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5')); -$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6')); -$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7')); -$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8')); -$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9')); -$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10')); +$templateProcessor->setValue('rowValue#1', 'Sun'); +$templateProcessor->setValue('rowValue#2', 'Mercury'); +$templateProcessor->setValue('rowValue#3', 'Venus'); +$templateProcessor->setValue('rowValue#4', 'Earth'); +$templateProcessor->setValue('rowValue#5', 'Mars'); +$templateProcessor->setValue('rowValue#6', 'Jupiter'); +$templateProcessor->setValue('rowValue#7', 'Saturn'); +$templateProcessor->setValue('rowValue#8', 'Uranus'); +$templateProcessor->setValue('rowValue#9', 'Neptun'); +$templateProcessor->setValue('rowValue#10', 'Pluto'); + +$templateProcessor->setValue('rowNumber#1', '1'); +$templateProcessor->setValue('rowNumber#2', '2'); +$templateProcessor->setValue('rowNumber#3', '3'); +$templateProcessor->setValue('rowNumber#4', '4'); +$templateProcessor->setValue('rowNumber#5', '5'); +$templateProcessor->setValue('rowNumber#6', '6'); +$templateProcessor->setValue('rowNumber#7', '7'); +$templateProcessor->setValue('rowNumber#8', '8'); +$templateProcessor->setValue('rowNumber#9', '9'); +$templateProcessor->setValue('rowNumber#10', '10'); // Table with a spanned cell $templateProcessor->cloneRow('userId', 3); -$templateProcessor->setValue('userId#1', htmlspecialchars('1')); -$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James')); -$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor')); -$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773')); +$templateProcessor->setValue('userId#1', '1'); +$templateProcessor->setValue('userFirstName#1', 'James'); +$templateProcessor->setValue('userName#1', 'Taylor'); +$templateProcessor->setValue('userPhone#1', '+1 428 889 773'); -$templateProcessor->setValue('userId#2', htmlspecialchars('2')); -$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert')); -$templateProcessor->setValue('userName#2', htmlspecialchars('Bell')); -$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774')); +$templateProcessor->setValue('userId#2', '2'); +$templateProcessor->setValue('userFirstName#2', 'Robert'); +$templateProcessor->setValue('userName#2', 'Bell'); +$templateProcessor->setValue('userPhone#2', '+1 428 889 774'); -$templateProcessor->setValue('userId#3', htmlspecialchars('3')); -$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael')); -$templateProcessor->setValue('userName#3', htmlspecialchars('Ray')); -$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775')); +$templateProcessor->setValue('userId#3', '3'); +$templateProcessor->setValue('userFirstName#3', 'Michael'); +$templateProcessor->setValue('userName#3', 'Ray'); +$templateProcessor->setValue('userPhone#3', '+1 428 889 775'); echo date('H:i:s'), ' Saving the result document...', EOL; $templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx'); diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php index dd364562d0..f91b1c56b4 100644 --- a/samples/Sample_08_ParagraphPagination.php +++ b/samples/Sample_08_ParagraphPagination.php @@ -6,68 +6,58 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->setDefaultParagraphStyle( array( - 'align' => 'both', + 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::BOTH, 'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12), 'spacing' => 120, ) ); -// Sample +// New section $section = $phpWord->addSection(); $section->addText( - htmlspecialchars( - 'Below are the samples on how to control your paragraph ' - . 'pagination. See "Line and Page Break" tab on paragraph properties ' - . 'window to see the attribute set by these controls.' - ), + 'Below are the samples on how to control your paragraph ' + . 'pagination. See "Line and Page Break" tab on paragraph properties ' + . 'window to see the attribute set by these controls.', array('bold' => true), array('space' => array('before' => 360, 'after' => 480)) ); $section->addText( - htmlspecialchars( - 'Paragraph with widowControl = false (default: true). ' - . 'A "widow" is the last line of a paragraph printed by itself at the top ' - . 'of a page. An "orphan" is the first line of a paragraph printed by ' - . 'itself at the bottom of a page. Set this option to "false" if you want ' - . 'to disable this automatic control.' - ), + 'Paragraph with widowControl = false (default: true). ' + . 'A "widow" is the last line of a paragraph printed by itself at the top ' + . 'of a page. An "orphan" is the first line of a paragraph printed by ' + . 'itself at the bottom of a page. Set this option to "false" if you want ' + . 'to disable this automatic control.', null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)) ); $section->addText( - htmlspecialchars( - 'Paragraph with keepNext = true (default: false). ' - . '"Keep with next" is used to prevent Word from inserting automatic page ' - . 'breaks between paragraphs. Set this option to "true" if you do not want ' - . 'your paragraph to be separated with the next paragraph.' - ), + 'Paragraph with keepNext = true (default: false). ' + . '"Keep with next" is used to prevent Word from inserting automatic page ' + . 'breaks between paragraphs. Set this option to "true" if you do not want ' + . 'your paragraph to be separated with the next paragraph.', null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)) ); $section->addText( - htmlspecialchars( - 'Paragraph with keepLines = true (default: false). ' - . '"Keep lines together" will prevent Word from inserting an automatic page ' - . 'break within a paragraph. Set this option to "true" if you do not want ' - . 'all lines of your paragraph to be in the same page.' - ), + 'Paragraph with keepLines = true (default: false). ' + . '"Keep lines together" will prevent Word from inserting an automatic page ' + . 'break within a paragraph. Set this option to "true" if you do not want ' + . 'all lines of your paragraph to be in the same page.', null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)) ); -$section->addText(htmlspecialchars('Keep scrolling. More below.')); +$section->addText('Keep scrolling. More below.'); $section->addText( - htmlspecialchars( - 'Paragraph with pageBreakBefore = true (default: false). ' - . 'Different with all other control above, "page break before" separates ' - . 'your paragraph into the next page. This option is most useful for ' - . 'heading styles.' - ), + 'Paragraph with pageBreakBefore = true (default: false). ' + . 'Different with all other control above, "page break before" separates ' + . 'your paragraph into the next page. This option is most useful for ' + . 'heading styles.', null, array('pageBreakBefore' => true) ); diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php index 5c305c8342..53d32e0888 100644 --- a/samples/Sample_09_Tables.php +++ b/samples/Sample_09_Tables.php @@ -11,89 +11,132 @@ $rows = 10; $cols = 5; -$section->addText(htmlspecialchars('Basic table'), $header); +$section->addText('Basic table', $header); $table = $section->addTable(); for ($r = 1; $r <= 8; $r++) { $table->addRow(); for ($c = 1; $c <= 5; $c++) { - $table->addCell(1750)->addText(htmlspecialchars("Row {$r}, Cell {$c}")); + $table->addCell(1750)->addText("Row {$r}, Cell {$c}"); } } // 2. Advanced table $section->addTextBreak(1); -$section->addText(htmlspecialchars('Fancy table'), $header); - -$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80); -$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); -$styleCell = array('valign' => 'center'); -$styleCellBTLR = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR); -$fontStyle = array('bold' => true, 'align' => 'center'); -$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow); -$table = $section->addTable('Fancy Table'); +$section->addText('Fancy table', $header); + +$fancyTableStyleName = 'Fancy Table'; +$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER); +$fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); +$fancyTableCellStyle = array('valign' => 'center'); +$fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR); +$fancyTableFontStyle = array('bold' => true); +$phpWord->addTableStyle($fancyTableStyleName, $fancyTableStyle, $fancyTableFirstRowStyle); +$table = $section->addTable($fancyTableStyleName); $table->addRow(900); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4'), $fontStyle); -$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5'), $fontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 1', $fancyTableFontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 2', $fancyTableFontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 3', $fancyTableFontStyle); +$table->addCell(2000, $fancyTableCellStyle)->addText('Row 4', $fancyTableFontStyle); +$table->addCell(500, $fancyTableCellBtlrStyle)->addText('Row 5', $fancyTableFontStyle); for ($i = 1; $i <= 8; $i++) { $table->addRow(); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); + $table->addCell(2000)->addText("Cell {$i}"); + $table->addCell(2000)->addText("Cell {$i}"); + $table->addCell(2000)->addText("Cell {$i}"); + $table->addCell(2000)->addText("Cell {$i}"); $text = (0== $i % 2) ? 'X' : ''; - $table->addCell(500)->addText(htmlspecialchars($text)); + $table->addCell(500)->addText($text); } -// 3. colspan (gridSpan) and rowspan (vMerge) +/** + * 3. colspan (gridSpan) and rowspan (vMerge) + * --------------------- + * | | B | | + * | A |--------| E | + * | | C | D | | + * --------------------- + */ $section->addPageBreak(); -$section->addText(htmlspecialchars('Table with colspan and rowspan'), $header); +$section->addText('Table with colspan and rowspan', $header); -$styleTable = array('borderSize' => 6, 'borderColor' => '999999'); +$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '999999'); $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00'); $cellRowContinue = array('vMerge' => 'continue'); $cellColSpan = array('gridSpan' => 2, 'valign' => 'center'); -$cellHCentered = array('align' => 'center'); +$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER); $cellVCentered = array('valign' => 'center'); -$phpWord->addTableStyle('Colspan Rowspan', $styleTable); -$table = $section->addTable('Colspan Rowspan'); +$spanTableStyleName = 'Colspan Rowspan'; +$phpWord->addTableStyle($spanTableStyleName, $fancyTableStyle); +$table = $section->addTable($spanTableStyleName); $table->addRow(); $cell1 = $table->addCell(2000, $cellRowSpan); $textrun1 = $cell1->addTextRun($cellHCentered); -$textrun1->addText(htmlspecialchars('A')); -$textrun1->addFootnote()->addText(htmlspecialchars('Row span')); +$textrun1->addText('A'); +$textrun1->addFootnote()->addText('Row span'); $cell2 = $table->addCell(4000, $cellColSpan); $textrun2 = $cell2->addTextRun($cellHCentered); -$textrun2->addText(htmlspecialchars('B')); -$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span')); +$textrun2->addText('B'); +$textrun2->addFootnote()->addText('Column span'); -$table->addCell(2000, $cellRowSpan)->addText(htmlspecialchars('E'), null, $cellHCentered); +$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered); $table->addRow(); $table->addCell(null, $cellRowContinue); -$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C'), null, $cellHCentered); -$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D'), null, $cellHCentered); +$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered); +$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered); $table->addCell(null, $cellRowContinue); -// 4. Nested table +/** + * 4. colspan (gridSpan) and rowspan (vMerge) + * --------------------- + * | | B | 1 | + * | A | |----| + * | | | 2 | + * | |---|----|----| + * | | C | D | 3 | + * --------------------- + * @see https://github.com/PHPOffice/PHPWord/issues/806 + */ +$section->addPageBreak(); +$section->addText('Table with colspan and rowspan', $header); + +$styleTable = ['borderSize' => 6, 'borderColor' => '999999']; +$phpWord->addTableStyle('Colspan Rowspan', $styleTable); +$table = $section->addTable('Colspan Rowspan'); + +$row = $table->addRow(); + +$row->addCell(null, ['vMerge' => 'restart'])->addText('A'); +$row->addCell(null, ['gridSpan' => 2, 'vMerge' => 'restart',])->addText('B'); +$row->addCell()->addText('1'); + +$row = $table->addRow(); +$row->addCell(null, ['vMerge' => 'continue']); +$row->addCell(null, ['vMerge' => 'continue','gridSpan' => 2,]); +$row->addCell()->addText('2'); +$row = $table->addRow(); +$row->addCell(null, ['vMerge' => 'continue']); +$row->addCell()->addText('C'); +$row->addCell()->addText('D'); +$row->addCell()->addText('3'); + +// 5. Nested table $section->addTextBreak(2); -$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.'), $header); +$section->addText('Nested table in a centered and 50% width table.', $header); -$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'align' => 'center')); +$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER)); $cell = $table->addRow()->addCell(); -$cell->addText(htmlspecialchars('This cell contains nested table.')); -$innerCell = $cell->addTable(array('align' => 'center'))->addRow()->addCell(); -$innerCell->addText(htmlspecialchars('Inside nested table')); +$cell->addText('This cell contains nested table.'); +$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell(); +$innerCell->addText('Inside nested table'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php index f3553bfef2..2541af86dc 100644 --- a/samples/Sample_10_EastAsianFontStyle.php +++ b/samples/Sample_10_EastAsianFontStyle.php @@ -7,7 +7,7 @@ $section = $phpWord->addSection(); $header = array('size' => 16, 'bold' => true); //1.Use EastAisa FontStyle -$section->addText(htmlspecialchars('中文楷体样式测试'), array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); +$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php index 51082b6679..b99d81f8dd 100644 --- a/samples/Sample_12_HeaderFooter.php +++ b/samples/Sample_12_HeaderFooter.php @@ -15,50 +15,47 @@ $table->addRow(); $cell = $table->addCell(4500); $textrun = $cell->addTextRun(); -$textrun->addText(htmlspecialchars('This is the header with ')); -$textrun->addLink('http://google.com', htmlspecialchars('link to Google')); -$table->addCell(4500)->addImage( - 'resources/PhpWord.png', - array('width' => 80, 'height' => 80, 'align' => 'right') -); +$textrun->addText('This is the header with '); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); +$table->addCell(4500)->addImage('resources/PhpWord.png', array('width' => 80, 'height' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END)); // Add header for all other pages $subsequent = $section->addHeader(); -$subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!')); +$subsequent->addText('Subsequent pages in Section 1 will Have this!'); $subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80)); // Add footer $footer = $section->addFooter(); -$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.'), null, array('align' => 'center')); -$footer->addLink('http://google.com', htmlspecialchars('Direct Google')); +$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$footer->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...')); +$section->addText('Some text...'); // Create a second page $section->addPageBreak(); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...')); +$section->addText('Some text...'); // Create a third page $section->addPageBreak(); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...')); +$section->addText('Some text...'); // New portrait section $section2 = $phpWord->addSection(); $sec2Header = $section2->addHeader(); -$sec2Header->addText(htmlspecialchars('All pages in Section 2 will Have this!')); +$sec2Header->addText('All pages in Section 2 will Have this!'); // Write some text $section2->addTextBreak(); -$section2->addText(htmlspecialchars('Some text...')); +$section2->addText('Some text...'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php index d13912119b..a3c2af23a9 100644 --- a/samples/Sample_13_Images.php +++ b/samples/Sample_13_Images.php @@ -7,17 +7,17 @@ // Begin code $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Local image without any styles:')); +$section->addText('Local image without any styles:'); $section->addImage('resources/_mars.jpg'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Local image with styles:')); -$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center')); +$section->addText('Local image with styles:'); +$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); $section->addTextBreak(2); // Remote image $source = 'http://php.net/images/logos/php-med-trans-light.gif'; -$section->addText(htmlspecialchars("Remote image from: {$source}")); +$section->addText("Remote image from: {$source}"); $section->addImage($source); //Wrapping style @@ -25,7 +25,7 @@ $wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight'); foreach ($wrappingStyles as $wrappingStyle) { $section->addTextBreak(5); - $section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}")); + $section->addText("Wrapping style {$wrappingStyle}"); $section->addImage( 'resources/_earth.jpg', array( @@ -37,12 +37,12 @@ 'wrappingStyle' => $wrappingStyle, ) ); - $section->addText(htmlspecialchars($text)); + $section->addText($text); } //Absolute positioning $section->addTextBreak(3); -$section->addText(htmlspecialchars('Absolute positioning: see top right corner of page')); +$section->addText('Absolute positioning: see top right corner of page'); $section->addImage( 'resources/_mars.jpg', array( @@ -59,8 +59,8 @@ //Relative positioning $section->addTextBreak(3); -$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,')); -$section->addText(htmlspecialchars('Vertical position top relative to line')); +$section->addText('Relative positioning: Horizontal position center relative to column,'); +$section->addText('Vertical position top relative to line'); $section->addImage( 'resources/_mars.jpg', array( diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php index 3a29e3fdee..689ac3d3eb 100644 --- a/samples/Sample_14_ListItem.php +++ b/samples/Sample_14_ListItem.php @@ -5,15 +5,16 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code -$section = $phpWord->addSection(); +// Define styles +$fontStyleName = 'myOwnStyle'; +$phpWord->addFontStyle($fontStyleName, array('color' => 'FF0000')); -// Style definition +$paragraphStyleName = 'P-Style'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spaceAfter' => 95)); -$phpWord->addFontStyle('myOwnStyle', array('color' => 'FF0000')); -$phpWord->addParagraphStyle('P-Style', array('spaceAfter' => 95)); +$multilevelNumberingStyleName = 'multilevel'; $phpWord->addNumberingStyle( - 'multilevel', + $multilevelNumberingStyleName, array( 'type' => 'multilevel', 'levels' => array( @@ -22,56 +23,59 @@ ), ) ); -$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED); -// Lists +$predefinedMultilevelStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED); + +// New section +$section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Multilevel list.')); -$section->addListItem(htmlspecialchars('List Item I'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item I.a'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item I.b'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item II'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item II.a'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item III'), 0, null, 'multilevel'); +// Lists +$section->addText('Multilevel list.'); +$section->addListItem('List Item I', 0, null, $multilevelNumberingStyleName); +$section->addListItem('List Item I.a', 1, null, $multilevelNumberingStyleName); +$section->addListItem('List Item I.b', 1, null, $multilevelNumberingStyleName); +$section->addListItem('List Item II', 0, null, $multilevelNumberingStyleName); +$section->addListItem('List Item II.a', 1, null, $multilevelNumberingStyleName); +$section->addListItem('List Item III', 0, null, $multilevelNumberingStyleName); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Basic simple bulleted list.')); -$section->addListItem(htmlspecialchars('List Item 1')); -$section->addListItem(htmlspecialchars('List Item 2')); -$section->addListItem(htmlspecialchars('List Item 3')); +$section->addText('Basic simple bulleted list.'); +$section->addListItem('List Item 1'); +$section->addListItem('List Item 2'); +$section->addListItem('List Item 3'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Continue from multilevel list above.')); -$section->addListItem(htmlspecialchars('List Item IV'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item IV.a'), 1, null, 'multilevel'); +$section->addText('Continue from multilevel list above.'); +$section->addListItem('List Item IV', 0, null, $multilevelNumberingStyleName); +$section->addListItem('List Item IV.a', 1, null, $multilevelNumberingStyleName); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Multilevel predefined list.')); -$section->addListItem(htmlspecialchars('List Item 1'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 2'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 3'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 4'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 5'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 6'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 7'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addText('Multilevel predefined list.'); +$section->addListItem('List Item 1', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 2', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 3', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 4', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 5', 2, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 6', 1, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); +$section->addListItem('List Item 7', 0, $fontStyleName, $predefinedMultilevelStyle, $paragraphStyleName); $section->addTextBreak(2); -$section->addText(htmlspecialchars('List with inline formatting.')); +$section->addText('List with inline formatting.'); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 1')); -$listItemRun->addText(htmlspecialchars(' in bold'), array('bold' => true)); +$listItemRun->addText('List item 1'); +$listItemRun->addText(' in bold', array('bold' => true)); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 2')); -$listItemRun->addText(htmlspecialchars(' in italic'), array('italic' => true)); +$listItemRun->addText('List item 2'); +$listItemRun->addText(' in italic', array('italic' => true)); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 3')); -$listItemRun->addText(htmlspecialchars(' underlined'), array('underline' => 'dash')); +$listItemRun->addText('List item 3'); +$listItemRun->addText(' underlined', array('underline' => 'dash')); $section->addTextBreak(2); // Numbered heading - +$headingNumberingStyleName = 'headingNumbering'; $phpWord->addNumberingStyle( - 'headingNumbering', + $headingNumberingStyleName, array('type' => 'multilevel', 'levels' => array( array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'), @@ -80,13 +84,13 @@ ), ) ); -$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0)); -$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1)); -$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2)); +$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 0)); +$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 1)); +$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => $headingNumberingStyleName, 'numLevel' => 2)); -$section->addTitle(htmlspecialchars('Heading 1'), 1); -$section->addTitle(htmlspecialchars('Heading 2'), 2); -$section->addTitle(htmlspecialchars('Heading 3'), 3); +$section->addTitle('Heading 1', 1); +$section->addTitle('Heading 2', 2); +$section->addTitle('Heading 3', 3); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php index dd06670e65..86c7973bc1 100644 --- a/samples/Sample_15_Link.php +++ b/samples/Sample_15_Link.php @@ -5,20 +5,22 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// Define styles +$linkFontStyleName = 'myOwnLinStyle'; +$phpWord->addLinkStyle($linkFontStyleName, array('bold' => true, 'color' => '808000')); + +// New section $section = $phpWord->addSection(); // Add hyperlink elements $section->addLink( - 'http://www.google.com', - htmlspecialchars('Best search engine'), + 'https://github.com/PHPOffice/PHPWord', + 'PHPWord on GitHub', array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) ); $section->addTextBreak(2); - -$phpWord->addLinkStyle('myOwnLinkStyle', array('bold' => true, 'color' => '808000')); -$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle'); -$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle'); +$section->addLink('http://www.bing.com', null, $linkFontStyleName); +$section->addLink('http://www.yahoo.com', null, $linkFontStyleName); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php index 2a216c2378..8b05b9e8ac 100644 --- a/samples/Sample_16_Object.php +++ b/samples/Sample_16_Object.php @@ -7,7 +7,7 @@ // Begin code $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('You can open this OLE object by double clicking on the icon:')); +$section->addText('You can open this OLE object by double clicking on the icon:'); $section->addTextBreak(2); $section->addObject('resources/_sheet.xls'); diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php index 8f8889b83c..306595eb39 100644 --- a/samples/Sample_17_TitleTOC.php +++ b/samples/Sample_17_TitleTOC.php @@ -5,66 +5,63 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// New section $section = $phpWord->addSection(); -// Define the TOC font style -$fontStyle = array('spaceAfter' => 60, 'size' => 12); -$fontStyle2 = array('size' => 10); - -// Add title styles +// Define styles +$fontStyle12 = array('spaceAfter' => 60, 'size' => 12); +$fontStyle10 = array('size' => 10); $phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true)); $phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666')); $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true)); $phpWord->addTitleStyle(4, array('size' => 12)); // Add text elements -$section->addText(htmlspecialchars('Table of contents 1')); +$section->addText('Table of contents 1'); $section->addTextBreak(2); // Add TOC #1 -$toc = $section->addTOC($fontStyle); +$toc = $section->addTOC($fontStyle12); $section->addTextBreak(2); // Filler -$section->addText(htmlspecialchars('Text between TOC')); +$section->addText('Text between TOC'); $section->addTextBreak(2); // Add TOC #1 -$section->addText(htmlspecialchars('Table of contents 2')); +$section->addText('Table of contents 2'); $section->addTextBreak(2); -$toc2 = $section->addTOC($fontStyle2); +$toc2 = $section->addTOC($fontStyle10); $toc2->setMinDepth(2); $toc2->setMaxDepth(3); - // Add Titles $section->addPageBreak(); -$section->addTitle(htmlspecialchars('Foo & Bar'), 1); -$section->addText(htmlspecialchars('Some text...')); +$section->addTitle('Foo n Bar', 1); +$section->addText('Some text...'); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('I am a Subtitle of Title 1'), 2); +$section->addTitle('I am a Subtitle of Title 1', 2); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Some more text...')); +$section->addText('Some more text...'); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('Another Title (Title 2)'), 1); -$section->addText(htmlspecialchars('Some text...')); +$section->addTitle('Another Title (Title 2)', 1); +$section->addText('Some text...'); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('I am Title 3'), 1); -$section->addText(htmlspecialchars('And more text...')); +$section->addTitle('I am Title 3', 1); +$section->addText('And more text...'); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3'), 2); -$section->addText(htmlspecialchars('Again and again, more text...')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1'), 3); -$section->addText(htmlspecialchars('Text')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1'), 4); -$section->addText(htmlspecialchars('Text')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2'), 4); -$section->addText(htmlspecialchars('Text')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.2'), 3); -$section->addText(htmlspecialchars('Text')); +$section->addTitle('I am a Subtitle of Title 3', 2); +$section->addText('Again and again, more text...'); +$section->addTitle('Subtitle 3.1.1', 3); +$section->addText('Text'); +$section->addTitle('Subtitle 3.1.1.1', 4); +$section->addText('Text'); +$section->addTitle('Subtitle 3.1.1.2', 4); +$section->addText('Text'); +$section->addTitle('Subtitle 3.1.2', 3); +$section->addText('Text'); echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL; diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php index f630bdf22d..dbab2b7f26 100644 --- a/samples/Sample_18_Watermark.php +++ b/samples/Sample_18_Watermark.php @@ -6,11 +6,10 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code - $section = $phpWord->addSection(); $header = $section->addHeader(); $header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); -$section->addText(htmlspecialchars('The header reference to the current section includes a watermark image.')); +$section->addText('The header reference to the current section includes a watermark image.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php index fc0e5419b0..17e2b1cbd7 100644 --- a/samples/Sample_19_TextBreak.php +++ b/samples/Sample_19_TextBreak.php @@ -5,25 +5,31 @@ 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)); -$fontStyle = array('size' => 24); +// Define styles +$fontStyle24 = array('size' => 24); +$paragraphStyle24 = array('spacing' => 240, 'size' => 24); + +$fontStyleName = 'fontStyle'; +$phpWord->addFontStyle($fontStyleName, array('size' => 9)); + +$paragraphStyleName = 'paragraphStyle'; +$phpWord->addParagraphStyle($paragraphStyleName, array('spacing' => 480)); + +// New section $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Text break with no style:')); + +$section->addText('Text break with no style:'); $section->addTextBreak(); -$section->addText(htmlspecialchars('Text break with defined font style:')); -$section->addTextBreak(1, 'fontStyle'); -$section->addText(htmlspecialchars('Text break with defined paragraph style:')); -$section->addTextBreak(1, null, 'paragraphStyle'); -$section->addText(htmlspecialchars('Text break with inline font style:')); -$section->addTextBreak(1, $fontStyle); -$section->addText(htmlspecialchars('Text break with inline paragraph style:')); -$section->addTextBreak(1, null, $paragraphStyle); -$section->addText(htmlspecialchars('Done.')); +$section->addText('Text break with defined font style:'); +$section->addTextBreak(1, $fontStyleName); +$section->addText('Text break with defined paragraph style:'); +$section->addTextBreak(1, null, $paragraphStyleName); +$section->addText('Text break with inline font style:'); +$section->addTextBreak(1, $fontStyle24); +$section->addText('Text break with inline paragraph style:'); +$section->addTextBreak(1, null, $paragraphStyle24); +$section->addText('Done.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_20_BGColor.php b/samples/Sample_20_BGColor.php index ebee8544fa..628ae8902e 100644 --- a/samples/Sample_20_BGColor.php +++ b/samples/Sample_20_BGColor.php @@ -4,17 +4,16 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); + +// New section $section = $phpWord->addSection(); $section->addText( - htmlspecialchars('This is some text highlighted using fgColor (limited to 15 colors) '), + 'This is some text highlighted using fgColor (limited to 15 colors)', array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW) ); -$section->addText( - htmlspecialchars('This one uses bgColor and is using hex value (0xfbbb10)'), - array('bgColor' => 'fbbb10') -); -$section->addText(htmlspecialchars('Compatible with font colors'), array('color' => '0000ff', 'bgColor' => 'fbbb10')); +$section->addText('This one uses bgColor and is using hex value (0xfbbb10)', array('bgColor' => 'fbbb10')); +$section->addText('Compatible with font colors', array('color' => '0000ff', 'bgColor' => 'fbbb10')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php index df3162c33c..ca33de3bcd 100644 --- a/samples/Sample_21_TableRowRules.php +++ b/samples/Sample_21_TableRowRules.php @@ -4,30 +4,24 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); + +// New section $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.')); +$section->addText('By default, when you insert an image, it adds a textbreak after its content.'); +$section->addText('If we want a simple border around an image, we wrap the image inside a table->row->cell'); $section->addText( - htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell') -); -$section->addText( - htmlspecialchars( - 'On the image with the red border, even if we set the row height to the height of the image, ' - . 'the textbreak is still there:' - ) + 'On the image with the red border, even if we set the row height to the height of the image, ' + . 'the textbreak is still there:' ); $table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0)); $table1->addRow(3750); $cell1 = $table1->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => 'ff0000')); -$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'align' => 'center')); +$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); $section->addTextBreak(); -$section->addText( - htmlspecialchars( - "But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:" - ) -); +$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:"); $table2 = $section->addTable( array( @@ -39,13 +33,11 @@ ); $table2->addRow(3750, array('exactHeight' => true)); $cell2 = $table2->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => '00ff00')); -$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'align' => 'center')); +$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); $section->addTextBreak(); -$section->addText( - htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.') -); -$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));")); +$section->addText('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.'); +$section->addText('So: $' . "table2->addRow(3750, array('exactHeight'=>true));"); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_22_CheckBox.php b/samples/Sample_22_CheckBox.php index b5d4a7a5a8..5a2ac3e2cc 100644 --- a/samples/Sample_22_CheckBox.php +++ b/samples/Sample_22_CheckBox.php @@ -5,14 +5,16 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Check box in section')); -$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1')); -$section->addText(htmlspecialchars('Check box in table cell')); + +$section->addText('Check box in section'); +$section->addCheckBox('chkBox1', 'Checkbox 1'); +$section->addText('Check box in table cell'); $table = $section->addTable(); $table->addRow(); $cell = $table->addCell(); -$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2')); +$cell->addCheckBox('chkBox2', 'Checkbox 2'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_25_TextBox.php b/samples/Sample_25_TextBox.php index afeb863d1c..7655e25f9d 100644 --- a/samples/Sample_25_TextBox.php +++ b/samples/Sample_25_TextBox.php @@ -5,40 +5,41 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); // In section $textbox = $section->addTextBox( array( - 'align' => 'center', + 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000', ) ); -$textbox->addText(htmlspecialchars('Text box content in section.')); -$textbox->addText(htmlspecialchars('Another line.')); +$textbox->addText('Text box content in section.'); +$textbox->addText('Another line.'); $cell = $textbox->addTable()->addRow()->addCell(); -$cell->addText(htmlspecialchars('Table inside textbox')); +$cell->addText('Table inside textbox'); // Inside table $section->addTextBreak(2); $cell = $section->addTable()->addRow()->addCell(300); $textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100)); -$textbox->addText(htmlspecialchars('Textbox inside table')); +$textbox->addText('Textbox inside table'); // Inside header with textrun $header = $section->addHeader(); $textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00')); $textrun = $textbox->addTextRun(); -$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ')); -$textrun->addText(htmlspecialchars('with bold text'), array('bold' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addLink('http://www.google.com', htmlspecialchars('link')); -$textrun->addText(htmlspecialchars(', and image ')); +$textrun->addText('TextBox in header. TextBox can contain a TextRun '); +$textrun->addText('with bold text', array('bold' => true)); +$textrun->addText(', '); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); +$textrun->addText(', and image '); $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$textrun->addText(htmlspecialchars('.')); +$textrun->addText('.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_27_Field.php b/samples/Sample_27_Field.php index 9bdbef8243..5774789561 100644 --- a/samples/Sample_27_Field.php +++ b/samples/Sample_27_Field.php @@ -5,24 +5,24 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// New section $section = $phpWord->addSection(); // Add Field elements // See Element/Field.php for all options -$section->addText(htmlspecialchars('Date field:')); +$section->addText('Date field:'); $section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat')); -$section->addText(htmlspecialchars('Page field:')); +$section->addText('Page field:'); $section->addField('PAGE', array('format' => 'ArabicDash')); -$section->addText(htmlspecialchars('Number of pages field:')); +$section->addText('Number of pages field:'); $section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat')); -$textrun = $section->addTextRun(array('align' => 'center')); -$textrun->addText(htmlspecialchars('This is the date of lunar calendar ')); +$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); +$textrun->addText('This is the date of lunar calendar '); $textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar')); -$textrun->addText(htmlspecialchars(' written in a textrun.')); +$textrun->addText(' written in a textrun.'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_29_Line.php b/samples/Sample_29_Line.php index 8bb192cfc8..030308eef1 100644 --- a/samples/Sample_29_Line.php +++ b/samples/Sample_29_Line.php @@ -5,12 +5,12 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); -// Begin code +// New section $section = $phpWord->addSection(); // Add Line elements // See Element/Line.php for all options -$section->addText(htmlspecialchars('Horizontal Line (Inline style):')); +$section->addText('Horizontal Line (Inline style):'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), @@ -18,7 +18,7 @@ 'positioning' => 'absolute', ) ); -$section->addText(htmlspecialchars('Vertical Line (Inline style):')); +$section->addText('Vertical Line (Inline style):'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), @@ -29,7 +29,7 @@ // Two text break $section->addTextBreak(1); -$section->addText(htmlspecialchars('Positioned Line (red):')); +$section->addText('Positioned Line (red):'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), @@ -44,7 +44,7 @@ ) ); -$section->addText(htmlspecialchars('Horizontal Formatted Line')); +$section->addText('Horizontal Formatted Line'); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15), diff --git a/samples/Sample_31_Shape.php b/samples/Sample_31_Shape.php index 3df71b4cc8..33628fcea4 100644 --- a/samples/Sample_31_Shape.php +++ b/samples/Sample_31_Shape.php @@ -3,14 +3,16 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; - $phpWord = new \PhpOffice\PhpWord\PhpWord(); -$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true)); +// New section $section = $phpWord->addSection(); +// Define styles +$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true)); + // Arc -$section->addTitle(htmlspecialchars('Arc'), 1); +$section->addTitle('Arc', 1); $section->addShape( 'arc', array( @@ -21,7 +23,7 @@ ); // Curve -$section->addTitle(htmlspecialchars('Curve'), 1); +$section->addTitle('Curve', 1); $section->addShape( 'curve', array( @@ -38,7 +40,7 @@ ); // Line -$section->addTitle(htmlspecialchars('Line'), 1); +$section->addTitle('Line', 1); $section->addShape( 'line', array( @@ -54,7 +56,7 @@ ); // Polyline -$section->addTitle(htmlspecialchars('Polyline'), 1); +$section->addTitle('Polyline', 1); $section->addShape( 'polyline', array( @@ -64,7 +66,7 @@ ); // Rectangle -$section->addTitle(htmlspecialchars('Rectangle'), 1); +$section->addTitle('Rectangle', 1); $section->addShape( 'rect', array( @@ -77,7 +79,7 @@ ); // Oval -$section->addTitle(htmlspecialchars('Oval'), 1); +$section->addTitle('Oval', 1); $section->addShape( 'oval', array( diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php index b61a646fde..2c6458ca4a 100644 --- a/samples/Sample_32_Chart.php +++ b/samples/Sample_32_Chart.php @@ -5,14 +5,15 @@ // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; - $phpWord = new \PhpOffice\PhpWord\PhpWord(); + +// Define styles $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); $phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); // 2D charts $section = $phpWord->addSection(); -$section->addTitle(htmlspecialchars('2D charts'), 1); +$section->addTitle('2D charts', 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); $chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar'); @@ -38,7 +39,7 @@ // 3D charts $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addTitle(htmlspecialchars('3D charts'), 1); +$section->addTitle('3D charts', 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); $chartTypes = array('pie', 'bar', 'column', 'line', 'area'); diff --git a/samples/Sample_33_FormField.php b/samples/Sample_33_FormField.php index 9f356810dc..a855d42a02 100644 --- a/samples/Sample_33_FormField.php +++ b/samples/Sample_33_FormField.php @@ -6,18 +6,19 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->getProtection()->setEditing('forms'); +// New section $section = $phpWord->addSection(); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput ')); +$textrun->addText('Form fields can be added in a text run and can be in form of textinput '); $textrun->addFormField('textinput')->setName('MyTextBox'); -$textrun->addText(htmlspecialchars(', checkbox ')); +$textrun->addText(', checkbox '); $textrun->addFormField('checkbox')->setDefault(true); -$textrun->addText(htmlspecialchars(', or dropdown ')); +$textrun->addText(', or dropdown '); $textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3')); -$textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.')); +$textrun->addText('. You have to set document protection to "forms" to enable dropdown.'); -$section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.')); +$section->addText('They can also be added as a stand alone paragraph.'); $section->addFormField('textinput')->setValue('Your name'); // Save file diff --git a/samples/Sample_34_SDT.php b/samples/Sample_34_SDT.php index 19ac42fe34..a50422796e 100644 --- a/samples/Sample_34_SDT.php +++ b/samples/Sample_34_SDT.php @@ -5,18 +5,19 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Combobox: ')); +$textrun->addText('Combobox: '); $textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2')); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Date: ')); +$textrun->addText('Date: '); $textrun->addSDT('date'); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Drop down list: ')); +$textrun->addText('Drop down list: '); $textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2')); // Save file diff --git a/samples/Sample_35_InternalLink.php b/samples/Sample_35_InternalLink.php index 1b907f8724..5ab7d9b4d9 100644 --- a/samples/Sample_35_InternalLink.php +++ b/samples/Sample_35_InternalLink.php @@ -6,13 +6,13 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); -$section->addTitle(htmlspecialchars('This is page 1'), 1); +$section->addTitle('This is page 1', 1); $linkIsInternal = true; -$section->addLink('MyBookmark', htmlspecialchars('Take me to page 3'), null, null, $linkIsInternal); +$section->addLink('MyBookmark', 'Take me to page 3', null, null, $linkIsInternal); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('This is page 2'), 1); +$section->addTitle('This is page 2', 1); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('This is page 3'), 1); +$section->addTitle('This is page 3', 1); $section->addBookmark('MyBookmark'); // Save file diff --git a/samples/Sample_36_RTL.php b/samples/Sample_36_RTL.php index ec326ae025..615557d78e 100644 --- a/samples/Sample_36_RTL.php +++ b/samples/Sample_36_RTL.php @@ -5,12 +5,14 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); +// New section $section = $phpWord->addSection(); + $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('This is a Left to Right paragraph.')); +$textrun->addText('This is a Left to Right paragraph.'); -$textrun = $section->addTextRun(array('align' => 'right')); -$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است'), array('rtl' => true)); +$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END)); +$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true)); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_Footer.php b/samples/Sample_Footer.php index 95ac693fc3..2d89bfd253 100644 --- a/samples/Sample_Footer.php +++ b/samples/Sample_Footer.php @@ -1,7 +1,4 @@ '); define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); define('IS_INDEX', SCRIPT_FILENAME == 'index'); -Autoloader::register(); Settings::loadConfig(); // Set writers @@ -26,6 +20,9 @@ $writers['PDF'] = null; } +// Turn output escaping on +Settings::setOutputEscapingEnabled(true); + // Return to the caller script when runs by CLI if (CLI) { return; diff --git a/samples/resources/Sample_28_ReadRTF.rtf b/samples/resources/Sample_28_ReadRTF.rtf index 6f9ac0f8b8..ccccc0e707 100644 --- a/samples/resources/Sample_28_ReadRTF.rtf +++ b/samples/resources/Sample_28_ReadRTF.rtf @@ -16,6 +16,6 @@ \pard\nowidctlpar\qc\sa100{\cf0\f0\fs32\b\i I am styled by both font and paragraph style.}\par \pard\nowidctlpar{\cf1\f1\fs40\b\i\ul\strike\super I am inline styled.}\par \par -{\field {\*\fldinst {HYPERLINK "http://www.google.com"}}{\fldrslt {Google}}}\par +{\field {\*\fldinst {HYPERLINK "https://github.com/PHPOffice/PHPWord"}}{\fldrslt {PHPWord on GitHub}}}\par \par } \ No newline at end of file diff --git a/src/PhpWord/Autoloader.php b/src/PhpWord/Autoloader.php deleted file mode 100644 index 68da845de3..0000000000 --- a/src/PhpWord/Autoloader.php +++ /dev/null @@ -1,58 +0,0 @@ -addImage($src, $style); - } - /** * Create textrun element * + * @deprecated 0.10.0 + * * @param mixed $paragraphStyle + * * @return \PhpOffice\PhpWord\Element\TextRun - * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function createTextRun($paragraphStyle = null) @@ -274,9 +267,12 @@ public function createTextRun($paragraphStyle = null) /** * Create footnote element * + * @deprecated 0.10.0 + * * @param mixed $paragraphStyle + * * @return \PhpOffice\PhpWord\Element\Footnote - * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function createFootnote($paragraphStyle = null) diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php index 99a7a1becc..b0ed8ae27a 100644 --- a/src/PhpWord/Element/AbstractElement.php +++ b/src/PhpWord/Element/AbstractElement.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -19,7 +19,6 @@ use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Style; /** * Element abstract class @@ -378,8 +377,11 @@ protected function setNewStyle($styleObject, $styleValue = null, $returnObject = * @param mixed $value * @param array $enum * @param mixed $default + * * @return mixed + * * @throws \InvalidArgumentException + * * @todo Merge with the same method in AbstractStyle */ protected function setEnumVal($value = null, $enum = array(), $default = null) diff --git a/src/PhpWord/Element/Bookmark.php b/src/PhpWord/Element/Bookmark.php index d5b8ff6fba..c865893fad 100644 --- a/src/PhpWord/Element/Bookmark.php +++ b/src/PhpWord/Element/Bookmark.php @@ -11,14 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; -use PhpOffice\PhpWord\Style; +use PhpOffice\Common\Text as CommonText; /** * Bookmark element @@ -47,7 +46,7 @@ class Bookmark extends AbstractElement public function __construct($name) { - $this->name = String::toUTF8($name); + $this->name = CommonText::toUTF8($name); return $this; } diff --git a/src/PhpWord/Element/Cell.php b/src/PhpWord/Element/Cell.php index cac37a7804..28e517fd83 100644 --- a/src/PhpWord/Element/Cell.php +++ b/src/PhpWord/Element/Cell.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Chart.php b/src/PhpWord/Element/Chart.php index 66c59ff52c..f98c1d7426 100644 --- a/src/PhpWord/Element/Chart.php +++ b/src/PhpWord/Element/Chart.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/CheckBox.php b/src/PhpWord/Element/CheckBox.php index d3b2a3c6f4..3fc578ef37 100644 --- a/src/PhpWord/Element/CheckBox.php +++ b/src/PhpWord/Element/CheckBox.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\Common\Text as CommonText; /** * Check box element @@ -56,7 +56,7 @@ public function __construct($name = null, $text = null, $fontStyle = null, $para */ public function setName($name) { - $this->name = String::toUTF8($name); + $this->name = CommonText::toUTF8($name); return $this; } diff --git a/src/PhpWord/Element/Endnote.php b/src/PhpWord/Element/Endnote.php index 1000055520..2d8e473179 100644 --- a/src/PhpWord/Element/Endnote.php +++ b/src/PhpWord/Element/Endnote.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Field.php b/src/PhpWord/Element/Field.php index 1eaa6f242f..48dc1d2eba 100644 --- a/src/PhpWord/Element/Field.php +++ b/src/PhpWord/Element/Field.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -94,7 +94,9 @@ public function __construct($type = null, $properties = array(), $options = arra * Set Field type * * @param string $type + * * @return string + * * @throws \InvalidArgumentException */ public function setType($type = null) @@ -123,7 +125,9 @@ public function getType() * Set Field properties * * @param array $properties + * * @return self + * * @throws \InvalidArgumentException */ public function setProperties($properties = array()) @@ -153,7 +157,9 @@ public function getProperties() * Set Field options * * @param array $options + * * @return self + * * @throws \InvalidArgumentException */ public function setOptions($options = array()) diff --git a/src/PhpWord/Element/Footer.php b/src/PhpWord/Element/Footer.php index 8e19eaf7db..01c6d25c9e 100644 --- a/src/PhpWord/Element/Footer.php +++ b/src/PhpWord/Element/Footer.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Footnote.php b/src/PhpWord/Element/Footnote.php index 162a703ed5..73350bb785 100644 --- a/src/PhpWord/Element/Footnote.php +++ b/src/PhpWord/Element/Footnote.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -20,7 +20,7 @@ use PhpOffice\PhpWord\Style\Paragraph; /** - * Footnote element + * @codeCoverageIgnore */ class Footnote extends AbstractContainer { @@ -67,9 +67,9 @@ public function getParagraphStyle() /** * Get Footnote Reference ID * - * @return int * @deprecated 0.10.0 - * @codeCoverageIgnore + * + * @return int */ public function getReferenceId() { @@ -79,9 +79,9 @@ public function getReferenceId() /** * Set Footnote Reference ID * - * @param int $rId * @deprecated 0.10.0 - * @codeCoverageIgnore + * + * @param int $rId */ public function setReferenceId($rId) { diff --git a/src/PhpWord/Element/FormField.php b/src/PhpWord/Element/FormField.php index 7bd61be1e7..c7cb44d240 100644 --- a/src/PhpWord/Element/FormField.php +++ b/src/PhpWord/Element/FormField.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Header.php b/src/PhpWord/Element/Header.php index feaa86e81a..d4afdb867f 100644 --- a/src/PhpWord/Element/Header.php +++ b/src/PhpWord/Element/Header.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php index cab2527a4e..2cce610d94 100644 --- a/src/PhpWord/Element/Image.php +++ b/src/PhpWord/Element/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -126,6 +126,7 @@ class Image extends AbstractElement * @param string $source * @param mixed $style * @param boolean $watermark + * * @throws \PhpOffice\PhpWord\Exception\InvalidImageException * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException */ @@ -365,7 +366,9 @@ public function getImageStringData($base64 = false) * Check memory image, supported type, image functions, and proportional width/height. * * @param string $source + * * @return void + * * @throws \PhpOffice\PhpWord\Exception\InvalidImageException * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException */ @@ -425,7 +428,9 @@ private function setSourceType($source) * @since 0.12.0 Throws CreateTemporaryFileException. * * @param string $source + * * @return array|null + * * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException */ private function getArchiveImageSize($source) @@ -517,6 +522,7 @@ private function setProportionalSize($actualWidth, $actualHeight) * Get is watermark * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getIsWatermark() @@ -528,6 +534,7 @@ public function getIsWatermark() * Get is memory image * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getIsMemImage() diff --git a/src/PhpWord/Element/Line.php b/src/PhpWord/Element/Line.php index b76ac4fb32..3e94a3a6bf 100644 --- a/src/PhpWord/Element/Line.php +++ b/src/PhpWord/Element/Line.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Link.php b/src/PhpWord/Element/Link.php index 9d0eb76662..4a72e167f0 100644 --- a/src/PhpWord/Element/Link.php +++ b/src/PhpWord/Element/Link.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -78,8 +78,8 @@ class Link extends AbstractElement */ public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false) { - $this->source = String::toUTF8($source); - $this->text = is_null($text) ? $this->source : String::toUTF8($text); + $this->source = CommonText::toUTF8($source); + $this->text = is_null($text) ? $this->source : CommonText::toUTF8($text); $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); $this->internal = $internal; @@ -129,8 +129,10 @@ public function getParagraphStyle() /** * Get link target * - * @return string * @deprecated 0.12.0 + * + * @return string + * * @codeCoverageIgnore */ public function getTarget() @@ -141,8 +143,10 @@ public function getTarget() /** * Get Link source * - * @return string * @deprecated 0.10.0 + * + * @return string + * * @codeCoverageIgnore */ public function getLinkSrc() @@ -153,8 +157,10 @@ public function getLinkSrc() /** * Get Link name * - * @return string * @deprecated 0.10.0 + * + * @return string + * * @codeCoverageIgnore */ public function getLinkName() diff --git a/src/PhpWord/Element/ListItem.php b/src/PhpWord/Element/ListItem.php index 4cb8d33952..25ace0905b 100644 --- a/src/PhpWord/Element/ListItem.php +++ b/src/PhpWord/Element/ListItem.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; /** @@ -57,7 +57,7 @@ class ListItem extends AbstractElement */ public function __construct($text, $depth = 0, $fontStyle = null, $listStyle = null, $paragraphStyle = null) { - $this->textObject = new Text(String::toUTF8($text), $fontStyle, $paragraphStyle); + $this->textObject = new Text(CommonText::toUTF8($text), $fontStyle, $paragraphStyle); $this->depth = $depth; // Version >= 0.10.0 will pass numbering style name. Older version will use old method diff --git a/src/PhpWord/Element/ListItemRun.php b/src/PhpWord/Element/ListItemRun.php index 1b77830db3..53440db617 100644 --- a/src/PhpWord/Element/ListItemRun.php +++ b/src/PhpWord/Element/ListItemRun.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord -* @copyright 2010-2014 PHPWord contributors +* @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Object.php b/src/PhpWord/Element/Object.php index 31943ba68a..7285030c0c 100644 --- a/src/PhpWord/Element/Object.php +++ b/src/PhpWord/Element/Object.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -65,6 +65,7 @@ class Object extends AbstractElement * * @param string $source * @param mixed $style + * * @throws \PhpOffice\PhpWord\Exception\InvalidObjectException */ public function __construct($source, $style = null) @@ -142,8 +143,10 @@ public function setImageRelationId($rId) /** * Get Object ID * - * @return int * @deprecated 0.10.0 + * + * @return int + * * @codeCoverageIgnore */ public function getObjectId() @@ -154,8 +157,10 @@ public function getObjectId() /** * Set Object ID * - * @param int $objId * @deprecated 0.10.0 + * + * @param int $objId + * * @codeCoverageIgnore */ public function setObjectId($objId) diff --git a/src/PhpWord/Element/PageBreak.php b/src/PhpWord/Element/PageBreak.php index a1e7e998e8..d9d4bc641b 100644 --- a/src/PhpWord/Element/PageBreak.php +++ b/src/PhpWord/Element/PageBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/PreserveText.php b/src/PhpWord/Element/PreserveText.php index 44aef3b40e..65e17e35b5 100644 --- a/src/PhpWord/Element/PreserveText.php +++ b/src/PhpWord/Element/PreserveText.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -61,7 +61,7 @@ public function __construct($text = null, $fontStyle = null, $paragraphStyle = n $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); - $this->text = String::toUTF8($text); + $this->text = CommonText::toUTF8($text); $matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if (isset($matches[0])) { $this->text = $matches; diff --git a/src/PhpWord/Element/Row.php b/src/PhpWord/Element/Row.php index e2df632551..05fde7e43d 100644 --- a/src/PhpWord/Element/Row.php +++ b/src/PhpWord/Element/Row.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/SDT.php b/src/PhpWord/Element/SDT.php index c69ed42772..58a477d92b 100644 --- a/src/PhpWord/Element/SDT.php +++ b/src/PhpWord/Element/SDT.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index d746f69bb3..1e926d2f57 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -11,18 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Style\Section as SectionStyle; -/** - * Section - */ class Section extends AbstractContainer { /** @@ -82,6 +78,8 @@ public function setStyle($style = null) * Get section style * * @return \PhpOffice\PhpWord\Style\Section + * + * @codeCoverageIgnore */ public function getStyle() { @@ -91,9 +89,11 @@ public function getStyle() /** * Add header * + * @since 0.10.0 + * * @param string $type + * * @return Header - * @since 0.10.0 */ public function addHeader($type = Header::AUTO) { @@ -103,9 +103,11 @@ public function addHeader($type = Header::AUTO) /** * Add footer * + * @since 0.10.0 + * * @param string $type + * * @return Footer - * @since 0.10.0 */ public function addFooter($type = Header::AUTO) { @@ -116,6 +118,8 @@ public function addFooter($type = Header::AUTO) * Get header elements * * @return Header[] + * + * @codeCoverageIgnore */ public function getHeaders() { @@ -126,6 +130,8 @@ public function getHeaders() * Get footer elements * * @return Footer[] + * + * @codeCoverageIgnore */ public function getFooters() { @@ -153,11 +159,14 @@ public function hasDifferentFirstPage() /** * Add header/footer * + * @since 0.10.0 + * * @param string $type * @param boolean $header + * * @return Header|Footer - * @throws \PhpOffice\PhpWord\Exception\Exception - * @since 0.10.0 + * + * @throws \Exception */ private function addHeaderFooter($type = Header::AUTO, $header = true) { @@ -175,7 +184,7 @@ private function addHeaderFooter($type = Header::AUTO, $header = true) $collection[$index] = $container; return $container; } else { - throw new Exception('Invalid header/footer type.'); + throw new \Exception('Invalid header/footer type.'); } } @@ -183,8 +192,10 @@ private function addHeaderFooter($type = Header::AUTO, $header = true) /** * Set section style * - * @param array $settings * @deprecated 0.12.0 + * + * @param array $settings + * * @codeCoverageIgnore */ public function setSettings($settings = null) @@ -195,8 +206,10 @@ public function setSettings($settings = null) /** * Get section style * - * @return \PhpOffice\PhpWord\Style\Section * @deprecated 0.12.0 + * + * @return \PhpOffice\PhpWord\Style\Section + * * @codeCoverageIgnore */ public function getSettings() @@ -207,8 +220,10 @@ public function getSettings() /** * Create header * - * @return Header * @deprecated 0.10.0 + * + * @return Header + * * @codeCoverageIgnore */ public function createHeader() @@ -219,8 +234,10 @@ public function createHeader() /** * Create footer * - * @return Footer * @deprecated 0.10.0 + * + * @return Footer + * * @codeCoverageIgnore */ public function createFooter() @@ -231,8 +248,10 @@ public function createFooter() /** * Get footer * - * @return Footer * @deprecated 0.10.0 + * + * @return Footer + * * @codeCoverageIgnore */ public function getFooter() diff --git a/src/PhpWord/Element/Shape.php b/src/PhpWord/Element/Shape.php index a7a96d1884..4717afb8f8 100644 --- a/src/PhpWord/Element/Shape.php +++ b/src/PhpWord/Element/Shape.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/TOC.php b/src/PhpWord/Element/TOC.php index a56d9ffe40..54ae384433 100644 --- a/src/PhpWord/Element/TOC.php +++ b/src/PhpWord/Element/TOC.php @@ -11,8 +11,8 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors - * @license http://www.gnu.org/licenses/lgpl.txt LGPL + * @copyright 2010-2016 PHPWord contributors + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; diff --git a/src/PhpWord/Element/Table.php b/src/PhpWord/Element/Table.php index 5f0b8f7953..357af37ae5 100644 --- a/src/PhpWord/Element/Table.php +++ b/src/PhpWord/Element/Table.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Text.php b/src/PhpWord/Element/Text.php index 52fccb3f28..0de9cdeaf2 100644 --- a/src/PhpWord/Element/Text.php +++ b/src/PhpWord/Element/Text.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -136,7 +136,7 @@ public function getParagraphStyle() */ public function setText($text) { - $this->text = String::toUTF8($text); + $this->text = CommonText::toUTF8($text); return $this; } diff --git a/src/PhpWord/Element/TextBox.php b/src/PhpWord/Element/TextBox.php index d929bf35db..4a1e51310b 100644 --- a/src/PhpWord/Element/TextBox.php +++ b/src/PhpWord/Element/TextBox.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/TextBreak.php b/src/PhpWord/Element/TextBreak.php index aa6ab582b2..893fa87531 100644 --- a/src/PhpWord/Element/TextBreak.php +++ b/src/PhpWord/Element/TextBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/TextRun.php b/src/PhpWord/Element/TextRun.php index c356cfa8e1..c2ce4f9981 100644 --- a/src/PhpWord/Element/TextRun.php +++ b/src/PhpWord/Element/TextRun.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Element/Title.php b/src/PhpWord/Element/Title.php index cf1d49c81a..eabb1feb82 100644 --- a/src/PhpWord/Element/Title.php +++ b/src/PhpWord/Element/Title.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\Common\Text as CommonText; use PhpOffice\PhpWord\Style; /** @@ -61,7 +61,7 @@ class Title extends AbstractElement */ public function __construct($text, $depth = 1) { - $this->text = String::toUTF8($text); + $this->text = CommonText::toUTF8($text); $this->depth = $depth; if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) { $this->style = "Heading{$this->depth}"; diff --git a/src/PhpWord/Escaper/AbstractEscaper.php b/src/PhpWord/Escaper/AbstractEscaper.php new file mode 100644 index 0000000000..6ddcbb51b2 --- /dev/null +++ b/src/PhpWord/Escaper/AbstractEscaper.php @@ -0,0 +1,46 @@ +escapeSingleValue($item); + } + } else { + $input = $this->escapeSingleValue($input); + } + + return $input; + } +} diff --git a/tests/PhpWord/Tests/Shared/XMLWriterTest.php b/src/PhpWord/Escaper/EscaperInterface.php similarity index 54% rename from tests/PhpWord/Tests/Shared/XMLWriterTest.php rename to src/PhpWord/Escaper/EscaperInterface.php index 08db39184f..c34cf370af 100644 --- a/tests/PhpWord/Tests/Shared/XMLWriterTest.php +++ b/src/PhpWord/Escaper/EscaperInterface.php @@ -11,30 +11,23 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Shared; - -use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Shared\XMLWriter; +namespace PhpOffice\PhpWord\Escaper; /** - * Test class for PhpOffice\PhpWord\Shared\XMLWriter + * @since 0.13.0 + * + * @codeCoverageIgnore */ -class XMLWriterTest extends \PHPUnit_Framework_TestCase +interface EscaperInterface { /** - * Test method exception + * @param mixed $input * - * @expectedException \BadMethodCallException - * @expectedExceptionMessage Method 'foo' does not exists. + * @return mixed */ - public function testCallException() - { - Settings::setCompatibility(false); - $object = new XMLWriter(); - $object->foo(); - } + public function escape($input); } diff --git a/src/PhpWord/Escaper/RegExp.php b/src/PhpWord/Escaper/RegExp.php new file mode 100644 index 0000000000..de510bcf01 --- /dev/null +++ b/src/PhpWord/Escaper/RegExp.php @@ -0,0 +1,33 @@ + $code || $code >= 80) { + return '{\u' . $code . '}'; + } else { + return chr($code); + } + } + + protected function escapeMultibyteCharacter($code) + { + return '\uc0{\u' . $code . '}'; + } + + /** + * @see http://www.randomchaos.com/documents/?source=php_and_unicode + */ + protected function escapeSingleValue($input) + { + $escapedValue = ''; + + $numberOfBytes = 1; + $bytes = array(); + for ($i = 0; $i < strlen($input); ++$i) { + $character = $input[$i]; + $asciiCode = ord($character); + + if ($asciiCode < 128) { + $escapedValue .= $this->escapeAsciiCharacter($asciiCode); + } else { + if (0 == count($bytes)) { + if ($asciiCode < 224) { + $numberOfBytes = 2; + } else if ($asciiCode < 240) { + $numberOfBytes = 3; + } else if ($asciiCode < 248) { + $numberOfBytes = 4; + } + } + + $bytes[] = $asciiCode; + + if ($numberOfBytes == count($bytes)) { + if (4 == $numberOfBytes) { + $multibyteCode = ($bytes[0] % 8) * 262144 + ($bytes[1] % 64) * 4096 + ($bytes[2] % 64) * 64 + ($bytes[3] % 64); + } elseif (3 == $numberOfBytes) { + $multibyteCode = ($bytes[0] % 16) * 4096 + ($bytes[1] % 64) * 64 + ($bytes[2] % 64); + } else { + $multibyteCode = ($bytes[0] % 32) * 64 + ($bytes[1] % 64); + } + + if (65279 != $multibyteCode) { + $escapedValue .= $multibyteCode < 128 ? $this->escapeAsciiCharacter($multibyteCode) : $this->escapeMultibyteCharacter($multibyteCode); + } + + $numberOfBytes = 1; + $bytes = array(); + } + } + } + + return $escapedValue; + } +} diff --git a/src/PhpWord/Escaper/Xml.php b/src/PhpWord/Escaper/Xml.php new file mode 100644 index 0000000000..274cade5b0 --- /dev/null +++ b/src/PhpWord/Escaper/Xml.php @@ -0,0 +1,32 @@ +_SummaryInformation = $ole->getStream($ole->summaryInformation); // Get Document Summary Information data - $this->_DocumentSummaryInformation = $ole->getStream($ole->documentSummaryInformation); + $this->_DocumentSummaryInformation = $ole->getStream($ole->docSummaryInfos); } private function getNumInLcb($lcb, $iSize) diff --git a/src/PhpWord/Reader/ODText.php b/src/PhpWord/Reader/ODText.php index d992f7fd3c..e8c868861c 100644 --- a/src/PhpWord/Reader/ODText.php +++ b/src/PhpWord/Reader/ODText.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Reader for ODText diff --git a/src/PhpWord/Reader/ODText/AbstractPart.php b/src/PhpWord/Reader/ODText/AbstractPart.php index 95f700847e..5ec2f22d7a 100644 --- a/src/PhpWord/Reader/ODText/AbstractPart.php +++ b/src/PhpWord/Reader/ODText/AbstractPart.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Reader/ODText/Content.php b/src/PhpWord/Reader/ODText/Content.php index cf2fd65368..7362b02ca2 100644 --- a/src/PhpWord/Reader/ODText/Content.php +++ b/src/PhpWord/Reader/ODText/Content.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\ODText; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Content reader diff --git a/src/PhpWord/Reader/ODText/Meta.php b/src/PhpWord/Reader/ODText/Meta.php index d08ce3a679..9533c38bd8 100644 --- a/src/PhpWord/Reader/ODText/Meta.php +++ b/src/PhpWord/Reader/ODText/Meta.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\ODText; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Meta reader diff --git a/src/PhpWord/Reader/RTF.php b/src/PhpWord/Reader/RTF.php index 9d5d813bf4..b6d2e21eeb 100644 --- a/src/PhpWord/Reader/RTF.php +++ b/src/PhpWord/Reader/RTF.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -31,7 +31,9 @@ class RTF extends AbstractReader implements ReaderInterface * Loads PhpWord from file * * @param string $docFile + * * @throws \Exception + * * @return \PhpOffice\PhpWord\PhpWord */ public function load($docFile) diff --git a/src/PhpWord/Reader/RTF/Document.php b/src/PhpWord/Reader/RTF/Document.php index 3f63e3398e..4e0f2c3559 100644 --- a/src/PhpWord/Reader/RTF/Document.php +++ b/src/PhpWord/Reader/RTF/Document.php @@ -11,13 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\RTF; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\SimpleType\Jc; /** * RTF document reader @@ -140,7 +141,7 @@ public function read(PhpWord $phpWord) 125 => 'markClosing', // } 92 => 'markBackslash', // \ 10 => 'markNewline', // LF - 13 => 'markNewline' // CR + 13 => 'markNewline', // CR ); $this->phpWord = $phpWord; @@ -159,7 +160,7 @@ public function read(PhpWord $phpWord) $markerFunction = $markers[$ascii]; $this->$markerFunction(); } else { - if ($this->isControl === false) { // Non control word: Push character + if (false === $this->isControl) { // Non control word: Push character $this->pushText($char); } else { if (preg_match("/^[a-zA-Z0-9-]?$/", $char)) { // No delimiter: Buffer control @@ -169,7 +170,7 @@ public function read(PhpWord $phpWord) if ($this->isFirst) { $this->isFirst = false; } else { - if ($char == ' ') { // Discard space as a control word delimiter + if (' ' == $char) { // Discard space as a control word delimiter $this->flushControl(true); } } @@ -255,12 +256,12 @@ private function flush($isControl = false) */ private function flushControl($isControl = false) { - if (preg_match("/^([A-Za-z]+)(-?[0-9]*) ?$/", $this->control, $match) === 1) { + if (1 === preg_match("/^([A-Za-z]+)(-?[0-9]*) ?$/", $this->control, $match)) { list(, $control, $parameter) = $match; $this->parseControl($control, $parameter); } - if ($isControl === true) { + if (true === $isControl) { $this->setControl(false); } } @@ -276,7 +277,7 @@ private function flushText() if (isset($this->flags['property'])) { // Set property $this->flags['value'] = $this->text; } else { // Set text - if ($this->flags['paragraph'] === true) { + if (true === $this->flags['paragraph']) { $this->flags['paragraph'] = false; $this->flags['text'] = $this->text; } @@ -311,9 +312,9 @@ private function setControl($value) */ private function pushText($char) { - if ($char == '<') { + if ('<' == $char) { $this->text .= "<"; - } elseif ($char == '>') { + } elseif ('>' == $char) { $this->text .= ">"; } else { $this->text .= $char; @@ -336,7 +337,7 @@ private function parseControl($control, $parameter) 'u' => array(self::STYL, 'font', 'underline', true), 'strike' => array(self::STYL, 'font', 'strikethrough',true), 'fs' => array(self::STYL, 'font', 'size', $parameter), - 'qc' => array(self::STYL, 'paragraph', 'align', 'center'), + 'qc' => array(self::STYL, 'paragraph', 'alignment', Jc::CENTER), 'sa' => array(self::STYL, 'paragraph', 'spaceAfter', $parameter), 'fonttbl' => array(self::SKIP, 'fonttbl', null), 'colortbl' => array(self::SKIP, 'colortbl', null), diff --git a/src/PhpWord/Reader/ReaderInterface.php b/src/PhpWord/Reader/ReaderInterface.php index 361c413796..4f5231a767 100644 --- a/src/PhpWord/Reader/ReaderInterface.php +++ b/src/PhpWord/Reader/ReaderInterface.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index ebe6c4f765..da20eb8763 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; use PhpOffice\PhpWord\Shared\ZipArchive; /** diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 021bdba11e..f429ff7519 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Abstract part reader @@ -92,7 +92,7 @@ public function setRels($value) /** * Read w:p. * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @param mixed $parent * @param string $docPart @@ -122,16 +122,16 @@ protected function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, $pa $instrText = $xmlReader->getValue('w:instrText', $node); if ($xmlReader->elementExists('w:fldChar', $node)) { $fldCharType = $xmlReader->getAttribute('w:fldCharType', $node, 'w:fldChar'); - if ($fldCharType == 'begin') { + if ('begin' == $fldCharType) { $ignoreText = true; - } elseif ($fldCharType == 'end') { + } elseif ('end' == $fldCharType) { $ignoreText = false; } } if (!is_null($instrText)) { $textContent .= '{' . $instrText . '}'; } else { - if ($ignoreText === false) { + if (false === $ignoreText) { $textContent .= $xmlReader->getValue('w:t', $node); } } @@ -163,7 +163,7 @@ protected function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, $pa $runCount = $xmlReader->countElements('w:r', $domNode); $linkCount = $xmlReader->countElements('w:hyperlink', $domNode); $runLinkCount = $runCount + $linkCount; - if ($runLinkCount == 0) { + if (0 == $runLinkCount) { $parent->addTextBreak(null, $paragraphStyle); } else { $nodes = $xmlReader->getElements('*', $domNode); @@ -183,7 +183,7 @@ protected function readParagraph(XMLReader $xmlReader, \DOMElement $domNode, $pa /** * Read w:r. * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @param mixed $parent * @param string $docPart @@ -200,7 +200,7 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, $fontStyle = $this->readFontStyle($xmlReader, $domNode); // Link - if ($domNode->nodeName == 'w:hyperlink') { + if ('w:hyperlink' == $domNode->nodeName) { $rId = $xmlReader->getAttribute('r:id', $domNode); $textContent = $xmlReader->getValue('w:r/w:t', $domNode); $target = $this->getMediaTarget($docPart, $rId); @@ -246,7 +246,7 @@ protected function readRun(XMLReader $xmlReader, \DOMElement $domNode, $parent, /** * Read w:tbl. * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @param mixed $parent * @param string $docPart @@ -264,26 +264,26 @@ protected function readTable(XMLReader $xmlReader, \DOMElement $domNode, $parent $table = $parent->addTable($tblStyle); $tblNodes = $xmlReader->getElements('*', $domNode); foreach ($tblNodes as $tblNode) { - if ($tblNode->nodeName == 'w:tblGrid') { // Column + if ('w:tblGrid' == $tblNode->nodeName) { // Column // @todo Do something with table columns - } elseif ($tblNode->nodeName == 'w:tr') { // Row + } elseif ('w:tr' == $tblNode->nodeName) { // Row $rowHeight = $xmlReader->getAttribute('w:val', $tblNode, 'w:trPr/w:trHeight'); $rowHRule = $xmlReader->getAttribute('w:hRule', $tblNode, 'w:trPr/w:trHeight'); $rowHRule = $rowHRule == 'exact' ? true : false; $rowStyle = array( - 'tblHeader' => $xmlReader->elementExists('w:trPr/w:tblHeader', $tblNode), - 'cantSplit' => $xmlReader->elementExists('w:trPr/w:cantSplit', $tblNode), + 'tblHeader' => $xmlReader->elementExists('w:trPr/w:tblHeader', $tblNode), + 'cantSplit' => $xmlReader->elementExists('w:trPr/w:cantSplit', $tblNode), 'exactHeight' => $rowHRule, ); $row = $table->addRow($rowHeight, $rowStyle); $rowNodes = $xmlReader->getElements('*', $tblNode); foreach ($rowNodes as $rowNode) { - if ($rowNode->nodeName == 'w:trPr') { // Row style + if ('w:trPr' == $rowNode->nodeName) { // Row style // @todo Do something with row style - } elseif ($rowNode->nodeName == 'w:tc') { // Cell + } elseif ('w:tc' == $rowNode->nodeName) { // Cell $cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW'); $cellStyle = null; $cellStyleNode = $xmlReader->getElement('w:tcPr', $rowNode); @@ -294,7 +294,7 @@ protected function readTable(XMLReader $xmlReader, \DOMElement $domNode, $parent $cell = $row->addCell($cellWidth, $cellStyle); $cellNodes = $xmlReader->getElements('*', $rowNode); foreach ($cellNodes as $cellNode) { - if ($cellNode->nodeName == 'w:p') { // Paragraph + if ('w:p' == $cellNode->nodeName) { // Paragraph $this->readParagraph($xmlReader, $cellNode, $cell, $docPart); } } @@ -307,7 +307,7 @@ protected function readTable(XMLReader $xmlReader, \DOMElement $domNode, $parent /** * Read w:pPr. * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @return array|null */ @@ -320,7 +320,7 @@ protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode $styleNode = $xmlReader->getElement('w:pPr', $domNode); $styleDefs = array( 'styleName' => array(self::READ_VALUE, 'w:pStyle'), - 'align' => array(self::READ_VALUE, 'w:jc'), + 'alignment' => array(self::READ_VALUE, 'w:jc'), 'basedOn' => array(self::READ_VALUE, 'w:basedOn'), 'next' => array(self::READ_VALUE, 'w:next'), 'indent' => array(self::READ_VALUE, 'w:ind', 'w:left'), @@ -339,7 +339,7 @@ protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode /** * Read w:rPr * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @return array|null */ @@ -349,7 +349,7 @@ protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode) return null; } // Hyperlink has an extra w:r child - if ($domNode->nodeName == 'w:hyperlink') { + if ('w:hyperlink' == $domNode->nodeName) { $domNode = $xmlReader->getElement('w:r', $domNode); } if (!$xmlReader->elementExists('w:rPr', $domNode)) { @@ -382,7 +382,7 @@ protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode) /** * Read w:tblPr * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @return string|array|null * @todo Capture w:tblStylePr w:type="firstRow" @@ -399,7 +399,6 @@ protected function readTableStyle(XMLReader $xmlReader, \DOMElement $domNode) } else { $styleNode = $xmlReader->getElement('w:tblPr', $domNode); $styleDefs = array(); - // $styleDefs['styleName'] = array(self::READ_VALUE, 'w:tblStyle'); foreach ($margins as $side) { $ucfSide = ucfirst($side); $styleDefs["cellMargin$ucfSide"] = array(self::READ_VALUE, "w:tblCellMar/w:$side", 'w:w'); @@ -419,7 +418,7 @@ protected function readTableStyle(XMLReader $xmlReader, \DOMElement $domNode) /** * Read w:tcPr * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @return array */ @@ -439,7 +438,7 @@ private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode) /** * Read style definition * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $parentNode * @param array $styleDefs * @ignoreScrutinizerPatch @@ -482,13 +481,13 @@ private function readStyleDef($method, $attributeValue, $expected) { $style = $attributeValue; - if ($method == self::READ_SIZE) { + if (self::READ_SIZE == $method) { $style = $attributeValue / 2; - } elseif ($method == self::READ_TRUE) { + } elseif (self::READ_TRUE == $method) { $style = true; - } elseif ($method == self::READ_FALSE) { + } elseif (self::READ_FALSE == $method) { $style = false; - } elseif ($method == self::READ_EQUAL) { + } elseif (self::READ_EQUAL == $method) { $style = $attributeValue == $expected; } diff --git a/src/PhpWord/Reader/Word2007/DocPropsApp.php b/src/PhpWord/Reader/Word2007/DocPropsApp.php index ddbe474f1a..6b1410a56a 100644 --- a/src/PhpWord/Reader/Word2007/DocPropsApp.php +++ b/src/PhpWord/Reader/Word2007/DocPropsApp.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Reader/Word2007/DocPropsCore.php b/src/PhpWord/Reader/Word2007/DocPropsCore.php index 54537525b6..417a93bd3f 100644 --- a/src/PhpWord/Reader/Word2007/DocPropsCore.php +++ b/src/PhpWord/Reader/Word2007/DocPropsCore.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Core properties reader diff --git a/src/PhpWord/Reader/Word2007/DocPropsCustom.php b/src/PhpWord/Reader/Word2007/DocPropsCustom.php index eb725b2ec3..979a244197 100644 --- a/src/PhpWord/Reader/Word2007/DocPropsCustom.php +++ b/src/PhpWord/Reader/Word2007/DocPropsCustom.php @@ -11,15 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\Metadata\DocInfo; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Custom properties reader diff --git a/src/PhpWord/Reader/Word2007/Document.php b/src/PhpWord/Reader/Word2007/Document.php index e1beed0666..b89a99ad14 100644 --- a/src/PhpWord/Reader/Word2007/Document.php +++ b/src/PhpWord/Reader/Word2007/Document.php @@ -11,15 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Document reader @@ -99,7 +99,7 @@ private function readHeaderFooter($settings, Section &$section) /** * Read w:sectPr * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $domNode * @ignoreScrutinizerPatch * @return array @@ -142,7 +142,7 @@ private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode) /** * Read w:p node. * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $node * @param \PhpOffice\PhpWord\Element\Section &$section * @return void @@ -172,7 +172,7 @@ private function readWPNode(XMLReader $xmlReader, \DOMElement $node, Section &$s /** * Read w:sectPr node. * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $node * @param \PhpOffice\PhpWord\Element\Section &$section * @return void diff --git a/src/PhpWord/Reader/Word2007/Endnotes.php b/src/PhpWord/Reader/Word2007/Endnotes.php index c493c34790..7bcafc6a10 100644 --- a/src/PhpWord/Reader/Word2007/Endnotes.php +++ b/src/PhpWord/Reader/Word2007/Endnotes.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Reader/Word2007/Footnotes.php b/src/PhpWord/Reader/Word2007/Footnotes.php index 6f6adc879e..3d85af716c 100644 --- a/src/PhpWord/Reader/Word2007/Footnotes.php +++ b/src/PhpWord/Reader/Word2007/Footnotes.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Footnotes reader diff --git a/src/PhpWord/Reader/Word2007/Numbering.php b/src/PhpWord/Reader/Word2007/Numbering.php index 872d45033b..a00a630740 100644 --- a/src/PhpWord/Reader/Word2007/Numbering.php +++ b/src/PhpWord/Reader/Word2007/Numbering.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Numbering reader @@ -90,7 +90,7 @@ public function read(PhpWord $phpWord) /** * Read numbering level definition from w:abstractNum and w:num * - * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \PhpOffice\Common\XMLReader $xmlReader * @param \DOMElement $subnode * @param integer $levelId * @return array @@ -105,7 +105,7 @@ private function readLevel(XMLReader $xmlReader, \DOMElement $subnode, $levelId) $level['restart'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlRestart'); $level['suffix'] = $xmlReader->getAttribute('w:val', $subnode, 'w:suff'); $level['text'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlText'); - $level['align'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlJc'); + $level['alignment'] = $xmlReader->getAttribute('w:val', $subnode, 'w:lvlJc'); $level['tab'] = $xmlReader->getAttribute('w:pos', $subnode, 'w:pPr/w:tabs/w:tab'); $level['left'] = $xmlReader->getAttribute('w:left', $subnode, 'w:pPr/w:ind'); $level['hanging'] = $xmlReader->getAttribute('w:hanging', $subnode, 'w:pPr/w:ind'); diff --git a/src/PhpWord/Reader/Word2007/Styles.php b/src/PhpWord/Reader/Word2007/Styles.php index 299fe1df77..645c9830c2 100644 --- a/src/PhpWord/Reader/Word2007/Styles.php +++ b/src/PhpWord/Reader/Word2007/Styles.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Reader\Word2007; +use PhpOffice\Common\XMLReader; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLReader; /** * Styles reader diff --git a/src/PhpWord/Settings.php b/src/PhpWord/Settings.php index 67b1dbedbd..e049c46ed1 100644 --- a/src/PhpWord/Settings.php +++ b/src/PhpWord/Settings.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -126,6 +126,14 @@ class Settings */ private static $tempDir = ''; + /** + * Enables built-in output escaping mechanism. + * Default value is `false` for backward compatibility with versions below 0.13.0. + * + * @var bool + */ + private static $outputEscapingEnabled = false; + /** * Return the compatibility option used by the XMLWriter * @@ -282,6 +290,7 @@ public static function setMeasurementUnit($value) * @since 0.12.0 * * @param string $tempDir The user defined path to temporary directory. + * * @return void */ public static function setTempDir($tempDir) @@ -307,6 +316,30 @@ public static function getTempDir() return $tempDir; } + /** + * @since 0.13.0 + * + * @return boolean + * + * @codeCoverageIgnore + */ + public static function isOutputEscapingEnabled() + { + return self::$outputEscapingEnabled; + } + + /** + * @since 0.13.0 + * + * @param boolean $outputEscapingEnabled + * + * @codeCoverageIgnore + */ + public static function setOutputEscapingEnabled($outputEscapingEnabled) + { + self::$outputEscapingEnabled = $outputEscapingEnabled; + } + /** * Get default font name * @@ -407,6 +440,7 @@ public static function loadConfig($filename = null) * Return the compatibility option used by the XMLWriter * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public static function getCompatibility() diff --git a/src/PhpWord/Shared/Converter.php b/src/PhpWord/Shared/Converter.php index c6727edd55..e5cb5b25f0 100644 --- a/src/PhpWord/Shared/Converter.php +++ b/src/PhpWord/Shared/Converter.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Shared/Drawing.php b/src/PhpWord/Shared/Drawing.php deleted file mode 100644 index e3a33e5b69..0000000000 --- a/src/PhpWord/Shared/Drawing.php +++ /dev/null @@ -1,217 +0,0 @@ -' . $html . ''; } @@ -73,7 +73,7 @@ public static function addHtml($element, $html, $fullHTML = false) */ protected static function parseInlineStyle($node, $styles = array()) { - if ($node->nodeType == XML_ELEMENT_NODE) { + if (XML_ELEMENT_NODE == $node->nodeType) { $attributes = $node->attributes; // get all the attributes(eg: id, class) foreach ($attributes as $attribute) { @@ -173,7 +173,7 @@ protected static function parseNode($node, $element, $styles = array(), $data = */ private static function parseChildNodes($node, $element, $styles, $data) { - if ($node->nodeName != 'li') { + if ('li' != $node->nodeName) { $cNodes = $node->childNodes; if (count($cNodes) > 0) { foreach ($cNodes as $cNode) { @@ -361,7 +361,7 @@ private static function parseStyle($attribute, $styles) } break; case 'text-align': - $styles['align'] = $cValue; + $styles['alignment'] = $cValue; // todo: any mapping? break; case 'color': $styles['color'] = trim($cValue, "#"); diff --git a/src/PhpWord/Shared/OLERead.php b/src/PhpWord/Shared/OLERead.php index 82815afc4b..cf9b15d3e6 100644 --- a/src/PhpWord/Shared/OLERead.php +++ b/src/PhpWord/Shared/OLERead.php @@ -1,15 +1,22 @@ 127 ? '\uc0{\u' . $value . '}' : chr($value); - } - } - - return $entities; - } - - /** - * Return name without underscore for < 0.10.0 variable name compatibility - * - * @param string $value - * @return string - */ - public static function removeUnderscorePrefix($value) - { - if (!is_null($value)) { - if (substr($value, 0, 1) == '_') { - $value = substr($value, 1); - } - } - - return $value; - } - - /** - * Build control characters array. - * - * @return void - */ - private static function buildControlCharacters() - { - for ($i = 0; $i <= 19; ++$i) { - if ($i != 9 && $i != 10 && $i != 13) { - $find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_'; - $replace = chr($i); - self::$controlCharacters[$find] = $replace; - } - } - } -} diff --git a/src/PhpWord/Shared/XMLReader.php b/src/PhpWord/Shared/XMLReader.php deleted file mode 100644 index ca6869eb3c..0000000000 --- a/src/PhpWord/Shared/XMLReader.php +++ /dev/null @@ -1,192 +0,0 @@ -open($zipFile); - $content = $zip->getFromName($xmlFile); - $zip->close(); - - if ($content === false) { - return false; - } else { - return $this->getDomFromString($content); - } - } - - /** - * Get DOMDocument from content string - * - * @param string $content - * @return \DOMDocument - */ - public function getDomFromString($content) - { - $this->dom = new \DOMDocument(); - $this->dom->loadXML($content); - - return $this->dom; - } - - /** - * Get elements - * - * @param string $path - * @param \DOMElement $contextNode - * @return \DOMNodeList - */ - public function getElements($path, \DOMElement $contextNode = null) - { - if ($this->dom === null) { - return array(); - } - if ($this->xpath === null) { - $this->xpath = new \DOMXpath($this->dom); - } - - if (is_null($contextNode)) { - return $this->xpath->query($path); - } else { - return $this->xpath->query($path, $contextNode); - } - } - - /** - * Get element - * - * @param string $path - * @param \DOMElement $contextNode - * @return \DOMElement|null - */ - public function getElement($path, \DOMElement $contextNode = null) - { - $elements = $this->getElements($path, $contextNode); - if ($elements->length > 0) { - return $elements->item(0); - } else { - return null; - } - } - - /** - * Get element attribute - * - * @param string $attribute - * @param \DOMElement $contextNode - * @param string $path - * @return string|null - */ - public function getAttribute($attribute, \DOMElement $contextNode = null, $path = null) - { - $return = null; - if ($path !== null) { - $elements = $this->getElements($path, $contextNode); - if ($elements->length > 0) { - /** @var \DOMElement $node Type hint */ - $node = $elements->item(0); - $return = $node->getAttribute($attribute); - } - } else { - if ($contextNode !== null) { - $return = $contextNode->getAttribute($attribute); - } - } - - return ($return == '') ? null : $return; - } - - /** - * Get element value - * - * @param string $path - * @param \DOMElement $contextNode - * @return string|null - */ - public function getValue($path, \DOMElement $contextNode = null) - { - $elements = $this->getElements($path, $contextNode); - if ($elements->length > 0) { - return $elements->item(0)->nodeValue; - } else { - return null; - } - } - - /** - * Count elements - * - * @param string $path - * @param \DOMElement $contextNode - * @return integer - */ - public function countElements($path, \DOMElement $contextNode = null) - { - $elements = $this->getElements($path, $contextNode); - - return $elements->length; - } - - /** - * Element exists - * - * @param string $path - * @param \DOMElement $contextNode - * @return boolean - */ - public function elementExists($path, \DOMElement $contextNode = null) - { - return $this->getElements($path, $contextNode)->length > 0; - } -} diff --git a/src/PhpWord/Shared/XMLWriter.php b/src/PhpWord/Shared/XMLWriter.php deleted file mode 100644 index 2134f62a9d..0000000000 --- a/src/PhpWord/Shared/XMLWriter.php +++ /dev/null @@ -1,202 +0,0 @@ -xmlWriter = new \XMLWriter(); - - // Open temporary storage - if ($tempLocation == self::STORAGE_MEMORY) { - $this->xmlWriter->openMemory(); - } else { - // Create temporary filename - $this->tempFile = tempnam($tempFolder, 'xml'); - - // Fallback to memory when temporary file cannot be used - // @codeCoverageIgnoreStart - // Can't find any test case. Uncomment when found. - if (false === $this->tempFile || false === $this->xmlWriter->openUri($this->tempFile)) { - $this->xmlWriter->openMemory(); - } - // @codeCoverageIgnoreEnd - } - - // Set xml Compatibility - $compatibility = Settings::hasCompatibility(); - if ($compatibility) { - $this->xmlWriter->setIndent(false); - $this->xmlWriter->setIndentString(''); - } else { - $this->xmlWriter->setIndent(true); - $this->xmlWriter->setIndentString(' '); - } - } - - /** - * Destructor - */ - public function __destruct() - { - // Destruct XMLWriter - unset($this->xmlWriter); - - // Unlink temporary files - if ($this->tempFile != '') { - @unlink($this->tempFile); - } - } - - /** - * Catch function calls (and pass them to internal XMLWriter) - * - * @param mixed $function - * @param mixed $args - * @throws \BadMethodCallException - */ - public function __call($function, $args) - { - // Catch exception - if (method_exists($this->xmlWriter, $function) === false) { - throw new \BadMethodCallException("Method '{$function}' does not exists."); - } - - // Run method - try { - @call_user_func_array(array($this->xmlWriter, $function), $args); - } catch (\Exception $ex) { - // Do nothing! - } - } - - /** - * Get written data - * - * @return string XML data - */ - public function getData() - { - if ($this->tempFile == '') { - return $this->xmlWriter->outputMemory(true); - } else { - $this->xmlWriter->flush(); - return file_get_contents($this->tempFile); - } - } - - /** - * Write simple element and attribute(s) block - * - * There are two options: - * 1. If the `$attributes` is an array, then it's an associative array of attributes - * 2. If not, then it's a simple attribute-value pair - * - * @param string $element - * @param string|array $attributes - * @param string $value - * @return void - */ - public function writeElementBlock($element, $attributes, $value = null) - { - $this->xmlWriter->startElement($element); - if (!is_array($attributes)) { - $attributes = array($attributes => $value); - } - foreach ($attributes as $attribute => $value) { - $this->xmlWriter->writeAttribute($attribute, $value); - } - $this->xmlWriter->endElement(); - } - - /** - * Write element if ... - * - * @param bool $condition - * @param string $element - * @param string $attribute - * @param mixed $value - * @return void - */ - public function writeElementIf($condition, $element, $attribute = null, $value = null) - { - if ($condition == true) { - if (is_null($attribute)) { - $this->xmlWriter->writeElement($element, $value); - } else { - $this->xmlWriter->startElement($element); - $this->xmlWriter->writeAttribute($attribute, $value); - $this->xmlWriter->endElement(); - } - } - } - - /** - * Write attribute if ... - * - * @param bool $condition - * @param string $attribute - * @param mixed $value - * @return void - */ - public function writeAttributeIf($condition, $attribute, $value) - { - if ($condition == true) { - $this->xmlWriter->writeAttribute($attribute, $value); - } - } -} diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php index 157959e8e9..4dc4af4e14 100644 --- a/src/PhpWord/Shared/ZipArchive.php +++ b/src/PhpWord/Shared/ZipArchive.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -151,7 +151,9 @@ public function open($filename, $flags = null) * Close the active archive * * @return bool + * * @throws \PhpOffice\PhpWord\Exception\Exception + * * @codeCoverageIgnore Can't find any test case. Uncomment when found. */ public function close() diff --git a/src/PhpWord/SimpleType/Jc.php b/src/PhpWord/SimpleType/Jc.php new file mode 100644 index 0000000000..e90674a449 --- /dev/null +++ b/src/PhpWord/SimpleType/Jc.php @@ -0,0 +1,98 @@ + array( + self::START, + self::CENTER, + self::END, + self::BOTH, + self::MEDIUM_KASHIDA, + self::DISTRIBUTE, + self::NUM_TAB, + self::HIGH_KASHIDA, + self::LOW_KASHIDA, + self::THAI_DISTRIBUTE, + self::LEFT, + self::RIGHT, + self::JUSTIFY, + ), + 'strict' => InArray::COMPARE_STRICT, + ) + ); + } +} diff --git a/src/PhpWord/SimpleType/JcTable.php b/src/PhpWord/SimpleType/JcTable.php new file mode 100644 index 0000000000..d9648477d3 --- /dev/null +++ b/src/PhpWord/SimpleType/JcTable.php @@ -0,0 +1,52 @@ + array(self::START, self::CENTER, self::END), + 'strict' => InArray::COMPARE_STRICT, + ) + ); + } +} diff --git a/src/PhpWord/Style.php b/src/PhpWord/Style.php index ab03106fce..57d9d69208 100644 --- a/src/PhpWord/Style.php +++ b/src/PhpWord/Style.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/AbstractStyle.php b/src/PhpWord/Style/AbstractStyle.php index ab1a1ee729..05c79ea2da 100644 --- a/src/PhpWord/Style/AbstractStyle.php +++ b/src/PhpWord/Style/AbstractStyle.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\Common\Text; /** * Abstract style class @@ -161,7 +161,7 @@ public function setStyleValue($key, $value) if (isset($this->aliases[$key])) { $key = $this->aliases[$key]; } - $method = 'set' . String::removeUnderscorePrefix($key); + $method = 'set' . Text::removeUnderscorePrefix($key); if (method_exists($this, $method)) { $this->$method($value); } @@ -278,7 +278,9 @@ protected function setFloatVal($value, $default = null) * @param mixed $value * @param array $enum * @param mixed $default + * * @return mixed + * * @throws \InvalidArgumentException */ protected function setEnumVal($value = null, $enum = array(), $default = null) @@ -337,9 +339,12 @@ protected function setPairedVal(&$property, &$pairProperty, $value) /** * Set style using associative array * + * @deprecated 0.11.0 + * * @param array $style + * * @return self - * @deprecated 0.11.0 + * * @codeCoverageIgnore */ public function setArrayStyle(array $style = array()) diff --git a/src/PhpWord/Style/Alignment.php b/src/PhpWord/Style/Alignment.php deleted file mode 100644 index 3beabe376a..0000000000 --- a/src/PhpWord/Style/Alignment.php +++ /dev/null @@ -1,78 +0,0 @@ -setStyleByArray($style); - } - - /** - * Get alignment - * - * @return string - */ - public function getValue() - { - return $this->value; - } - - /** - * Set alignment - * - * @param string $value - * @return self - */ - public function setValue($value = null) - { - if (strtolower($value) == self::ALIGN_JUSTIFY) { - $value = self::ALIGN_BOTH; - } - $enum = array(self::ALIGN_LEFT, self::ALIGN_RIGHT, self::ALIGN_CENTER, self::ALIGN_BOTH, self::ALIGN_JUSTIFY); - $this->value = $this->setEnumVal($value, $enum, $this->value); - - return $this; - } -} diff --git a/src/PhpWord/Style/Border.php b/src/PhpWord/Style/Border.php index 84116d7a70..d3bc2e571c 100644 --- a/src/PhpWord/Style/Border.php +++ b/src/PhpWord/Style/Border.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php index 11290c8752..7bab8b56c2 100644 --- a/src/PhpWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -240,6 +240,7 @@ public function setShading($value = null) * Get default border color * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getDefaultBorderColor() diff --git a/src/PhpWord/Style/Chart.php b/src/PhpWord/Style/Chart.php index 13b72a33f5..8e1f4b61b5 100644 --- a/src/PhpWord/Style/Chart.php +++ b/src/PhpWord/Style/Chart.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Extrusion.php b/src/PhpWord/Style/Extrusion.php index ccbb26505b..d8c5e65ffc 100644 --- a/src/PhpWord/Style/Extrusion.php +++ b/src/PhpWord/Style/Extrusion.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Fill.php b/src/PhpWord/Style/Fill.php index 08c7a85739..cf6ffb4115 100644 --- a/src/PhpWord/Style/Fill.php +++ b/src/PhpWord/Style/Fill.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Font.php b/src/PhpWord/Style/Font.php index 8980258b43..b625e3b8a9 100644 --- a/src/PhpWord/Style/Font.php +++ b/src/PhpWord/Style/Font.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -787,6 +787,7 @@ public function setShading($value = null) * Get bold * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getBold() @@ -798,6 +799,7 @@ public function getBold() * Get italic * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getItalic() @@ -809,6 +811,7 @@ public function getItalic() * Get superscript * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getSuperScript() @@ -820,6 +823,7 @@ public function getSuperScript() * Get subscript * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getSubScript() @@ -831,6 +835,7 @@ public function getSubScript() * Get strikethrough * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getStrikethrough() @@ -842,6 +847,7 @@ public function getStrikethrough() * Get paragraph style * * @deprecated 0.11.0 + * * @codeCoverageIgnore */ public function getParagraphStyle() diff --git a/src/PhpWord/Style/Frame.php b/src/PhpWord/Style/Frame.php index 5fef5f0182..97faacfb91 100644 --- a/src/PhpWord/Style/Frame.php +++ b/src/PhpWord/Style/Frame.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\SimpleType\Jc; + /** * Frame defines the size and position of an object * @@ -88,11 +90,9 @@ class Frame extends AbstractStyle const WRAP_INFRONT = 'infront'; /** - * Alignment - * - * @var \PhpOffice\PhpWord\Style\Alignment + * @var string */ - private $alignment; + private $alignment = ''; /** * Unit @@ -178,33 +178,61 @@ class Frame extends AbstractStyle */ public function __construct($style = array()) { - $this->alignment = new Alignment(); $this->setStyleByArray($style); } /** - * Get alignment + * @since 0.13.0 * * @return string */ - public function getAlign() + public function getAlignment() { - return $this->alignment->getValue(); + return $this->alignment; } /** - * Set alignment + * @since 0.13.0 * * @param string $value + * * @return self */ - public function setAlign($value = null) + public function setAlignment($value) { - $this->alignment->setValue($value); + if (Jc::getValidator()->isValid($value)) { + $this->alignment = $value; + } return $this; } + /** + * @deprecated 0.13.0 Use the `getAlignment` method instead. + * + * @return string + * + * @codeCoverageIgnore + */ + public function getAlign() + { + return $this->getAlignment(); + } + + /** + * @deprecated 0.13.0 Use the `setAlignment` method instead. + * + * @param string $value + * + * @return self + * + * @codeCoverageIgnore + */ + public function setAlign($value = null) + { + return $this->setAlignment($value); + } + /** * Get unit * diff --git a/src/PhpWord/Style/Image.php b/src/PhpWord/Style/Image.php index babfa6798e..f2c88b5f0f 100644 --- a/src/PhpWord/Style/Image.php +++ b/src/PhpWord/Style/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; @@ -133,7 +133,9 @@ public function getWrappingStyle() * Set wrapping style * * @param string $wrappingStyle + * * @throws \InvalidArgumentException + * * @return self */ public function setWrappingStyle($wrappingStyle) @@ -157,7 +159,9 @@ public function getPositioning() * Set positioning type * * @param string $positioning + * * @throws \InvalidArgumentException + * * @return self */ public function setPositioning($positioning) @@ -181,7 +185,9 @@ public function getPosHorizontal() * Set horizontal alignment * * @param string $alignment + * * @throws \InvalidArgumentException + * * @return self */ public function setPosHorizontal($alignment) @@ -205,7 +211,9 @@ public function getPosVertical() * Set vertical alignment * * @param string $alignment + * * @throws \InvalidArgumentException + * * @return self */ public function setPosVertical($alignment) @@ -229,7 +237,9 @@ public function getPosHorizontalRel() * Set horizontal relation * * @param string $relto + * * @throws \InvalidArgumentException + * * @return self */ public function setPosHorizontalRel($relto) @@ -253,7 +263,9 @@ public function getPosVerticalRel() * Set vertical relation * * @param string $relto + * * @throws \InvalidArgumentException + * * @return self */ public function setPosVerticalRel($relto) diff --git a/src/PhpWord/Style/Indentation.php b/src/PhpWord/Style/Indentation.php index 5854204a9c..0408929b8f 100644 --- a/src/PhpWord/Style/Indentation.php +++ b/src/PhpWord/Style/Indentation.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Line.php b/src/PhpWord/Style/Line.php index 44f5422991..f8cc4026f0 100644 --- a/src/PhpWord/Style/Line.php +++ b/src/PhpWord/Style/Line.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; diff --git a/src/PhpWord/Style/LineNumbering.php b/src/PhpWord/Style/LineNumbering.php index b93ce03f0f..e125f47717 100644 --- a/src/PhpWord/Style/LineNumbering.php +++ b/src/PhpWord/Style/LineNumbering.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/ListItem.php b/src/PhpWord/Style/ListItem.php index a689c691c0..18ea0bf264 100644 --- a/src/PhpWord/Style/ListItem.php +++ b/src/PhpWord/Style/ListItem.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -155,7 +155,7 @@ private function getListTypeStyle() } // Property mapping for numbering level information - $properties = array('start', 'format', 'text', 'align', 'tabPos', 'left', 'hanging', 'font', 'hint'); + $properties = array('start', 'format', 'text', 'alignment', 'tabPos', 'left', 'hanging', 'font', 'hint'); // Legacy level information $listTypeStyles = array( diff --git a/src/PhpWord/Style/Numbering.php b/src/PhpWord/Style/Numbering.php index 726af2bec7..0d4fd85d3e 100644 --- a/src/PhpWord/Style/Numbering.php +++ b/src/PhpWord/Style/Numbering.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/NumberingLevel.php b/src/PhpWord/Style/NumberingLevel.php index 32e61c8962..51ae61486c 100644 --- a/src/PhpWord/Style/NumberingLevel.php +++ b/src/PhpWord/Style/NumberingLevel.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\SimpleType\Jc; + /** * Numbering level definition * @@ -81,12 +83,9 @@ class NumberingLevel extends AbstractStyle private $text; /** - * Align left|center|right|both - * * @var string - * @link http://www.schemacentral.com/sc/ooxml/e-w_lvlJc-1.html */ - private $align; + private $alignment = ''; /** * Left @@ -281,26 +280,55 @@ public function setText($value) } /** - * Get align + * @since 0.13.0 + * + * @return string + */ + public function getAlignment() + { + return $this->alignment; + } + + /** + * @since 0.13.0 + * + * @param string $value + * + * @return self + */ + public function setAlignment($value) + { + if (Jc::getValidator()->isValid($value)) { + $this->alignment = $value; + } + + return $this; + } + + /** + * @deprecated 0.13.0 Use the `getAlignment` method instead. * * @return string + * + * @codeCoverageIgnore */ public function getAlign() { - return $this->align; + return $this->getAlignment(); } /** - * Set align + * @deprecated 0.13.0 Use the `setAlignment` method instead. * * @param string $value + * * @return self + * + * @codeCoverageIgnore */ public function setAlign($value) { - $enum = array('left', 'center', 'right', 'both'); - $this->align = $this->setEnumVal($value, $enum, $this->align); - return $this; + return $this->setAlignment($value); } /** diff --git a/src/PhpWord/Style/Outline.php b/src/PhpWord/Style/Outline.php index bfd14a1457..8628c4c5fb 100644 --- a/src/PhpWord/Style/Outline.php +++ b/src/PhpWord/Style/Outline.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Paper.php b/src/PhpWord/Style/Paper.php index 642666b5f1..ed1c59ebeb 100644 --- a/src/PhpWord/Style/Paper.php +++ b/src/PhpWord/Style/Paper.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 964a4ec960..c6e60efb27 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -11,14 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; +use PhpOffice\Common\Text; use PhpOffice\PhpWord\Exception\InvalidStyleException; -use PhpOffice\PhpWord\Shared\String; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Paragraph style @@ -76,11 +77,9 @@ class Paragraph extends Border private $next; /** - * Alignment - * - * @var \PhpOffice\PhpWord\Style\Alignment + * @var string */ - private $alignment; + private $alignment = ''; /** * Indentation @@ -159,14 +158,6 @@ class Paragraph extends Border */ private $shading; - /** - * Create new instance - */ - public function __construct() - { - $this->alignment = new Alignment(); - } - /** * Set Style value * @@ -176,10 +167,10 @@ public function __construct() */ public function setStyleValue($key, $value) { - $key = String::removeUnderscorePrefix($key); - if ($key == 'indent' || $key == 'hanging') { + $key = Text::removeUnderscorePrefix($key); + if ('indent' == $key || 'hanging' == $key) { $value = $value * 720; - } elseif ($key == 'spacing') { + } elseif ('spacing' == $key) { $value += 240; // because line height of 1 matches 240 twips } @@ -202,7 +193,7 @@ public function getStyleValues() 'name' => $this->getStyleName(), 'basedOn' => $this->getBasedOn(), 'next' => $this->getNext(), - 'alignment' => $this->getAlign(), + 'alignment' => $this->getAlignment(), 'indentation' => $this->getIndentation(), 'spacing' => $this->getSpace(), 'pagination' => array( @@ -223,28 +214,57 @@ public function getStyleValues() } /** - * Get alignment + * @since 0.13.0 * * @return string */ - public function getAlign() + public function getAlignment() { - return $this->alignment->getValue(); + return $this->alignment; } /** - * Set alignment + * @since 0.13.0 * * @param string $value + * * @return self */ - public function setAlign($value = null) + public function setAlignment($value) { - $this->alignment->setValue($value); + if (Jc::getValidator()->isValid($value)) { + $this->alignment = $value; + } return $this; } + /** + * @deprecated 0.13.0 Use the `getAlignment` method instead. + * + * @return string + * + * @codeCoverageIgnore + */ + public function getAlign() + { + return $this->getAlignment(); + } + + /** + * @deprecated 0.13.0 Use the `setAlignment` method instead. + * + * @param string $value + * + * @return self + * + * @codeCoverageIgnore + */ + public function setAlign($value = null) + { + return $this->setAlignment($value); + } + /** * Get parent style ID * @@ -458,7 +478,9 @@ public function getLineHeight() * Set the line height * * @param int|float|string $lineHeight + * * @return self + * * @throws \PhpOffice\PhpWord\Exception\InvalidStyleException */ public function setLineHeight($lineHeight) @@ -643,6 +665,7 @@ public function setTabs($value = null) * Get allow first/last line to display on a separate page setting * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getWidowControl() @@ -654,6 +677,7 @@ public function getWidowControl() * Get keep paragraph with next paragraph setting * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getKeepNext() @@ -665,6 +689,7 @@ public function getKeepNext() * Get keep all lines on one page setting * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getKeepLines() @@ -676,6 +701,7 @@ public function getKeepLines() * Get start paragraph on next page setting * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getPageBreakBefore() diff --git a/src/PhpWord/Style/Row.php b/src/PhpWord/Style/Row.php index 45897aed5e..5be03b6972 100644 --- a/src/PhpWord/Style/Row.php +++ b/src/PhpWord/Style/Row.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -125,6 +125,7 @@ public function setExactHeight($value = true) * Get tblHeader * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getTblHeader() @@ -136,6 +137,7 @@ public function getTblHeader() * Get cantSplit * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getCantSplit() @@ -147,6 +149,7 @@ public function getCantSplit() * Get exactHeight * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getExactHeight() diff --git a/src/PhpWord/Style/Section.php b/src/PhpWord/Style/Section.php index 128e8e6b21..62eb8f1158 100644 --- a/src/PhpWord/Style/Section.php +++ b/src/PhpWord/Style/Section.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -35,14 +35,14 @@ class Section extends Border * * @const int|float */ - const DEFAULT_WIDTH = 11870; // In twip - const DEFAULT_HEIGHT = 16787; // In twip - const DEFAULT_MARGIN = 1440; // In twip - const DEFAULT_GUTTER = 0; // In twip - const DEFAULT_HEADER_HEIGHT = 720; // In twip - const DEFAULT_FOOTER_HEIGHT = 720; // In twip + const DEFAULT_WIDTH = 11870; // In twips. + const DEFAULT_HEIGHT = 16787; // In twips. + const DEFAULT_MARGIN = 1440; // In twips. + const DEFAULT_GUTTER = 0; // In twips. + const DEFAULT_HEADER_HEIGHT = 720; // In twips. + const DEFAULT_FOOTER_HEIGHT = 720; // In twips. const DEFAULT_COLUMN_COUNT = 1; - const DEFAULT_COLUMN_SPACING = 720; // In twip + const DEFAULT_COLUMN_SPACING = 720; // In twips. /** * Page Orientation diff --git a/src/PhpWord/Style/Shading.php b/src/PhpWord/Style/Shading.php index 5c9742c962..ab4fce8214 100644 --- a/src/PhpWord/Style/Shading.php +++ b/src/PhpWord/Style/Shading.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Shadow.php b/src/PhpWord/Style/Shadow.php index deafbff0f8..f8f693a97f 100644 --- a/src/PhpWord/Style/Shadow.php +++ b/src/PhpWord/Style/Shadow.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Shape.php b/src/PhpWord/Style/Shape.php index c9809920bb..01b6158873 100644 --- a/src/PhpWord/Style/Shape.php +++ b/src/PhpWord/Style/Shape.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Spacing.php b/src/PhpWord/Style/Spacing.php index 9c9f3a8167..8d7cfeb221 100644 --- a/src/PhpWord/Style/Spacing.php +++ b/src/PhpWord/Style/Spacing.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/TOC.php b/src/PhpWord/Style/TOC.php index 5285565278..eb4b2253ff 100644 --- a/src/PhpWord/Style/TOC.php +++ b/src/PhpWord/Style/TOC.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -25,8 +25,9 @@ class TOC extends Tab /** * Tab leader types for backward compatibility * - * @const string * @deprecated 0.11.0 + * + * @const string */ const TABLEADER_DOT = self::TAB_LEADER_DOT; const TABLEADER_UNDERSCORE = self::TAB_LEADER_UNDERSCORE; diff --git a/src/PhpWord/Style/Tab.php b/src/PhpWord/Style/Tab.php index 900e1fbdf9..33e518c8b5 100644 --- a/src/PhpWord/Style/Tab.php +++ b/src/PhpWord/Style/Tab.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php index 24f5066777..91809528a7 100644 --- a/src/PhpWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -11,15 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Style; -/** - * Table style - */ +use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\SimpleType\JcTable; + class Table extends Border { /** @@ -107,9 +107,9 @@ class Table extends Border private $shading; /** - * @var \PhpOffice\PhpWord\Style\Alignment Alignment + * @var string */ - private $alignment; + private $alignment = ''; /** * @var int|float Width value @@ -129,8 +129,6 @@ class Table extends Border */ public function __construct($tableStyle = null, $firstRowStyle = null) { - $this->alignment = new Alignment(); - // Clone first row from table style, but with certain properties disabled if ($firstRowStyle !== null && is_array($firstRowStyle)) { $this->firstRowStyle = clone $this; @@ -494,28 +492,57 @@ public function setShading($value = null) } /** - * Get alignment + * @since 0.13.0 * * @return string */ - public function getAlign() + public function getAlignment() { - return $this->alignment->getValue(); + return $this->alignment; } /** - * Set alignment + * @since 0.13.0 * * @param string $value + * * @return self */ - public function setAlign($value = null) + public function setAlignment($value) { - $this->alignment->setValue($value); + if (JcTable::getValidator()->isValid($value) || Jc::getValidator()->isValid($value)) { + $this->alignment = $value; + } return $this; } + /** + * @deprecated 0.13.0 Use the `getAlignment` method instead. + * + * @return string + * + * @codeCoverageIgnore + */ + public function getAlign() + { + return $this->getAlignment(); + } + + /** + * @deprecated 0.13.0 Use the `setAlignment` method instead. + * + * @param string $value + * + * @return self + * + * @codeCoverageIgnore + */ + public function setAlign($value = null) + { + return $this->setAlignment($value); + } + /** * Get width * @@ -574,7 +601,7 @@ public function setUnit($value = null) */ private function getTableOnlyProperty($property) { - if ($this->isFirstRow === false) { + if (false === $this->isFirstRow) { return $this->$property; } @@ -594,8 +621,8 @@ private function getTableOnlyProperty($property) */ private function setTableOnlyProperty($property, $value, $isNumeric = true) { - if ($this->isFirstRow === false) { - if ($isNumeric === true) { + if (false === $this->isFirstRow) { + if (true === $isNumeric) { $this->$property = $this->setNumericVal($value, $this->$property); } else { $this->$property = $value; diff --git a/src/PhpWord/Style/TextBox.php b/src/PhpWord/Style/TextBox.php index 6220b74096..600fb8eabf 100644 --- a/src/PhpWord/Style/TextBox.php +++ b/src/PhpWord/Style/TextBox.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Template.php b/src/PhpWord/Template.php index f6ad790eab..87ccd8ed0b 100644 --- a/src/PhpWord/Template.php +++ b/src/PhpWord/Template.php @@ -11,14 +11,16 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord; /** - * @deprecated 0.12.0 Use \PhpOffice\PhpWord\TemplateProcessor instead. + * @deprecated 0.12.0 Use `\PhpOffice\PhpWord\TemplateProcessor` instead. + * + * @codeCoverageIgnore */ class Template extends TemplateProcessor { diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index ce92bacfbe..e7a8d039c4 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -11,17 +11,19 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord; +use PhpOffice\PhpWord\Escaper\RegExp; +use PhpOffice\PhpWord\Escaper\Xml; use PhpOffice\PhpWord\Exception\CopyFileException; use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\Shared\String; use PhpOffice\PhpWord\Shared\ZipArchive; +use Zend\Stdlib\StringUtils; class TemplateProcessor { @@ -98,61 +100,140 @@ public function __construct($documentTemplate) ); $index++; } - $this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName('word/document.xml')); + $this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName($this->getMainPartName())); + } + + /** + * @param string $xml + * @param \XSLTProcessor $xsltProcessor + * + * @return string + * + * @throws \PhpOffice\PhpWord\Exception\Exception + */ + protected function transformSingleXml($xml, $xsltProcessor) + { + $domDocument = new \DOMDocument(); + if (false === $domDocument->loadXML($xml)) { + throw new Exception('Could not load the given XML document.'); + } + + $transformedXml = $xsltProcessor->transformToXml($domDocument); + if (false === $transformedXml) { + throw new Exception('Could not transform the given XML document.'); + } + + return $transformedXml; + } + + /** + * @param mixed $xml + * @param \XSLTProcessor $xsltProcessor + * + * @return mixed + */ + protected function transformXml($xml, $xsltProcessor) + { + if (is_array($xml)) { + foreach ($xml as &$item) { + $item = $this->transformSingleXml($item, $xsltProcessor); + } + } else { + $xml = $this->transformSingleXml($xml, $xsltProcessor); + } + + return $xml; } /** * Applies XSL style sheet to template's parts. + * + * Note: since the method doesn't make any guess on logic of the provided XSL style sheet, + * make sure that output is correctly escaped. Otherwise you may get broken document. * - * @param \DOMDocument $xslDOMDocument + * @param \DOMDocument $xslDomDocument * @param array $xslOptions - * @param string $xslOptionsURI + * @param string $xslOptionsUri * * @return void * * @throws \PhpOffice\PhpWord\Exception\Exception */ - public function applyXslStyleSheet($xslDOMDocument, $xslOptions = array(), $xslOptionsURI = '') + public function applyXslStyleSheet($xslDomDocument, $xslOptions = array(), $xslOptionsUri = '') { $xsltProcessor = new \XSLTProcessor(); - $xsltProcessor->importStylesheet($xslDOMDocument); - - if (false === $xsltProcessor->setParameter($xslOptionsURI, $xslOptions)) { + $xsltProcessor->importStylesheet($xslDomDocument); + if (false === $xsltProcessor->setParameter($xslOptionsUri, $xslOptions)) { throw new Exception('Could not set values for the given XSL style sheet parameters.'); } - $xmlDOMDocument = new \DOMDocument(); - if (false === $xmlDOMDocument->loadXML($this->tempDocumentMainPart)) { - throw new Exception('Could not load XML from the given template.'); + $this->tempDocumentHeaders = $this->transformXml($this->tempDocumentHeaders, $xsltProcessor); + $this->tempDocumentMainPart = $this->transformXml($this->tempDocumentMainPart, $xsltProcessor); + $this->tempDocumentFooters = $this->transformXml($this->tempDocumentFooters, $xsltProcessor); + } + + /** + * @param string $macro + * + * @return string + */ + protected static function ensureMacroCompleted($macro) + { + if (substr($macro, 0, 2) !== '${' && substr($macro, -1) !== '}') { + $macro = '${' . $macro . '}'; } - $xmlTransformed = $xsltProcessor->transformToXml($xmlDOMDocument); - if (false === $xmlTransformed) { - throw new Exception('Could not transform the given XML document.'); + return $macro; + } + + /** + * @param string $subject + * + * @return string + */ + protected static function ensureUtf8Encoded($subject) + { + if (!StringUtils::isValidUtf8($subject)) { + $subject = utf8_encode($subject); } - $this->tempDocumentMainPart = $xmlTransformed; + return $subject; } /** - * @param mixed $macro + * @param mixed $search * @param mixed $replace * @param integer $limit * * @return void */ - public function setValue($macro, $replace, $limit = self::MAXIMUM_REPLACEMENTS_DEFAULT) + public function setValue($search, $replace, $limit = self::MAXIMUM_REPLACEMENTS_DEFAULT) { - foreach ($this->tempDocumentHeaders as $index => $headerXML) { - $this->tempDocumentHeaders[$index] = $this->setValueForPart($this->tempDocumentHeaders[$index], $macro, $replace, $limit); + if (is_array($search)) { + foreach ($search as &$item) { + $item = self::ensureMacroCompleted($item); + } + } else { + $search = self::ensureMacroCompleted($search); } - $this->tempDocumentMainPart = $this->setValueForPart($this->tempDocumentMainPart, $macro, $replace, $limit); + if (is_array($replace)) { + foreach ($replace as &$item) { + $item = self::ensureUtf8Encoded($item); + } + } else { + $replace = self::ensureUtf8Encoded($replace); + } - foreach ($this->tempDocumentFooters as $index => $headerXML) { - $this->tempDocumentFooters[$index] = $this->setValueForPart($this->tempDocumentFooters[$index], $macro, $replace, $limit); + if (Settings::isOutputEscapingEnabled()) { + $xmlEscaper = new Xml(); + $replace = $xmlEscaper->escape($replace); } + + $this->tempDocumentHeaders = $this->setValueForPart($search, $replace, $this->tempDocumentHeaders, $limit); + $this->tempDocumentMainPart = $this->setValueForPart($search, $replace, $this->tempDocumentMainPart, $limit); + $this->tempDocumentFooters = $this->setValueForPart($search, $replace, $this->tempDocumentFooters, $limit); } /** @@ -317,14 +398,14 @@ public function deleteBlock($blockname) */ public function save() { - foreach ($this->tempDocumentHeaders as $index => $headerXML) { - $this->zipClass->addFromString($this->getHeaderName($index), $this->tempDocumentHeaders[$index]); + foreach ($this->tempDocumentHeaders as $index => $xml) { + $this->zipClass->addFromString($this->getHeaderName($index), $xml); } - $this->zipClass->addFromString('word/document.xml', $this->tempDocumentMainPart); + $this->zipClass->addFromString($this->getMainPartName(), $this->tempDocumentMainPart); - foreach ($this->tempDocumentFooters as $index => $headerXML) { - $this->zipClass->addFromString($this->getFooterName($index), $this->tempDocumentFooters[$index]); + foreach ($this->tempDocumentFooters as $index => $xml) { + $this->zipClass->addFromString($this->getFooterName($index), $xml); } // Close zip file @@ -353,7 +434,7 @@ public function saveAs($fileName) } /* - * Note: we do not use ``rename`` function here, because it looses file ownership data on Windows platform. + * Note: we do not use `rename` function here, because it looses file ownership data on Windows platform. * As a result, user cannot open the file directly getting "Access denied" message. * * @see https://github.com/PHPOffice/PHPWord/issues/532 @@ -366,8 +447,6 @@ public function saveAs($fileName) * Finds parts of broken macros and sticks them together. * Macros, while being edited, could be implicitly broken by some of the word processors. * - * @since 0.13.0 - * * @param string $documentPart The document part in XML representation. * * @return string @@ -377,7 +456,7 @@ protected function fixBrokenMacros($documentPart) $fixedDocumentPart = $documentPart; $fixedDocumentPart = preg_replace_callback( - '|\$\{([^\}]+)\}|U', + '|\$[^{]*\{[^}]*\}|U', function ($match) { return strip_tags($match[0]); }, @@ -390,30 +469,21 @@ function ($match) { /** * Find and replace macros in the given XML section. * + * @param mixed $search + * @param mixed $replace * @param string $documentPartXML - * @param string $search - * @param string $replace * @param integer $limit * * @return string */ - protected function setValueForPart($documentPartXML, $search, $replace, $limit) + protected function setValueForPart($search, $replace, $documentPartXML, $limit) { - if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { - $search = '${' . $search . '}'; - } - - if (!String::isUTF8($replace)) { - $replace = utf8_encode($replace); - } - // Note: we can't use the same function for both cases here, because of performance considerations. if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) { return str_replace($search, $replace, $documentPartXML); } else { - $regExpDelim = '/'; - $escapedSearch = preg_quote($search, $regExpDelim); - return preg_replace("{$regExpDelim}{$escapedSearch}{$regExpDelim}u", $replace, $documentPartXML, $limit); + $regExpEscaper = new RegExp(); + return preg_replace($regExpEscaper->escape($search), $replace, $documentPartXML, $limit); } } @@ -432,27 +502,35 @@ protected function getVariablesForPart($documentPartXML) } /** - * Get the name of the footer file for $index. + * Get the name of the header file for $index. * * @param integer $index * * @return string */ - protected function getFooterName($index) + protected function getHeaderName($index) { - return sprintf('word/footer%d.xml', $index); + return sprintf('word/header%d.xml', $index); } /** - * Get the name of the header file for $index. + * @return string + */ + protected function getMainPartName() + { + return 'word/document.xml'; + } + + /** + * Get the name of the footer file for $index. * * @param integer $index * * @return string */ - protected function getHeaderName($index) + protected function getFooterName($index) { - return sprintf('word/header%d.xml', $index); + return sprintf('word/footer%d.xml', $index); } /** diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 599d8a6fdd..78ec5acd85 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -97,6 +97,7 @@ abstract class AbstractWriter implements WriterInterface * Get PhpWord object * * @return \PhpOffice\PhpWord\PhpWord + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function getPhpWord() @@ -150,7 +151,9 @@ public function isUseDiskCaching() * * @param bool $value * @param string $directory + * * @return self + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function setUseDiskCaching($value = false, $directory = null) @@ -234,6 +237,7 @@ protected function getTempFile($filename) * Cleanup temporary file. * * @return void + * * @throws \PhpOffice\PhpWord\Exception\CopyFileException */ protected function cleanupTempFile() @@ -267,7 +271,9 @@ protected function clearTempDir() * Get ZipArchive object * * @param string $filename + * * @return \PhpOffice\PhpWord\Shared\ZipArchive + * * @throws \Exception */ protected function getZipArchive($filename) @@ -295,10 +301,13 @@ protected function getZipArchive($filename) /** * Open file for writing * + * @since 0.11.0 + * * @param string $filename + * * @return resource + * * @throws \Exception - * @since 0.11.0 */ protected function openFile($filename) { @@ -423,6 +432,7 @@ private function deleteDir($dir) * Get use disk caching status * * @deprecated 0.10.0 + * * @codeCoverageIgnore */ public function getUseDiskCaching() diff --git a/src/PhpWord/Writer/HTML.php b/src/PhpWord/Writer/HTML.php index 5c58acfc9d..5668f18436 100644 --- a/src/PhpWord/Writer/HTML.php +++ b/src/PhpWord/Writer/HTML.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -64,7 +64,9 @@ public function __construct(PhpWord $phpWord = null) * Save PhpWord to file. * * @param string $filename + * * @return void + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) @@ -127,8 +129,10 @@ public function addNote($noteId, $noteMark) /** * Write document * - * @return string * @deprecated 0.11.0 + * + * @return string + * * @codeCoverageIgnore */ public function writeDocument() diff --git a/src/PhpWord/Writer/HTML/Element/AbstractElement.php b/src/PhpWord/Writer/HTML/Element/AbstractElement.php index 73f88d3d8d..294d6de7f2 100644 --- a/src/PhpWord/Writer/HTML/Element/AbstractElement.php +++ b/src/PhpWord/Writer/HTML/Element/AbstractElement.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -19,6 +19,7 @@ use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Writer\AbstractWriter; +use Zend\Escaper\Escaper; /** * Abstract HTML element writer @@ -48,6 +49,11 @@ abstract class AbstractElement */ protected $withoutP = false; + /** + * @var \Zend\Escaper\Escaper + */ + protected $escaper; + /** * Write element */ @@ -65,6 +71,7 @@ public function __construct(AbstractWriter $parentWriter, Element $element, $wit $this->parentWriter = $parentWriter; $this->element = $element; $this->withoutP = $withoutP; + $this->escaper = new Escaper(); } /** diff --git a/src/PhpWord/Writer/HTML/Element/Container.php b/src/PhpWord/Writer/HTML/Element/Container.php index 147329dd85..88384a12d4 100644 --- a/src/PhpWord/Writer/HTML/Element/Container.php +++ b/src/PhpWord/Writer/HTML/Element/Container.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/Endnote.php b/src/PhpWord/Writer/HTML/Element/Endnote.php index 3da8a8fb34..b049e43766 100644 --- a/src/PhpWord/Writer/HTML/Element/Endnote.php +++ b/src/PhpWord/Writer/HTML/Element/Endnote.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/Footnote.php b/src/PhpWord/Writer/HTML/Element/Footnote.php index f59545de10..b5aa0a0afc 100644 --- a/src/PhpWord/Writer/HTML/Element/Footnote.php +++ b/src/PhpWord/Writer/HTML/Element/Footnote.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/Image.php b/src/PhpWord/Writer/HTML/Element/Image.php index ab78990bd4..9c69d41f1f 100644 --- a/src/PhpWord/Writer/HTML/Element/Image.php +++ b/src/PhpWord/Writer/HTML/Element/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/Link.php b/src/PhpWord/Writer/HTML/Element/Link.php index 4e99810c7b..bff57cfc20 100644 --- a/src/PhpWord/Writer/HTML/Element/Link.php +++ b/src/PhpWord/Writer/HTML/Element/Link.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; +use PhpOffice\PhpWord\Settings; + /** * Link element HTML writer * @@ -37,7 +39,11 @@ public function write() $content = ''; $content .= $this->writeOpening(); - $content .= "element->getSource()}\">{$this->element->getText()}"; + if (Settings::isOutputEscapingEnabled()) { + $content .= "escaper->escapeHtmlAttr($this->element->getSource())}\">{$this->escaper->escapeHtml($this->element->getText())}"; + } else { + $content .= "element->getSource()}\">{$this->element->getText()}"; + } $content .= $this->writeClosing(); return $content; diff --git a/src/PhpWord/Writer/HTML/Element/ListItem.php b/src/PhpWord/Writer/HTML/Element/ListItem.php index ef8eb34d75..d8b1e4ed89 100644 --- a/src/PhpWord/Writer/HTML/Element/ListItem.php +++ b/src/PhpWord/Writer/HTML/Element/ListItem.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; +use PhpOffice\PhpWord\Settings; + /** * ListItem element HTML writer * @@ -35,8 +37,11 @@ public function write() return ''; } - $text = $this->element->getTextObject()->getText(); - $content = '

' . $text . '

' . PHP_EOL; + if (Settings::isOutputEscapingEnabled()) { + $content = '

' . $this->escaper->escapeHtml($this->element->getTextObject()->getText()) . '

' . PHP_EOL; + } else { + $content = '

' . $this->element->getTextObject()->getText() . '

' . PHP_EOL; + } return $content; } diff --git a/src/PhpWord/Writer/HTML/Element/PageBreak.php b/src/PhpWord/Writer/HTML/Element/PageBreak.php index 774ed9d23c..8b332dcfaf 100644 --- a/src/PhpWord/Writer/HTML/Element/PageBreak.php +++ b/src/PhpWord/Writer/HTML/Element/PageBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/Table.php b/src/PhpWord/Writer/HTML/Element/Table.php index 9027603b8f..9025f01aac 100644 --- a/src/PhpWord/Writer/HTML/Element/Table.php +++ b/src/PhpWord/Writer/HTML/Element/Table.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/Text.php b/src/PhpWord/Writer/HTML/Element/Text.php index 0c31df3632..874515958c 100644 --- a/src/PhpWord/Writer/HTML/Element/Text.php +++ b/src/PhpWord/Writer/HTML/Element/Text.php @@ -11,12 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter; @@ -72,7 +73,11 @@ public function write() $content .= $this->writeOpening(); $content .= $this->openingText; $content .= $this->openingTags; - $content .= $element->getText(); + if (Settings::isOutputEscapingEnabled()) { + $content .= $this->escaper->escapeHtml($element->getText()); + } else { + $content .= $element->getText(); + } $content .= $this->closingTags; $content .= $this->closingText; $content .= $this->writeClosing(); @@ -130,7 +135,12 @@ protected function writeClosing() { $content = ''; if (!$this->withoutP) { - $content .= $this->closingText; + if (Settings::isOutputEscapingEnabled()) { + $content .= $this->escaper->escapeHtml($this->closingText); + } else { + $content .= $this->closingText; + } + $content .= "

" . PHP_EOL; } diff --git a/src/PhpWord/Writer/HTML/Element/TextBreak.php b/src/PhpWord/Writer/HTML/Element/TextBreak.php index 30560e9684..9b23d739b8 100644 --- a/src/PhpWord/Writer/HTML/Element/TextBreak.php +++ b/src/PhpWord/Writer/HTML/Element/TextBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/TextRun.php b/src/PhpWord/Writer/HTML/Element/TextRun.php index b6bfaceaeb..492f7597e3 100644 --- a/src/PhpWord/Writer/HTML/Element/TextRun.php +++ b/src/PhpWord/Writer/HTML/Element/TextRun.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Element/Title.php b/src/PhpWord/Writer/HTML/Element/Title.php index c054ccf98b..23c2993804 100644 --- a/src/PhpWord/Writer/HTML/Element/Title.php +++ b/src/PhpWord/Writer/HTML/Element/Title.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Element; +use PhpOffice\PhpWord\Settings; + /** * TextRun element HTML writer * @@ -36,7 +38,11 @@ public function write() } $tag = 'h' . $this->element->getDepth(); - $text = $this->element->getText(); + if (Settings::isOutputEscapingEnabled()) { + $text = $this->escaper->escapeHtml($this->element->getText()); + } else { + $text = $this->element->getText(); + } $content = "<{$tag}>{$text}" . PHP_EOL; return $content; diff --git a/src/PhpWord/Writer/HTML/Part/AbstractPart.php b/src/PhpWord/Writer/HTML/Part/AbstractPart.php index 124cc15a8a..638f846b98 100644 --- a/src/PhpWord/Writer/HTML/Part/AbstractPart.php +++ b/src/PhpWord/Writer/HTML/Part/AbstractPart.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -19,32 +19,36 @@ use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Writer\AbstractWriter; +use Zend\Escaper\Escaper; /** - * Abstract HTML part writer - * * @since 0.11.0 */ abstract class AbstractPart { /** - * Parent writer - * * @var \PhpOffice\PhpWord\Writer\AbstractWriter */ private $parentWriter; /** - * Write part - * + * @var \Zend\Escaper\Escaper + */ + protected $escaper; + + public function __construct() + { + $this->escaper = new Escaper(); + } + + /** * @return string */ abstract public function write(); /** - * Set parent writer. - * * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer + * * @return void */ public function setParentWriter(AbstractWriter $writer = null) @@ -53,9 +57,8 @@ public function setParentWriter(AbstractWriter $writer = null) } /** - * Get parent writer - * * @return \PhpOffice\PhpWord\Writer\AbstractWriter + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function getParentWriter() diff --git a/src/PhpWord/Writer/HTML/Part/Body.php b/src/PhpWord/Writer/HTML/Part/Body.php index b91ca3ad2d..0d852a57fd 100644 --- a/src/PhpWord/Writer/HTML/Part/Body.php +++ b/src/PhpWord/Writer/HTML/Part/Body.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Part/Head.php b/src/PhpWord/Writer/HTML/Part/Head.php index 503f75b879..fa4c383346 100644 --- a/src/PhpWord/Writer/HTML/Part/Head.php +++ b/src/PhpWord/Writer/HTML/Part/Head.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -41,14 +41,14 @@ public function write() { $docProps = $this->getParentWriter()->getPhpWord()->getDocInfo(); $propertiesMapping = array( - 'creator' => 'author', - 'title' => '', + 'creator' => 'author', + 'title' => '', 'description' => '', - 'subject' => '', - 'keywords' => '', - 'category' => '', - 'company' => '', - 'manager' => '' + 'subject' => '', + 'keywords' => '', + 'category' => '', + 'company' => '', + 'manager' => '' ); $title = $docProps->getTitle(); $title = ($title != '') ? $title : 'PHPWord'; @@ -62,8 +62,9 @@ public function write() $value = ($value == '') ? $key : $value; $method = "get" . $key; if ($docProps->$method() != '') { - $content .= '' . PHP_EOL; + $content .= '' . PHP_EOL; } } $content .= $this->writeStyles(); diff --git a/src/PhpWord/Writer/HTML/Style/AbstractStyle.php b/src/PhpWord/Writer/HTML/Style/AbstractStyle.php index 07ef16184c..10a0a9addf 100644 --- a/src/PhpWord/Writer/HTML/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/HTML/Style/AbstractStyle.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Style/Font.php b/src/PhpWord/Writer/HTML/Style/Font.php index 8645a1f402..c202af9397 100644 --- a/src/PhpWord/Writer/HTML/Style/Font.php +++ b/src/PhpWord/Writer/HTML/Style/Font.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Style/Generic.php b/src/PhpWord/Writer/HTML/Style/Generic.php index df94d4922e..e3d2b3522a 100644 --- a/src/PhpWord/Writer/HTML/Style/Generic.php +++ b/src/PhpWord/Writer/HTML/Style/Generic.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Style/Image.php b/src/PhpWord/Writer/HTML/Style/Image.php index 13be3665cd..36a9fecaad 100644 --- a/src/PhpWord/Writer/HTML/Style/Image.php +++ b/src/PhpWord/Writer/HTML/Style/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/HTML/Style/Paragraph.php b/src/PhpWord/Writer/HTML/Style/Paragraph.php index 8b326a5cfa..593c6dca93 100644 --- a/src/PhpWord/Writer/HTML/Style/Paragraph.php +++ b/src/PhpWord/Writer/HTML/Style/Paragraph.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\HTML\Style; +use PhpOffice\PhpWord\SimpleType\Jc; + /** * Paragraph style HTML writer * @@ -38,8 +40,42 @@ public function write() $css = array(); // Alignment - $align = $style->getAlign(); - $css['text-align'] = $this->getValueIf(!is_null($align), $align); + if ('' !== $style->getAlignment()) { + $textAlign = ''; + + switch ($style->getAlignment()) { + case Jc::START: + case Jc::NUM_TAB: + case Jc::LEFT: + $textAlign = 'left'; + break; + + case Jc::CENTER: + $textAlign = 'center'; + break; + + case Jc::END: + case Jc::MEDIUM_KASHIDA: + case Jc::HIGH_KASHIDA: + case Jc::LOW_KASHIDA: + case Jc::RIGHT: + $textAlign = 'right'; + break; + + case Jc::BOTH: + case Jc::DISTRIBUTE: + case Jc::THAI_DISTRIBUTE: + case Jc::JUSTIFY: + $textAlign = 'justify'; + break; + + default: + $textAlign = 'left'; + break; + } + + $css['text-align'] = $textAlign; + } // Spacing $spacing = $style->getSpace(); diff --git a/src/PhpWord/Writer/ODText.php b/src/PhpWord/Writer/ODText.php index 8fa364bec9..40bc6c2fbe 100644 --- a/src/PhpWord/Writer/ODText.php +++ b/src/PhpWord/Writer/ODText.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/AbstractElement.php b/src/PhpWord/Writer/ODText/Element/AbstractElement.php index 9fb24364a3..0ca43e4fc1 100644 --- a/src/PhpWord/Writer/ODText/Element/AbstractElement.php +++ b/src/PhpWord/Writer/ODText/Element/AbstractElement.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/Container.php b/src/PhpWord/Writer/ODText/Element/Container.php index 8b7807d68f..212cd184b8 100644 --- a/src/PhpWord/Writer/ODText/Element/Container.php +++ b/src/PhpWord/Writer/ODText/Element/Container.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/Image.php b/src/PhpWord/Writer/ODText/Element/Image.php index 3cbb38542a..c6b16cfce5 100644 --- a/src/PhpWord/Writer/ODText/Element/Image.php +++ b/src/PhpWord/Writer/ODText/Element/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/Link.php b/src/PhpWord/Writer/ODText/Element/Link.php index adb64f8599..cb0226a3b0 100644 --- a/src/PhpWord/Writer/ODText/Element/Link.php +++ b/src/PhpWord/Writer/ODText/Element/Link.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; +use PhpOffice\PhpWord\Settings; + /** * Text element writer * @@ -42,7 +44,11 @@ public function write() $xmlWriter->startElement('text:a'); $xmlWriter->writeAttribute('xlink:type', 'simple'); $xmlWriter->writeAttribute('xlink:href', $element->getSource()); - $xmlWriter->writeRaw($element->getText()); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($element->getText()); + } else { + $xmlWriter->writeRaw($element->getText()); + } $xmlWriter->endElement(); // text:a if (!$this->withoutP) { diff --git a/src/PhpWord/Writer/ODText/Element/Table.php b/src/PhpWord/Writer/ODText/Element/Table.php index f26960b828..f6a2f8456d 100644 --- a/src/PhpWord/Writer/ODText/Element/Table.php +++ b/src/PhpWord/Writer/ODText/Element/Table.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/Text.php b/src/PhpWord/Writer/ODText/Element/Text.php index 4fc53bfee5..cff684812b 100644 --- a/src/PhpWord/Writer/ODText/Element/Text.php +++ b/src/PhpWord/Writer/ODText/Element/Text.php @@ -11,13 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; use PhpOffice\PhpWord\Exception\Exception; +use PhpOffice\PhpWord\Settings; /** * Text element writer @@ -56,7 +57,11 @@ public function write() } elseif (is_string($paragraphStyle)) { $xmlWriter->writeAttribute('text:style-name', $paragraphStyle); } - $xmlWriter->writeRaw($element->getText()); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($element->getText()); + } else { + $xmlWriter->writeRaw($element->getText()); + } } else { if (empty($paragraphStyle)) { $xmlWriter->writeAttribute('text:style-name', 'Standard'); @@ -68,7 +73,11 @@ public function write() if (is_string($fontStyle)) { $xmlWriter->writeAttribute('text:style-name', $fontStyle); } - $xmlWriter->writeRaw($element->getText()); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($element->getText()); + } else { + $xmlWriter->writeRaw($element->getText()); + } $xmlWriter->endElement(); } if (!$this->withoutP) { diff --git a/src/PhpWord/Writer/ODText/Element/TextBreak.php b/src/PhpWord/Writer/ODText/Element/TextBreak.php index ef3186f4f2..b0f5009e19 100644 --- a/src/PhpWord/Writer/ODText/Element/TextBreak.php +++ b/src/PhpWord/Writer/ODText/Element/TextBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/TextRun.php b/src/PhpWord/Writer/ODText/Element/TextRun.php index 52240e8fc4..037170163a 100644 --- a/src/PhpWord/Writer/ODText/Element/TextRun.php +++ b/src/PhpWord/Writer/ODText/Element/TextRun.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Element/Title.php b/src/PhpWord/Writer/ODText/Element/Title.php index d45f5e12bc..b20ba9447a 100644 --- a/src/PhpWord/Writer/ODText/Element/Title.php +++ b/src/PhpWord/Writer/ODText/Element/Title.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Element; +use PhpOffice\PhpWord\Settings; + /** * Title element writer * @@ -37,7 +39,11 @@ public function write() $xmlWriter->startElement('text:h'); $xmlWriter->writeAttribute('text:outline-level', $element->getDepth()); - $xmlWriter->writeRaw($element->getText()); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($element->getText()); + } else { + $xmlWriter->writeRaw($element->getText()); + } $xmlWriter->endElement(); // text:h } } diff --git a/src/PhpWord/Writer/ODText/Part/AbstractPart.php b/src/PhpWord/Writer/ODText/Part/AbstractPart.php index edc8d07f4f..dc377e0f99 100644 --- a/src/PhpWord/Writer/ODText/Part/AbstractPart.php +++ b/src/PhpWord/Writer/ODText/Part/AbstractPart.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart; @@ -36,7 +36,7 @@ abstract class AbstractPart extends Word2007AbstractPart /** * Write common root attributes. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ protected function writeCommonRootAttributes(XMLWriter $xmlWriter) @@ -73,7 +73,7 @@ protected function writeCommonRootAttributes(XMLWriter $xmlWriter) /** * Write font faces declaration. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ protected function writeFontFaces(XMLWriter $xmlWriter) diff --git a/src/PhpWord/Writer/ODText/Part/Content.php b/src/PhpWord/Writer/ODText/Part/Content.php index 4bde66ee97..61f8e7e27b 100644 --- a/src/PhpWord/Writer/ODText/Part/Content.php +++ b/src/PhpWord/Writer/ODText/Part/Content.php @@ -11,18 +11,18 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\Image; use PhpOffice\PhpWord\Element\Table; use PhpOffice\PhpWord\Element\Text; use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; @@ -110,7 +110,7 @@ public function write() * * @since 0.11.0 * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writeAutoStyles(XMLWriter $xmlWriter) @@ -134,7 +134,7 @@ private function writeAutoStyles(XMLWriter $xmlWriter) /** * Write automatic styles. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writeTextStyles(XMLWriter $xmlWriter) diff --git a/src/PhpWord/Writer/ODText/Part/Manifest.php b/src/PhpWord/Writer/ODText/Part/Manifest.php index 7c695e9bd4..237c1a11d5 100644 --- a/src/PhpWord/Writer/ODText/Part/Manifest.php +++ b/src/PhpWord/Writer/ODText/Part/Manifest.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Part/Meta.php b/src/PhpWord/Writer/ODText/Part/Meta.php index 15c81a4e9c..f16db161ea 100644 --- a/src/PhpWord/Writer/ODText/Part/Meta.php +++ b/src/PhpWord/Writer/ODText/Part/Meta.php @@ -11,13 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\Common\XMLWriter; +use PhpOffice\PhpWord\Settings; /** * ODText meta part writer: meta.xml @@ -86,7 +87,7 @@ public function write() /** * Write individual property * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $property * @param string $value * @return void @@ -100,7 +101,11 @@ private function writeCustomProperty(XMLWriter $xmlWriter, $property, $value) // if ($type !== null) { // $xmlWriter->writeAttribute('meta:value-type', $type); // } - $xmlWriter->writeRaw($value); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($value); + } else { + $xmlWriter->writeRaw($value); + } $xmlWriter->endElement(); // meta:user-defined } } diff --git a/src/PhpWord/Writer/ODText/Part/Mimetype.php b/src/PhpWord/Writer/ODText/Part/Mimetype.php index 1da4edb0b5..7cf78b4b08 100644 --- a/src/PhpWord/Writer/ODText/Part/Mimetype.php +++ b/src/PhpWord/Writer/ODText/Part/Mimetype.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Part/Styles.php b/src/PhpWord/Writer/ODText/Part/Styles.php index 7522872d7e..b50be0e804 100644 --- a/src/PhpWord/Writer/ODText/Part/Styles.php +++ b/src/PhpWord/Writer/ODText/Part/Styles.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\ODText\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; /** @@ -63,7 +63,7 @@ public function write() /** * Write default styles. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writeDefault(XMLWriter $xmlWriter) @@ -108,7 +108,7 @@ private function writeDefault(XMLWriter $xmlWriter) /** * Write named styles. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writeNamed(XMLWriter $xmlWriter) @@ -130,7 +130,7 @@ private function writeNamed(XMLWriter $xmlWriter) /** * Write page layout styles. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writePageLayout(XMLWriter $xmlWriter) @@ -183,7 +183,7 @@ private function writePageLayout(XMLWriter $xmlWriter) /** * Write master style. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writeMaster(XMLWriter $xmlWriter) diff --git a/src/PhpWord/Writer/ODText/Style/AbstractStyle.php b/src/PhpWord/Writer/ODText/Style/AbstractStyle.php index 18d6ce1071..7bc49cb36c 100644 --- a/src/PhpWord/Writer/ODText/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/ODText/Style/AbstractStyle.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Style/Font.php b/src/PhpWord/Writer/ODText/Style/Font.php index 4518450555..5d8e5753d6 100644 --- a/src/PhpWord/Writer/ODText/Style/Font.php +++ b/src/PhpWord/Writer/ODText/Style/Font.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Style/Image.php b/src/PhpWord/Writer/ODText/Style/Image.php index 21b9c4ee93..447f449ce3 100644 --- a/src/PhpWord/Writer/ODText/Style/Image.php +++ b/src/PhpWord/Writer/ODText/Style/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Style/Paragraph.php b/src/PhpWord/Writer/ODText/Style/Paragraph.php index 03e605a196..1d82181071 100644 --- a/src/PhpWord/Writer/ODText/Style/Paragraph.php +++ b/src/PhpWord/Writer/ODText/Style/Paragraph.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -54,7 +54,7 @@ public function write() } else { $xmlWriter->writeAttribute('fo:margin-top', $marginTop . 'cm'); $xmlWriter->writeAttribute('fo:margin-bottom', $marginBottom . 'cm'); - $xmlWriter->writeAttribute('fo:text-align', $style->getAlign()); + $xmlWriter->writeAttribute('fo:text-align', $style->getAlignment()); } $xmlWriter->endElement(); //style:paragraph-properties diff --git a/src/PhpWord/Writer/ODText/Style/Section.php b/src/PhpWord/Writer/ODText/Style/Section.php index fa432856c7..79d57adb8b 100644 --- a/src/PhpWord/Writer/ODText/Style/Section.php +++ b/src/PhpWord/Writer/ODText/Style/Section.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/ODText/Style/Table.php b/src/PhpWord/Writer/ODText/Style/Table.php index dbfb94ed84..ff3cc423fe 100644 --- a/src/PhpWord/Writer/ODText/Style/Table.php +++ b/src/PhpWord/Writer/ODText/Style/Table.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/PDF.php b/src/PhpWord/Writer/PDF.php index 178655633c..5e5d9d71cf 100644 --- a/src/PhpWord/Writer/PDF.php +++ b/src/PhpWord/Writer/PDF.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PhpWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -39,6 +39,7 @@ class PDF * Instantiate a new renderer of the configured type within this container class * * @param \PhpOffice\PhpWord\PhpWord $phpWord + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __construct(PhpWord $phpWord) diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index 572e4b1dfd..2778aa5243 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PhpWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -77,6 +77,7 @@ abstract class AbstractRenderer extends HTML * Create new instance * * @param PhpWord $phpWord PhpWord object + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __construct(PhpWord $phpWord) @@ -169,7 +170,9 @@ public function setOrientation($value = 'default') * Save PhpWord to PDF file, pre-save * * @param string $filename Name of the file to save as + * * @return resource + * * @throws \PhpOffice\PhpWord\Exception\Exception */ protected function prepareForSave($filename = null) @@ -190,7 +193,9 @@ protected function prepareForSave($filename = null) * Save PhpWord to PDF file, post-save * * @param resource $fileHandle + * * @return void + * * @throws Exception */ protected function restoreStateAfterSave($fileHandle) diff --git a/src/PhpWord/Writer/PDF/DomPDF.php b/src/PhpWord/Writer/PDF/DomPDF.php index 47054c4a48..e31f3aae95 100644 --- a/src/PhpWord/Writer/PDF/DomPDF.php +++ b/src/PhpWord/Writer/PDF/DomPDF.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PhpWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/PDF/MPDF.php b/src/PhpWord/Writer/PDF/MPDF.php index 46d456d4f7..028ffac725 100644 --- a/src/PhpWord/Writer/PDF/MPDF.php +++ b/src/PhpWord/Writer/PDF/MPDF.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PhpWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/PDF/TCPDF.php b/src/PhpWord/Writer/PDF/TCPDF.php index 36849e24ad..e1e1900604 100644 --- a/src/PhpWord/Writer/PDF/TCPDF.php +++ b/src/PhpWord/Writer/PDF/TCPDF.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PhpWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -22,6 +22,8 @@ /** * TCPDF writer * + * @deprecated 0.13.0 Use `DomPDF` or `MPDF` instead. + * * @link http://www.tcpdf.org/ * @since 0.11.0 */ diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php index 58210c997f..887b1c67b3 100644 --- a/src/PhpWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -58,7 +58,9 @@ public function __construct(PhpWord $phpWord = null) * Save content to file. * * @param string $filename + * * @return void + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) diff --git a/src/PhpWord/Writer/RTF/Element/AbstractElement.php b/src/PhpWord/Writer/RTF/Element/AbstractElement.php index 73da5cbddb..289733dca5 100644 --- a/src/PhpWord/Writer/RTF/Element/AbstractElement.php +++ b/src/PhpWord/Writer/RTF/Element/AbstractElement.php @@ -11,16 +11,20 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Element; -use PhpOffice\PhpWord\Shared\String; -use PhpOffice\PhpWord\Style\Font as FontStyle; +use PhpOffice\Common\Text as CommonText; +use PhpOffice\PhpWord\Element\AbstractElement as Element; +use PhpOffice\PhpWord\Escaper\Rtf; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; +use PhpOffice\PhpWord\Writer\AbstractWriter; use PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement as HTMLAbstractElement; use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter; @@ -46,6 +50,13 @@ abstract class AbstractElement extends HTMLAbstractElement */ private $paragraphStyle; + public function __construct(AbstractWriter $parentWriter, Element $element, $withoutP = false) + { + parent::__construct($parentWriter, $element, $withoutP); + + $this->escaper = new Rtf(); + } + /** * Get font and paragraph styles. * @@ -112,7 +123,11 @@ protected function writeOpening() */ protected function writeText($text) { - return String::toUnicode($text); + if (Settings::isOutputEscapingEnabled()) { + return $this->escaper->escape($text); + } else { + return CommonText::toUnicode($text); // todo: replace with `return $text;` later. + } } /** diff --git a/src/PhpWord/Writer/RTF/Element/Container.php b/src/PhpWord/Writer/RTF/Element/Container.php index cb95b84bd2..7a1b0b07f7 100644 --- a/src/PhpWord/Writer/RTF/Element/Container.php +++ b/src/PhpWord/Writer/RTF/Element/Container.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/Image.php b/src/PhpWord/Writer/RTF/Element/Image.php index 52e705e9e2..e950d30b39 100644 --- a/src/PhpWord/Writer/RTF/Element/Image.php +++ b/src/PhpWord/Writer/RTF/Element/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/Link.php b/src/PhpWord/Writer/RTF/Element/Link.php index adbc7976ce..f106d57dd7 100644 --- a/src/PhpWord/Writer/RTF/Element/Link.php +++ b/src/PhpWord/Writer/RTF/Element/Link.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/ListItem.php b/src/PhpWord/Writer/RTF/Element/ListItem.php index b795143cdb..b2ba612d4f 100644 --- a/src/PhpWord/Writer/RTF/Element/ListItem.php +++ b/src/PhpWord/Writer/RTF/Element/ListItem.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/PageBreak.php b/src/PhpWord/Writer/RTF/Element/PageBreak.php index c8d16e0678..ac2bb8ecb6 100644 --- a/src/PhpWord/Writer/RTF/Element/PageBreak.php +++ b/src/PhpWord/Writer/RTF/Element/PageBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/Table.php b/src/PhpWord/Writer/RTF/Element/Table.php index 7c4329f719..c65d724871 100644 --- a/src/PhpWord/Writer/RTF/Element/Table.php +++ b/src/PhpWord/Writer/RTF/Element/Table.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/Text.php b/src/PhpWord/Writer/RTF/Element/Text.php index 38ef4c948c..b5a28adf74 100644 --- a/src/PhpWord/Writer/RTF/Element/Text.php +++ b/src/PhpWord/Writer/RTF/Element/Text.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/TextBreak.php b/src/PhpWord/Writer/RTF/Element/TextBreak.php index 57dc634994..0f76aea2fa 100644 --- a/src/PhpWord/Writer/RTF/Element/TextBreak.php +++ b/src/PhpWord/Writer/RTF/Element/TextBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/TextRun.php b/src/PhpWord/Writer/RTF/Element/TextRun.php index e756371633..f63f338ddc 100644 --- a/src/PhpWord/Writer/RTF/Element/TextRun.php +++ b/src/PhpWord/Writer/RTF/Element/TextRun.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Element/Title.php b/src/PhpWord/Writer/RTF/Element/Title.php index b9645a6897..894f52cc2e 100644 --- a/src/PhpWord/Writer/RTF/Element/Title.php +++ b/src/PhpWord/Writer/RTF/Element/Title.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Part/AbstractPart.php b/src/PhpWord/Writer/RTF/Part/AbstractPart.php index b10e5654c7..152493db7b 100644 --- a/src/PhpWord/Writer/RTF/Part/AbstractPart.php +++ b/src/PhpWord/Writer/RTF/Part/AbstractPart.php @@ -11,19 +11,62 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Part; -use PhpOffice\PhpWord\Writer\HTML\Part\AbstractPart as HTMLAbstractPart; +use PhpOffice\PhpWord\Escaper\Rtf; +use PhpOffice\PhpWord\Exception\Exception; +use PhpOffice\PhpWord\Writer\AbstractWriter; /** - * Abstract RTF part writer - * * @since 0.11.0 */ -abstract class AbstractPart extends HTMLAbstractPart +abstract class AbstractPart { + /** + * @var \PhpOffice\PhpWord\Writer\AbstractWriter + */ + private $parentWriter; + + /** + * @var \PhpOffice\PhpWord\Escaper\EscaperInterface + */ + protected $escaper; + + public function __construct() + { + $this->escaper = new Rtf(); + } + + /** + * @return string + */ + abstract public function write(); + + /** + * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer + * + * @return void + */ + public function setParentWriter(AbstractWriter $writer = null) + { + $this->parentWriter = $writer; + } + + /** + * @return \PhpOffice\PhpWord\Writer\AbstractWriter + * + * @throws \PhpOffice\PhpWord\Exception\Exception + */ + public function getParentWriter() + { + if ($this->parentWriter !== null) { + return $this->parentWriter; + } else { + throw new Exception('No parent WriterInterface assigned.'); + } + } } diff --git a/src/PhpWord/Writer/RTF/Part/Document.php b/src/PhpWord/Writer/RTF/Part/Document.php index edcdbd84a4..24ee7b0add 100644 --- a/src/PhpWord/Writer/RTF/Part/Document.php +++ b/src/PhpWord/Writer/RTF/Part/Document.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -65,7 +65,11 @@ private function writeInfo() $content .= '\info'; foreach ($properties as $property) { $method = 'get' . (isset($mapping[$property]) ? $mapping[$property] : $property); - $value = $docProps->$method(); + if (!in_array($property, $dateFields) && Settings::isOutputEscapingEnabled()) { + $value = $this->escaper->escape($docProps->$method()); + } else { + $value = $docProps->$method(); + } $value = in_array($property, $dateFields) ? $this->getDateValue($value) : $value; $content .= "{\\{$property} {$value}}"; } @@ -105,7 +109,6 @@ private function writeFormatting() */ private function writeSections() { - $content = ''; $sections = $this->getParentWriter()->getPhpWord()->getSections(); diff --git a/src/PhpWord/Writer/RTF/Part/Header.php b/src/PhpWord/Writer/RTF/Part/Header.php index 31fbb7f4af..56a5034995 100644 --- a/src/PhpWord/Writer/RTF/Part/Header.php +++ b/src/PhpWord/Writer/RTF/Part/Header.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -173,7 +173,7 @@ private function writeGenerator() { $content = ''; - $content .= '{\*\generator PhpWord;}'; // Set the generator + $content .= '{\*\generator PHPWord;}'; // Set the generator $content .= PHP_EOL; return $content; diff --git a/src/PhpWord/Writer/RTF/Style/AbstractStyle.php b/src/PhpWord/Writer/RTF/Style/AbstractStyle.php index 7b55fdc2f9..417be9cff9 100644 --- a/src/PhpWord/Writer/RTF/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/RTF/Style/AbstractStyle.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Style/Border.php b/src/PhpWord/Writer/RTF/Style/Border.php index 88c517ad79..9f7ee2c0ae 100644 --- a/src/PhpWord/Writer/RTF/Style/Border.php +++ b/src/PhpWord/Writer/RTF/Style/Border.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 20c47aee08..6567ec33bd 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/RTF/Style/Paragraph.php b/src/PhpWord/Writer/RTF/Style/Paragraph.php index 1a7de0a35b..046adc8c67 100644 --- a/src/PhpWord/Writer/RTF/Style/Paragraph.php +++ b/src/PhpWord/Writer/RTF/Style/Paragraph.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\RTF\Style; -use PhpOffice\PhpWord\Style\Alignment; +use PhpOffice\PhpWord\SimpleType\Jc; /** * RTF paragraph style writer @@ -26,7 +26,6 @@ */ class Paragraph extends AbstractStyle { - /** * Depth of table container nested level; Primarily used for RTF writer/reader * @@ -49,13 +48,12 @@ public function write() } $alignments = array( - Alignment::ALIGN_LEFT => '\ql', - Alignment::ALIGN_RIGHT => '\qr', - Alignment::ALIGN_CENTER => '\qc', - Alignment::ALIGN_BOTH => '\qj', + Jc::START => '\ql', + Jc::END => '\qr', + Jc::CENTER => '\qc', + Jc::BOTH => '\qj', ); - $align = $style->getAlign(); $spaceAfter = $style->getSpaceAfter(); $spaceBefore = $style->getSpaceBefore(); @@ -63,8 +61,8 @@ public function write() if ($this->nestedLevel == 0) { $content .= '\pard\nowidctlpar '; } - if (isset($alignments[$align])) { - $content .= $alignments[$align]; + if (isset($alignments[$style->getAlignment()])) { + $content .= $alignments[$style->getAlignment()]; } $content .= $this->getValueIf($spaceBefore !== null, '\sb' . $spaceBefore); $content .= $this->getValueIf($spaceAfter !== null, '\sa' . $spaceAfter); diff --git a/src/PhpWord/Writer/RTF/Style/Section.php b/src/PhpWord/Writer/RTF/Style/Section.php index 4169b630cc..dcdc0aaf3b 100644 --- a/src/PhpWord/Writer/RTF/Style/Section.php +++ b/src/PhpWord/Writer/RTF/Style/Section.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index 09d095093f..8e10f5f604 100644 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php index 3b6432ed6a..f5a454d297 100644 --- a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php +++ b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php @@ -11,15 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\Text as CommonText; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\AbstractElement as Element; -use PhpOffice\PhpWord\Shared\String; -use PhpOffice\PhpWord\Shared\XMLWriter; /** * Abstract element writer @@ -31,7 +31,7 @@ abstract class AbstractElement /** * XML writer * - * @var \PhpOffice\PhpWord\Shared\XMLWriter + * @var \PhpOffice\Common\XMLWriter */ private $xmlWriter; @@ -57,7 +57,7 @@ abstract public function write(); /** * Create new instance * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param bool $withoutP */ @@ -71,7 +71,7 @@ public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = /** * Get XML Writer * - * @return \PhpOffice\PhpWord\Shared\XMLWriter + * @return \PhpOffice\Common\XMLWriter */ protected function getXmlWriter() { @@ -167,6 +167,6 @@ private function writeTextStyle($styleType) */ protected function getText($text) { - return String::controlCharacterPHP2OOXML($text); + return CommonText::controlCharacterPHP2OOXML($text); } } diff --git a/src/PhpWord/Writer/Word2007/Element/Bookmark.php b/src/PhpWord/Writer/Word2007/Element/Bookmark.php index df5a104a18..424fb0ab79 100644 --- a/src/PhpWord/Writer/Word2007/Element/Bookmark.php +++ b/src/PhpWord/Writer/Word2007/Element/Bookmark.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/Chart.php b/src/PhpWord/Writer/Word2007/Element/Chart.php index ccd8cd77db..12602532a9 100644 --- a/src/PhpWord/Writer/Word2007/Element/Chart.php +++ b/src/PhpWord/Writer/Word2007/Element/Chart.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/CheckBox.php b/src/PhpWord/Writer/Word2007/Element/CheckBox.php index deafbd1de3..7424985cfc 100644 --- a/src/PhpWord/Writer/Word2007/Element/CheckBox.php +++ b/src/PhpWord/Writer/Word2007/Element/CheckBox.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; + /** * CheckBox element writer * @@ -63,7 +65,7 @@ public function write() $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw(' FORMCHECKBOX '); + $xmlWriter->text(' FORMCHECKBOX '); $xmlWriter->endElement();// w:instrText $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); @@ -83,7 +85,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($this->getText($element->getText())); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($this->getText($element->getText())); + } else { + $xmlWriter->writeRaw($this->getText($element->getText())); + } $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r diff --git a/src/PhpWord/Writer/Word2007/Element/Container.php b/src/PhpWord/Writer/Word2007/Element/Container.php index 771fe5c34e..0efd0ebc43 100644 --- a/src/PhpWord/Writer/Word2007/Element/Container.php +++ b/src/PhpWord/Writer/Word2007/Element/Container.php @@ -11,16 +11,16 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement; use PhpOffice\PhpWord\Element\AbstractElement as Element; use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement; -use PhpOffice\PhpWord\Shared\XMLWriter; /** * Container element writer (section, textrun, header, footnote, cell, etc.) @@ -73,7 +73,7 @@ public function write() /** * Write individual element * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param bool $withoutP * @return string diff --git a/src/PhpWord/Writer/Word2007/Element/Endnote.php b/src/PhpWord/Writer/Word2007/Element/Endnote.php index f627c13c9d..9363489e45 100644 --- a/src/PhpWord/Writer/Word2007/Element/Endnote.php +++ b/src/PhpWord/Writer/Word2007/Element/Endnote.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/Field.php b/src/PhpWord/Writer/Word2007/Element/Field.php index b9c3c34b81..ae4c66ba8e 100644 --- a/src/PhpWord/Writer/Word2007/Element/Field.php +++ b/src/PhpWord/Writer/Word2007/Element/Field.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -79,9 +79,7 @@ public function write() $xmlWriter->endElement(); // w:noProof $xmlWriter->endElement(); // w:rPr - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw('1'); - $xmlWriter->endElement(); // w:t + $xmlWriter->writeElement('w:t', '1'); $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:fldSimple diff --git a/src/PhpWord/Writer/Word2007/Element/Footnote.php b/src/PhpWord/Writer/Word2007/Element/Footnote.php index 5640a90db4..53fcd6a045 100644 --- a/src/PhpWord/Writer/Word2007/Element/Footnote.php +++ b/src/PhpWord/Writer/Word2007/Element/Footnote.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/FormField.php b/src/PhpWord/Writer/Word2007/Element/FormField.php index 432dc9c23b..27df756f06 100644 --- a/src/PhpWord/Writer/Word2007/Element/FormField.php +++ b/src/PhpWord/Writer/Word2007/Element/FormField.php @@ -11,14 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\FormField as FormFieldElement; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\PhpWord\Settings; /** * FormField element writer @@ -78,7 +79,7 @@ public function write() $this->writeFontStyle(); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw("{$instruction}"); + $xmlWriter->text("{$instruction}"); $xmlWriter->endElement();// w:instrText $xmlWriter->endElement(); // w:r @@ -91,7 +92,11 @@ public function write() $this->writeFontStyle(); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($value); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($value); + } else { + $xmlWriter->writeRaw($value); + } $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r @@ -107,7 +112,7 @@ public function write() * Write textinput. * * @link http://www.datypic.com/sc/ooxml/t-w_CT_FFTextInput.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\FormField $element * @return void */ @@ -124,7 +129,7 @@ private function writeTextInput(XMLWriter $xmlWriter, FormFieldElement $element) * Write checkbox. * * @link http://www.datypic.com/sc/ooxml/t-w_CT_FFCheckBox.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\FormField $element * @return void */ @@ -148,7 +153,7 @@ private function writeCheckBox(XMLWriter $xmlWriter, FormFieldElement $element) * Write dropdown. * * @link http://www.datypic.com/sc/ooxml/t-w_CT_FFDDList.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\FormField $element * @return void */ diff --git a/src/PhpWord/Writer/Word2007/Element/Image.php b/src/PhpWord/Writer/Word2007/Element/Image.php index 7398842397..914c78ea49 100644 --- a/src/PhpWord/Writer/Word2007/Element/Image.php +++ b/src/PhpWord/Writer/Word2007/Element/Image.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\Image as ImageElement; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Image as ImageStyleWriter; /** diff --git a/src/PhpWord/Writer/Word2007/Element/Line.php b/src/PhpWord/Writer/Word2007/Element/Line.php index a6c7c24081..ade91fb84f 100644 --- a/src/PhpWord/Writer/Word2007/Element/Line.php +++ b/src/PhpWord/Writer/Word2007/Element/Line.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/Link.php b/src/PhpWord/Writer/Word2007/Element/Link.php index 2cb8407f5b..5f7ad278c9 100644 --- a/src/PhpWord/Writer/Word2007/Element/Link.php +++ b/src/PhpWord/Writer/Word2007/Element/Link.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; + /** * Link element writer * @@ -54,7 +56,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($element->getText()); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($element->getText()); + } else { + $xmlWriter->writeRaw($element->getText()); + } $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:hyperlink diff --git a/src/PhpWord/Writer/Word2007/Element/ListItem.php b/src/PhpWord/Writer/Word2007/Element/ListItem.php index 0f559a4e1d..53644ffa67 100644 --- a/src/PhpWord/Writer/Word2007/Element/ListItem.php +++ b/src/PhpWord/Writer/Word2007/Element/ListItem.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/ListItemRun.php b/src/PhpWord/Writer/Word2007/Element/ListItemRun.php index 289cb05476..1ac17a98a9 100644 --- a/src/PhpWord/Writer/Word2007/Element/ListItemRun.php +++ b/src/PhpWord/Writer/Word2007/Element/ListItemRun.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/Object.php b/src/PhpWord/Writer/Word2007/Element/Object.php index a9cc449abf..4fdf6feda8 100644 --- a/src/PhpWord/Writer/Word2007/Element/Object.php +++ b/src/PhpWord/Writer/Word2007/Element/Object.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/PageBreak.php b/src/PhpWord/Writer/Word2007/Element/PageBreak.php index fb831ca7ac..363a8c2c3a 100644 --- a/src/PhpWord/Writer/Word2007/Element/PageBreak.php +++ b/src/PhpWord/Writer/Word2007/Element/PageBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/ParagraphAlignment.php b/src/PhpWord/Writer/Word2007/Element/ParagraphAlignment.php new file mode 100644 index 0000000000..2c775d1445 --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Element/ParagraphAlignment.php @@ -0,0 +1,60 @@ +attributes['w:val'] = $value; + } + + /** + * @since 0.13.0 + * + * @return string + */ + final public function getName() + { + return $this->name; + } + + /** + * @since 0.13.0 + * + * @return string[] + */ + final public function getAttributes() + { + return $this->attributes; + } +} diff --git a/src/PhpWord/Writer/Word2007/Element/PreserveText.php b/src/PhpWord/Writer/Word2007/Element/PreserveText.php index 894b3050f3..82c6f87b0f 100644 --- a/src/PhpWord/Writer/Word2007/Element/PreserveText.php +++ b/src/PhpWord/Writer/Word2007/Element/PreserveText.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; + /** * PreserveText element writer * @@ -60,7 +62,11 @@ public function write() $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($text); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($text); + } else { + $xmlWriter->writeRaw($text); + } $xmlWriter->endElement(); $xmlWriter->endElement(); @@ -82,7 +88,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($this->getText($text)); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($this->getText($text)); + } else { + $xmlWriter->writeRaw($this->getText($text)); + } $xmlWriter->endElement(); $xmlWriter->endElement(); } diff --git a/src/PhpWord/Writer/Word2007/Element/SDT.php b/src/PhpWord/Writer/Word2007/Element/SDT.php index 79d7004dd6..313bf7e07b 100644 --- a/src/PhpWord/Writer/Word2007/Element/SDT.php +++ b/src/PhpWord/Writer/Word2007/Element/SDT.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\SDT as SDTElement; -use PhpOffice\PhpWord\Shared\XMLWriter; /** * Structured document tag element writer @@ -58,9 +58,7 @@ public function write() // Content $xmlWriter->startElement('w:sdtContent'); $xmlWriter->startElement('w:r'); - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw('Pick value'); - $xmlWriter->endElement(); // w:t + $xmlWriter->writeElement('w:t', 'Pick value'); $xmlWriter->endElement(); // w:r $xmlWriter->endElement(); // w:sdtContent @@ -73,7 +71,7 @@ public function write() * Write combo box. * * @link http://www.datypic.com/sc/ooxml/t-w_CT_SdtComboBox.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\SDT $element * @return void */ @@ -93,7 +91,7 @@ private function writeComboBox(XMLWriter $xmlWriter, SDTElement $element) * Write drop down list. * * @link http://www.datypic.com/sc/ooxml/t-w_CT_SdtDropDownList.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\SDT $element * @return void */ @@ -106,7 +104,7 @@ private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element) * Write date. * * @link http://www.datypic.com/sc/ooxml/t-w_CT_SdtDate.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\SDT $element * @return void */ diff --git a/src/PhpWord/Writer/Word2007/Element/Shape.php b/src/PhpWord/Writer/Word2007/Element/Shape.php index bd9320a258..f282c4a536 100644 --- a/src/PhpWord/Writer/Word2007/Element/Shape.php +++ b/src/PhpWord/Writer/Word2007/Element/Shape.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\Shape as ShapeElement; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Shape as ShapeStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\Shape as ShapeStyleWriter; @@ -78,7 +78,7 @@ public function write() /** * Write arc. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style * @return void */ @@ -93,7 +93,7 @@ private function writeArc(XMLWriter $xmlWriter, ShapeStyle $style) /** * Write curve. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style * @return void */ @@ -109,7 +109,7 @@ private function writeCurve(XMLWriter $xmlWriter, ShapeStyle $style) /** * Write line. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style * @return void */ @@ -124,7 +124,7 @@ private function writeLine(XMLWriter $xmlWriter, ShapeStyle $style) /** * Write polyline. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style * @return void */ @@ -136,7 +136,7 @@ private function writePolyline(XMLWriter $xmlWriter, ShapeStyle $style) /** * Write rectangle. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Shape $style * @return void */ diff --git a/src/PhpWord/Writer/Word2007/Element/TOC.php b/src/PhpWord/Writer/Word2007/Element/TOC.php index db2a65d07b..996edb64e5 100644 --- a/src/PhpWord/Writer/Word2007/Element/TOC.php +++ b/src/PhpWord/Writer/Word2007/Element/TOC.php @@ -11,14 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\TOC as TOCElement; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; @@ -66,7 +67,7 @@ public function write() /** * Write title * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\TOC $element * @param \PhpOffice\PhpWord\Element\Title $title * @param bool $writeFieldMark @@ -99,9 +100,13 @@ private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, $title, $ $styleWriter = new FontStyleWriter($xmlWriter, $fontStyle); $styleWriter->write(); } - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw($title->getText()); - $xmlWriter->endElement(); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->writeElement('w:t', $title->getText()); + } else { + $xmlWriter->startElement('w:t'); + $xmlWriter->writeRaw($title->getText()); + $xmlWriter->endElement(); + } $xmlWriter->endElement(); // w:r $xmlWriter->startElement('w:r'); @@ -117,7 +122,7 @@ private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, $title, $ $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw("PAGEREF _Toc{$rId} \h"); + $xmlWriter->text("PAGEREF _Toc{$rId} \h"); $xmlWriter->endElement(); $xmlWriter->endElement(); @@ -135,7 +140,7 @@ private function writeTitle(XMLWriter $xmlWriter, TOCElement $element, $title, $ /** * Write style * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\TOC $element * @param int $indent * @return void @@ -182,7 +187,7 @@ private function writeStyle(XMLWriter $xmlWriter, TOCElement $element, $indent) /** * Write TOC Field. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\TOC $element * @return void */ @@ -200,7 +205,7 @@ private function writeFieldMark(XMLWriter $xmlWriter, TOCElement $element) $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:instrText'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw("TOC \o {$minDepth}-{$maxDepth} \h \z \u"); + $xmlWriter->text("TOC \o {$minDepth}-{$maxDepth} \h \z \u"); $xmlWriter->endElement(); $xmlWriter->endElement(); diff --git a/src/PhpWord/Writer/Word2007/Element/Table.php b/src/PhpWord/Writer/Word2007/Element/Table.php index f090d05c89..093666ee22 100644 --- a/src/PhpWord/Writer/Word2007/Element/Table.php +++ b/src/PhpWord/Writer/Word2007/Element/Table.php @@ -11,16 +11,16 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\Cell as CellElement; use PhpOffice\PhpWord\Element\Row as RowElement; use PhpOffice\PhpWord\Element\Table as TableElement; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Cell as CellStyle; use PhpOffice\PhpWord\Style\Row as RowStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\Cell as CellStyleWriter; @@ -73,7 +73,7 @@ public function write() /** * Write column. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Table $element * @return void */ @@ -110,7 +110,7 @@ private function writeColumns(XMLWriter $xmlWriter, TableElement $element) /** * Write row. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Row $row * @return void */ @@ -137,7 +137,7 @@ private function writeRow(XMLWriter $xmlWriter, RowElement $row) /** * Write cell. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Cell $cell * @return void */ diff --git a/src/PhpWord/Writer/Word2007/Element/TableAlignment.php b/src/PhpWord/Writer/Word2007/Element/TableAlignment.php new file mode 100644 index 0000000000..45459a388c --- /dev/null +++ b/src/PhpWord/Writer/Word2007/Element/TableAlignment.php @@ -0,0 +1,60 @@ +attributes['w:val'] = $value; + } + + /** + * @since 0.13.0 + * + * @return string + */ + final public function getName() + { + return $this->name; + } + + /** + * @since 0.13.0 + * + * @return string[] + */ + final public function getAttributes() + { + return $this->attributes; + } +} diff --git a/src/PhpWord/Writer/Word2007/Element/Text.php b/src/PhpWord/Writer/Word2007/Element/Text.php index cfb991c2d0..2df4892bfe 100644 --- a/src/PhpWord/Writer/Word2007/Element/Text.php +++ b/src/PhpWord/Writer/Word2007/Element/Text.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; + /** * Text element writer * @@ -45,7 +47,11 @@ public function write() $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw($this->getText($element->getText())); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->text($this->getText($element->getText())); + } else { + $xmlWriter->writeRaw($this->getText($element->getText())); + } $xmlWriter->endElement(); $xmlWriter->endElement(); // w:r diff --git a/src/PhpWord/Writer/Word2007/Element/TextBox.php b/src/PhpWord/Writer/Word2007/Element/TextBox.php index fe62c644f3..3c4f48c27f 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Element/TextBox.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/TextBreak.php b/src/PhpWord/Writer/Word2007/Element/TextBreak.php index fb52b86e62..a9e6f613ac 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextBreak.php +++ b/src/PhpWord/Writer/Word2007/Element/TextBreak.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/TextRun.php b/src/PhpWord/Writer/Word2007/Element/TextRun.php index 844e0b6bbb..1e95ab5ccf 100644 --- a/src/PhpWord/Writer/Word2007/Element/TextRun.php +++ b/src/PhpWord/Writer/Word2007/Element/TextRun.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Element/Title.php b/src/PhpWord/Writer/Word2007/Element/Title.php index ce9aeea529..925d4c433f 100644 --- a/src/PhpWord/Writer/Word2007/Element/Title.php +++ b/src/PhpWord/Writer/Word2007/Element/Title.php @@ -11,12 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Element; +use PhpOffice\PhpWord\Settings; + /** * TextRun element writer * @@ -60,9 +62,13 @@ public function write() // Actual text $xmlWriter->startElement('w:r'); - $xmlWriter->startElement('w:t'); - $xmlWriter->writeRaw($this->getText($element->getText())); - $xmlWriter->endElement(); + if (Settings::isOutputEscapingEnabled()) { + $xmlWriter->writeElement('w:t', $this->getText($element->getText())); + } else { + $xmlWriter->startElement('w:t'); + $xmlWriter->writeRaw($this->getText($element->getText())); + $xmlWriter->endElement(); + } $xmlWriter->endElement(); // Bookmark end diff --git a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php index e26853d737..26734aa097 100644 --- a/src/PhpWord/Writer/Word2007/Part/AbstractPart.php +++ b/src/PhpWord/Writer/Word2007/Part/AbstractPart.php @@ -11,14 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Writer\AbstractWriter; /** @@ -60,6 +61,7 @@ public function setParentWriter(AbstractWriter $writer = null) * Get parent writer * * @return \PhpOffice\PhpWord\Writer\AbstractWriter + * * @throws \PhpOffice\PhpWord\Exception\Exception */ public function getParentWriter() @@ -74,7 +76,7 @@ public function getParentWriter() /** * Get XML Writer * - * @return \PhpOffice\PhpWord\Shared\XMLWriter + * @return \PhpOffice\Common\XMLWriter */ protected function getXmlWriter() { @@ -85,9 +87,9 @@ protected function getXmlWriter() } } if ($useDiskCaching) { - return new XMLWriter(XMLWriter::STORAGE_DISK, $this->parentWriter->getDiskCachingDirectory()); + return new XMLWriter(XMLWriter::STORAGE_DISK, $this->parentWriter->getDiskCachingDirectory(), Settings::hasCompatibility()); } else { - return new XMLWriter(XMLWriter::STORAGE_MEMORY); + return new XMLWriter(XMLWriter::STORAGE_MEMORY, './', Settings::hasCompatibility()); } } } diff --git a/src/PhpWord/Writer/Word2007/Part/Chart.php b/src/PhpWord/Writer/Word2007/Part/Chart.php index 8423762c30..3dd3968b49 100644 --- a/src/PhpWord/Writer/Word2007/Part/Chart.php +++ b/src/PhpWord/Writer/Word2007/Part/Chart.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\Chart as ChartElement; -use PhpOffice\PhpWord\Shared\XMLWriter; /** * Word2007 chart part writer: word/charts/chartx.xml @@ -96,7 +96,7 @@ public function write() * Write chart * * @link http://www.datypic.com/sc/ooxml/t-draw-chart_CT_Chart.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writeChart(XMLWriter $xmlWriter) @@ -121,7 +121,7 @@ private function writeChart(XMLWriter $xmlWriter) * @link http://www.datypic.com/sc/ooxml/t-draw-chart_CT_AreaChart.html * @link http://www.datypic.com/sc/ooxml/t-draw-chart_CT_RadarChart.html * @link http://www.datypic.com/sc/ooxml/t-draw-chart_CT_ScatterChart.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @return void */ private function writePlotArea(XMLWriter $xmlWriter) @@ -180,7 +180,7 @@ private function writePlotArea(XMLWriter $xmlWriter) /** * Write series. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param bool $scatter * @return void */ @@ -219,7 +219,7 @@ private function writeSeries(XMLWriter $xmlWriter, $scatter = false) /** * Write series items. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $type * @param array $values * @return void @@ -241,11 +241,13 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) foreach ($values as $value) { $xmlWriter->startElement('c:pt'); $xmlWriter->writeAttribute('idx', $index); - - $xmlWriter->startElement('c:v'); - $xmlWriter->writeRaw($value); - $xmlWriter->endElement(); // c:v - + if (\PhpOffice\PhpWord\Settings::isOutputEscapingEnabled()) { + $xmlWriter->writeElement('c:v', $value); + } else { + $xmlWriter->startElement('c:v'); + $xmlWriter->writeRaw($value); + $xmlWriter->endElement(); + } $xmlWriter->endElement(); // c:pt $index++; } @@ -258,7 +260,7 @@ private function writeSeriesItem(XMLWriter $xmlWriter, $type, $values) * Write axis * * @link http://www.datypic.com/sc/ooxml/t-draw-chart_CT_CatAx.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $type * @return void */ @@ -301,7 +303,7 @@ private function writeAxis(XMLWriter $xmlWriter, $type) * Write shape * * @link http://www.datypic.com/sc/ooxml/t-a_CT_ShapeProperties.html - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param bool $line * @return void */ diff --git a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php index 6ae4e8758e..1c81f34366 100644 --- a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php +++ b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\Common\XMLWriter; /** * Word2007 contenttypes part writer: [Content_Types].xml @@ -79,7 +79,7 @@ public function write() /** * Write content types element * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer + * @param \PhpOffice\Common\XMLWriter $xmlWriter XML Writer * @param array $parts * @param boolean $isDefault * @return void diff --git a/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php b/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php index 421ceefec2..adfe752f80 100644 --- a/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php +++ b/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php b/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php index 252be01f02..afb6f286e7 100644 --- a/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php +++ b/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -54,13 +54,13 @@ public function write() // dcterms:created $xmlWriter->startElement('dcterms:created'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); - $xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getCreated())); + $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getCreated())); $xmlWriter->endElement(); // dcterms:modified $xmlWriter->startElement('dcterms:modified'); $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); - $xmlWriter->writeRaw(date($this->dateFormat, $phpWord->getDocInfo()->getModified())); + $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getModified())); $xmlWriter->endElement(); $xmlWriter->endElement(); // cp:coreProperties diff --git a/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php b/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php index ba6547d9b9..63ed8edeea 100644 --- a/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php +++ b/src/PhpWord/Writer/Word2007/Part/DocPropsCustom.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -60,9 +60,7 @@ public function write() $xmlWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false'); break; case 'd': - $xmlWriter->startElement('vt:filetime'); - $xmlWriter->writeRaw(date($this->dateFormat, $propertyValue)); - $xmlWriter->endElement(); + $xmlWriter->writeElement('vt:filetime', date($this->dateFormat, $propertyValue)); break; default: $xmlWriter->writeElement('vt:lpwstr', $propertyValue); diff --git a/src/PhpWord/Writer/Word2007/Part/Document.php b/src/PhpWord/Writer/Word2007/Part/Document.php index ea607f09b7..411946f51c 100644 --- a/src/PhpWord/Writer/Word2007/Part/Document.php +++ b/src/PhpWord/Writer/Word2007/Part/Document.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\Section; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter; @@ -81,7 +81,7 @@ public function write() /** * Write begin section. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Section $section * @return void */ @@ -97,7 +97,7 @@ private function writeSection(XMLWriter $xmlWriter, Section $section) /** * Write end section. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Section $section * @return void */ diff --git a/src/PhpWord/Writer/Word2007/Part/Endnotes.php b/src/PhpWord/Writer/Word2007/Part/Endnotes.php index f07bac5f70..bc15cf1e13 100644 --- a/src/PhpWord/Writer/Word2007/Part/Endnotes.php +++ b/src/PhpWord/Writer/Word2007/Part/Endnotes.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/FontTable.php b/src/PhpWord/Writer/Word2007/Part/FontTable.php index 314cf58679..08f0ad0e05 100644 --- a/src/PhpWord/Writer/Word2007/Part/FontTable.php +++ b/src/PhpWord/Writer/Word2007/Part/FontTable.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/Footer.php b/src/PhpWord/Writer/Word2007/Part/Footer.php index db6a2b334b..3e4e4fee2c 100644 --- a/src/PhpWord/Writer/Word2007/Part/Footer.php +++ b/src/PhpWord/Writer/Word2007/Part/Footer.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/Footnotes.php b/src/PhpWord/Writer/Word2007/Part/Footnotes.php index 9ceefd82ee..fd69214980 100644 --- a/src/PhpWord/Writer/Word2007/Part/Footnotes.php +++ b/src/PhpWord/Writer/Word2007/Part/Footnotes.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Element\Footnote; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; @@ -135,7 +135,7 @@ public function setElements($elements) /** * Write note item. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Footnote|\PhpOffice\PhpWord\Element\Endnote $element * @return void */ @@ -164,7 +164,7 @@ protected function writeNote(XMLWriter $xmlWriter, $element) $xmlWriter->startElement('w:r'); $xmlWriter->startElement('w:t'); $xmlWriter->writeAttribute('xml:space', 'preserve'); - $xmlWriter->writeRaw(' '); + $xmlWriter->text(' '); $xmlWriter->endElement(); // w:t $xmlWriter->endElement(); // w:r diff --git a/src/PhpWord/Writer/Word2007/Part/Header.php b/src/PhpWord/Writer/Word2007/Part/Header.php index 638111d7f3..438e503eca 100644 --- a/src/PhpWord/Writer/Word2007/Part/Header.php +++ b/src/PhpWord/Writer/Word2007/Part/Header.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/Numbering.php b/src/PhpWord/Writer/Word2007/Part/Numbering.php index bbb8eeb455..c5c9b4c724 100644 --- a/src/PhpWord/Writer/Word2007/Part/Numbering.php +++ b/src/PhpWord/Writer/Word2007/Part/Numbering.php @@ -11,16 +11,16 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\Common\XMLWriter; +use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Numbering as NumberingStyle; use PhpOffice\PhpWord\Style\NumberingLevel; -use PhpOffice\PhpWord\Style; /** * Word2007 numbering part writer: word/numbering.xml @@ -97,7 +97,7 @@ public function write() /** * Write level. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @return void */ @@ -108,17 +108,18 @@ private function writeLevel(XMLWriter $xmlWriter, NumberingLevel $level) // Numbering level properties $properties = array( - 'start' => 'start', - 'format' => 'numFmt', - 'restart' => 'lvlRestart', - 'pStyle' => 'pStyle', - 'suffix' => 'suff', - 'text' => 'lvlText', - 'align' => 'lvlJc' + 'start' => 'start', + 'format' => 'numFmt', + 'restart' => 'lvlRestart', + 'pStyle' => 'pStyle', + 'suffix' => 'suff', + 'text' => 'lvlText', + 'alignment' => 'lvlJc', ); foreach ($properties as $property => $nodeName) { $getMethod = "get{$property}"; - if (!is_null($level->$getMethod())) { + if ('' !== $level->$getMethod() // this condition is now supported by `alignment` only + && !is_null($level->$getMethod())) { $xmlWriter->startElement("w:{$nodeName}"); $xmlWriter->writeAttribute('w:val', $level->$getMethod()); $xmlWriter->endElement(); // w:start @@ -137,7 +138,7 @@ private function writeLevel(XMLWriter $xmlWriter, NumberingLevel $level) * * @since 0.11.0 * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @return void * @todo Use paragraph style writer @@ -170,7 +171,7 @@ private function writeParagraph(XMLWriter $xmlWriter, NumberingLevel $level) * * @since 0.11.0 * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\NumberingLevel $level * @return void * @todo Use font style writer diff --git a/src/PhpWord/Writer/Word2007/Part/Rels.php b/src/PhpWord/Writer/Word2007/Part/Rels.php index 9a7f444bd4..4a3b5b673d 100644 --- a/src/PhpWord/Writer/Word2007/Part/Rels.php +++ b/src/PhpWord/Writer/Word2007/Part/Rels.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\Shared\XMLWriter; /** * Word2007 main relationship writer: _rels/.rels @@ -49,7 +49,7 @@ public function write() /** * Write relationships. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param array $xmlRels * @param array $mediaRels * @param int $relId @@ -77,7 +77,7 @@ protected function writeRels(XMLWriter $xmlWriter, $xmlRels = array(), $mediaRel /** * Write media relationships. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param int $relId * @param array $mediaRel * @return void @@ -103,12 +103,14 @@ private function writeMediaRel(XMLWriter $xmlWriter, $relId, $mediaRel) * Format: * * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param int $relId Relationship ID * @param string $type Relationship type * @param string $target Relationship target * @param string $targetMode Relationship target mode + * * @return void + * * @throws \PhpOffice\PhpWord\Exception\Exception */ private function writeRel(XMLWriter $xmlWriter, $relId, $type, $target, $targetMode = '') diff --git a/src/PhpWord/Writer/Word2007/Part/RelsDocument.php b/src/PhpWord/Writer/Word2007/Part/RelsDocument.php index 744e14f9a2..c60dba286f 100644 --- a/src/PhpWord/Writer/Word2007/Part/RelsDocument.php +++ b/src/PhpWord/Writer/Word2007/Part/RelsDocument.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/RelsPart.php b/src/PhpWord/Writer/Word2007/Part/RelsPart.php index 627a2bcd1b..e8939c7fa1 100644 --- a/src/PhpWord/Writer/Word2007/Part/RelsPart.php +++ b/src/PhpWord/Writer/Word2007/Part/RelsPart.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/Settings.php b/src/PhpWord/Writer/Word2007/Part/Settings.php index 50399c4aa0..5c6f646cae 100644 --- a/src/PhpWord/Writer/Word2007/Part/Settings.php +++ b/src/PhpWord/Writer/Word2007/Part/Settings.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ @@ -64,7 +64,7 @@ public function write() /** * Write indivual setting, recursive to any child settings. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $settingKey * @param array|string $settingValue * @return void diff --git a/src/PhpWord/Writer/Word2007/Part/Styles.php b/src/PhpWord/Writer/Word2007/Part/Styles.php index 0194222948..7bcb8d92a4 100644 --- a/src/PhpWord/Writer/Word2007/Part/Styles.php +++ b/src/PhpWord/Writer/Word2007/Part/Styles.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Part; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Settings as PhpWordSettings; -use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; @@ -77,7 +77,7 @@ public function write() /** * Write default font and other default styles. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\AbstractStyle[] $styles * @return void */ @@ -142,7 +142,7 @@ private function writeDefaultStyles(XMLWriter $xmlWriter, $styles) /** * Write font style. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $styleName * @param \PhpOffice\PhpWord\Style\Font $style * @return void @@ -196,7 +196,7 @@ private function writeFontStyle(XMLWriter $xmlWriter, $styleName, FontStyle $sty /** * Write paragraph style. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $styleName * @param \PhpOffice\PhpWord\Style\Paragraph $style * @return void @@ -229,7 +229,7 @@ private function writeParagraphStyle(XMLWriter $xmlWriter, $styleName, Paragraph /** * Write table style. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $styleName * @param \PhpOffice\PhpWord\Style\Table $style * @return void diff --git a/src/PhpWord/Writer/Word2007/Part/Theme.php b/src/PhpWord/Writer/Word2007/Part/Theme.php index 62911c548d..e9b16bfcc2 100644 --- a/src/PhpWord/Writer/Word2007/Part/Theme.php +++ b/src/PhpWord/Writer/Word2007/Part/Theme.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Part/WebSettings.php b/src/PhpWord/Writer/Word2007/Part/WebSettings.php index f800ebdeb8..ce42063da7 100644 --- a/src/PhpWord/Writer/Word2007/Part/WebSettings.php +++ b/src/PhpWord/Writer/Word2007/Part/WebSettings.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php b/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php index 16335680f0..d0ee5a0def 100644 --- a/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Shared\XMLWriter; /** * Style writer @@ -30,7 +30,7 @@ abstract class AbstractStyle /** * XML writer * - * @var \PhpOffice\PhpWord\Shared\XMLWriter + * @var \PhpOffice\Common\XMLWriter */ private $xmlWriter; @@ -49,7 +49,7 @@ abstract public function write(); /** * Create new instance. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string|\PhpOffice\PhpWord\Style\AbstractStyle $style */ public function __construct(XMLWriter $xmlWriter, $style = null) @@ -61,7 +61,7 @@ public function __construct(XMLWriter $xmlWriter, $style = null) /** * Get XML Writer * - * @return \PhpOffice\PhpWord\Shared\XMLWriter + * @return \PhpOffice\Common\XMLWriter */ protected function getXmlWriter() { @@ -106,7 +106,7 @@ protected function convertTwip($value, $default = 0) /** * Write child style. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $name * @param mixed $value * @return void diff --git a/src/PhpWord/Writer/Word2007/Style/Alignment.php b/src/PhpWord/Writer/Word2007/Style/Alignment.php deleted file mode 100644 index fabaf8eac4..0000000000 --- a/src/PhpWord/Writer/Word2007/Style/Alignment.php +++ /dev/null @@ -1,46 +0,0 @@ -getStyle(); - if (!$style instanceof \PhpOffice\PhpWord\Style\Alignment) { - return; - } - $value = $style->getValue(); - if ($value !== null) { - $xmlWriter = $this->getXmlWriter(); - $xmlWriter->startElement('w:jc'); - $xmlWriter->writeAttribute('w:val', $value); - $xmlWriter->endElement(); // w:jc - } - } -} diff --git a/src/PhpWord/Writer/Word2007/Style/Cell.php b/src/PhpWord/Writer/Word2007/Style/Cell.php index 0f90b3aa91..c9156de133 100644 --- a/src/PhpWord/Writer/Word2007/Style/Cell.php +++ b/src/PhpWord/Writer/Word2007/Style/Cell.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Extrusion.php b/src/PhpWord/Writer/Word2007/Style/Extrusion.php index ba1ee590ec..3ecd76e4fe 100644 --- a/src/PhpWord/Writer/Word2007/Style/Extrusion.php +++ b/src/PhpWord/Writer/Word2007/Style/Extrusion.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Fill.php b/src/PhpWord/Writer/Word2007/Style/Fill.php index 645f1ab053..7ce6810635 100644 --- a/src/PhpWord/Writer/Word2007/Style/Fill.php +++ b/src/PhpWord/Writer/Word2007/Style/Fill.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Font.php b/src/PhpWord/Writer/Word2007/Style/Font.php index 9371f97003..97cf3088b9 100644 --- a/src/PhpWord/Writer/Word2007/Style/Font.php +++ b/src/PhpWord/Writer/Word2007/Style/Font.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Frame.php b/src/PhpWord/Writer/Word2007/Style/Frame.php index 28ebeaf52e..9c6ddaefad 100644 --- a/src/PhpWord/Writer/Word2007/Style/Frame.php +++ b/src/PhpWord/Writer/Word2007/Style/Frame.php @@ -11,15 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; -use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Style\Alignment as AlignmentStyle; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Style\Frame as FrameStyle; +use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment; /** * Frame style writer @@ -89,15 +89,23 @@ public function writeAlignment() $xmlWriter = $this->getXmlWriter(); $xmlWriter->startElement('w:pPr'); - $styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $style->getAlign()))); - $styleWriter->write(); - $xmlWriter->endElement(); // w:pPr + + if ('' !== $style->getAlignment()) { + $paragraphAlignment = new ParagraphAlignment($style->getAlignment()); + $xmlWriter->startElement($paragraphAlignment->getName()); + foreach ($paragraphAlignment->getAttributes() as $attributeName => $attributeValue) { + $xmlWriter->writeAttribute($attributeName, $attributeValue); + } + $xmlWriter->endElement(); + } + + $xmlWriter->endElement(); } /** - * Write alignment. + * Write wrap. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Frame $style * @param string $wrap * @return void diff --git a/src/PhpWord/Writer/Word2007/Style/Image.php b/src/PhpWord/Writer/Word2007/Style/Image.php index cabf37ce3b..3bbe751eba 100644 --- a/src/PhpWord/Writer/Word2007/Style/Image.php +++ b/src/PhpWord/Writer/Word2007/Style/Image.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Indentation.php b/src/PhpWord/Writer/Word2007/Style/Indentation.php index a1b4d8d113..a7edaee188 100644 --- a/src/PhpWord/Writer/Word2007/Style/Indentation.php +++ b/src/PhpWord/Writer/Word2007/Style/Indentation.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Line.php b/src/PhpWord/Writer/Word2007/Style/Line.php index 48e27492ac..3407c2523c 100644 --- a/src/PhpWord/Writer/Word2007/Style/Line.php +++ b/src/PhpWord/Writer/Word2007/Style/Line.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/LineNumbering.php b/src/PhpWord/Writer/Word2007/Style/LineNumbering.php index d06fa2d697..592fb7bb97 100644 --- a/src/PhpWord/Writer/Word2007/Style/LineNumbering.php +++ b/src/PhpWord/Writer/Word2007/Style/LineNumbering.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php index 30029112f8..68ba70d2df 100644 --- a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php +++ b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\Common\XMLWriter; /** * Margin border style writer @@ -72,7 +72,7 @@ public function write() /** * Write side. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param string $side * @param int $width * @param string $color diff --git a/src/PhpWord/Writer/Word2007/Style/Outline.php b/src/PhpWord/Writer/Word2007/Style/Outline.php index 06064d188a..620720b399 100644 --- a/src/PhpWord/Writer/Word2007/Style/Outline.php +++ b/src/PhpWord/Writer/Word2007/Style/Outline.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Paragraph.php b/src/PhpWord/Writer/Word2007/Style/Paragraph.php index 039b78bfad..2cb08bee17 100644 --- a/src/PhpWord/Writer/Word2007/Style/Paragraph.php +++ b/src/PhpWord/Writer/Word2007/Style/Paragraph.php @@ -11,16 +11,16 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; -use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Style\Alignment as AlignmentStyle; -use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; +use PhpOffice\PhpWord\Writer\Word2007\Element\ParagraphAlignment; /** * Paragraph style writer @@ -91,17 +91,23 @@ private function writeStyle() $xmlWriter->writeElementIf($styles['name'] !== null, 'w:pStyle', 'w:val', $styles['name']); } - // Alignment - $styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $styles['alignment']))); - $styleWriter->write(); - // Pagination $xmlWriter->writeElementIf($styles['pagination']['widowControl'] === false, 'w:widowControl', 'w:val', '0'); $xmlWriter->writeElementIf($styles['pagination']['keepNext'] === true, 'w:keepNext', 'w:val', '1'); $xmlWriter->writeElementIf($styles['pagination']['keepLines'] === true, 'w:keepLines', 'w:val', '1'); $xmlWriter->writeElementIf($styles['pagination']['pageBreak'] === true, 'w:pageBreakBefore', 'w:val', '1'); - // Child style: indentation, spacing, and shading + // Paragraph alignment + if ('' !== $styles['alignment']) { + $paragraphAlignment = new ParagraphAlignment($styles['alignment']); + $xmlWriter->startElement($paragraphAlignment->getName()); + foreach ($paragraphAlignment->getAttributes() as $attributeName => $attributeValue) { + $xmlWriter->writeAttribute($attributeName, $attributeValue); + } + $xmlWriter->endElement(); + } + + // Child style: alignment, indentation, spacing, and shading $this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']); $this->writeChildStyle($xmlWriter, 'Spacing', $styles['spacing']); $this->writeChildStyle($xmlWriter, 'Shading', $styles['shading']); @@ -132,7 +138,7 @@ private function writeStyle() /** * Write tabs. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Tab[] $tabs * @return void */ @@ -151,7 +157,7 @@ private function writeTabs(XMLWriter $xmlWriter, $tabs) /** * Write numbering. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param array $numbering * @return void */ diff --git a/src/PhpWord/Writer/Word2007/Style/Row.php b/src/PhpWord/Writer/Word2007/Style/Row.php index 98841dd846..e8b7e1a5b1 100644 --- a/src/PhpWord/Writer/Word2007/Style/Row.php +++ b/src/PhpWord/Writer/Word2007/Style/Row.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Section.php b/src/PhpWord/Writer/Word2007/Style/Section.php index 486d0ed228..60b5d86967 100644 --- a/src/PhpWord/Writer/Word2007/Style/Section.php +++ b/src/PhpWord/Writer/Word2007/Style/Section.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Shading.php b/src/PhpWord/Writer/Word2007/Style/Shading.php index 8ef8c6b184..c3594b24fd 100644 --- a/src/PhpWord/Writer/Word2007/Style/Shading.php +++ b/src/PhpWord/Writer/Word2007/Style/Shading.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Shadow.php b/src/PhpWord/Writer/Word2007/Style/Shadow.php index cc74605994..239c161d5e 100644 --- a/src/PhpWord/Writer/Word2007/Style/Shadow.php +++ b/src/PhpWord/Writer/Word2007/Style/Shadow.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Shape.php b/src/PhpWord/Writer/Word2007/Style/Shape.php index ba8dce5bd1..4ed1469d5d 100644 --- a/src/PhpWord/Writer/Word2007/Style/Shape.php +++ b/src/PhpWord/Writer/Word2007/Style/Shape.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Spacing.php b/src/PhpWord/Writer/Word2007/Style/Spacing.php index 2f7e122a22..bd2d06aa02 100644 --- a/src/PhpWord/Writer/Word2007/Style/Spacing.php +++ b/src/PhpWord/Writer/Word2007/Style/Spacing.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Tab.php b/src/PhpWord/Writer/Word2007/Style/Tab.php index aa00acc788..9867023f6e 100644 --- a/src/PhpWord/Writer/Word2007/Style/Tab.php +++ b/src/PhpWord/Writer/Word2007/Style/Tab.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/Word2007/Style/Table.php b/src/PhpWord/Writer/Word2007/Style/Table.php index 8bbad107c3..570e85bb7b 100644 --- a/src/PhpWord/Writer/Word2007/Style/Table.php +++ b/src/PhpWord/Writer/Word2007/Style/Table.php @@ -11,15 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ namespace PhpOffice\PhpWord\Writer\Word2007\Style; -use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Style\Alignment as AlignmentStyle; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\Style\Table as TableStyle; +use PhpOffice\PhpWord\Writer\Word2007\Element\TableAlignment; /** * Table style writer @@ -50,7 +50,7 @@ public function write() $xmlWriter->startElement('w:tblStyle'); $xmlWriter->writeAttribute('w:val', $style); $xmlWriter->endElement(); - if ($this->width !== null) { + if (null !== $this->width) { $this->writeWidth($xmlWriter, $this->width, 'pct'); } $xmlWriter->endElement(); @@ -60,7 +60,7 @@ public function write() /** * Write full style. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style * @return void */ @@ -69,9 +69,15 @@ private function writeStyle(XMLWriter $xmlWriter, TableStyle $style) // w:tblPr $xmlWriter->startElement('w:tblPr'); - // Alignment - $styleWriter = new Alignment($xmlWriter, new AlignmentStyle(array('value' => $style->getAlign()))); - $styleWriter->write(); + // Table alignment + if ('' !== $style->getAlignment()) { + $tableAlignment = new TableAlignment($style->getAlignment()); + $xmlWriter->startElement($tableAlignment->getName()); + foreach ($tableAlignment->getAttributes() as $attributeName => $attributeValue) { + $xmlWriter->writeAttribute($attributeName, $attributeValue); + } + $xmlWriter->endElement(); + } $this->writeWidth($xmlWriter, $style->getWidth(), $style->getUnit()); $this->writeMargin($xmlWriter, $style); @@ -91,7 +97,7 @@ private function writeStyle(XMLWriter $xmlWriter, TableStyle $style) /** * Write width. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param int $width * @param string $unit * @return void @@ -107,7 +113,7 @@ private function writeWidth(XMLWriter $xmlWriter, $width, $unit) /** * Write margin. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style * @return void */ @@ -127,7 +133,7 @@ private function writeMargin(XMLWriter $xmlWriter, TableStyle $style) /** * Write border. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style * @return void */ @@ -148,7 +154,7 @@ private function writeBorder(XMLWriter $xmlWriter, TableStyle $style) /** * Write row style. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style * @return void */ @@ -168,13 +174,13 @@ private function writeFirstRow(XMLWriter $xmlWriter, TableStyle $style) /** * Write shading. * - * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\Common\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Style\Table $style * @return void */ private function writeShading(XMLWriter $xmlWriter, TableStyle $style) { - if ($style->getShading() !== null) { + if (null !== $style->getShading()) { $xmlWriter->startElement('w:tcPr'); $styleWriter = new Shading($xmlWriter, $style->getShading()); diff --git a/src/PhpWord/Writer/Word2007/Style/TextBox.php b/src/PhpWord/Writer/Word2007/Style/TextBox.php index 20c68c7421..f8f94da37f 100644 --- a/src/PhpWord/Writer/Word2007/Style/TextBox.php +++ b/src/PhpWord/Writer/Word2007/Style/TextBox.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/src/PhpWord/Writer/WriterInterface.php b/src/PhpWord/Writer/WriterInterface.php index eda99f2788..1ccdf3213d 100644 --- a/src/PhpWord/Writer/WriterInterface.php +++ b/src/PhpWord/Writer/WriterInterface.php @@ -11,7 +11,7 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ diff --git a/tests/PhpWord/Tests/Collection/CollectionTest.php b/tests/PhpWord/Collection/CollectionTest.php similarity index 62% rename from tests/PhpWord/Tests/Collection/CollectionTest.php rename to tests/PhpWord/Collection/CollectionTest.php index 833b3e8072..4b2fa0ca71 100644 --- a/tests/PhpWord/Tests/Collection/CollectionTest.php +++ b/tests/PhpWord/Collection/CollectionTest.php @@ -1,19 +1,26 @@ getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); $ival = rand(0, 100); $stub->setElementIndex($ival); - $this->assertEquals($stub->getElementIndex(), $ival); + $this->assertEquals($ival, $stub->getElementIndex()); } /** @@ -40,6 +40,6 @@ public function testElementId() { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); $stub->setElementId(); - $this->assertEquals(strlen($stub->getElementId()), 6); + $this->assertEquals(6, strlen($stub->getElementId())); } } diff --git a/tests/PhpWord/Tests/Element/CellTest.php b/tests/PhpWord/Element/CellTest.php similarity index 87% rename from tests/PhpWord/Tests/Element/CellTest.php rename to tests/PhpWord/Element/CellTest.php index aa07ec0394..f1d6a28040 100644 --- a/tests/PhpWord/Tests/Element/CellTest.php +++ b/tests/PhpWord/Element/CellTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Cell; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Cell @@ -34,7 +32,7 @@ public function testConstruct() $oCell = new Cell(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $oCell); - $this->assertEquals($oCell->getWidth(), null); + $this->assertNull($oCell->getWidth()); } /** @@ -45,7 +43,7 @@ public function testConstructWithStyleArray() $oCell = new Cell(null, array('valign' => 'center')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Cell', $oCell->getStyle()); - $this->assertEquals($oCell->getWidth(), null); + $this->assertNull($oCell->getWidth()); } /** @@ -70,7 +68,7 @@ public function testAddTextNotUTF8() $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('ééé', $element->getText()); } /** @@ -106,7 +104,7 @@ public function testAddListItem() $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); - $this->assertEquals($element->getTextObject()->getText(), 'text'); + $this->assertEquals('text', $element->getTextObject()->getText()); } /** @@ -119,7 +117,7 @@ public function testAddListItemNotUTF8() $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); - $this->assertEquals($element->getTextObject()->getText(), 'ééé'); + $this->assertEquals('ééé', $element->getTextObject()->getText()); } /** @@ -127,7 +125,7 @@ public function testAddListItemNotUTF8() */ public function testAddImageSection() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oCell = new Cell(); $element = $oCell->addImage($src); @@ -140,7 +138,7 @@ public function testAddImageSection() */ public function testAddImageHeader() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oCell = new Cell('header', 1); $element = $oCell->addImage($src); @@ -153,7 +151,7 @@ public function testAddImageHeader() */ public function testAddImageFooter() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oCell = new Cell('footer', 1); $element = $oCell->addImage($src); @@ -167,9 +165,7 @@ public function testAddImageFooter() public function testAddImageSectionByUrl() { $oCell = new Cell(); - $element = $oCell->addImage( - 'http://php.net/images/logos/php-med-trans-light.gif' - ); + $element = $oCell->addImage('http://php.net/images/logos/php-med-trans-light.gif'); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); @@ -180,7 +176,7 @@ public function testAddImageSectionByUrl() */ public function testAddObjectXLS() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oCell = new Cell(); $element = $oCell->addObject($src); @@ -195,7 +191,7 @@ public function testAddObjectXLS() */ public function testAddObjectException() { - $src = __DIR__ . "/../_files/xsl/passthrough.xsl"; + $src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $oCell = new Cell(); $oCell->addObject($src); } @@ -224,7 +220,7 @@ public function testAddPreserveTextNotUTF8() $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals($element->getText(), array('ééé')); + $this->assertEquals(array('ééé'), $element->getText()); } /** diff --git a/tests/PhpWord/Tests/Element/CheckBoxTest.php b/tests/PhpWord/Element/CheckBoxTest.php similarity index 78% rename from tests/PhpWord/Tests/Element/CheckBoxTest.php rename to tests/PhpWord/Element/CheckBoxTest.php index 8f7bf3cd0f..183d22db5c 100644 --- a/tests/PhpWord/Tests/Element/CheckBoxTest.php +++ b/tests/PhpWord/Element/CheckBoxTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\CheckBox; +use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\Style\Font; /** @@ -35,7 +35,7 @@ public function testConstruct() $oCheckBox = new CheckBox(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $oCheckBox); - $this->assertEquals(null, $oCheckBox->getText()); + $this->assertNull($oCheckBox->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle()); } @@ -47,8 +47,8 @@ public function testCheckBox() { $oCheckBox = new CheckBox('chkBox', 'CheckBox'); - $this->assertEquals($oCheckBox->getName(), 'chkBox'); - $this->assertEquals($oCheckBox->getText(), 'CheckBox'); + $this->assertEquals('chkBox', $oCheckBox->getName()); + $this->assertEquals('CheckBox', $oCheckBox->getText()); } /** @@ -57,7 +57,7 @@ public function testCheckBox() public function testFont() { $oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle'); - $this->assertEquals($oCheckBox->getFontStyle(), 'fontStyle'); + $this->assertEquals('fontStyle', $oCheckBox->getFontStyle()); $oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle()); @@ -70,7 +70,7 @@ public function testFontObject() { $font = new Font(); $oCheckBox = new CheckBox('chkBox', 'CheckBox', $font); - $this->assertEquals($oCheckBox->getFontStyle(), $font); + $this->assertEquals($font, $oCheckBox->getFontStyle()); } /** @@ -79,9 +79,9 @@ public function testFontObject() public function testParagraph() { $oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle', 'paragraphStyle'); - $this->assertEquals($oCheckBox->getParagraphStyle(), 'paragraphStyle'); + $this->assertEquals('paragraphStyle', $oCheckBox->getParagraphStyle()); - $oCheckBox->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); + $oCheckBox->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle()); } } diff --git a/tests/PhpWord/Tests/Element/FieldTest.php b/tests/PhpWord/Element/FieldTest.php similarity index 76% rename from tests/PhpWord/Tests/Element/FieldTest.php rename to tests/PhpWord/Element/FieldTest.php index 2f9193d461..b9afad1f89 100644 --- a/tests/PhpWord/Tests/Element/FieldTest.php +++ b/tests/PhpWord/Element/FieldTest.php @@ -11,14 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Field; -use PhpOffice\PhpWord\PhpWord; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Field @@ -45,7 +42,7 @@ public function testConstructWithType() $oField = new Field('DATE'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField); - $this->assertEquals($oField->getType(), 'DATE'); + $this->assertEquals('DATE', $oField->getType()); } /** @@ -53,11 +50,11 @@ public function testConstructWithType() */ public function testConstructWithTypeProperties() { - $oField = new Field('DATE', array('dateformat'=>'d-M-yyyy')); + $oField = new Field('DATE', array('dateformat' => 'd-M-yyyy')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField); - $this->assertEquals($oField->getType(), 'DATE'); - $this->assertEquals($oField->getProperties(), array('dateformat'=>'d-M-yyyy')); + $this->assertEquals('DATE', $oField->getType()); + $this->assertEquals(array('dateformat' => 'd-M-yyyy'), $oField->getProperties()); } /** @@ -65,12 +62,12 @@ public function testConstructWithTypeProperties() */ public function testConstructWithTypePropertiesOptions() { - $oField = new Field('DATE', array('dateformat'=>'d-M-yyyy'), array('SakaEraCalendar', 'PreserveFormat')); + $oField = new Field('DATE', array('dateformat' => 'd-M-yyyy'), array('SakaEraCalendar', 'PreserveFormat')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField); - $this->assertEquals($oField->getType(), 'DATE'); - $this->assertEquals($oField->getProperties(), array('dateformat'=>'d-M-yyyy')); - $this->assertEquals($oField->getOptions(), array('SakaEraCalendar', 'PreserveFormat')); + $this->assertEquals('DATE', $oField->getType()); + $this->assertEquals(array('dateformat' => 'd-M-yyyy'), $oField->getProperties()); + $this->assertEquals(array('SakaEraCalendar', 'PreserveFormat'), $oField->getOptions()); } /** diff --git a/tests/PhpWord/Tests/Element/FooterTest.php b/tests/PhpWord/Element/FooterTest.php similarity index 88% rename from tests/PhpWord/Tests/Element/FooterTest.php rename to tests/PhpWord/Element/FooterTest.php index c5d04b410a..33a211d3a9 100644 --- a/tests/PhpWord/Tests/Element/FooterTest.php +++ b/tests/PhpWord/Element/FooterTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Footer; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Footer @@ -35,7 +33,7 @@ public function testConstruct() $oFooter = new Footer($iVal); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter); - $this->assertEquals($oFooter->getSectionId(), $iVal); + $this->assertEquals($iVal, $oFooter->getSectionId()); } /** @@ -60,7 +58,7 @@ public function testAddTextNotUTF8() $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('ééé', $element->getText()); } /** @@ -104,7 +102,7 @@ public function testAddTable() */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oFooter = new Footer(1); $element = $oFooter->addImage($src); @@ -118,9 +116,7 @@ public function testAddImage() public function testAddImageByUrl() { $oFooter = new Footer(1); - $element = $oFooter->addImage( - 'http://php.net/images/logos/php-med-trans-light.gif' - ); + $element = $oFooter->addImage('http://php.net/images/logos/php-med-trans-light.gif'); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); @@ -148,7 +144,7 @@ public function testAddPreserveTextNotUTF8() $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals($element->getText(), array('ééé')); + $this->assertEquals(array('ééé'), $element->getText()); } /** @@ -171,7 +167,7 @@ public function testRelationID() $iVal = rand(1, 1000); $oFooter->setRelationId($iVal); - $this->assertEquals($oFooter->getRelationId(), $iVal); + $this->assertEquals($iVal, $oFooter->getRelationId()); $this->assertEquals(Footer::AUTO, $oFooter->getType()); } } diff --git a/tests/PhpWord/Tests/Element/FootnoteTest.php b/tests/PhpWord/Element/FootnoteTest.php similarity index 87% rename from tests/PhpWord/Tests/Element/FootnoteTest.php rename to tests/PhpWord/Element/FootnoteTest.php index 2ba015d741..a3f3b4d8d3 100644 --- a/tests/PhpWord/Tests/Element/FootnoteTest.php +++ b/tests/PhpWord/Element/FootnoteTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Footnote; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Footnote @@ -35,7 +33,7 @@ public function testConstruct() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $oFootnote); $this->assertCount(0, $oFootnote->getElements()); - $this->assertEquals($oFootnote->getParagraphStyle(), null); + $this->assertNull($oFootnote->getParagraphStyle()); } /** @@ -45,7 +43,7 @@ public function testConstructString() { $oFootnote = new Footnote('pStyle'); - $this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle'); + $this->assertEquals('pStyle', $oFootnote->getParagraphStyle()); } /** @@ -90,7 +88,7 @@ public function testAddTextBreak() public function testAddLink() { $oFootnote = new Footnote(); - $element = $oFootnote->addLink('http://www.google.fr'); + $element = $oFootnote->addLink('https://github.com/PHPOffice/PHPWord'); $this->assertCount(1, $oFootnote->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); @@ -105,7 +103,7 @@ public function testReferenceId() $iVal = rand(1, 1000); $oFootnote->setRelationId($iVal); - $this->assertEquals($oFootnote->getRelationId(), $iVal); + $this->assertEquals($iVal, $oFootnote->getRelationId()); } /** diff --git a/tests/PhpWord/Tests/Element/HeaderTest.php b/tests/PhpWord/Element/HeaderTest.php similarity index 86% rename from tests/PhpWord/Tests/Element/HeaderTest.php rename to tests/PhpWord/Element/HeaderTest.php index 796b24f012..f75910aa98 100644 --- a/tests/PhpWord/Tests/Element/HeaderTest.php +++ b/tests/PhpWord/Element/HeaderTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Header; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Header @@ -35,8 +33,8 @@ public function testConstructDefault() $oHeader = new Header($iVal); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Header', $oHeader); - $this->assertEquals($oHeader->getSectionId(), $iVal); - $this->assertEquals($oHeader->getType(), Header::AUTO); + $this->assertEquals($iVal, $oHeader->getSectionId()); + $this->assertEquals(Header::AUTO, $oHeader->getType()); } /** @@ -49,7 +47,7 @@ public function testAddText() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oHeader->getElements()); - $this->assertEquals($element->getText(), 'text'); + $this->assertEquals('text', $element->getText()); } /** @@ -62,7 +60,7 @@ public function testAddTextNotUTF8() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oHeader->getElements()); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('ééé', $element->getText()); } /** @@ -113,7 +111,7 @@ public function testAddTable() */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oHeader = new Header(1); $element = $oHeader->addImage($src); @@ -127,9 +125,7 @@ public function testAddImage() public function testAddImageByUrl() { $oHeader = new Header(1); - $element = $oHeader->addImage( - 'http://php.net/images/logos/php-med-trans-light.gif' - ); + $element = $oHeader->addImage('http://php.net/images/logos/php-med-trans-light.gif'); $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); @@ -157,7 +153,7 @@ public function testAddPreserveTextNotUTF8() $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals($element->getText(), array('ééé')); + $this->assertEquals(array('ééé'), $element->getText()); } /** @@ -165,7 +161,7 @@ public function testAddPreserveTextNotUTF8() */ public function testAddWatermark() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oHeader = new Header(1); $element = $oHeader->addWatermark($src); @@ -192,7 +188,7 @@ public function testRelationId() $iVal = rand(1, 1000); $oHeader->setRelationId($iVal); - $this->assertEquals($oHeader->getRelationId(), $iVal); + $this->assertEquals($iVal, $oHeader->getRelationId()); } /** @@ -204,7 +200,7 @@ public function testResetType() $oHeader->firstPage(); $oHeader->resetType(); - $this->assertEquals($oHeader->getType(), Header::AUTO); + $this->assertEquals(Header::AUTO, $oHeader->getType()); } /** @@ -215,7 +211,7 @@ public function testFirstPage() $oHeader = new Header(1); $oHeader->firstPage(); - $this->assertEquals($oHeader->getType(), Header::FIRST); + $this->assertEquals(Header::FIRST, $oHeader->getType()); } /** @@ -226,7 +222,7 @@ public function testEvenPage() $oHeader = new Header(1); $oHeader->evenPage(); - $this->assertEquals($oHeader->getType(), Header::EVEN); + $this->assertEquals(Header::EVEN, $oHeader->getType()); } /** diff --git a/tests/PhpWord/Tests/Element/ImageTest.php b/tests/PhpWord/Element/ImageTest.php similarity index 68% rename from tests/PhpWord/Tests/Element/ImageTest.php rename to tests/PhpWord/Element/ImageTest.php index 11b33d8785..c463b0c4d4 100644 --- a/tests/PhpWord/Tests/Element/ImageTest.php +++ b/tests/PhpWord/Element/ImageTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\Image; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Element\Image @@ -31,14 +31,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $src = __DIR__ . "/../_files/images/firefox.png"; + $src = __DIR__ . '/../_files/images/firefox.png'; $oImage = new Image($src); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage); - $this->assertEquals($oImage->getSource(), $src); - $this->assertEquals($oImage->getMediaId(), md5($src)); - $this->assertEquals($oImage->isWatermark(), false); - $this->assertEquals($oImage->getSourceType(), Image::SOURCE_LOCAL); + $this->assertEquals($src, $oImage->getSource()); + $this->assertEquals(md5($src), $oImage->getMediaId()); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x + $this->assertEquals(false, $oImage->isWatermark()); + $this->assertEquals(Image::SOURCE_LOCAL, $oImage->getSourceType()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); } @@ -47,11 +48,15 @@ public function testConstruct() */ public function testConstructWithStyle() { - $src = __DIR__ . "/../_files/images/firefox.png"; + $src = __DIR__ . '/../_files/images/firefox.png'; $oImage = new Image( $src, - array('width' => 210, 'height' => 210, 'align' => 'center', - 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND) + array( + 'width' => 210, + 'height' => 210, + 'alignment' => Jc::CENTER, + 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND, + ) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); @@ -72,15 +77,15 @@ public function testImages() foreach ($images as $imageData) { list($source, $type, $extension, $createFunction, $imageFunction) = $imageData; - $source = __DIR__ . "/../_files/images/" . $source; + $source = __DIR__ . "/../_files/images/{$source}"; $image = new Image($source); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image); - $this->assertEquals($image->getSource(), $source); - $this->assertEquals($image->getMediaId(), md5($source)); - $this->assertEquals($image->getImageType(), $type); - $this->assertEquals($image->getImageExtension(), $extension); - $this->assertEquals($image->getImageCreateFunction(), $createFunction); - $this->assertEquals($image->getImageFunction(), $imageFunction); + $this->assertEquals($source, $image->getSource()); + $this->assertEquals(md5($source), $image->getMediaId()); + $this->assertEquals($type, $image->getImageType()); + $this->assertEquals($extension, $image->getImageExtension()); + $this->assertEquals($createFunction, $image->getImageCreateFunction()); + $this->assertEquals($imageFunction, $image->getImageFunction()); $this->assertFalse($image->isMemImage()); } } @@ -91,8 +96,8 @@ public function testImages() public function testStyle() { $oImage = new Image( - __DIR__ . "/../_files/images/earth.jpg", - array('height' => 210, 'align' => 'center') + __DIR__ . '/../_files/images/earth.jpg', + array('height' => 210, 'alignment' => Jc::CENTER) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); @@ -105,7 +110,7 @@ public function testStyle() */ public function testInvalidImageLocal() { - new Image(__DIR__ . "/../_files/images/thisisnotarealimage"); + new Image(__DIR__ . '/../_files/images/thisisnotarealimage'); } /** @@ -135,10 +140,10 @@ public function testUnsupportedImage() */ public function testRelationID() { - $oImage = new Image(__DIR__ . "/../_files/images/earth.jpg", array('width' => 100)); + $oImage = new Image(__DIR__ . '/../_files/images/earth.jpg', array('width' => 100)); $iVal = rand(1, 1000); $oImage->setRelationId($iVal); - $this->assertEquals($oImage->getRelationId(), $iVal); + $this->assertEquals($iVal, $oImage->getRelationId()); } /** @@ -146,7 +151,7 @@ public function testRelationID() */ public function testArchivedImage() { - $archiveFile = __DIR__ . "/../_files/documents/reader.docx"; + $archiveFile = __DIR__ . '/../_files/documents/reader.docx'; $imageFile = 'word/media/image1.jpeg'; $image = new Image("zip://{$archiveFile}#{$imageFile}"); $this->assertEquals('image/jpeg', $image->getImageType()); diff --git a/tests/PhpWord/Tests/Element/LineTest.php b/tests/PhpWord/Element/LineTest.php similarity index 56% rename from tests/PhpWord/Tests/Element/LineTest.php rename to tests/PhpWord/Element/LineTest.php index 5add9a6b07..a7b15b0863 100644 --- a/tests/PhpWord/Tests/Element/LineTest.php +++ b/tests/PhpWord/Element/LineTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Line; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Line @@ -35,7 +33,7 @@ public function testConstruct() $oLine = new Line(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Line', $oLine); - $this->assertEquals($oLine->getStyle(), null); + $this->assertNull($oLine->getStyle()); } /** @@ -45,7 +43,7 @@ public function testStyleText() { $oLine = new Line('lineStyle'); - $this->assertEquals($oLine->getStyle(), 'lineStyle'); + $this->assertEquals('lineStyle', $oLine->getStyle()); } /** @@ -55,19 +53,19 @@ public function testStyleArray() { $oLine = new Line( array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(14), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), - 'positioning' => 'absolute', + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(14), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), + 'positioning' => 'absolute', 'posHorizontalRel' => 'page', - 'posVerticalRel' => 'page', - 'flip' => true, - 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5), - 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), - 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, - 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, - 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, - 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, - 'weight' => 10 + 'posVerticalRel' => 'page', + 'flip' => true, + 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5), + 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), + 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, + 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, + 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, + 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, + 'weight' => 10, ) ); diff --git a/tests/PhpWord/Tests/Element/LinkTest.php b/tests/PhpWord/Element/LinkTest.php similarity index 65% rename from tests/PhpWord/Tests/Element/LinkTest.php rename to tests/PhpWord/Element/LinkTest.php index ada6a36a9f..40f07a1f1e 100644 --- a/tests/PhpWord/Tests/Element/LinkTest.php +++ b/tests/PhpWord/Element/LinkTest.php @@ -11,13 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\Link; use PhpOffice\PhpWord\Style\Font; /** @@ -33,13 +32,13 @@ class LinkTest extends \PHPUnit_Framework_TestCase */ public function testConstructDefault() { - $oLink = new Link('http://www.google.com'); + $oLink = new Link('https://github.com/PHPOffice/PHPWord'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink); - $this->assertEquals($oLink->getSource(), 'http://www.google.com'); - $this->assertEquals($oLink->getText(), $oLink->getSource()); - $this->assertEquals($oLink->getFontStyle(), null); - $this->assertEquals($oLink->getParagraphStyle(), null); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource()); + $this->assertEquals($oLink->getSource(), $oLink->getText()); + $this->assertNull($oLink->getFontStyle()); + $this->assertNull($oLink->getParagraphStyle()); } /** @@ -48,15 +47,15 @@ public function testConstructDefault() public function testConstructWithParamsArray() { $oLink = new Link( - 'http://www.google.com', - 'Search Engine', + 'https://github.com/PHPOffice/PHPWord', + 'PHPWord on GitHub', array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink); - $this->assertEquals($oLink->getSource(), 'http://www.google.com'); - $this->assertEquals($oLink->getText(), 'Search Engine'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource()); + $this->assertEquals('PHPWord on GitHub', $oLink->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle()); } @@ -66,10 +65,10 @@ public function testConstructWithParamsArray() */ public function testConstructWithParamsString() { - $oLink = new Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle'); + $oLink = new Link('https://github.com/PHPOffice/PHPWord', null, 'fontStyle', 'paragraphStyle'); - $this->assertEquals($oLink->getFontStyle(), 'fontStyle'); - $this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle'); + $this->assertEquals('fontStyle', $oLink->getFontStyle()); + $this->assertEquals('paragraphStyle', $oLink->getParagraphStyle()); } /** @@ -77,10 +76,10 @@ public function testConstructWithParamsString() */ public function testRelationId() { - $oLink = new Link('http://www.google.com'); + $oLink = new Link('https://github.com/PHPOffice/PHPWord'); $iVal = rand(1, 1000); $oLink->setRelationId($iVal); - $this->assertEquals($oLink->getRelationId(), $iVal); + $this->assertEquals($iVal, $oLink->getRelationId()); } } diff --git a/tests/PhpWord/Tests/Element/ListItemRunTest.php b/tests/PhpWord/Element/ListItemRunTest.php similarity index 80% rename from tests/PhpWord/Tests/Element/ListItemRunTest.php rename to tests/PhpWord/Element/ListItemRunTest.php index 7bb0c25d71..91609357f9 100644 --- a/tests/PhpWord/Tests/Element/ListItemRunTest.php +++ b/tests/PhpWord/Element/ListItemRunTest.php @@ -11,14 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\ListItemRun; -use PhpOffice\PhpWord\PhpWord; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\ListItemRun @@ -36,7 +33,7 @@ public function testConstructNull() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun); $this->assertCount(0, $oListItemRun->getElements()); - $this->assertEquals($oListItemRun->getParagraphStyle(), null); + $this->assertNull($oListItemRun->getParagraphStyle()); } /** @@ -48,7 +45,7 @@ public function testConstructString() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun); $this->assertCount(0, $oListItemRun->getElements()); - $this->assertEquals($oListItemRun->getParagraphStyle(), 'pStyle'); + $this->assertEquals('pStyle', $oListItemRun->getParagraphStyle()); } /** @@ -82,8 +79,9 @@ public function testStyle() $oListItemRun = new ListItemRun(1, array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItemRun->getStyle()); - $this->assertEquals($oListItemRun->getStyle()->getListType(), \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER); + $this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItemRun->getStyle()->getListType()); } + /** * getDepth */ @@ -92,7 +90,7 @@ public function testDepth() $iVal = rand(1, 1000); $oListItemRun = new ListItemRun($iVal); - $this->assertEquals($oListItemRun->getDepth(), $iVal); + $this->assertEquals($iVal, $oListItemRun->getDepth()); } /** @@ -105,7 +103,7 @@ public function testAddText() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getText(), 'text'); + $this->assertEquals('text', $element->getText()); } /** @@ -118,7 +116,7 @@ public function testAddTextNotUTF8() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('ééé', $element->getText()); } /** @@ -127,11 +125,11 @@ public function testAddTextNotUTF8() public function testAddLink() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addLink('http://www.google.fr'); + $element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); } /** @@ -140,12 +138,12 @@ public function testAddLink() public function testAddLinkWithName() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addLink('http://www.google.fr', utf8_decode('ééé')); + $element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); + $this->assertEquals('PHPWord on GitHub', $element->getText()); } /** @@ -164,7 +162,7 @@ public function testAddTextBreak() */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oListItemRun = new ListItemRun(); $element = $oListItemRun->addImage($src); diff --git a/tests/PhpWord/Tests/Element/ListItemTest.php b/tests/PhpWord/Element/ListItemTest.php similarity index 72% rename from tests/PhpWord/Tests/Element/ListItemTest.php rename to tests/PhpWord/Element/ListItemTest.php index 1362eb4392..2dc4f65ccb 100644 --- a/tests/PhpWord/Tests/Element/ListItemTest.php +++ b/tests/PhpWord/Element/ListItemTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\ListItem; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\ListItem @@ -42,18 +40,10 @@ public function testText() */ public function testStyle() { - $oListItem = new ListItem( - 'text', - 1, - null, - array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER) - ); + $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 - ); + $this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItem->getStyle()->getListType()); } /** @@ -64,6 +54,6 @@ public function testDepth() $iVal = rand(1, 1000); $oListItem = new ListItem('text', $iVal); - $this->assertEquals($oListItem->getDepth(), $iVal); + $this->assertEquals($iVal, $oListItem->getDepth()); } } diff --git a/tests/PhpWord/Tests/Element/ObjectTest.php b/tests/PhpWord/Element/ObjectTest.php similarity index 76% rename from tests/PhpWord/Tests/Element/ObjectTest.php rename to tests/PhpWord/Element/ObjectTest.php index 6b82313453..44516b617e 100644 --- a/tests/PhpWord/Tests/Element/ObjectTest.php +++ b/tests/PhpWord/Element/ObjectTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Object; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Object @@ -32,12 +30,12 @@ class ObjectTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithSupportedFiles() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); - $this->assertEquals($oObject->getSource(), $src); + $this->assertEquals($src, $oObject->getSource()); } /** @@ -47,7 +45,7 @@ public function testConstructWithSupportedFiles() */ public function testConstructWithNotSupportedFiles() { - $src = __DIR__ . "/../_files/xsl/passthrough.xsl"; + $src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $oObject = new Object($src); $oObject->getSource(); } @@ -57,12 +55,12 @@ public function testConstructWithNotSupportedFiles() */ public function testConstructWithSupportedFilesAndStyle() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src, array('width' => '230px')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); - $this->assertEquals($oObject->getSource(), $src); + $this->assertEquals($src, $oObject->getSource()); } /** @@ -70,12 +68,12 @@ public function testConstructWithSupportedFilesAndStyle() */ public function testRelationId() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setRelationId($iVal); - $this->assertEquals($oObject->getRelationId(), $iVal); + $this->assertEquals($iVal, $oObject->getRelationId()); } /** @@ -83,11 +81,11 @@ public function testRelationId() */ public function testImageRelationId() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setImageRelationId($iVal); - $this->assertEquals($oObject->getImageRelationId(), $iVal); + $this->assertEquals($iVal, $oObject->getImageRelationId()); } } diff --git a/tests/PhpWord/Tests/Element/PageBreakTest.php b/tests/PhpWord/Element/PageBreakTest.php similarity index 89% rename from tests/PhpWord/Tests/Element/PageBreakTest.php rename to tests/PhpWord/Element/PageBreakTest.php index 6b038a8257..3d8b1db616 100644 --- a/tests/PhpWord/Tests/Element/PageBreakTest.php +++ b/tests/PhpWord/Element/PageBreakTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\PageBreak; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\PageBreak diff --git a/tests/PhpWord/Tests/Element/PreserveTextTest.php b/tests/PhpWord/Element/PreserveTextTest.php similarity index 62% rename from tests/PhpWord/Tests/Element/PreserveTextTest.php rename to tests/PhpWord/Element/PreserveTextTest.php index 36841ca8e6..33e2272a2b 100644 --- a/tests/PhpWord/Tests/Element/PreserveTextTest.php +++ b/tests/PhpWord/Element/PreserveTextTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\PreserveText; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Element\PreserveText @@ -34,9 +34,9 @@ public function testConstruct() $oPreserveText = new PreserveText(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $oPreserveText); - $this->assertEquals($oPreserveText->getText(), null); - $this->assertEquals($oPreserveText->getFontStyle(), null); - $this->assertEquals($oPreserveText->getParagraphStyle(), null); + $this->assertNull($oPreserveText->getText()); + $this->assertNull($oPreserveText->getFontStyle()); + $this->assertNull($oPreserveText->getParagraphStyle()); } /** @@ -45,9 +45,9 @@ public function testConstruct() public function testConstructWithString() { $oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph'); - $this->assertEquals($oPreserveText->getText(), array('text')); - $this->assertEquals($oPreserveText->getFontStyle(), 'styleFont'); - $this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); + $this->assertEquals(array('text'), $oPreserveText->getText()); + $this->assertEquals('styleFont', $oPreserveText->getFontStyle()); + $this->assertEquals('styleParagraph', $oPreserveText->getParagraphStyle()); } /** @@ -55,15 +55,8 @@ public function testConstructWithString() */ public function testConstructWithArray() { - $oPreserveText = new PreserveText( - 'text', - array('size' => 16, 'color' => '1B2232'), - array('align' => 'center') - ); + $oPreserveText = new PreserveText('text', array('size' => 16, 'color' => '1B2232'), array('alignment' => Jc::CENTER)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle()); - $this->assertInstanceOf( - 'PhpOffice\\PhpWord\\Style\\Paragraph', - $oPreserveText->getParagraphStyle() - ); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oPreserveText->getParagraphStyle()); } } diff --git a/tests/PhpWord/Tests/Element/RowTest.php b/tests/PhpWord/Element/RowTest.php similarity index 88% rename from tests/PhpWord/Tests/Element/RowTest.php rename to tests/PhpWord/Element/RowTest.php index c377bb7cd2..58a166f493 100644 --- a/tests/PhpWord/Tests/Element/RowTest.php +++ b/tests/PhpWord/Element/RowTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Row; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Row @@ -35,7 +33,7 @@ public function testConstruct() $oRow = new Row(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow); - $this->assertEquals($oRow->getHeight(), null); + $this->assertNull($oRow->getHeight()); $this->assertInternalType('array', $oRow->getCells()); $this->assertCount(0, $oRow->getCells()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); @@ -49,7 +47,7 @@ public function testConstructWithParams() $iVal = rand(1, 1000); $oRow = new Row($iVal, array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF')); - $this->assertEquals($oRow->getHeight(), $iVal); + $this->assertEquals($iVal, $oRow->getHeight()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); } diff --git a/tests/PhpWord/Tests/Element/SDTTest.php b/tests/PhpWord/Element/SDTTest.php similarity index 93% rename from tests/PhpWord/Tests/Element/SDTTest.php rename to tests/PhpWord/Element/SDTTest.php index 8c7b4bf328..52705bc124 100644 --- a/tests/PhpWord/Tests/Element/SDTTest.php +++ b/tests/PhpWord/Element/SDTTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\SDT; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\SDT diff --git a/tests/PhpWord/Tests/Element/SectionTest.php b/tests/PhpWord/Element/SectionTest.php similarity index 62% rename from tests/PhpWord/Tests/Element/SectionTest.php rename to tests/PhpWord/Element/SectionTest.php index 853ebc5d3f..78010bc9ed 100644 --- a/tests/PhpWord/Tests/Element/SectionTest.php +++ b/tests/PhpWord/Element/SectionTest.php @@ -11,63 +11,24 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\Header; -use PhpOffice\PhpWord\Element\Section; -use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Style; /** - * Test class for PhpOffice\PhpWord\Element\Section - * + * @covers \PhpOffice\PhpWord\Element\Section + * @coversDefaultClass \PhpOffice\PhpWord\Element\Section * @runTestsInSeparateProcesses */ class SectionTest extends \PHPUnit_Framework_TestCase { /** - * Get style - */ - public function testGetStyle() - { - $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getStyle(), 'style', new Section(0)); - } - - /** - * Get elements - */ - public function testGetElements() - { - $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getElements(), 'elements', new Section(0)); - } - - /** - * Get footer - */ - public function testGetFooters() - { - $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getFooters(), 'footers', new Section(0)); - } - - /** - * Get headers - */ - public function testGetHeaders() - { - $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getHeaders(), 'headers', new Section(0)); - } - - /** - * Set settings + * @covers ::setStyle */ public function testSetStyle() { @@ -78,13 +39,12 @@ public function testSetStyle() } /** - * Add elements + * @coversNothing */ public function testAddElements() { - $objectSource = __DIR__ . "/../_files/documents/reader.docx"; - $imageSource = __DIR__ . "/../_files/images/PhpWord.png"; - // $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; + $objectSource = __DIR__ . '/../_files/documents/reader.docx'; + $imageSource = __DIR__ . '/../_files/images/PhpWord.png'; $section = new Section(0); $section->setPhpWord(new PhpWord()); @@ -103,9 +63,21 @@ public function testAddElements() $section->addTOC(); $elementCollection = $section->getElements(); - $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', - 'Table', 'ListItem', 'Object', 'Image', - 'Title', 'TextRun', 'Footnote', 'CheckBox', 'TOC'); + $elementTypes = array( + 'Text', + 'Link', + 'TextBreak', + 'PageBreak', + 'Table', + 'ListItem', + 'Object', + 'Image', + 'Title', + 'TextRun', + 'Footnote', + 'CheckBox', + 'TOC', + ); $elmCount = 0; foreach ($elementTypes as $elementType) { $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$elmCount]); @@ -114,19 +86,20 @@ public function testAddElements() } /** - * Test add object exception - * + * @coversNothing * @expectedException \PhpOffice\PhpWord\Exception\InvalidObjectException */ public function testAddObjectException() { - $source = __DIR__ . "/_files/xsl/passthrough.xsl"; + $source = __DIR__ . '/_files/xsl/passthrough.xsl'; $section = new Section(0); $section->addObject($source); } /** * Add title with predefined style + * + * @coversNothing */ public function testAddTitleWithStyle() { @@ -136,26 +109,29 @@ public function testAddTitleWithStyle() $section->addTitle('Test', 1); $elementCollection = $section->getElements(); - $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\Title", $elementCollection[0]); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $elementCollection[0]); } /** - * Create header footer + * @covers ::addHeader + * @covers ::addFooter + * @covers ::hasDifferentFirstPage */ - public function testCreateHeaderFooter() + public function testAddHeaderFooter() { $object = new Section(0); $elements = array('Header', 'Footer'); foreach ($elements as $element) { - $method = "create{$element}"; + $method = "add{$element}"; $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$element}", $object->$method()); } $this->assertFalse($object->hasDifferentFirstPage()); } /** - * Add header has different first page + * @covers ::addHeader + * @covers ::hasDifferentFirstPage */ public function testHasDifferentFirstPage() { @@ -166,10 +142,9 @@ public function testHasDifferentFirstPage() } /** - * Add header exception - * - * @expectedException Exception - * @expectedExceptionMesssage Invalid header/footer type. + * @covers ::addHeader + * @expectedException \Exception + * @expectedExceptionMessage Invalid header/footer type. */ public function testAddHeaderException() { diff --git a/tests/PhpWord/Tests/Element/TOCTest.php b/tests/PhpWord/Element/TOCTest.php similarity index 90% rename from tests/PhpWord/Tests/Element/TOCTest.php rename to tests/PhpWord/Element/TOCTest.php index d0ebf343fe..6b5867bc12 100644 --- a/tests/PhpWord/Tests/Element/TOCTest.php +++ b/tests/PhpWord/Element/TOCTest.php @@ -11,14 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\Title; -use PhpOffice\PhpWord\Element\TOC; use PhpOffice\PhpWord\PhpWord; /** @@ -34,9 +32,9 @@ class TOCTest extends \PHPUnit_Framework_TestCase public function testConstructWithStyleArray() { $expected = array( - 'position' => 9062, - 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT, - 'indent' => 200, + 'position' => 9062, + 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT, + 'indent' => 200, ); $object = new TOC(array('size' => 11), array('position' => $expected['position'])); $tocStyle = $object->getStyleTOC(); diff --git a/tests/PhpWord/Tests/Element/TableTest.php b/tests/PhpWord/Element/TableTest.php similarity index 79% rename from tests/PhpWord/Tests/Element/TableTest.php rename to tests/PhpWord/Element/TableTest.php index 0977639f32..785ec40aa3 100644 --- a/tests/PhpWord/Tests/Element/TableTest.php +++ b/tests/PhpWord/Element/TableTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Table; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Table @@ -35,9 +33,9 @@ public function testConstruct() $oTable = new Table(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $oTable); - $this->assertEquals($oTable->getStyle(), null); - $this->assertEquals($oTable->getWidth(), null); - $this->assertEquals($oTable->getRows(), array()); + $this->assertNull($oTable->getStyle()); + $this->assertNull($oTable->getWidth()); + $this->assertEquals(array(), $oTable->getRows()); $this->assertCount(0, $oTable->getRows()); } @@ -48,7 +46,7 @@ public function testStyleText() { $oTable = new Table('tableStyle'); - $this->assertEquals($oTable->getStyle(), 'tableStyle'); + $this->assertEquals('tableStyle', $oTable->getStyle()); } /** @@ -56,11 +54,7 @@ public function testStyleText() */ public function testStyleArray() { - $oTable = new Table(array( - 'borderSize' => 6, - 'borderColor' => '006699', - 'cellMargin' => 80 - )); + $oTable = new Table(array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle()); } @@ -71,9 +65,9 @@ public function testStyleArray() public function testWidth() { $oTable = new Table(); - $iVal = rand(1, 1000); + $iVal = rand(1, 1000); $oTable->setWidth($iVal); - $this->assertEquals($oTable->getWidth(), $iVal); + $this->assertEquals($iVal, $oTable->getWidth()); } /** @@ -81,7 +75,7 @@ public function testWidth() */ public function testRow() { - $oTable = new Table(); + $oTable = new Table(); $element = $oTable->addRow(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element); $this->assertCount(1, $oTable->getRows()); diff --git a/tests/PhpWord/Tests/Element/TextBoxTest.php b/tests/PhpWord/Element/TextBoxTest.php similarity index 68% rename from tests/PhpWord/Tests/Element/TextBoxTest.php rename to tests/PhpWord/Element/TextBoxTest.php index 2c6da4655d..cb3fdb99df 100644 --- a/tests/PhpWord/Tests/Element/TextBoxTest.php +++ b/tests/PhpWord/Element/TextBoxTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\TextBox; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\TextBox @@ -35,7 +33,7 @@ public function testConstruct() $oTextBox = new TextBox(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextBox', $oTextBox); - $this->assertEquals($oTextBox->getStyle(), null); + $this->assertNull($oTextBox->getStyle()); } /** @@ -45,7 +43,7 @@ public function testStyleText() { $oTextBox = new TextBox('textBoxStyle'); - $this->assertEquals($oTextBox->getStyle(), 'textBoxStyle'); + $this->assertEquals('textBoxStyle', $oTextBox->getStyle()); } /** @@ -55,15 +53,15 @@ public function testStyleArray() { $oTextBox = new TextBox( array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.5), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(17.5), + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.5), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(17.5), 'positioning' => 'absolute', - 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.4), - 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.9), - 'stroke' => 0, + 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.4), + 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.9), + 'stroke' => 0, 'innerMargin' => 0, - 'borderSize' => 1, - 'borderColor' => '' + 'borderSize' => 1, + 'borderColor' => '', ) ); diff --git a/tests/PhpWord/Tests/Element/TextBreakTest.php b/tests/PhpWord/Element/TextBreakTest.php similarity index 94% rename from tests/PhpWord/Tests/Element/TextBreakTest.php rename to tests/PhpWord/Element/TextBreakTest.php index 1d9479ee3e..40ed696550 100644 --- a/tests/PhpWord/Tests/Element/TextBreakTest.php +++ b/tests/PhpWord/Element/TextBreakTest.php @@ -11,13 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\TextBreak; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; diff --git a/tests/PhpWord/Tests/Element/TextRunTest.php b/tests/PhpWord/Element/TextRunTest.php similarity index 82% rename from tests/PhpWord/Tests/Element/TextRunTest.php rename to tests/PhpWord/Element/TextRunTest.php index de62a920da..efd8d6f3f7 100644 --- a/tests/PhpWord/Tests/Element/TextRunTest.php +++ b/tests/PhpWord/Element/TextRunTest.php @@ -11,13 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\PhpWord; /** @@ -36,7 +35,7 @@ public function testConstructNull() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun); $this->assertCount(0, $oTextRun->getElements()); - $this->assertEquals($oTextRun->getParagraphStyle(), null); + $this->assertNull($oTextRun->getParagraphStyle()); } /** @@ -48,7 +47,7 @@ public function testConstructString() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun); $this->assertCount(0, $oTextRun->getElements()); - $this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle'); + $this->assertEquals('pStyle', $oTextRun->getParagraphStyle()); } /** @@ -73,7 +72,7 @@ public function testAddText() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getText(), 'text'); + $this->assertEquals('text', $element->getText()); } /** @@ -86,7 +85,7 @@ public function testAddTextNotUTF8() $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('ééé', $element->getText()); } /** @@ -95,11 +94,11 @@ public function testAddTextNotUTF8() public function testAddLink() { $oTextRun = new TextRun(); - $element = $oTextRun->addLink('http://www.google.fr'); + $element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); } /** @@ -108,12 +107,12 @@ public function testAddLink() public function testAddLinkWithName() { $oTextRun = new TextRun(); - $element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé')); + $element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); + $this->assertEquals('PHPWord on GitHub', $element->getText()); } /** @@ -132,7 +131,7 @@ public function testAddTextBreak() */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oTextRun = new TextRun(); $element = $oTextRun->addImage($src); diff --git a/tests/PhpWord/Tests/Element/TextTest.php b/tests/PhpWord/Element/TextTest.php similarity index 79% rename from tests/PhpWord/Tests/Element/TextTest.php rename to tests/PhpWord/Element/TextTest.php index a306d4b938..d2fe0472b5 100644 --- a/tests/PhpWord/Tests/Element/TextTest.php +++ b/tests/PhpWord/Element/TextTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; +namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Element\Text; +use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\Style\Font; /** @@ -35,7 +35,7 @@ public function testConstruct() $oText = new Text(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oText); - $this->assertEquals(null, $oText->getText()); + $this->assertNull($oText->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); } @@ -47,7 +47,7 @@ public function testText() { $oText = new Text('text'); - $this->assertEquals($oText->getText(), 'text'); + $this->assertEquals('text', $oText->getText()); } /** @@ -56,7 +56,7 @@ public function testText() public function testFont() { $oText = new Text('text', 'fontStyle'); - $this->assertEquals($oText->getFontStyle(), 'fontStyle'); + $this->assertEquals('fontStyle', $oText->getFontStyle()); $oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle()); @@ -69,7 +69,7 @@ public function testFontObject() { $font = new Font(); $oText = new Text('text', $font); - $this->assertEquals($oText->getFontStyle(), $font); + $this->assertEquals($font, $oText->getFontStyle()); } /** @@ -78,9 +78,9 @@ public function testFontObject() public function testParagraph() { $oText = new Text('text', 'fontStyle', 'paragraphStyle'); - $this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle'); + $this->assertEquals('paragraphStyle', $oText->getParagraphStyle()); - $oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); + $oText->setParagraphStyle(array('alignment' => Jc::CENTER, 'spaceAfter' => 100)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); } } diff --git a/tests/PhpWord/Tests/Element/TitleTest.php b/tests/PhpWord/Element/TitleTest.php similarity index 82% rename from tests/PhpWord/Tests/Element/TitleTest.php rename to tests/PhpWord/Element/TitleTest.php index ca65c8eb94..2b886e5e9a 100644 --- a/tests/PhpWord/Tests/Element/TitleTest.php +++ b/tests/PhpWord/Element/TitleTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Element; - -use PhpOffice\PhpWord\Element\Title; +namespace PhpOffice\PhpWord\Element; /** * Test class for PhpOffice\PhpWord\Element\Title @@ -35,7 +33,7 @@ public function testConstruct() $oTitle = new Title('text'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $oTitle); - $this->assertEquals($oTitle->getText(), 'text'); + $this->assertEquals('text', $oTitle->getText()); } /** @@ -45,6 +43,6 @@ public function testStyleNull() { $oTitle = new Title('text'); - $this->assertEquals($oTitle->getStyle(), null); + $this->assertNull($oTitle->getStyle()); } } diff --git a/tests/PhpWord/Tests/Exception/CopyFileExceptionTest.php b/tests/PhpWord/Exception/CopyFileExceptionTest.php similarity index 89% rename from tests/PhpWord/Tests/Exception/CopyFileExceptionTest.php rename to tests/PhpWord/Exception/CopyFileExceptionTest.php index 3d92595f25..0bc2e32241 100644 --- a/tests/PhpWord/Tests/Exception/CopyFileExceptionTest.php +++ b/tests/PhpWord/Exception/CopyFileExceptionTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Exception; - -use PhpOffice\PhpWord\Exception\CopyFileException; +namespace PhpOffice\PhpWord\Exception; /** * @covers \PhpOffice\PhpWord\Exception\CopyFileException diff --git a/tests/PhpWord/Tests/Exception/CreateTemporaryFileExceptionTest.php b/tests/PhpWord/Exception/CreateTemporaryFileExceptionTest.php similarity index 88% rename from tests/PhpWord/Tests/Exception/CreateTemporaryFileExceptionTest.php rename to tests/PhpWord/Exception/CreateTemporaryFileExceptionTest.php index 7cf0cb773d..d68bf573fe 100644 --- a/tests/PhpWord/Tests/Exception/CreateTemporaryFileExceptionTest.php +++ b/tests/PhpWord/Exception/CreateTemporaryFileExceptionTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Exception; - -use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; +namespace PhpOffice\PhpWord\Exception; /** * @covers \PhpOffice\PhpWord\Exception\CreateTemporaryFileException diff --git a/tests/PhpWord/Tests/Exception/ExceptionTest.php b/tests/PhpWord/Exception/ExceptionTest.php similarity index 89% rename from tests/PhpWord/Tests/Exception/ExceptionTest.php rename to tests/PhpWord/Exception/ExceptionTest.php index 38d0f7f2c7..4c14abb9ed 100644 --- a/tests/PhpWord/Tests/Exception/ExceptionTest.php +++ b/tests/PhpWord/Exception/ExceptionTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Exception; - -use PhpOffice\PhpWord\Exception\Exception; +namespace PhpOffice\PhpWord\Exception; /** * Test class for PhpOffice\PhpWord\Exception\Exception diff --git a/tests/PhpWord/Tests/Exception/InvalidImageExceptionTest.php b/tests/PhpWord/Exception/InvalidImageExceptionTest.php similarity index 88% rename from tests/PhpWord/Tests/Exception/InvalidImageExceptionTest.php rename to tests/PhpWord/Exception/InvalidImageExceptionTest.php index 7c6303e306..d83aa878d4 100644 --- a/tests/PhpWord/Tests/Exception/InvalidImageExceptionTest.php +++ b/tests/PhpWord/Exception/InvalidImageExceptionTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Exception; - -use PhpOffice\PhpWord\Exception\InvalidImageException; +namespace PhpOffice\PhpWord\Exception; /** * Test class for PhpOffice\PhpWord\Exception\InvalidImageException diff --git a/tests/PhpWord/Tests/Exception/InvalidStyleExceptionTest.php b/tests/PhpWord/Exception/InvalidStyleExceptionTest.php similarity index 88% rename from tests/PhpWord/Tests/Exception/InvalidStyleExceptionTest.php rename to tests/PhpWord/Exception/InvalidStyleExceptionTest.php index 3cff7376ff..5038ed2f0d 100644 --- a/tests/PhpWord/Tests/Exception/InvalidStyleExceptionTest.php +++ b/tests/PhpWord/Exception/InvalidStyleExceptionTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Exception; - -use PhpOffice\PhpWord\Exception\InvalidStyleException; +namespace PhpOffice\PhpWord\Exception; /** * Test class for PhpOffice\PhpWord\Exception\InvalidStyleException diff --git a/tests/PhpWord/Tests/Exception/UnsupportedImageTypeExceptionTest.php b/tests/PhpWord/Exception/UnsupportedImageTypeExceptionTest.php similarity index 88% rename from tests/PhpWord/Tests/Exception/UnsupportedImageTypeExceptionTest.php rename to tests/PhpWord/Exception/UnsupportedImageTypeExceptionTest.php index 0a1020eb4e..251ed957bf 100644 --- a/tests/PhpWord/Tests/Exception/UnsupportedImageTypeExceptionTest.php +++ b/tests/PhpWord/Exception/UnsupportedImageTypeExceptionTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Exception; - -use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException; +namespace PhpOffice\PhpWord\Exception; /** * Test class for PhpOffice\PhpWord\Exception\UnsupportedImageTypeExceptionTest diff --git a/tests/PhpWord/Tests/IOFactoryTest.php b/tests/PhpWord/IOFactoryTest.php similarity index 90% rename from tests/PhpWord/Tests/IOFactoryTest.php rename to tests/PhpWord/IOFactoryTest.php index 60db16d050..9c2d1e676f 100644 --- a/tests/PhpWord/Tests/IOFactoryTest.php +++ b/tests/PhpWord/IOFactoryTest.php @@ -11,14 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; - -use PhpOffice\PhpWord\IOFactory; -use PhpOffice\PhpWord\PhpWord; +namespace PhpOffice\PhpWord; /** * Test class for PhpOffice\PhpWord\IOFactory @@ -74,7 +71,7 @@ public function testNonexistentReaderCanNotBeCreated() */ public function testLoad() { - $file = __DIR__ . "/_files/templates/blank.docx"; + $file = __DIR__ . '/_files/templates/blank.docx'; $this->assertInstanceOf( 'PhpOffice\\PhpWord\\PhpWord', IOFactory::load($file) diff --git a/tests/PhpWord/Tests/MediaTest.php b/tests/PhpWord/MediaTest.php similarity index 87% rename from tests/PhpWord/Tests/MediaTest.php rename to tests/PhpWord/MediaTest.php index 0196a7e1a2..25480313b7 100644 --- a/tests/PhpWord/Tests/MediaTest.php +++ b/tests/PhpWord/MediaTest.php @@ -11,14 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; +namespace PhpOffice\PhpWord; use PhpOffice\PhpWord\Element\Image; -use PhpOffice\PhpWord\Media; /** * Test class for PhpOffice\PhpWord\Media @@ -32,7 +31,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase */ public function testGetSectionMediaElementsWithNull() { - $this->assertEquals(Media::getElements('section'), array()); + $this->assertEquals(array(), Media::getElements('section')); } /** @@ -48,8 +47,8 @@ public function testCountSectionMediaElementsWithNull() */ public function testAddSectionMediaElement() { - $local = __DIR__ . "/_files/images/mars.jpg"; - $object = __DIR__ . "/_files/documents/sheet.xls"; + $local = __DIR__ . '/_files/images/mars.jpg'; + $object = __DIR__ . '/_files/documents/sheet.xls'; $remote = 'http://php.net/images/logos/php-med-trans-light.gif'; Media::addElement('section', 'image', $local, new Image($local)); Media::addElement('section', 'image', $local, new Image($local)); @@ -77,7 +76,7 @@ public function testAddSectionLinkElement() */ public function testAddHeaderMediaElement() { - $local = __DIR__ . "/_files/images/mars.jpg"; + $local = __DIR__ . '/_files/images/mars.jpg'; $remote = 'http://php.net/images/logos/php-med-trans-light.gif'; Media::addElement('header1', 'image', $local, new Image($local)); Media::addElement('header1', 'image', $local, new Image($local)); @@ -92,7 +91,7 @@ public function testAddHeaderMediaElement() */ public function testAddFooterMediaElement() { - $local = __DIR__ . "/_files/images/mars.jpg"; + $local = __DIR__ . '/_files/images/mars.jpg'; $remote = 'http://php.net/images/logos/php-med-trans-light.gif'; Media::addElement('footer1', 'image', $local, new Image($local)); Media::addElement('footer1', 'image', $local, new Image($local)); @@ -112,6 +111,6 @@ public function testAddFooterMediaElement() */ public function testAddElementImageException() { - Media::addElement('section', 'image', __DIR__ . "/_files/images/mars.jpg"); + Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg'); } } diff --git a/tests/PhpWord/Tests/Metadata/DocInfoTest.php b/tests/PhpWord/Metadata/DocInfoTest.php similarity index 69% rename from tests/PhpWord/Tests/Metadata/DocInfoTest.php rename to tests/PhpWord/Metadata/DocInfoTest.php index c860a0d9a9..235727106e 100644 --- a/tests/PhpWord/Tests/Metadata/DocInfoTest.php +++ b/tests/PhpWord/Metadata/DocInfoTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Metadata; - -use PhpOffice\PhpWord\Metadata\DocInfo; +namespace PhpOffice\PhpWord\Metadata; /** * Test class for PhpOffice\PhpWord\Metadata\DocInfo @@ -182,42 +180,22 @@ public function testCustomProperty() $oProperties->setCustomProperty('key3', 3); $oProperties->setCustomProperty('key4', 4.4); $oProperties->setCustomProperty('key5', 'value5'); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_STRING, - $oProperties->getCustomPropertyType('key1') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_BOOLEAN, - $oProperties->getCustomPropertyType('key2') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_INTEGER, - $oProperties->getCustomPropertyType('key3') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_FLOAT, - $oProperties->getCustomPropertyType('key4') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_STRING, - $oProperties->getCustomPropertyType('key5') - ); - $this->assertEquals(null, $oProperties->getCustomPropertyType('key6')); - $this->assertEquals(null, $oProperties->getCustomPropertyValue('key1')); - $this->assertEquals(true, $oProperties->getCustomPropertyValue('key2')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key1')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, $oProperties->getCustomPropertyType('key2')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, $oProperties->getCustomPropertyType('key3')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, $oProperties->getCustomPropertyType('key4')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key5')); + $this->assertNull($oProperties->getCustomPropertyType('key6')); + $this->assertNull($oProperties->getCustomPropertyValue('key1')); + $this->assertTrue($oProperties->getCustomPropertyValue('key2')); $this->assertEquals(3, $oProperties->getCustomPropertyValue('key3')); $this->assertEquals(4.4, $oProperties->getCustomPropertyValue('key4')); $this->assertEquals('value5', $oProperties->getCustomPropertyValue('key5')); - $this->assertEquals(null, $oProperties->getCustomPropertyValue('key6')); - $this->assertEquals(true, $oProperties->isCustomPropertySet('key5')); + $this->assertNull($oProperties->getCustomPropertyValue('key6')); + $this->assertTrue($oProperties->isCustomPropertySet('key5')); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x $this->assertEquals(false, $oProperties->isCustomPropertySet('key6')); - $this->assertEquals(array( - 'key1', - 'key2', - 'key3', - 'key4', - 'key5' - ), $oProperties->getCustomProperties()); + $this->assertEquals(array('key1', 'key2', 'key3', 'key4', 'key5'), $oProperties->getCustomProperties()); } /** @@ -226,49 +204,25 @@ public function testCustomProperty() public function testConvertProperty() { $this->assertEquals('', DocInfo::convertProperty('a', 'empty')); - $this->assertEquals(null, DocInfo::convertProperty('a', 'null')); + $this->assertNull(DocInfo::convertProperty('a', 'null')); $this->assertEquals(8, DocInfo::convertProperty('8', 'int')); $this->assertEquals(8, DocInfo::convertProperty('8.3', 'uint')); $this->assertEquals(8.3, DocInfo::convertProperty('8.3', 'decimal')); $this->assertEquals('8.3', DocInfo::convertProperty('8.3', 'lpstr')); $this->assertEquals(strtotime('10/11/2013'), DocInfo::convertProperty('10/11/2013', 'date')); - $this->assertEquals(true, DocInfo::convertProperty('true', 'bool')); + $this->assertTrue(DocInfo::convertProperty('true', 'bool')); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x $this->assertEquals(false, DocInfo::convertProperty('1', 'bool')); $this->assertEquals('1', DocInfo::convertProperty('1', 'array')); $this->assertEquals('1', DocInfo::convertProperty('1', '')); - - $this->assertEquals( - DocInfo::PROPERTY_TYPE_INTEGER, - DocInfo::convertPropertyType('int') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_INTEGER, - DocInfo::convertPropertyType('uint') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_FLOAT, - DocInfo::convertPropertyType('decimal') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_STRING, - DocInfo::convertPropertyType('lpstr') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_DATE, - DocInfo::convertPropertyType('date') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_BOOLEAN, - DocInfo::convertPropertyType('bool') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_UNKNOWN, - DocInfo::convertPropertyType('array') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_UNKNOWN, - DocInfo::convertPropertyType('') - ); + $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('int')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('uint')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, DocInfo::convertPropertyType('decimal')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, DocInfo::convertPropertyType('lpstr')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_DATE, DocInfo::convertPropertyType('date')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, DocInfo::convertPropertyType('bool')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType('array')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType('')); } } diff --git a/tests/PhpWord/Tests/PhpWordTest.php b/tests/PhpWord/PhpWordTest.php similarity index 95% rename from tests/PhpWord/Tests/PhpWordTest.php rename to tests/PhpWord/PhpWordTest.php index 85c6a7f291..459c67a0aa 100644 --- a/tests/PhpWord/Tests/PhpWordTest.php +++ b/tests/PhpWord/PhpWordTest.php @@ -11,16 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; +namespace PhpOffice\PhpWord; use PhpOffice\PhpWord\Metadata\DocInfo; -use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\PhpWord @@ -124,7 +121,7 @@ public function testAddTitleStyle() */ public function testLoadTemplate() { - $templateFqfn = __DIR__ . "/_files/templates/blank.docx"; + $templateFqfn = __DIR__ . '/_files/templates/blank.docx'; $phpWord = new PhpWord(); $this->assertInstanceOf( diff --git a/tests/PhpWord/Tests/Reader/HTMLTest.php b/tests/PhpWord/Reader/HTMLTest.php similarity index 94% rename from tests/PhpWord/Tests/Reader/HTMLTest.php rename to tests/PhpWord/Reader/HTMLTest.php index cb3dc55c29..6e3039cf18 100644 --- a/tests/PhpWord/Tests/Reader/HTMLTest.php +++ b/tests/PhpWord/Reader/HTMLTest.php @@ -11,11 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Reader; +namespace PhpOffice\PhpWord\Reader; use PhpOffice\PhpWord\IOFactory; diff --git a/tests/PhpWord/Tests/Reader/ODTextTest.php b/tests/PhpWord/Reader/ODTextTest.php similarity index 92% rename from tests/PhpWord/Tests/Reader/ODTextTest.php rename to tests/PhpWord/Reader/ODTextTest.php index fc4d2e337e..1bdce2e635 100644 --- a/tests/PhpWord/Tests/Reader/ODTextTest.php +++ b/tests/PhpWord/Reader/ODTextTest.php @@ -11,11 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Reader; +namespace PhpOffice\PhpWord\Reader; use PhpOffice\PhpWord\IOFactory; diff --git a/tests/PhpWord/Tests/Reader/RTFTest.php b/tests/PhpWord/Reader/RTFTest.php similarity index 94% rename from tests/PhpWord/Tests/Reader/RTFTest.php rename to tests/PhpWord/Reader/RTFTest.php index c495db6884..79cf13a716 100644 --- a/tests/PhpWord/Tests/Reader/RTFTest.php +++ b/tests/PhpWord/Reader/RTFTest.php @@ -11,11 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Reader; +namespace PhpOffice\PhpWord\Reader; use PhpOffice\PhpWord\IOFactory; diff --git a/tests/PhpWord/Tests/Reader/Word2007Test.php b/tests/PhpWord/Reader/Word2007Test.php similarity index 92% rename from tests/PhpWord/Tests/Reader/Word2007Test.php rename to tests/PhpWord/Reader/Word2007Test.php index f2257012a5..9be78a5b72 100644 --- a/tests/PhpWord/Tests/Reader/Word2007Test.php +++ b/tests/PhpWord/Reader/Word2007Test.php @@ -11,14 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Reader; +namespace PhpOffice\PhpWord\Reader; use PhpOffice\PhpWord\IOFactory; -use PhpOffice\PhpWord\Reader\Word2007; /** * Test class for PhpOffice\PhpWord\Reader\Word2007 diff --git a/tests/PhpWord/Tests/SettingsTest.php b/tests/PhpWord/SettingsTest.php similarity index 89% rename from tests/PhpWord/Tests/SettingsTest.php rename to tests/PhpWord/SettingsTest.php index 0d3d66aecc..f5ac3ed6a0 100644 --- a/tests/PhpWord/Tests/SettingsTest.php +++ b/tests/PhpWord/SettingsTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; - -use PhpOffice\PhpWord\Settings; +namespace PhpOffice\PhpWord; /** * Test class for PhpOffice\PhpWord\Settings @@ -122,21 +120,22 @@ public function testSetGetDefaultFontSize() public function testLoadConfig() { $expected = array( - 'compatibility' => true, - 'zipClass' => 'ZipArchive', - 'pdfRendererName' => 'DomPDF', - 'pdfRendererPath' => '', - 'defaultFontName' => 'Arial', - 'defaultFontSize' => 10, + 'compatibility' => true, + 'zipClass' => 'ZipArchive', + 'pdfRendererName' => 'DomPDF', + 'pdfRendererPath' => '', + 'defaultFontName' => 'Arial', + 'defaultFontSize' => 10, + 'outputEscapingEnabled' => false, ); // Test default value $this->assertEquals($expected, Settings::loadConfig()); // Test with valid file - $this->assertEquals($expected, Settings::loadConfig(__DIR__ . '/../../../phpword.ini.dist')); + $this->assertEquals($expected, Settings::loadConfig(__DIR__ . '/../../phpword.ini.dist')); // Test with invalid file - $this->assertEmpty(Settings::loadConfig(__DIR__ . '/../../../phpunit.xml.dist')); + $this->assertEmpty(Settings::loadConfig(__DIR__ . '/../../phpunit.xml.dist')); } } diff --git a/tests/PhpWord/Tests/Shared/ConverterTest.php b/tests/PhpWord/Shared/ConverterTest.php similarity index 96% rename from tests/PhpWord/Tests/Shared/ConverterTest.php rename to tests/PhpWord/Shared/ConverterTest.php index 002e2e33bf..e307f09b1e 100644 --- a/tests/PhpWord/Tests/Shared/ConverterTest.php +++ b/tests/PhpWord/Shared/ConverterTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Shared; - -use PhpOffice\PhpWord\Shared\Converter; +namespace PhpOffice\PhpWord\Shared; /** * Test class for PhpOffice\PhpWord\Shared\Converter diff --git a/tests/PhpWord/Tests/Shared/HtmlTest.php b/tests/PhpWord/Shared/HtmlTest.php similarity index 90% rename from tests/PhpWord/Tests/Shared/HtmlTest.php rename to tests/PhpWord/Shared/HtmlTest.php index c4c0fc9d5a..c651fd4a53 100644 --- a/tests/PhpWord/Tests/Shared/HtmlTest.php +++ b/tests/PhpWord/Shared/HtmlTest.php @@ -11,14 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Shared; +namespace PhpOffice\PhpWord\Shared; use PhpOffice\PhpWord\Element\Section; -use PhpOffice\PhpWord\Shared\Html; /** * Test class for PhpOffice\PhpWord\Shared\Html @@ -43,8 +42,8 @@ public function testAddHtml() } // Styles - $content .= '

'; + $content .= '

'; foreach ($styles as $style) { $content .= "<{$style}>{$style}"; } diff --git a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php b/tests/PhpWord/Shared/ZipArchiveTest.php similarity index 84% rename from tests/PhpWord/Tests/Shared/ZipArchiveTest.php rename to tests/PhpWord/Shared/ZipArchiveTest.php index 11a0d9a33c..1adcfbfc5d 100644 --- a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php +++ b/tests/PhpWord/Shared/ZipArchiveTest.php @@ -11,14 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Shared; +namespace PhpOffice\PhpWord\Shared; use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Shared\ZipArchive; /** * Test class for PhpOffice\PhpWord\Shared\ZipArchive @@ -67,10 +66,10 @@ public function testCloseException() public function testZipArchive($zipClass = 'ZipArchive') { // Preparation - $existingFile = __DIR__ . "/../_files/documents/sheet.xls"; - $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; - $destination1 = __DIR__ . "/../_files/documents/extract1"; - $destination2 = __DIR__ . "/../_files/documents/extract2"; + $existingFile = __DIR__ . '/../_files/documents/sheet.xls'; + $zipFile = __DIR__ . '/../_files/documents/ziptest.zip'; + $destination1 = __DIR__ . '/../_files/documents/extract1'; + $destination2 = __DIR__ . '/../_files/documents/extract2'; @mkdir($destination1); @mkdir($destination2); @@ -122,12 +121,12 @@ public function testPCLZip() private function deleteDir($dir) { foreach (scandir($dir) as $file) { - if ($file === '.' || $file === '..') { + if ('.' === $file || '..' === $file) { continue; - } elseif (is_file($dir . "/" . $file)) { - unlink($dir . "/" . $file); - } elseif (is_dir($dir . "/" . $file)) { - $this->deleteDir($dir . "/" . $file); + } elseif (is_file($dir . '/' . $file)) { + unlink($dir . '/' . $file); + } elseif (is_dir($dir . '/' . $file)) { + $this->deleteDir($dir . '/' . $file); } } diff --git a/tests/PhpWord/Tests/Style/AbstractStyleTest.php b/tests/PhpWord/Style/AbstractStyleTest.php similarity index 92% rename from tests/PhpWord/Tests/Style/AbstractStyleTest.php rename to tests/PhpWord/Style/AbstractStyleTest.php index d35e109076..f7c6f6c516 100644 --- a/tests/PhpWord/Tests/Style/AbstractStyleTest.php +++ b/tests/PhpWord/Style/AbstractStyleTest.php @@ -11,11 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\AbstractStyle @@ -42,7 +42,7 @@ public function testSetValNormal() { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); - $this->assertEquals(true, self::callProtectedMethod($stub, 'setBoolVal', array(true, false))); + $this->assertTrue(self::callProtectedMethod($stub, 'setBoolVal', array(true, false))); $this->assertEquals(12, self::callProtectedMethod($stub, 'setIntVal', array(12, 200))); $this->assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', array(871.1, 2.1))); $this->assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', array('871.1', 2.1))); @@ -56,6 +56,7 @@ public function testSetValDefault() { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x $this->assertEquals(false, self::callProtectedMethod($stub, 'setBoolVal', array('a', false))); $this->assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', array('foo', 200))); $this->assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', array('foo', 2.1))); diff --git a/tests/PhpWord/Tests/Style/CellTest.php b/tests/PhpWord/Style/CellTest.php similarity index 76% rename from tests/PhpWord/Tests/Style/CellTest.php rename to tests/PhpWord/Style/CellTest.php index f913172806..51f4e8952c 100644 --- a/tests/PhpWord/Tests/Style/CellTest.php +++ b/tests/PhpWord/Style/CellTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Cell; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Cell @@ -35,19 +33,19 @@ public function testSetGetNormal() $object = new Cell(); $attributes = array( - 'valign' => Cell::VALIGN_TOP, - 'textDirection' => Cell::TEXT_DIR_BTLR, - 'bgColor' => 'FFFF00', - 'borderTopSize' => 120, - 'borderTopColor' => 'FFFF00', - 'borderLeftSize' => 120, - 'borderLeftColor' => 'FFFF00', - 'borderRightSize' => 120, - 'borderRightColor' => 'FFFF00', - 'borderBottomSize' => 120, + 'valign' => Cell::VALIGN_TOP, + 'textDirection' => Cell::TEXT_DIR_BTLR, + 'bgColor' => 'FFFF00', + 'borderTopSize' => 120, + 'borderTopColor' => 'FFFF00', + 'borderLeftSize' => 120, + 'borderLeftColor' => 'FFFF00', + 'borderRightSize' => 120, + 'borderRightColor' => 'FFFF00', + 'borderBottomSize' => 120, 'borderBottomColor' => 'FFFF00', - 'gridSpan' => 2, - 'vMerge' => Cell::VMERGE_RESTART, + 'gridSpan' => 2, + 'vMerge' => Cell::VMERGE_RESTART, ); foreach ($attributes as $key => $value) { $set = "set{$key}"; diff --git a/tests/PhpWord/Tests/Style/FontTest.php b/tests/PhpWord/Style/FontTest.php similarity index 64% rename from tests/PhpWord/Tests/Style/FontTest.php rename to tests/PhpWord/Style/FontTest.php index c21ea4ce3e..61648d4ebf 100644 --- a/tests/PhpWord/Tests/Style/FontTest.php +++ b/tests/PhpWord/Style/FontTest.php @@ -11,16 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; +namespace PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Style\Font; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; +use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Style\Font @@ -42,7 +41,7 @@ public function tearDown() */ public function testInitiation() { - $object = new Font('text', array('align' => 'both')); + $object = new Font('text', array('alignment' => Jc::BOTH)); $this->assertEquals('text', $object->getStyleType()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); @@ -57,31 +56,31 @@ public function testSetStyleValueWithNullOrEmpty() $object = new Font(); $attributes = array( - 'name' => null, - 'size' => null, - 'hint' => null, - 'color' => null, - 'bold' => false, - 'italic' => false, - 'underline' => Font::UNDERLINE_NONE, - 'superScript' => false, - 'subScript' => false, - 'strikethrough' => false, + 'name' => null, + 'size' => null, + 'hint' => null, + 'color' => null, + 'bold' => false, + 'italic' => false, + 'underline' => Font::UNDERLINE_NONE, + 'superScript' => false, + 'subScript' => false, + 'strikethrough' => false, 'doubleStrikethrough' => false, - 'smallCaps' => false, - 'allCaps' => false, - 'fgColor' => null, - 'bgColor' => null, - 'scale' => null, - 'spacing' => null, - 'kerning' => null, + 'smallCaps' => false, + 'allCaps' => false, + 'fgColor' => null, + 'bgColor' => null, + 'scale' => null, + 'spacing' => null, + 'kerning' => null, ); foreach ($attributes as $key => $default) { $get = is_bool($default) ? "is{$key}" : "get{$key}"; $this->assertEquals($default, $object->$get()); - $object->setStyleValue("$key", null); + $object->setStyleValue($key, null); $this->assertEquals($default, $object->$get()); - $object->setStyleValue("$key", ''); + $object->setStyleValue($key, ''); $this->assertEquals($default, $object->$get()); } } @@ -94,25 +93,25 @@ public function testSetStyleValueNormal() $object = new Font(); $attributes = array( - 'name' => 'Times New Roman', - 'size' => 9, - 'color' => '999999', - 'hint' => 'eastAsia', - 'bold' => true, - 'italic' => true, - 'underline' => Font::UNDERLINE_HEAVY, - 'superScript' => true, - 'subScript' => false, - 'strikethrough' => true, + 'name' => 'Times New Roman', + 'size' => 9, + 'color' => '999999', + 'hint' => 'eastAsia', + 'bold' => true, + 'italic' => true, + 'underline' => Font::UNDERLINE_HEAVY, + 'superScript' => true, + 'subScript' => false, + 'strikethrough' => true, 'doubleStrikethrough' => false, - 'smallCaps' => true, - 'allCaps' => false, - 'fgColor' => Font::FGCOLOR_YELLOW, - 'bgColor' => 'FFFF00', - 'lineHeight' => 2, - 'scale' => 150, - 'spacing' => 240, - 'kerning' => 10, + 'smallCaps' => true, + 'allCaps' => false, + 'fgColor' => Font::FGCOLOR_YELLOW, + 'bgColor' => 'FFFF00', + 'lineHeight' => 2, + 'scale' => 150, + 'spacing' => 240, + 'kerning' => 10, ); $object->setStyleByArray($attributes); foreach ($attributes as $key => $value) { @@ -130,9 +129,7 @@ public function testLineHeight() $section = $phpWord->addSection(); // Test style array - $text = $section->addText('This is a test', array( - 'line-height' => 2.0 - )); + $text = $section->addText('This is a test', array('line-height' => 2.0)); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); @@ -160,7 +157,7 @@ public function testLineHeight() */ public function testLineHeightFloatval() { - $object = new Font(null, array('align' => 'center')); + $object = new Font(null, array('alignment' => Jc::CENTER)); $object->setLineHeight('1.5pt'); $this->assertEquals(1.5, $object->getLineHeight()); } diff --git a/tests/PhpWord/Tests/Style/ImageTest.php b/tests/PhpWord/Style/ImageTest.php similarity index 68% rename from tests/PhpWord/Tests/Style/ImageTest.php rename to tests/PhpWord/Style/ImageTest.php index 1a679da3a2..c5bb5c7dc1 100644 --- a/tests/PhpWord/Tests/Style/ImageTest.php +++ b/tests/PhpWord/Style/ImageTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; +namespace PhpOffice\PhpWord\Style; -use PhpOffice\PhpWord\Style\Image; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Style\Image @@ -35,12 +35,12 @@ public function testSetGetNormal() $object = new Image(); $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline' + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', ); foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -58,16 +58,16 @@ public function testSetStyleValue() $object = new Image(); $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, - 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, - 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, + 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, + 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, 'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN, - 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_IMARGIN + 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_IMARGIN, ); foreach ($properties as $key => $value) { $get = "get{$key}"; diff --git a/tests/PhpWord/Tests/Style/IndentationTest.php b/tests/PhpWord/Style/IndentationTest.php similarity index 85% rename from tests/PhpWord/Tests/Style/IndentationTest.php rename to tests/PhpWord/Style/IndentationTest.php index d0e88f2cb2..477e131408 100644 --- a/tests/PhpWord/Tests/Style/IndentationTest.php +++ b/tests/PhpWord/Style/IndentationTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Indentation; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Indentation @@ -33,10 +31,10 @@ public function testGetSetProperties() { $object = new Indentation(); $properties = array( - 'left' => array(0, 10), - 'right' => array(0, 10), + 'left' => array(0, 10), + 'right' => array(0, 10), 'firstLine' => array(null, 20), - 'hanging' => array(null, 20), + 'hanging' => array(null, 20), ); foreach ($properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/LineNumberingTest.php b/tests/PhpWord/Style/LineNumberingTest.php similarity index 84% rename from tests/PhpWord/Tests/Style/LineNumberingTest.php rename to tests/PhpWord/Style/LineNumberingTest.php index bc4dc603f3..e8ef1367ea 100644 --- a/tests/PhpWord/Tests/Style/LineNumberingTest.php +++ b/tests/PhpWord/Style/LineNumberingTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\LineNumbering; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\LineNumbering @@ -33,10 +31,10 @@ public function testGetSetProperties() { $object = new LineNumbering(); $properties = array( - 'start' => array(1, 2), + 'start' => array(1, 2), 'increment' => array(1, 10), - 'distance' => array(null, 10), - 'restart' => array(null, 'continuous'), + 'distance' => array(null, 10), + 'restart' => array(null, 'continuous'), ); foreach ($properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/LineTest.php b/tests/PhpWord/Style/LineTest.php similarity index 75% rename from tests/PhpWord/Tests/Style/LineTest.php rename to tests/PhpWord/Style/LineTest.php index 02d5ba16a2..98e20b3de6 100644 --- a/tests/PhpWord/Tests/Style/LineTest.php +++ b/tests/PhpWord/Style/LineTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Line; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Image @@ -36,11 +34,11 @@ public function testSetGetNormal() $properties = array( 'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT, - 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, - 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, - 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, - 'weight' => 10, - 'color' => 'red' + 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, + 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, + 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, + 'weight' => 10, + 'color' => 'red', ); foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -59,11 +57,11 @@ public function testSetStyleValue() $properties = array( 'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT, - 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, - 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, - 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, - 'weight' => 10, - 'color' => 'red' + 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, + 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, + 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, + 'weight' => 10, + 'color' => 'red', ); foreach ($properties as $key => $value) { $get = "get{$key}"; @@ -71,13 +69,13 @@ public function testSetStyleValue() $this->assertEquals($value, $object->$get()); } } - + /** * Test set/get flip */ public function testSetGetFlip() { - $expected=true; + $expected = true; $object = new Line(); $object->setFlip($expected); $this->assertEquals($expected, $object->isFlip()); @@ -88,18 +86,18 @@ public function testSetGetFlip() */ public function testSetGetConnectorType() { - $expected=\PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT; + $expected = \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT; $object = new Line(); $object->setConnectorType($expected); $this->assertEquals($expected, $object->getConnectorType()); } - + /** * Test set/get weight */ public function testSetGetWeight() { - $expected=10; + $expected = 10; $object = new Line(); $object->setWeight($expected); $this->assertEquals($expected, $object->getWeight()); @@ -110,7 +108,7 @@ public function testSetGetWeight() */ public function testSetGetColor() { - $expected='red'; + $expected = 'red'; $object = new Line(); $object->setColor($expected); $this->assertEquals($expected, $object->getColor()); @@ -121,7 +119,7 @@ public function testSetGetColor() */ public function testSetGetDash() { - $expected=\PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT; + $expected = \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT; $object = new Line(); $object->setDash($expected); $this->assertEquals($expected, $object->getDash()); @@ -132,7 +130,7 @@ public function testSetGetDash() */ public function testSetGetBeginArrow() { - $expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK; + $expected = \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK; $object = new Line(); $object->setBeginArrow($expected); $this->assertEquals($expected, $object->getBeginArrow()); @@ -143,7 +141,7 @@ public function testSetGetBeginArrow() */ public function testSetGetEndArrow() { - $expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_CLASSIC; + $expected = \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_CLASSIC; $object = new Line(); $object->setEndArrow($expected); $this->assertEquals($expected, $object->getEndArrow()); diff --git a/tests/PhpWord/Tests/Style/ListItemTest.php b/tests/PhpWord/Style/ListItemTest.php similarity index 93% rename from tests/PhpWord/Tests/Style/ListItemTest.php rename to tests/PhpWord/Style/ListItemTest.php index a97c8dd604..2e8692e999 100644 --- a/tests/PhpWord/Tests/Style/ListItemTest.php +++ b/tests/PhpWord/Style/ListItemTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\ListItem; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\ListItem diff --git a/tests/PhpWord/Tests/Style/NumberingLevelTest.php b/tests/PhpWord/Style/NumberingLevelTest.php similarity index 68% rename from tests/PhpWord/Tests/Style/NumberingLevelTest.php rename to tests/PhpWord/Style/NumberingLevelTest.php index 8959a98317..c6cee11c53 100644 --- a/tests/PhpWord/Tests/Style/NumberingLevelTest.php +++ b/tests/PhpWord/Style/NumberingLevelTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; +namespace PhpOffice\PhpWord\Style; -use PhpOffice\PhpWord\Style\NumberingLevel; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Style\NumberingLevel @@ -34,19 +34,19 @@ public function testSetGetNormal() $object = new NumberingLevel(); $attributes = array( - 'level' => 1, - 'start' => 1, - 'format' => 'decimal', - 'restart' => 1, - 'pStyle' => 'pStyle', - 'suffix' => 'space', - 'text' => '%1.', - 'align' => 'left', - 'left' => 360, - 'hanging' => 360, - 'tabPos' => 360, - 'font' => 'Arial', - 'hint' => 'default', + 'level' => 1, + 'start' => 1, + 'format' => 'decimal', + 'restart' => 1, + 'pStyle' => 'pStyle', + 'suffix' => 'space', + 'text' => '%1.', + 'alignment' => Jc::START, + 'left' => 360, + 'hanging' => 360, + 'tabPos' => 360, + 'font' => 'Arial', + 'hint' => 'default', ); foreach ($attributes as $key => $value) { $set = "set{$key}"; diff --git a/tests/PhpWord/Tests/Style/NumberingTest.php b/tests/PhpWord/Style/NumberingTest.php similarity index 87% rename from tests/PhpWord/Tests/Style/NumberingTest.php rename to tests/PhpWord/Style/NumberingTest.php index e15753576b..ee9c032cb1 100644 --- a/tests/PhpWord/Tests/Style/NumberingTest.php +++ b/tests/PhpWord/Style/NumberingTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Numbering; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Numbering @@ -33,8 +31,8 @@ public function testGetSetProperties() { $this->object = new Numbering(); $this->properties = array( - 'numId' => array(null, 1), - 'type' => array(null, 'singleLevel'), + 'numId' => array(null, 1), + 'type' => array(null, 'singleLevel'), ); foreach ($this->properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/ParagraphTest.php b/tests/PhpWord/Style/ParagraphTest.php similarity index 78% rename from tests/PhpWord/Tests/Style/ParagraphTest.php rename to tests/PhpWord/Style/ParagraphTest.php index 73540b0c7b..c0096b0b1c 100644 --- a/tests/PhpWord/Tests/Style/ParagraphTest.php +++ b/tests/PhpWord/Style/ParagraphTest.php @@ -11,16 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; +namespace PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Style\Paragraph; -use PhpOffice\PhpWord\Style\Tab; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Style\Paragraph @@ -45,16 +43,16 @@ public function testSetStyleValueWithNullOrEmpty() $object = new Paragraph(); $attributes = array( - 'widowControl' => true, - 'keepNext' => false, - 'keepLines' => false, + 'widowControl' => true, + 'keepNext' => false, + 'keepLines' => false, 'pageBreakBefore' => false, ); foreach ($attributes as $key => $default) { $get = "get{$key}"; - $object->setStyleValue("$key", null); + $object->setStyleValue($key, null); $this->assertEquals($default, $object->$get()); - $object->setStyleValue("$key", ''); + $object->setStyleValue($key, ''); $this->assertEquals($default, $object->$get()); } } @@ -67,31 +65,26 @@ public function testSetStyleValueNormal() $object = new Paragraph(); $attributes = array( - 'align' => 'justify', - 'spaceAfter' => 240, - 'spaceBefore' => 240, - 'indent' => 1, - 'hanging' => 1, - 'spacing' => 120, - 'basedOn' => 'Normal', - 'next' => 'Normal', - 'numStyle' => 'numStyle', - 'numLevel' => 1, - 'widowControl' => false, - 'keepNext' => true, - 'keepLines' => true, + 'spaceAfter' => 240, + 'spaceBefore' => 240, + 'indent' => 1, + 'hanging' => 1, + 'spacing' => 120, + 'basedOn' => 'Normal', + 'next' => 'Normal', + 'numStyle' => 'numStyle', + 'numLevel' => 1, + 'widowControl' => false, + 'keepNext' => true, + 'keepLines' => true, 'pageBreakBefore' => true, ); foreach ($attributes as $key => $value) { $get = "get{$key}"; $object->setStyleValue("$key", $value); - if ($key == 'align') { - if ($value == 'justify') { - $value = 'both'; - } - } elseif ($key == 'indent' || $key == 'hanging') { + if ('indent' == $key || 'hanging' == $key) { $value = $value * 720; - } elseif ($key == 'spacing') { + } elseif ('spacing' == $key) { $value += 240; } $this->assertEquals($value, $object->$get()); @@ -131,9 +124,7 @@ public function testLineHeight() $section = $phpWord->addSection(); // Test style array - $text = $section->addText('This is a test', array(), array( - 'line-height' => 2.0 - )); + $text = $section->addText('This is a test', array(), array('line-height' => 2.0)); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); diff --git a/tests/PhpWord/Tests/Style/RowTest.php b/tests/PhpWord/Style/RowTest.php similarity index 88% rename from tests/PhpWord/Tests/Style/RowTest.php rename to tests/PhpWord/Style/RowTest.php index 679e9982a3..a89f73d238 100644 --- a/tests/PhpWord/Tests/Style/RowTest.php +++ b/tests/PhpWord/Style/RowTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Row; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Row @@ -35,8 +33,8 @@ public function testBooleanValue() $object = new Row(); $properties = array( - 'tblHeader' => true, - 'cantSplit' => false, + 'tblHeader' => true, + 'cantSplit' => false, 'exactHeight' => true, ); foreach ($properties as $key => $value) { @@ -63,8 +61,8 @@ public function testNonBooleanValue() $object = new Row(); $properties = array( - 'tblHeader' => 'a', - 'cantSplit' => 'b', + 'tblHeader' => 'a', + 'cantSplit' => 'b', 'exactHeight' => 'c', ); foreach ($properties as $key => $value) { diff --git a/tests/PhpWord/Tests/Style/SectionTest.php b/tests/PhpWord/Style/SectionTest.php similarity index 96% rename from tests/PhpWord/Tests/Style/SectionTest.php rename to tests/PhpWord/Style/SectionTest.php index e5becd7296..ed25ac367f 100644 --- a/tests/PhpWord/Tests/Style/SectionTest.php +++ b/tests/PhpWord/Style/SectionTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Section; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Section @@ -64,8 +62,15 @@ public function testSettingValue() $this->assertEquals($iVal, $oSettings->getHeaderHeight()); $oSettings->setSettingValue('lineNumbering', array()); - $oSettings->setSettingValue('lineNumbering', array('start' => 1, 'increment' => 1, - 'distance' => 240, 'restart' => 'newPage')); + $oSettings->setSettingValue( + 'lineNumbering', + array( + 'start' => 1, + 'increment' => 1, + 'distance' => 240, + 'restart' => 'newPage', + ) + ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\LineNumbering', $oSettings->getLineNumbering()); $oSettings->setSettingValue('lineNumbering', null); diff --git a/tests/PhpWord/Tests/Style/ShadingTest.php b/tests/PhpWord/Style/ShadingTest.php similarity index 92% rename from tests/PhpWord/Tests/Style/ShadingTest.php rename to tests/PhpWord/Style/ShadingTest.php index 5a965e1d10..d6378f8d39 100644 --- a/tests/PhpWord/Tests/Style/ShadingTest.php +++ b/tests/PhpWord/Style/ShadingTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Shading; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Shading diff --git a/tests/PhpWord/Tests/Style/SpacingTest.php b/tests/PhpWord/Style/SpacingTest.php similarity index 84% rename from tests/PhpWord/Tests/Style/SpacingTest.php rename to tests/PhpWord/Style/SpacingTest.php index a4022b74bd..79c9e4589d 100644 --- a/tests/PhpWord/Tests/Style/SpacingTest.php +++ b/tests/PhpWord/Style/SpacingTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Spacing; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Spacing @@ -34,9 +32,9 @@ public function testGetSetProperties() $object = new Spacing(); $properties = array( 'before' => array(null, 10), - 'after' => array(null, 10), - 'line' => array(null, 10), - 'rule' => array('auto', 'exact'), + 'after' => array(null, 10), + 'line' => array(null, 10), + 'rule' => array('auto', 'exact'), ); foreach ($properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/TOCTest.php b/tests/PhpWord/Style/TOCTest.php similarity index 92% rename from tests/PhpWord/Tests/Style/TOCTest.php rename to tests/PhpWord/Style/TOCTest.php index e6e32e6b9d..03620c178a 100644 --- a/tests/PhpWord/Tests/Style/TOCTest.php +++ b/tests/PhpWord/Style/TOCTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\TOC; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\TOC diff --git a/tests/PhpWord/Tests/Style/TabTest.php b/tests/PhpWord/Style/TabTest.php similarity index 92% rename from tests/PhpWord/Tests/Style/TabTest.php rename to tests/PhpWord/Style/TabTest.php index 784b4e4709..7724aa418c 100644 --- a/tests/PhpWord/Tests/Style/TabTest.php +++ b/tests/PhpWord/Style/TabTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; - -use PhpOffice\PhpWord\Style\Tab; +namespace PhpOffice\PhpWord\Style; /** * Test class for PhpOffice\PhpWord\Style\Tab diff --git a/tests/PhpWord/Tests/Style/TableTest.php b/tests/PhpWord/Style/TableTest.php similarity index 81% rename from tests/PhpWord/Tests/Style/TableTest.php rename to tests/PhpWord/Style/TableTest.php index 2afbab744a..5e878692c7 100644 --- a/tests/PhpWord/Tests/Style/TableTest.php +++ b/tests/PhpWord/Style/TableTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; +namespace PhpOffice\PhpWord\Style; -use PhpOffice\PhpWord\Style\Table; +use PhpOffice\PhpWord\SimpleType\JcTable; /** * Test class for PhpOffice\PhpWord\Style\Table @@ -57,26 +57,26 @@ public function testSetGetNormal() $object = new Table(); $attributes = array( - 'bgColor' => 'FF0000', - 'borderTopSize' => 4, - 'borderTopColor' => 'FF0000', - 'borderLeftSize' => 4, - 'borderLeftColor' => 'FF0000', - 'borderRightSize' => 4, - 'borderRightColor' => 'FF0000', - 'borderBottomSize' => 4, - 'borderBottomColor' => 'FF0000', - 'borderInsideHSize' => 4, + 'bgColor' => 'FF0000', + 'borderTopSize' => 4, + 'borderTopColor' => 'FF0000', + 'borderLeftSize' => 4, + 'borderLeftColor' => 'FF0000', + 'borderRightSize' => 4, + 'borderRightColor' => 'FF0000', + 'borderBottomSize' => 4, + 'borderBottomColor' => 'FF0000', + 'borderInsideHSize' => 4, 'borderInsideHColor' => 'FF0000', - 'borderInsideVSize' => 4, + 'borderInsideVSize' => 4, 'borderInsideVColor' => 'FF0000', - 'cellMarginTop' => 240, - 'cellMarginLeft' => 240, - 'cellMarginRight' => 240, - 'cellMarginBottom' => 240, - 'align' => 'center', - 'width' => 100, - 'unit' => 'pct', + 'cellMarginTop' => 240, + 'cellMarginLeft' => 240, + 'cellMarginRight' => 240, + 'cellMarginBottom' => 240, + 'alignment' => JcTable::CENTER, + 'width' => 100, + 'unit' => 'pct', ); foreach ($attributes as $key => $value) { $set = "set{$key}"; @@ -162,14 +162,8 @@ public function testSetStyleValue() $object->setStyleValue('cellMargin', 240); $object->setStyleValue('borderColor', '999999'); - $this->assertEquals( - array(120, 120, 120, 120, 120, 120), - $object->getBorderSize() - ); - $this->assertEquals( - array(240, 240, 240, 240), - $object->getCellMargin() - ); + $this->assertEquals(array(120, 120, 120, 120, 120, 120), $object->getBorderSize()); + $this->assertEquals(array(240, 240, 240, 240), $object->getCellMargin()); $this->assertEquals( array('999999', '999999', '999999', '999999', '999999', '999999'), $object->getBorderColor() diff --git a/tests/PhpWord/Tests/Style/TextBoxTest.php b/tests/PhpWord/Style/TextBoxTest.php similarity index 74% rename from tests/PhpWord/Tests/Style/TextBoxTest.php rename to tests/PhpWord/Style/TextBoxTest.php index cd2d86958d..ea7bc71f09 100644 --- a/tests/PhpWord/Tests/Style/TextBoxTest.php +++ b/tests/PhpWord/Style/TextBoxTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Style; +namespace PhpOffice\PhpWord\Style; -use PhpOffice\PhpWord\Style\TextBox; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Style\Image @@ -33,25 +33,25 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase public function testSetGetNormal() { $object = new TextBox(); - + $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red' + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', ); foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -60,32 +60,32 @@ public function testSetGetNormal() $this->assertEquals($value, $object->$get()); } } - + /** * Test setStyleValue method */ public function testSetStyleValue() { $object = new TextBox(); - + $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'alignment' => Jc::START, + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red' + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', ); foreach ($properties as $key => $value) { $get = "get{$key}"; @@ -93,7 +93,7 @@ public function testSetStyleValue() $this->assertEquals($value, $object->$get()); } } - + /** * Test setWrappingStyle exception * @@ -104,38 +104,39 @@ public function testSetWrappingStyleException() $object = new TextBox(); $object->setWrappingStyle('foo'); } - + /** * Test set/get width */ public function testSetGetWidth() { - $expected=200; + $expected = 200; $object = new TextBox(); $object->setWidth($expected); $this->assertEquals($expected, $object->getWidth()); } - + /** * Test set/get height */ public function testSetGetHeight() { - $expected=200; + $expected = 200; $object = new TextBox(); $object->setHeight($expected); $this->assertEquals($expected, $object->getHeight()); } - + /** * Test set/get height */ public function testSetGetAlign() { - $expected='left'; - $object = new TextBox(); - $object->setAlign($expected); - $this->assertEquals($expected, $object->getAlign()); + $textBox = new TextBox(); + + $expectedAlignment = Jc::START; + $textBox->setAlignment($expectedAlignment); + $this->assertEquals($expectedAlignment, $textBox->getAlignment()); } /** @@ -143,28 +144,29 @@ public function testSetGetAlign() */ public function testSetGetMarginTop() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setMarginTop($expected); $this->assertEquals($expected, $object->getMarginTop()); } - + /** * Test set/get marginLeft */ public function testSetGetMarginLeft() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setMarginLeft($expected); $this->assertEquals($expected, $object->getMarginLeft()); } + /** * Test set/get innerMarginTop */ public function testSetGetInnerMarginTop() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginTop($expected); $this->assertEquals($expected, $object->getInnerMarginTop()); @@ -175,96 +177,96 @@ public function testSetGetInnerMarginTop() */ public function testSetGetWrappingStyle() { - $expected='inline'; + $expected = 'inline'; $object = new TextBox(); $object->setWrappingStyle($expected); $this->assertEquals($expected, $object->getWrappingStyle()); } - + /** * Test set/get positioning */ public function testSetGetPositioning() { - $expected='absolute'; + $expected = 'absolute'; $object = new TextBox(); $object->setPositioning($expected); $this->assertEquals($expected, $object->getPositioning()); } - + /** * Test set/get posHorizontal */ public function testSetGetPosHorizontal() { - $expected='center'; + $expected = 'center'; $object = new TextBox(); $object->setPosHorizontal($expected); $this->assertEquals($expected, $object->getPosHorizontal()); } - + /** * Test set/get posVertical */ public function testSetGetPosVertical() { - $expected='top'; + $expected = 'top'; $object = new TextBox(); $object->setPosVertical($expected); $this->assertEquals($expected, $object->getPosVertical()); } - + /** * Test set/get posHorizontalRel */ public function testSetGetPosHorizontalRel() { - $expected='margin'; + $expected = 'margin'; $object = new TextBox(); $object->setPosHorizontalRel($expected); $this->assertEquals($expected, $object->getPosHorizontalRel()); } - + /** * Test set/get posVerticalRel */ public function testSetGetPosVerticalRel() { - $expected='page'; + $expected = 'page'; $object = new TextBox(); $object->setPosVerticalRel($expected); $this->assertEquals($expected, $object->getPosVerticalRel()); } - - + + /** * Test set/get innerMarginRight */ public function testSetGetInnerMarginRight() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginRight($expected); $this->assertEquals($expected, $object->getInnerMarginRight()); } - + /** * Test set/get innerMarginBottom */ public function testSetGetInnerMarginBottom() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginBottom($expected); $this->assertEquals($expected, $object->getInnerMarginBottom()); } - + /** * Test set/get innerMarginLeft */ public function testSetGetInnerMarginLeft() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginLeft($expected); $this->assertEquals($expected, $object->getInnerMarginLeft()); @@ -275,7 +277,7 @@ public function testSetGetInnerMarginLeft() */ public function testSetGetInnerMargin() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMargin($expected); $this->assertEquals(array($expected, $expected, $expected, $expected), $object->getInnerMargin()); @@ -286,18 +288,18 @@ public function testSetGetInnerMargin() */ public function testSetGetBorderSize() { - $expected=2; + $expected = 2; $object = new TextBox(); $object->setBorderSize($expected); $this->assertEquals($expected, $object->getBorderSize()); } - + /** * Test set/get borderColor */ public function testSetGetBorderColor() { - $expected='red'; + $expected = 'red'; $object = new TextBox(); $object->setBorderColor($expected); $this->assertEquals($expected, $object->getBorderColor()); diff --git a/tests/PhpWord/Tests/StyleTest.php b/tests/PhpWord/StyleTest.php similarity index 88% rename from tests/PhpWord/Tests/StyleTest.php rename to tests/PhpWord/StyleTest.php index 6165e4fd3b..57ec98f45f 100644 --- a/tests/PhpWord/Tests/StyleTest.php +++ b/tests/PhpWord/StyleTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; +namespace PhpOffice\PhpWord; -use PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Style @@ -44,7 +44,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase */ public function testStyles() { - $paragraph = array('align' => 'center'); + $paragraph = array('alignment' => Jc::CENTER); $font = array('italic' => true, '_bold' => true); $table = array('bgColor' => 'CCCCCC'); $styles = array( @@ -82,10 +82,10 @@ public function testStyles() */ public function testDefaultParagraphStyle() { - $paragraph = array('align' => 'center'); + $paragraph = array('alignment' => Jc::CENTER); Style::setDefaultParagraphStyle($paragraph); - $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\Paragraph", Style::getStyle('Normal')); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', Style::getStyle('Normal')); } } diff --git a/tests/PhpWord/Tests/TemplateProcessorTest.php b/tests/PhpWord/TemplateProcessorTest.php similarity index 70% rename from tests/PhpWord/Tests/TemplateProcessorTest.php rename to tests/PhpWord/TemplateProcessorTest.php index f75f7d3b05..11b43cf454 100644 --- a/tests/PhpWord/Tests/TemplateProcessorTest.php +++ b/tests/PhpWord/TemplateProcessorTest.php @@ -11,13 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; - -use PhpOffice\PhpWord\TemplateProcessor; +namespace PhpOffice\PhpWord; /** * @covers \PhpOffice\PhpWord\TemplateProcessor @@ -37,10 +35,10 @@ final public function testTemplateCanBeSavedInTemporaryLocation() $templateFqfn = __DIR__ . '/_files/templates/with_table_macros.docx'; $templateProcessor = new TemplateProcessor($templateFqfn); - $xslDOMDocument = new \DOMDocument(); - $xslDOMDocument->load(__DIR__ . "/_files/xsl/remove_tables_by_needle.xsl"); - foreach (array('${employee.', '${scoreboard.') as $needle) { - $templateProcessor->applyXslStyleSheet($xslDOMDocument, array('needle' => $needle)); + $xslDomDocument = new \DOMDocument(); + $xslDomDocument->load(__DIR__ . "/_files/xsl/remove_tables_by_needle.xsl"); + foreach (array('${employee.', '${scoreboard.', '${reference.') as $needle) { + $templateProcessor->applyXslStyleSheet($xslDomDocument, array('needle' => $needle)); } $documentFqfn = $templateProcessor->save(); @@ -50,19 +48,25 @@ final public function testTemplateCanBeSavedInTemporaryLocation() $templateZip = new \ZipArchive(); $templateZip->open($templateFqfn); - $templateXml = $templateZip->getFromName('word/document.xml'); + $templateHeaderXml = $templateZip->getFromName('word/header1.xml'); + $templateMainPartXml = $templateZip->getFromName('word/document.xml'); + $templateFooterXml = $templateZip->getFromName('word/footer1.xml'); if (false === $templateZip->close()) { throw new \Exception("Could not close zip file \"{$templateZip}\"."); } $documentZip = new \ZipArchive(); $documentZip->open($documentFqfn); - $documentXml = $documentZip->getFromName('word/document.xml'); + $documentHeaderXml = $documentZip->getFromName('word/header1.xml'); + $documentMainPartXml = $documentZip->getFromName('word/document.xml'); + $documentFooterXml = $documentZip->getFromName('word/footer1.xml'); if (false === $documentZip->close()) { throw new \Exception("Could not close zip file \"{$documentZip}\"."); } - $this->assertNotEquals($documentXml, $templateXml); + $this->assertNotEquals($templateHeaderXml, $documentHeaderXml); + $this->assertNotEquals($templateMainPartXml, $documentMainPartXml); + $this->assertNotEquals($templateFooterXml, $documentFooterXml); return $documentFqfn; } @@ -70,11 +74,13 @@ final public function testTemplateCanBeSavedInTemporaryLocation() /** * XSL stylesheet can be applied. * - * @param string $actualDocumentFqfn - * @throws \Exception + * @test * @covers ::applyXslStyleSheet * @depends testTemplateCanBeSavedInTemporaryLocation - * @test + * + * @param string $actualDocumentFqfn + * + * @throws \Exception */ final public function testXslStyleSheetCanBeApplied($actualDocumentFqfn) { @@ -82,19 +88,25 @@ final public function testXslStyleSheetCanBeApplied($actualDocumentFqfn) $actualDocumentZip = new \ZipArchive(); $actualDocumentZip->open($actualDocumentFqfn); - $actualDocumentXml = $actualDocumentZip->getFromName('word/document.xml'); + $actualHeaderXml = $actualDocumentZip->getFromName('word/header1.xml'); + $actualMainPartXml = $actualDocumentZip->getFromName('word/document.xml'); + $actualFooterXml = $actualDocumentZip->getFromName('word/footer1.xml'); if (false === $actualDocumentZip->close()) { throw new \Exception("Could not close zip file \"{$actualDocumentFqfn}\"."); } $expectedDocumentZip = new \ZipArchive(); $expectedDocumentZip->open($expectedDocumentFqfn); - $expectedDocumentXml = $expectedDocumentZip->getFromName('word/document.xml'); + $expectedHeaderXml = $expectedDocumentZip->getFromName('word/header1.xml'); + $expectedMainPartXml = $expectedDocumentZip->getFromName('word/document.xml'); + $expectedFooterXml = $expectedDocumentZip->getFromName('word/footer1.xml'); if (false === $expectedDocumentZip->close()) { throw new \Exception("Could not close zip file \"{$expectedDocumentFqfn}\"."); } - $this->assertXmlStringEqualsXmlString($expectedDocumentXml, $actualDocumentXml); + $this->assertXmlStringEqualsXmlString($expectedHeaderXml, $actualHeaderXml); + $this->assertXmlStringEqualsXmlString($expectedMainPartXml, $actualMainPartXml); + $this->assertXmlStringEqualsXmlString($expectedFooterXml, $actualFooterXml); } /** @@ -109,14 +121,14 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParamete { $templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/blank.docx'); - $xslDOMDocument = new \DOMDocument(); - $xslDOMDocument->load(__DIR__ . '/_files/xsl/passthrough.xsl'); + $xslDomDocument = new \DOMDocument(); + $xslDomDocument->load(__DIR__ . '/_files/xsl/passthrough.xsl'); /* * We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure. * This warning fails the test. */ - @$templateProcessor->applyXslStyleSheet($xslDOMDocument, array(1 => htmlspecialchars('somevalue', ENT_COMPAT, 'UTF-8'))); + @$templateProcessor->applyXslStyleSheet($xslDomDocument, array(1 => 'somevalue')); } /** @@ -124,25 +136,25 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParamete * * @covers ::applyXslStyleSheet * @expectedException \PhpOffice\PhpWord\Exception\Exception - * @expectedExceptionMessage Could not load XML from the given template. + * @expectedExceptionMessage Could not load the given XML document. * @test */ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate() { $templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/corrupted_main_document_part.docx'); - $xslDOMDocument = new \DOMDocument(); - $xslDOMDocument->load(__DIR__ . '/_files/xsl/passthrough.xsl'); + $xslDomDocument = new \DOMDocument(); + $xslDomDocument->load(__DIR__ . '/_files/xsl/passthrough.xsl'); /* * We have to use error control below, because \DOMDocument::loadXML omits warning on failure. * This warning fails the test. */ - @$templateProcessor->applyXslStyleSheet($xslDOMDocument); + @$templateProcessor->applyXslStyleSheet($xslDomDocument); } /** - * @civers ::setValue + * @covers ::setValue * @covers ::cloneRow * @covers ::saveAs * @test @@ -157,9 +169,9 @@ public function testCloneRow() ); $docName = 'clone-test-result.docx'; - $templateProcessor->setValue('tableHeader', utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); + $templateProcessor->setValue('tableHeader', utf8_decode('ééé')); $templateProcessor->cloneRow('userId', 1); - $templateProcessor->setValue('userId#1', htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $templateProcessor->setValue('userId#1', 'Test'); $templateProcessor->saveAs($docName); $docFound = file_exists($docName); unlink($docName); @@ -175,15 +187,13 @@ public function testMacrosCanBeReplacedInHeaderAndFooter() { $templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/header-footer.docx'); - $this->assertEquals( - array('documentContent', 'headerValue', 'footerValue'), - $templateProcessor->getVariables() - ); + $this->assertEquals(array('documentContent', 'headerValue', 'footerValue'), $templateProcessor->getVariables()); + + $macroNames = array('headerValue', 'documentContent', 'footerValue'); + $macroValues = array('Header Value', 'Document text.', 'Footer Value'); + $templateProcessor->setValue($macroNames, $macroValues); $docName = 'header-footer-test-result.docx'; - $templateProcessor->setValue('headerValue', htmlspecialchars('Header Value', ENT_COMPAT, 'UTF-8')); - $templateProcessor->setValue('documentContent', htmlspecialchars('Document text.', ENT_COMPAT, 'UTF-8')); - $templateProcessor->setValue('footerValue', htmlspecialchars('Footer Value', ENT_COMPAT, 'UTF-8')); $templateProcessor->saveAs($docName); $docFound = file_exists($docName); unlink($docName); diff --git a/tests/PhpWord/Tests/AutoloaderTest.php b/tests/PhpWord/Tests/AutoloaderTest.php deleted file mode 100644 index dace5bdb49..0000000000 --- a/tests/PhpWord/Tests/AutoloaderTest.php +++ /dev/null @@ -1,62 +0,0 @@ -assertContains( - array('PhpOffice\\PhpWord\\Autoloader', 'autoload'), - spl_autoload_functions() - ); - } - - /** - * Autoload - */ - public function testAutoload() - { - $declaredCount = count(get_declared_classes()); - Autoloader::autoload('Foo'); - $this->assertCount( - $declaredCount, - 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\\Exception\\InvalidStyleException'); - $this->assertTrue( - in_array('PhpOffice\\PhpWord\\Exception\\InvalidStyleException', get_declared_classes()), - 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' . - 'PhpOffice\\PhpWord\\Exception\\InvalidStyleException class' - ); - } -} diff --git a/tests/PhpWord/Tests/Shared/StringTest.php b/tests/PhpWord/Tests/Shared/StringTest.php deleted file mode 100644 index a3524eded8..0000000000 --- a/tests/PhpWord/Tests/Shared/StringTest.php +++ /dev/null @@ -1,75 +0,0 @@ -assertTrue(String::isUTF8('')); - $this->assertTrue(String::isUTF8('éééé')); - $this->assertFalse(String::isUTF8(utf8_decode('éééé'))); - } - - /** - * OOXML to PHP control character - */ - public function testControlCharacterOOXML2PHP() - { - $this->assertEquals('', String::controlCharacterOOXML2PHP('')); - $this->assertEquals(chr(0x08), String::controlCharacterOOXML2PHP('_x0008_')); - } - - /** - * PHP to OOXML control character - */ - public function testControlCharacterPHP2OOXML() - { - $this->assertEquals('', String::controlCharacterPHP2OOXML('')); - $this->assertEquals('_x0008_', String::controlCharacterPHP2OOXML(chr(0x08))); - } - - /** - * Test unicode conversion - */ - public function testToUnicode() - { - $this->assertEquals('a', String::toUnicode('a')); - $this->assertEquals('\uc0{\u8364}', String::toUnicode('€')); - $this->assertEquals('\uc0{\u233}', String::toUnicode('é')); - } - - /** - * Test remove underscore prefix - */ - public function testRemoveUnderscorePrefix() - { - $this->assertEquals('item', String::removeUnderscorePrefix('_item')); - } -} diff --git a/tests/PhpWord/Tests/Shared/XMLReaderTest.php b/tests/PhpWord/Tests/Shared/XMLReaderTest.php deleted file mode 100644 index 2bb6ef658d..0000000000 --- a/tests/PhpWord/Tests/Shared/XMLReaderTest.php +++ /dev/null @@ -1,75 +0,0 @@ -getDomFromZip($filename, 'yadayadaya'); - } - - /** - * Test get DOMDocument from ZipArchive returns false - */ - public function testGetDomFromZipReturnsFalse() - { - $filename = __DIR__ . "/../_files/documents/reader.docx.zip"; - $object = new XMLReader(); - $this->assertFalse($object->getDomFromZip($filename, 'yadayadaya')); - } - - /** - * Test get elements returns empty - */ - public function testGetElementsReturnsEmpty() - { - $object = new XMLReader(); - $this->assertEquals(array(), $object->getElements('w:document')); - } - - /** - * Test get element returns null - */ - public function testGetElementReturnsNull() - { - $filename = __DIR__ . "/../_files/documents/reader.docx.zip"; - - $object = new XMLReader(); - $object->getDomFromZip($filename, '[Content_Types].xml'); - $element = $object->getElements('*')->item(0); - - $this->assertNull($object->getElement('yadayadaya', $element)); - } -} diff --git a/tests/PhpWord/Tests/_files/documents/without_table_macros.docx b/tests/PhpWord/Tests/_files/documents/without_table_macros.docx deleted file mode 100644 index e4e9767fc1..0000000000 Binary files a/tests/PhpWord/Tests/_files/documents/without_table_macros.docx and /dev/null differ diff --git a/tests/PhpWord/Tests/_files/templates/with_table_macros.docx b/tests/PhpWord/Tests/_files/templates/with_table_macros.docx deleted file mode 100644 index cd5ed6cedb..0000000000 Binary files a/tests/PhpWord/Tests/_files/templates/with_table_macros.docx and /dev/null differ diff --git a/tests/PhpWord/Tests/Writer/HTML/ElementTest.php b/tests/PhpWord/Writer/HTML/ElementTest.php similarity index 78% rename from tests/PhpWord/Tests/Writer/HTML/ElementTest.php rename to tests/PhpWord/Writer/HTML/ElementTest.php index ae136d34d7..2a1e03dc28 100644 --- a/tests/PhpWord/Tests/Writer/HTML/ElementTest.php +++ b/tests/PhpWord/Writer/HTML/ElementTest.php @@ -11,10 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\HTML; +namespace PhpOffice\PhpWord\Writer\HTML; use PhpOffice\PhpWord\Element\Text as TextElement; use PhpOffice\PhpWord\Writer\HTML; @@ -46,11 +46,11 @@ public function testUnmatchedElements() */ public function testWriteTextElement() { - $object = new Text(new HTML(), new TextElement('A')); - $object->setOpeningText('-'); - $object->setClosingText('-'); + $object = new Text(new HTML(), new TextElement(htmlspecialchars('A', ENT_COMPAT, 'UTF-8'))); + $object->setOpeningText(htmlspecialchars('-', ENT_COMPAT, 'UTF-8')); + $object->setClosingText(htmlspecialchars('-', ENT_COMPAT, 'UTF-8')); $object->setWithoutP(true); - $this->assertEquals('-A-', $object->write()); + $this->assertEquals(htmlspecialchars('-A-', ENT_COMPAT, 'UTF-8'), $object->write()); } } diff --git a/tests/PhpWord/Tests/Writer/HTML/PartTest.php b/tests/PhpWord/Writer/HTML/PartTest.php similarity index 91% rename from tests/PhpWord/Tests/Writer/HTML/PartTest.php rename to tests/PhpWord/Writer/HTML/PartTest.php index 93e9a98ef8..137a092e42 100644 --- a/tests/PhpWord/Tests/Writer/HTML/PartTest.php +++ b/tests/PhpWord/Writer/HTML/PartTest.php @@ -11,10 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\HTML; +namespace PhpOffice\PhpWord\Writer\HTML; use PhpOffice\PhpWord\Writer\HTML\Part\Body; diff --git a/tests/PhpWord/Tests/Writer/HTML/StyleTest.php b/tests/PhpWord/Writer/HTML/StyleTest.php similarity index 89% rename from tests/PhpWord/Tests/Writer/HTML/StyleTest.php rename to tests/PhpWord/Writer/HTML/StyleTest.php index 8af1e47930..629efd7aa2 100644 --- a/tests/PhpWord/Tests/Writer/HTML/StyleTest.php +++ b/tests/PhpWord/Writer/HTML/StyleTest.php @@ -11,12 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\HTML; - -use PhpOffice\PhpWord\Shared\XMLWriter; +namespace PhpOffice\PhpWord\Writer\HTML; /** * Test class for PhpOffice\PhpWord\Writer\HTML\Style subnamespace diff --git a/tests/PhpWord/Tests/Writer/HTMLTest.php b/tests/PhpWord/Writer/HTMLTest.php similarity index 58% rename from tests/PhpWord/Tests/Writer/HTMLTest.php rename to tests/PhpWord/Writer/HTMLTest.php index c3339d1a4f..b2b10165fd 100644 --- a/tests/PhpWord/Tests/Writer/HTMLTest.php +++ b/tests/PhpWord/Writer/HTMLTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer; +namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Writer\HTML; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Writer\HTML @@ -53,29 +53,34 @@ public function testConstructWithNull() */ public function testSave() { - $localImage = __DIR__ . "/../_files/images/PhpWord.png"; + $localImage = __DIR__ . '/../_files/images/PhpWord.png'; $archiveImage = 'zip://' . __DIR__ . '/../_files/documents/reader.docx#word/media/image1.jpeg'; $gdImage = 'http://php.net/images/logos/php-med-trans-light.gif'; - $objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; - $file = __DIR__ . "/../_files/temp.html"; + $objectSrc = __DIR__ . '/../_files/documents/sheet.xls'; + $file = __DIR__ . '/../_files/temp.html'; $phpWord = new PhpWord(); $docProps = $phpWord->getDocInfo(); - $docProps->setTitle('HTML Test'); + $docProps->setTitle(htmlspecialchars('HTML Test', ENT_COMPAT, 'UTF-8')); $phpWord->addTitleStyle(1, array('bold' => true)); - $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, - 'color' => 'FF0000', 'fgColor' => 'FF0000')); - $phpWord->addParagraphStyle('Paragraph', array('align' => 'center', 'spaceAfter' => 20, 'spaceBefore' => 20)); + $phpWord->addFontStyle( + 'Font', + array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000') + ); + $phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER, 'spaceAfter' => 20, 'spaceBefore' => 20)); $section = $phpWord->addSection(); - $section->addText('Test 1', 'Font', 'Paragraph'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph'); $section->addTextBreak(); - $section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true, 'subscript' => true)); - $section->addLink('http://test.com'); - $section->addTitle('Test', 1); + $section->addText( + htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), + array('name' => 'Tahoma', 'bold' => true, 'italic' => true, 'subscript' => true) + ); + $section->addLink('https://github.com/PHPOffice/PHPWord'); + $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); $section->addPageBreak(); - $section->addListItem('Test'); + $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $section->addImage($localImage); $section->addImage($archiveImage); $section->addImage($gdImage); @@ -85,25 +90,28 @@ public function testSave() $section = $phpWord->addSection(); - $textrun = $section->addTextRun(array('align' => 'center')); - $textrun->addText('Test 3'); + $textrun = $section->addTextRun(array('alignment' => Jc::CENTER)); + $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8')); $textrun->addTextBreak(); $textrun = $section->addTextRun('Paragraph'); - $textrun->addLink('http://test.com'); + $textrun->addLink('https://github.com/PHPOffice/PHPWord'); $textrun->addImage($localImage); - $textrun->addFootnote()->addText('Footnote'); - $textrun->addEndnote()->addText('Endnote'); + $textrun->addFootnote()->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8')); + $textrun->addEndnote()->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8')); $section = $phpWord->addSection(); $table = $section->addTable(); $cell = $table->addRow()->addCell(); - $cell->addText('Test 1', array('superscript' => true, 'underline' => 'dash', 'strikethrough' => true)); + $cell->addText( + htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), + array('superscript' => true, 'underline' => 'dash', 'strikethrough' => true) + ); $cell->addTextRun(); - $cell->addLink('http://test.com'); + $cell->addLink('https://github.com/PHPOffice/PHPWord'); $cell->addTextBreak(); - $cell->addListItem('Test'); + $cell->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $cell->addImage($localImage); $cell->addObject($objectSrc); $cell->addFootnote(); diff --git a/tests/PhpWord/Tests/Writer/ODText/ElementTest.php b/tests/PhpWord/Writer/ODText/ElementTest.php similarity index 90% rename from tests/PhpWord/Tests/Writer/ODText/ElementTest.php rename to tests/PhpWord/Writer/ODText/ElementTest.php index fa9532d147..fb14aae571 100644 --- a/tests/PhpWord/Tests/Writer/ODText/ElementTest.php +++ b/tests/PhpWord/Writer/ODText/ElementTest.php @@ -11,12 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\ODText; +namespace PhpOffice\PhpWord\Writer\ODText; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\Common\XMLWriter; /** * Test class for PhpOffice\PhpWord\Writer\ODText\Element subnamespace diff --git a/tests/PhpWord/Tests/Writer/ODText/Part/AbstractPartTest.php b/tests/PhpWord/Writer/ODText/Part/AbstractPartTest.php similarity index 73% rename from tests/PhpWord/Tests/Writer/ODText/Part/AbstractPartTest.php rename to tests/PhpWord/Writer/ODText/Part/AbstractPartTest.php index 92fab26fdc..90874b47e9 100644 --- a/tests/PhpWord/Tests/Writer/ODText/Part/AbstractPartTest.php +++ b/tests/PhpWord/Writer/ODText/Part/AbstractPartTest.php @@ -11,13 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\ODText\Part; +namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\Writer\ODText; -use PhpWord\Tests\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\ODText\Part\AbstractPart @@ -33,26 +32,20 @@ class AbstractPartTest extends \PHPUnit_Framework_TestCase */ public function testSetGetParentWriter() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'); $object->setParentWriter(new ODText()); - $this->assertEquals( - new ODText(), - $object->getParentWriter() - ); + $this->assertEquals(new ODText(), $object->getParentWriter()); } /** * covers ::getParentWriter + * * @expectedException Exception * @expectedExceptionMessage No parent WriterInterface assigned. */ public function testSetGetParentWriterNull() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'); $object->getParentWriter(); } } diff --git a/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php b/tests/PhpWord/Writer/ODText/Part/ContentTest.php similarity index 80% rename from tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php rename to tests/PhpWord/Writer/ODText/Part/ContentTest.php index 85ddada6ba..5814fa603f 100644 --- a/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php +++ b/tests/PhpWord/Writer/ODText/Part/ContentTest.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\ODText\Part; +namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\ODText\Part\Content; +use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\ODText\Part\Content @@ -41,8 +41,8 @@ public function tearDown() */ public function testWriteContent() { - $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; $expected = 'Expected'; $phpWord = new PhpWord(); @@ -52,14 +52,14 @@ public function testWriteContent() $phpWord->setDefaultFontName('Verdana'); $phpWord->addFontStyle('Font', array('size' => 11)); - $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER)); $phpWord->addTableStyle('tblStyle', array('width' => 100)); $section = $phpWord->addSection(array('colsNum' => 2)); $section->addText($expected); $section->addText('Test font style', 'Font'); $section->addText('Test paragraph style', null, 'Paragraph'); - $section->addLink('http://test.com', 'Test link'); + $section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $section->addTitle('Test title', 1); $section->addTextBreak(); $section->addPageBreak(); @@ -75,7 +75,7 @@ public function testWriteContent() $cell = $table->addRow()->addCell(); $cell = $table->addRow()->addCell(); $cell->addText('Test'); - $cell->addLink('http://test.com', 'Test link'); + $cell->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); $cell->addTextBreak(); $cell->addListItem('Test list item'); $cell->addImage($imageSrc); @@ -90,7 +90,7 @@ public function testWriteContent() $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); - $element = "/office:document-content/office:body/office:text/text:section/text:p"; + $element = '/office:document-content/office:body/office:text/text:section/text:p'; $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue); } @@ -104,7 +104,7 @@ public function testWriteNoStyle() $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); - $element = "/office:document-content/office:automatic-styles/style:style"; + $element = '/office:document-content/office:automatic-styles/style:style'; $this->assertTrue($doc->elementExists($element, 'content.xml')); } } diff --git a/tests/PhpWord/Tests/Writer/ODText/StyleTest.php b/tests/PhpWord/Writer/ODText/StyleTest.php similarity index 90% rename from tests/PhpWord/Tests/Writer/ODText/StyleTest.php rename to tests/PhpWord/Writer/ODText/StyleTest.php index cd5ea0eb15..6b9793856a 100644 --- a/tests/PhpWord/Tests/Writer/ODText/StyleTest.php +++ b/tests/PhpWord/Writer/ODText/StyleTest.php @@ -11,12 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\ODText; +namespace PhpOffice\PhpWord\Writer\ODText; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\Common\XMLWriter; /** * Test class for PhpOffice\PhpWord\Writer\ODText\Style subnamespace diff --git a/tests/PhpWord/Tests/Writer/ODTextTest.php b/tests/PhpWord/Writer/ODTextTest.php similarity index 87% rename from tests/PhpWord/Tests/Writer/ODTextTest.php rename to tests/PhpWord/Writer/ODTextTest.php index 25b8095b10..d79a9d42a2 100644 --- a/tests/PhpWord/Tests/Writer/ODTextTest.php +++ b/tests/PhpWord/Writer/ODTextTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer; +namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Writer\ODText; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Writer\ODText @@ -65,18 +65,18 @@ public function testConstructWithNull() */ public function testSave() { - $imageSrc = __DIR__ . "/../_files/images/PhpWord.png"; - $objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; - $file = __DIR__ . "/../_files/temp.odt"; + $imageSrc = __DIR__ . '/../_files/images/PhpWord.png'; + $objectSrc = __DIR__ . '/../_files/documents/sheet.xls'; + $file = __DIR__ . '/../_files/temp.odt'; $phpWord = new PhpWord(); $phpWord->addFontStyle('Font', array('size' => 11)); - $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER)); $section = $phpWord->addSection(); $section->addText('Test 1', 'Font'); $section->addTextBreak(); $section->addText('Test 2', null, 'Paragraph'); - $section->addLink('http://test.com'); + $section->addLink('https://github.com/PHPOffice/PHPWord'); $section->addTitle('Test', 1); $section->addPageBreak(); $section->addTable()->addRow()->addCell()->addText('Test'); @@ -136,10 +136,7 @@ public function testSetGetUseDiskCaching() */ public function testSetUseDiskCachingException() { - $dir = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_BASE_DIR, 'foo') - ); + $dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $object = new ODText(); $object->setUseDiskCaching(true, $dir); diff --git a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php b/tests/PhpWord/Writer/PDF/DomPDFTest.php similarity index 94% rename from tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php rename to tests/PhpWord/Writer/PDF/DomPDFTest.php index 476c9011dc..67026a8439 100644 --- a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php +++ b/tests/PhpWord/Writer/PDF/DomPDFTest.php @@ -11,10 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\PDF; +namespace PhpOffice\PhpWord\Writer\PDF; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; @@ -33,7 +33,7 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase public function testConstruct() { define('DOMPDF_ENABLE_AUTOLOAD', false); - $file = __DIR__ . "/../../_files/dompdf.pdf"; + $file = __DIR__ . '/../../_files/dompdf.pdf'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); diff --git a/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php b/tests/PhpWord/Writer/PDF/MPDFTest.php similarity index 90% rename from tests/PhpWord/Tests/Writer/PDF/MPDFTest.php rename to tests/PhpWord/Writer/PDF/MPDFTest.php index 4728b7f148..b6c85a408e 100644 --- a/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php +++ b/tests/PhpWord/Writer/PDF/MPDFTest.php @@ -11,10 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\PDF; +namespace PhpOffice\PhpWord\Writer\PDF; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; @@ -32,7 +32,7 @@ class MPDFTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $file = __DIR__ . "/../../_files/mpdf.pdf"; + $file = __DIR__ . '/../../_files/mpdf.pdf'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); diff --git a/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php b/tests/PhpWord/Writer/PDF/TCPDFTest.php similarity index 88% rename from tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php rename to tests/PhpWord/Writer/PDF/TCPDFTest.php index c73f004352..aaec55eb12 100644 --- a/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php +++ b/tests/PhpWord/Writer/PDF/TCPDFTest.php @@ -11,10 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\PDF; +namespace PhpOffice\PhpWord\Writer\PDF; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; @@ -32,14 +32,14 @@ class TCPDFTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $file = __DIR__ . "/../../_files/tcpdf.pdf"; + $file = __DIR__ . '/../../_files/tcpdf.pdf'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); $section->addText('Test 1'); $rendererName = Settings::PDF_RENDERER_TCPDF; - $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf'); + $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnickcom/tcpdf'); Settings::setPdfRenderer($rendererName, $rendererLibraryPath); $writer = new PDF($phpWord); $writer->save($file); diff --git a/tests/PhpWord/Tests/Writer/PDFTest.php b/tests/PhpWord/Writer/PDFTest.php similarity index 90% rename from tests/PhpWord/Tests/Writer/PDFTest.php rename to tests/PhpWord/Writer/PDFTest.php index 87814b411f..75db6c037b 100644 --- a/tests/PhpWord/Tests/Writer/PDFTest.php +++ b/tests/PhpWord/Writer/PDFTest.php @@ -11,14 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer; +namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Settings; -use PhpOffice\PhpWord\Writer\PDF; /** * Test class for PhpOffice\PhpWord\Writer\PDF @@ -33,7 +32,7 @@ class PDFTest extends \PHPUnit_Framework_TestCase public function testConstruct() { define('DOMPDF_ENABLE_AUTOLOAD', false); - $file = __DIR__ . "/../_files/temp.pdf"; + $file = __DIR__ . '/../_files/temp.pdf'; $rendererName = Settings::PDF_RENDERER_DOMPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf'); diff --git a/tests/PhpWord/Tests/Writer/RTF/ElementTest.php b/tests/PhpWord/Writer/RTF/ElementTest.php similarity index 93% rename from tests/PhpWord/Tests/Writer/RTF/ElementTest.php rename to tests/PhpWord/Writer/RTF/ElementTest.php index e090b34921..47d01d009e 100644 --- a/tests/PhpWord/Tests/Writer/RTF/ElementTest.php +++ b/tests/PhpWord/Writer/RTF/ElementTest.php @@ -11,10 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\RTF; +namespace PhpOffice\PhpWord\Writer\RTF; use PhpOffice\PhpWord\Writer\RTF; diff --git a/tests/PhpWord/Tests/Writer/RTF/StyleTest.php b/tests/PhpWord/Writer/RTF/StyleTest.php similarity index 89% rename from tests/PhpWord/Tests/Writer/RTF/StyleTest.php rename to tests/PhpWord/Writer/RTF/StyleTest.php index 542e34fe7c..095d30d535 100644 --- a/tests/PhpWord/Tests/Writer/RTF/StyleTest.php +++ b/tests/PhpWord/Writer/RTF/StyleTest.php @@ -11,12 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\RTF; - -use PhpOffice\PhpWord\Shared\XMLWriter; +namespace PhpOffice\PhpWord\Writer\RTF; /** * Test class for PhpOffice\PhpWord\Writer\RTF\Style subnamespace diff --git a/tests/PhpWord/Tests/Writer/RTFTest.php b/tests/PhpWord/Writer/RTFTest.php similarity index 68% rename from tests/PhpWord/Tests/Writer/RTFTest.php rename to tests/PhpWord/Writer/RTFTest.php index 5b983b3578..0b4f6b0f78 100644 --- a/tests/PhpWord/Tests/Writer/RTFTest.php +++ b/tests/PhpWord/Writer/RTFTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer; +namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Writer\RTF; +use PhpOffice\PhpWord\SimpleType\Jc; /** * Test class for PhpOffice\PhpWord\Writer\RTF @@ -53,20 +53,22 @@ public function testConstructWithNull() */ public function testSave() { - $imageSrc = __DIR__ . "/../_files/images/PhpWord.png"; - $objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; - $file = __DIR__ . "/../_files/temp.rtf"; + $imageSrc = __DIR__ . '/../_files/images/PhpWord.png'; + $objectSrc = __DIR__ . '/../_files/documents/sheet.xls'; + $file = __DIR__ . '/../_files/temp.rtf'; $phpWord = new PhpWord(); - $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, - 'color' => 'FF0000', 'fgColor' => '00FF00')); - $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $phpWord->addFontStyle( + 'Font', + array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => '00FF00') + ); + $phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER)); $section = $phpWord->addSection(); - $section->addText('Test 1', 'Font', 'Paragraph'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph'); $section->addTextBreak(); - $section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true)); - $section->addLink('http://test.com'); - $section->addTitle('Test', 1); + $section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), array('name' => 'Tahoma', 'bold' => true, 'italic' => true)); + $section->addLink('https://github.com/PHPOffice/PHPWord'); + $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); $section->addPageBreak(); // Rowspan @@ -78,13 +80,13 @@ public function testSave() $cell = $section->addTable()->addRow()->addCell(); $cell->addTable()->addRow()->addCell(); - $section->addListItem('Test'); + $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $section->addImage($imageSrc); $section->addObject($objectSrc); $section->addTOC(); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); - $textrun->addText('Test 3'); + $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8')); $textrun->addTextBreak(); $writer = new RTF($phpWord); $writer->save($file); @@ -103,7 +105,7 @@ public function testSavePhpOutput() { $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText('Test'); + $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $writer = new RTF($phpWord); $writer->save('php://output'); } diff --git a/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php b/tests/PhpWord/Writer/Word2007/ElementTest.php similarity index 73% rename from tests/PhpWord/Tests/Writer/Word2007/ElementTest.php rename to tests/PhpWord/Writer/Word2007/ElementTest.php index 92a74c1544..027ba86a2e 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php +++ b/tests/PhpWord/Writer/Word2007/ElementTest.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007; +namespace PhpOffice\PhpWord\Writer\Word2007; +use PhpOffice\Common\XMLWriter; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Element subnamespace @@ -41,7 +41,7 @@ public function testUnmatchedElements() $elements = array( 'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC', - 'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT' + 'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT', ); foreach ($elements as $element) { $objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $element; @@ -65,7 +65,7 @@ public function testLineElement() $section->addLine(array('width' => 1000, 'height' => 1000, 'positioning' => 'absolute', 'flip' => true)); $doc = TestHelperDOCX::getDocument($phpWord); - $element = "/w:document/w:body/w:p/w:r/w:pict/v:shapetype"; + $element = '/w:document/w:body/w:p/w:r/w:pict/v:shapetype'; $this->assertTrue($doc->elementExists($element)); } @@ -81,8 +81,8 @@ public function testShapeElements() $section->addShape( 'arc', array( - 'points' => '-90 20', - 'frame' => array('width' => 120, 'height' => 120), + 'points' => '-90 20', + 'frame' => array('width' => 120, 'height' => 120), 'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'), ) ); @@ -91,9 +91,14 @@ public function testShapeElements() $section->addShape( 'curve', array( - 'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow', - 'outline' => array('color' => '#66cc00', 'weight' => 2, 'dash' => 'dash', - 'startArrow' => 'diamond', 'endArrow' => 'block'), + 'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow', + 'outline' => array( + 'color' => '#66cc00', + 'weight' => 2, + 'dash' => 'dash', + 'startArrow' => 'diamond', + 'endArrow' => 'block', + ), ) ); @@ -101,9 +106,15 @@ public function testShapeElements() $section->addShape( 'line', array( - 'points' => '1,1 150,30', - 'outline' => array('color' => '#cc00ff', 'line' => 'thickThin', 'weight' => 3, - 'startArrow' => 'oval', 'endArrow' => 'classic', 'endCap' => 'round'), + 'points' => '1,1 150,30', + 'outline' => array( + 'color' => '#cc00ff', + 'line' => 'thickThin', + 'weight' => 3, + 'startArrow' => 'oval', + 'endArrow' => 'classic', + 'endCap' => 'round', + ), ) ); @@ -111,9 +122,13 @@ public function testShapeElements() $section->addShape( 'polyline', array( - 'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', - 'outline' => array('color' => '#cc6666', 'weight' => 2, - 'startArrow' => 'none', 'endArrow' => 'classic'), + 'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', + 'outline' => array( + 'color' => '#cc6666', + 'weight' => 2, + 'startArrow' => 'none', + 'endArrow' => 'classic', + ), ) ); @@ -122,10 +137,10 @@ public function testShapeElements() 'rect', array( 'roundness' => 0.2, - 'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1), - 'fill' => array('color' => '#FFCC33'), - 'outline' => array('color' => '#990000', 'weight' => 1), - 'shadow' => array('color' => '#EEEEEE', 'offset' => '3pt,3pt'), + 'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1), + 'fill' => array('color' => '#FFCC33'), + 'outline' => array('color' => '#990000', 'weight' => 1), + 'shadow' => array('color' => '#EEEEEE', 'offset' => '3pt,3pt'), ) ); @@ -133,9 +148,9 @@ public function testShapeElements() $section->addShape( 'oval', array( - 'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1), - 'fill' => array('color' => '#33CC99'), - 'outline' => array('color' => '#333333', 'weight' => 2), + 'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1), + 'fill' => array('color' => '#33CC99'), + 'outline' => array('color' => '#333333', 'weight' => 2), 'extrusion' => array('type' => 'perspective', 'color' => '#EEEEEE'), ) ); @@ -191,7 +206,7 @@ public function testFormFieldElements() $doc = TestHelperDOCX::getDocument($phpWord); - $path = "/w:document/w:body/w:p/w:r/w:fldChar/w:ffData"; + $path = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData'; $this->assertTrue($doc->elementExists($path . '/w:textInput')); $this->assertTrue($doc->elementExists($path . '/w:checkBox')); $this->assertTrue($doc->elementExists($path . '/w:ddList')); @@ -211,7 +226,7 @@ public function testSDTElements() $doc = TestHelperDOCX::getDocument($phpWord); - $path = "/w:document/w:body/w:p/w:sdt/w:sdtPr"; + $path = '/w:document/w:body/w:p/w:sdt/w:sdtPr'; $this->assertTrue($doc->elementExists($path . '/w:comboBox')); $this->assertTrue($doc->elementExists($path . '/w:dropDownList')); $this->assertTrue($doc->elementExists($path . '/w:date')); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/AbstractPartTest.php b/tests/PhpWord/Writer/Word2007/Part/AbstractPartTest.php similarity index 70% rename from tests/PhpWord/Tests/Writer/Word2007/Part/AbstractPartTest.php rename to tests/PhpWord/Writer/Word2007/Part/AbstractPartTest.php index 2ff80ab83c..8f72cdfe96 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/AbstractPartTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/AbstractPartTest.php @@ -11,14 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; -use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractWriterPart; use PhpOffice\PhpWord\Writer\Word2007; -use PhpWord\Tests\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\AbstractWriterPart @@ -34,26 +32,20 @@ class AbstractWriterPartTest extends \PHPUnit_Framework_TestCase */ public function testSetGetParentWriter() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'); $object->setParentWriter(new Word2007()); - $this->assertEquals( - new Word2007(), - $object->getParentWriter() - ); + $this->assertEquals(new Word2007(), $object->getParentWriter()); } /** * covers ::getParentWriter + * * @expectedException Exception * @expectedExceptionMessage No parent WriterInterface assigned. */ public function testSetGetParentWriterNull() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'); $object->getParentWriter(); } } diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php similarity index 76% rename from tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php rename to tests/PhpWord/Writer/Word2007/Part/DocumentTest.php index ef36e0dd72..a9e6d8617c 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php @@ -11,15 +11,15 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\SimpleType\Jc; use PhpOffice\PhpWord\Style\Font; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\Word2007\Part\Document; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Document @@ -62,11 +62,11 @@ public function testWriteEndSectionPageNumbering() */ public function testElements() { - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; $phpWord = new PhpWord(); - $phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); - $phpWord->addTitleStyle(2, array('color'=>'666666')); + $phpWord->addTitleStyle(1, array('color' => '333333', 'bold' => true)); + $phpWord->addTitleStyle(2, array('color' => '666666')); $section = $phpWord->addSection(); $section->addTOC(); $section->addPageBreak(); @@ -80,24 +80,44 @@ public function testElements() $section->addTitle('Title 2', 2); $section->addObject($objectSrc); $section->addTextBox(array()); - $section->addTextBox(array('wrappingStyle' => 'square', 'positioning' => 'relative', - 'posHorizontalRel' => 'margin', 'posVerticalRel' => 'margin', - 'innerMargin' => 10, 'borderSize' => 1, 'borderColor' => '#FF0')); - $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center')); + $section->addTextBox( + array( + 'wrappingStyle' => 'square', + 'positioning' => 'relative', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'margin', + 'innerMargin' => 10, + 'borderSize' => 1, + 'borderColor' => '#FF0', + ) + ); + $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'alignment' => Jc::CENTER)); $section->addListItemRun()->addText('List item run 1'); - $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar')); - $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'SakaEraCalendar')); - $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'LastUsedFormat')); - $section->addField('PAGE', array('format'=>'ArabicDash')); + $section->addField( + 'DATE', + array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), + array('PreserveFormat', 'LunarCalendar') + ); + $section->addField( + 'DATE', + array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), + array('PreserveFormat', 'SakaEraCalendar') + ); + $section->addField( + 'DATE', + array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), + array('PreserveFormat', 'LastUsedFormat') + ); + $section->addField('PAGE', array('format' => 'ArabicDash')); $section->addLine( array( - 'width' => 10, - 'height' => 10, + 'width' => 10, + 'height' => 10, 'positioning' => 'absolute', - 'beginArrow' => 'block', - 'endArrow' => 'open', - 'dash' => 'rounddot', - 'weight' => 10 + 'beginArrow' => 'block', + 'endArrow' => 'open', + 'dash' => 'rounddot', + 'weight' => 10, ) ); @@ -131,25 +151,37 @@ public function testElements() */ public function testElementStyles() { - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; $tabs = array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)); $phpWord = new PhpWord(); - $phpWord->addParagraphStyle('pStyle', array( - 'align' => 'center', - 'tabs' => $tabs, - 'shading' => array('fill' => 'FFFF99'), - 'borderSize' => 4, - )); // Style #1 - $phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true, - 'scale' => 200, 'spacing' => 240, 'kerning' => 10)); // Style #2 + $phpWord->addParagraphStyle( + 'pStyle', + array( + 'alignment' => Jc::CENTER, + 'tabs' => $tabs, + 'shading' => array('fill' => 'FFFF99'), + 'borderSize' => 4, + ) + ); // Style #1 + $phpWord->addFontStyle( + 'fStyle', + array( + 'size' => '20', + 'bold' => true, + 'allCaps' => true, + 'scale' => 200, + 'spacing' => 240, + 'kerning' => 10, + ) + ); // Style #2 $phpWord->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3 $phpWord->addTableStyle('tStyle', array('borderSize' => 1)); - $fontStyle = new Font('text', array('align' => 'center')); + $fontStyle = new Font('text', array('alignment' => Jc::CENTER)); $section = $phpWord->addSection(); $section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #5 - $section->addObject($objectSrc, array('align' => 'center')); + $section->addObject($objectSrc, array('alignment' => Jc::CENTER)); $section->addTOC($fontStyle); $section->addTitle('Title 1', 1); $section->addTOC('fStyle'); @@ -187,9 +219,9 @@ public function testWriteText() $section->addText('Test', $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($phpWord); - $element = "/w:document/w:body/w:p/w:r/w:rPr/w:rStyle"; + $element = '/w:document/w:body/w:p/w:r/w:rPr/w:rStyle'; $this->assertEquals($rStyle, $doc->getElementAttribute($element, 'w:val')); - $element = "/w:document/w:body/w:p/w:pPr/w:pStyle"; + $element = '/w:document/w:body/w:p/w:pPr/w:pStyle'; $this->assertEquals($pStyle, $doc->getElementAttribute($element, 'w:val')); } @@ -199,8 +231,8 @@ public function testWriteText() public function testWriteTextRun() { $pStyle = 'pStyle'; - $aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120); - $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; + $aStyle = array('alignment' => Jc::BOTH, 'spaceBefore' => 120, 'spaceAfter' => 120); + $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg'; $phpWord = new PhpWord(); $phpWord->addParagraphStyle($pStyle, $aStyle); @@ -209,12 +241,12 @@ public function testWriteTextRun() $textrun->addText('Test'); $textrun->addTextBreak(); $textrun = $section->addTextRun($aStyle); - $textrun->addLink('http://test.com'); - $textrun->addImage($imageSrc, array('align' => 'center')); + $textrun->addLink('https://github.com/PHPOffice/PHPWord'); + $textrun->addImage($imageSrc, array('alignment' => Jc::CENTER)); $textrun->addFootnote(); $doc = TestHelperDOCX::getDocument($phpWord); - $parent = "/w:document/w:body/w:p"; + $parent = '/w:document/w:body/w:p'; $this->assertTrue($doc->elementExists("{$parent}/w:pPr/w:pStyle[@w:val='{$pStyle}']")); } @@ -227,13 +259,13 @@ public function testWriteLink() $section = $phpWord->addSection(); $fontStyleArray = array('bold' => true); $fontStyleName = 'Font Style'; - $paragraphStyleArray = array('align' => 'center'); + $paragraphStyleArray = array('alignment' => Jc::CENTER); $paragraphStyleName = 'Paragraph Style'; - $expected = 'PhpWord'; - $section->addLink('http://github.com/phpoffice/phpword', $expected); - $section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleArray, $paragraphStyleArray); - $section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleName, $paragraphStyleName); + $expected = 'PHPWord on GitHub'; + $section->addLink('https://github.com/PHPOffice/PHPWord', $expected); + $section->addLink('https://github.com/PHPOffice/PHPWord', 'Test', $fontStyleArray, $paragraphStyleArray); + $section->addLink('https://github.com/PHPOffice/PHPWord', 'Test', $fontStyleName, $paragraphStyleName); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); @@ -251,7 +283,7 @@ public function testWritePreserveText() $footer = $section->addFooter(); $fontStyleArray = array('bold' => true); $fontStyleName = 'Font'; - $paragraphStyleArray = array('align' => 'right'); + $paragraphStyleArray = array('alignment' => Jc::END); $paragraphStyleName = 'Paragraph'; $footer->addPreserveText('Page {PAGE}'); @@ -259,7 +291,7 @@ public function testWritePreserveText() $footer->addPreserveText('{PAGE}', $fontStyleName, $paragraphStyleName); $doc = TestHelperDOCX::getDocument($phpWord); - $preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml'); + $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')); @@ -296,12 +328,12 @@ public function testWriteTextBreak() public function testWriteImage() { $phpWord = new PhpWord(); - $styles = array('align' => 'left', 'width' => 40, 'height' => 40, 'marginTop' => -1, 'marginLeft' => -1); + $styles = array('alignment' => Jc::START, 'width' => 40, 'height' => 40, 'marginTop' => -1, 'marginLeft' => -1); $wraps = array('inline', 'behind', 'infront', 'square', 'tight'); $section = $phpWord->addSection(); foreach ($wraps as $wrap) { $styles['wrappingStyle'] = $wrap; - $section->addImage(__DIR__ . "/../../../_files/images/earth.jpg", $styles); + $section->addImage(__DIR__ . '/../../../_files/images/earth.jpg', $styles); } $archiveFile = realpath(__DIR__ . '/../../../_files/documents/reader.docx'); @@ -326,7 +358,7 @@ public function testWriteImage() */ public function testWriteWatermark() { - $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; + $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); @@ -334,8 +366,8 @@ public function testWriteWatermark() $header->addWatermark($imageSrc); $doc = TestHelperDOCX::getDocument($phpWord); - $element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference"); - $this->assertStringStartsWith("rId", $element->getAttribute('r:id')); + $element = $doc->getElement('/w:document/w:body/w:sectPr/w:headerReference'); + $this->assertStringStartsWith('rId', $element->getAttribute('r:id')); } /** @@ -348,7 +380,7 @@ public function testWriteTitle() $phpWord->addSection()->addTitle('Test', 1); $doc = TestHelperDOCX::getDocument($phpWord); - $element = "/w:document/w:body/w:p/w:pPr/w:pStyle"; + $element = '/w:document/w:body/w:p/w:pPr/w:pStyle'; $this->assertEquals('Heading1', $doc->getElementAttribute($element, 'w:val')); } @@ -380,10 +412,10 @@ public function testWriteParagraphStyle() $phpWord = new PhpWord(); $section = $phpWord->addSection(); $attributes = array( - 'align' => 'right', - 'widowControl' => false, - 'keepNext' => true, - 'keepLines' => true, + 'alignment' => Jc::END, + 'widowControl' => false, + 'keepNext' => true, + 'keepLines' => true, 'pageBreakBefore' => true, ); foreach ($attributes as $attribute => $value) { @@ -395,9 +427,9 @@ public function testWriteParagraphStyle() $attributeCount = 0; foreach ($attributes as $key => $value) { $attributeCount++; - $nodeName = ($key == 'align') ? 'jc' : $key; + $nodeName = ($key == 'alignment') ? 'jc' : $key; $path = "/w:document/w:body/w:p[{$attributeCount}]/w:pPr/w:{$nodeName}"; - if ($key != 'align') { + if ('alignment' != $key) { $value = $value ? 1 : 0; } $element = $doc->getElement($path); @@ -449,28 +481,28 @@ public function testWriteTableStyle() $phpWord = new PhpWord(); $rHeight = 120; $cWidth = 120; - $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; - - $tStyles["width"] = 50; - $tStyles["cellMarginTop"] = 120; - $tStyles["cellMarginRight"] = 120; - $tStyles["cellMarginBottom"] = 120; - $tStyles["cellMarginLeft"] = 120; - $rStyles["tblHeader"] = true; - $rStyles["cantSplit"] = true; - $cStyles["valign"] = 'top'; - $cStyles["textDirection"] = 'btLr'; - $cStyles["bgColor"] = 'FF0000'; - $cStyles["borderTopSize"] = 120; - $cStyles["borderBottomSize"] = 120; - $cStyles["borderLeftSize"] = 120; - $cStyles["borderRightSize"] = 120; - $cStyles["borderTopColor"] = 'FF0000'; - $cStyles["borderBottomColor"] = 'FF0000'; - $cStyles["borderLeftColor"] = 'FF0000'; - $cStyles["borderRightColor"] = 'FF0000'; - $cStyles["vMerge"] = 'restart'; + $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg'; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; + + $tStyles['width'] = 50; + $tStyles['cellMarginTop'] = 120; + $tStyles['cellMarginRight'] = 120; + $tStyles['cellMarginBottom'] = 120; + $tStyles['cellMarginLeft'] = 120; + $rStyles['tblHeader'] = true; + $rStyles['cantSplit'] = true; + $cStyles['valign'] = 'top'; + $cStyles['textDirection'] = 'btLr'; + $cStyles['bgColor'] = 'FF0000'; + $cStyles['borderTopSize'] = 120; + $cStyles['borderBottomSize'] = 120; + $cStyles['borderLeftSize'] = 120; + $cStyles['borderRightSize'] = 120; + $cStyles['borderTopColor'] = 'FF0000'; + $cStyles['borderBottomColor'] = 'FF0000'; + $cStyles['borderLeftColor'] = 'FF0000'; + $cStyles['borderRightColor'] = 'FF0000'; + $cStyles['vMerge'] = 'restart'; $section = $phpWord->addSection(); $table = $section->addTable($tStyles); @@ -479,7 +511,7 @@ public function testWriteTableStyle() $cell = $table->addCell($cWidth, $cStyles); $cell->addText('Test'); $cell->addTextBreak(); - $cell->addLink('http://google.com'); + $cell->addLink('https://github.com/PHPOffice/PHPWord'); $cell->addListItem('Test'); $cell->addImage($imageSrc); $cell->addObject($objectSrc); @@ -489,10 +521,6 @@ public function testWriteTableStyle() $doc = TestHelperDOCX::getDocument($phpWord); $parent = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellMar'; - // $this->assertEquals($tStyles['cellMarginTop'], $doc->getElementAttribute("{$parent}/w:top", 'w:w')); - // $this->assertEquals($tStyles['cellMarginRight'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); - // $this->assertEquals($tStyles['cellMarginBottom'], $doc->getElementAttribute("{$parent}/w:bottom", 'w:w')); - // $this->assertEquals($tStyles['cellMarginLeft'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); $parent = '/w:document/w:body/w:tbl/w:tr/w:trPr'; $this->assertEquals($rHeight, $doc->getElementAttribute("{$parent}/w:trHeight", 'w:val')); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/FooterTest.php b/tests/PhpWord/Writer/Word2007/Part/FooterTest.php similarity index 87% rename from tests/PhpWord/Tests/Writer/Word2007/Part/FooterTest.php rename to tests/PhpWord/Writer/Word2007/Part/FooterTest.php index 5c9d2d3081..9a7d809a86 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/FooterTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/FooterTest.php @@ -11,13 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Writer\Word2007; -use PhpOffice\PhpWord\Writer\Word2007\Part\Footer; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Footer @@ -32,7 +31,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase */ public function testWriteFooter() { - $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; + $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; $container = new \PhpOffice\PhpWord\Element\Footer(1); $container->addText(''); $container->addPreserveText(''); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/FootnotesTest.php b/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php similarity index 63% rename from tests/PhpWord/Tests/Writer/Word2007/Part/FootnotesTest.php rename to tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php index d7a3d667cf..2d48fe363a 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/FootnotesTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/FootnotesTest.php @@ -11,47 +11,41 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; +use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\TestHelperDOCX; /** - * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Notes - * + * @coversNothing * @runTestsInSeparateProcesses */ class FootnotesTest extends \PHPUnit_Framework_TestCase { - /** - * Executed before each method of the class - */ public function tearDown() { TestHelperDOCX::clear(); } - /** - * Write footnotes - */ public function testWriteFootnotes() { $phpWord = new PhpWord(); - $phpWord->addParagraphStyle('pStyle', array('align' => 'left')); + $phpWord->addParagraphStyle('pStyle', array('alignment' => Jc::START)); $section = $phpWord->addSection(); $section->addText('Text'); $footnote1 = $section->addFootnote('pStyle'); $footnote1->addText('Footnote'); $footnote1->addTextBreak(); - $footnote1->addLink('http://google.com'); - $footnote2 = $section->addEndnote(array('align' => 'left')); + $footnote1->addLink('https://github.com/PHPOffice/PHPWord'); + $footnote2 = $section->addEndnote(array('alignment' => Jc::START)); $footnote2->addText('Endnote'); $doc = TestHelperDOCX::getDocument($phpWord); - $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference")); - $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:endnoteReference")); + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference')); + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference')); } } diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/HeaderTest.php b/tests/PhpWord/Writer/Word2007/Part/HeaderTest.php similarity index 87% rename from tests/PhpWord/Tests/Writer/Word2007/Part/HeaderTest.php rename to tests/PhpWord/Writer/Word2007/Part/HeaderTest.php index e8c31ecfb0..6c285af6b9 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/HeaderTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/HeaderTest.php @@ -11,13 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Writer\Word2007; -use PhpOffice\PhpWord\Writer\Word2007\Part\Header; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Header @@ -31,7 +30,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase */ public function testWriteHeader() { - $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; + $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; $container = new \PhpOffice\PhpWord\Element\Header(1); $container->addText('Test'); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/NumberingTest.php b/tests/PhpWord/Writer/Word2007/Part/NumberingTest.php similarity index 68% rename from tests/PhpWord/Tests/Writer/Word2007/Part/NumberingTest.php rename to tests/PhpWord/Writer/Word2007/Part/NumberingTest.php index ebc3aa2e88..9d11e5cb94 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/NumberingTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/NumberingTest.php @@ -11,13 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; +use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Numbering @@ -47,20 +48,20 @@ public function testWriteNumbering() $phpWord->addNumberingStyle( 'numStyle', array( - 'type' => 'multilevel', + 'type' => 'multilevel', 'levels' => array( array( - 'start' => 1, - 'format' => 'decimal', - 'restart' => 1, - 'suffix' => 'space', - 'text' => '%1.', - 'align' => 'left', - 'left' => 360, - 'hanging' => 360, - 'tabPos' => 360, - 'font' => 'Arial', - 'hint' => 'default', + 'start' => 1, + 'format' => 'decimal', + 'restart' => 1, + 'suffix' => 'space', + 'text' => '%1.', + 'alignment' => Jc::START, + 'left' => 360, + 'hanging' => 360, + 'tabPos' => 360, + 'font' => 'Arial', + 'hint' => 'default', ), ) ) diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/SettingsTest.php b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php similarity index 92% rename from tests/PhpWord/Tests/Writer/Word2007/Part/SettingsTest.php rename to tests/PhpWord/Writer/Word2007/Part/SettingsTest.php index 7d4d1849c6..06d12abe51 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/SettingsTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/SettingsTest.php @@ -11,13 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/StylesTest.php b/tests/PhpWord/Writer/Word2007/Part/StylesTest.php similarity index 82% rename from tests/PhpWord/Tests/Writer/Word2007/Part/StylesTest.php rename to tests/PhpWord/Writer/Word2007/Part/StylesTest.php index 103caa81b5..f40387a182 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/StylesTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/StylesTest.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\Word2007\Part\Styles; +use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Styles @@ -43,20 +43,12 @@ public function testWriteStyles() { $phpWord = new PhpWord(); - $pStyle = array('align' => 'both'); + $pStyle = array('alignment' => Jc::BOTH); $pBase = array('basedOn' => 'Normal'); $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal'); $rStyle = array('size' => 20); - $tStyle = array( - 'bgColor' => 'FF0000', - 'cellMargin' => 120, - 'borderSize' => 120, - ); - $firstRowStyle = array( - 'bgColor' => '0000FF', - 'borderSize' => 120, - 'borderColor' => '00FF00', - ); + $tStyle = array('bgColor' => 'FF0000', 'cellMargin' => 120, 'borderSize' => 120); + $firstRowStyle = array('bgColor' => '0000FF', 'borderSize' => 120, 'borderColor' => '00FF00'); $phpWord->setDefaultParagraphStyle($pStyle); $phpWord->addParagraphStyle('Base Style', $pBase); $phpWord->addParagraphStyle('New Style', $pNew); diff --git a/tests/PhpWord/Tests/Writer/Word2007/PartTest.php b/tests/PhpWord/Writer/Word2007/PartTest.php similarity index 93% rename from tests/PhpWord/Tests/Writer/Word2007/PartTest.php rename to tests/PhpWord/Writer/Word2007/PartTest.php index c3d2933190..7af8ce3afd 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/PartTest.php +++ b/tests/PhpWord/Writer/Word2007/PartTest.php @@ -11,10 +11,10 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007; +namespace PhpOffice\PhpWord\Writer\Word2007; use PhpOffice\PhpWord\Writer\Word2007\Part\RelsPart; diff --git a/tests/PhpWord/Tests/Writer/Word2007/Style/FontTest.php b/tests/PhpWord/Writer/Word2007/Style/FontTest.php similarity index 86% rename from tests/PhpWord/Tests/Writer/Word2007/Style/FontTest.php rename to tests/PhpWord/Writer/Word2007/Style/FontTest.php index af11c054ff..50a7ecf765 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Style/FontTest.php +++ b/tests/PhpWord/Writer/Word2007/Style/FontTest.php @@ -11,14 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; +namespace PhpOffice\PhpWord\Writer\Word2007\Style; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\Word2007; -use PhpOffice\PhpWord\Writer\Word2007\Style\Font; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Font diff --git a/tests/PhpWord/Tests/Writer/Word2007/StyleTest.php b/tests/PhpWord/Writer/Word2007/StyleTest.php similarity index 90% rename from tests/PhpWord/Tests/Writer/Word2007/StyleTest.php rename to tests/PhpWord/Writer/Word2007/StyleTest.php index 8dd229c311..dfabec0358 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/StyleTest.php +++ b/tests/PhpWord/Writer/Word2007/StyleTest.php @@ -11,12 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer\Word2007; +namespace PhpOffice\PhpWord\Writer\Word2007; -use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\Common\XMLWriter; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Style subnamespace @@ -29,7 +29,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase public function testEmptyStyles() { $styles = array( - 'Alignment', 'Cell', 'Font', 'Image', 'Indentation', 'LineNumbering', + 'Cell', 'Font', 'Image', 'Indentation', 'LineNumbering', 'Paragraph', 'Row', 'Section', 'Shading', 'Spacing', 'Tab', 'Table', 'TextBox', 'Line', 'Shape', 'Frame', 'Outline', 'Fill', 'Shadow', 'Extrusion', ); diff --git a/tests/PhpWord/Tests/Writer/Word2007Test.php b/tests/PhpWord/Writer/Word2007Test.php similarity index 82% rename from tests/PhpWord/Tests/Writer/Word2007Test.php rename to tests/PhpWord/Writer/Word2007Test.php index db6e5cadd2..76ba2114f4 100644 --- a/tests/PhpWord/Tests/Writer/Word2007Test.php +++ b/tests/PhpWord/Writer/Word2007Test.php @@ -11,14 +11,14 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests\Writer; +namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\Word2007; +use PhpOffice\PhpWord\SimpleType\Jc; +use PhpOffice\PhpWord\TestHelperDOCX; /** * Test class for PhpOffice\PhpWord\Writer\Word2007 @@ -44,17 +44,17 @@ public function testConstruct() $writerParts = array( 'ContentTypes' => 'ContentTypes', - 'Rels' => 'Rels', - 'DocPropsApp' => 'DocPropsApp', - 'Document' => 'Document', - 'Styles' => 'Styles', - 'Numbering' => 'Numbering', - 'Settings' => 'Settings', - 'WebSettings' => 'WebSettings', - 'Header' => 'Header', - 'Footer' => 'Footer', - 'Footnotes' => 'Footnotes', - 'Endnotes' => 'Footnotes', + 'Rels' => 'Rels', + 'DocPropsApp' => 'DocPropsApp', + 'Document' => 'Document', + 'Styles' => 'Styles', + 'Numbering' => 'Numbering', + 'Settings' => 'Settings', + 'WebSettings' => 'WebSettings', + 'Header' => 'Header', + 'Footer' => 'Footer', + 'Footnotes' => 'Footnotes', + 'Endnotes' => 'Footnotes', ); foreach ($writerParts as $part => $type) { $this->assertInstanceOf( @@ -77,7 +77,7 @@ public function testSave() $remoteImage = 'http://php.net//images/logos/php-med-trans-light.gif'; $phpWord = new PhpWord(); $phpWord->addFontStyle('Font', array('size' => 11)); - $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER)); $section = $phpWord->addSection(); $section->addText('Test 1', 'Font', 'Paragraph'); $section->addTextBreak(); @@ -86,14 +86,14 @@ public function testSave() $textrun = $section->addTextRun(); $textrun->addText('Test 3'); $footnote = $textrun->addFootnote(); - $footnote->addLink('http://test.com'); + $footnote->addLink('https://github.com/PHPOffice/PHPWord'); $header = $section->addHeader(); $header->addImage($localImage); $footer = $section->addFooter(); $footer->addImage($remoteImage); $writer = new Word2007($phpWord); - $file = __DIR__ . "/../_files/temp.docx"; + $file = __DIR__ . '/../_files/temp.docx'; $writer->save($file); $this->assertTrue(file_exists($file)); @@ -114,7 +114,7 @@ public function testSaveUseDiskCaching() $writer = new Word2007($phpWord); $writer->setUseDiskCaching(true); - $file = __DIR__ . "/../_files/temp.docx"; + $file = __DIR__ . '/../_files/temp.docx'; $writer->save($file); $this->assertTrue(file_exists($file)); @@ -142,7 +142,7 @@ public function testCheckContentTypes() } $doc = TestHelperDOCX::getDocument($phpWord); - $mediaPath = $doc->getPath() . "/word/media"; + $mediaPath = $doc->getPath() . '/word/media'; foreach ($images as $source => $target) { $this->assertFileEquals( @@ -183,10 +183,7 @@ public function testSetGetUseDiskCaching() */ public function testSetUseDiskCachingException() { - $dir = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_BASE_DIR, 'foo') - ); + $dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $object = new Word2007(); $object->setUseDiskCaching(true, $dir); diff --git a/tests/PhpWord/Tests/_files/documents/reader.docx b/tests/PhpWord/_files/documents/reader.docx similarity index 100% rename from tests/PhpWord/Tests/_files/documents/reader.docx rename to tests/PhpWord/_files/documents/reader.docx diff --git a/tests/PhpWord/Tests/_files/documents/reader.docx.zip b/tests/PhpWord/_files/documents/reader.docx.zip similarity index 100% rename from tests/PhpWord/Tests/_files/documents/reader.docx.zip rename to tests/PhpWord/_files/documents/reader.docx.zip diff --git a/tests/PhpWord/Tests/_files/documents/reader.html b/tests/PhpWord/_files/documents/reader.html similarity index 100% rename from tests/PhpWord/Tests/_files/documents/reader.html rename to tests/PhpWord/_files/documents/reader.html diff --git a/tests/PhpWord/Tests/_files/documents/reader.odt b/tests/PhpWord/_files/documents/reader.odt similarity index 100% rename from tests/PhpWord/Tests/_files/documents/reader.odt rename to tests/PhpWord/_files/documents/reader.odt diff --git a/tests/PhpWord/Tests/_files/documents/reader.rtf b/tests/PhpWord/_files/documents/reader.rtf similarity index 88% rename from tests/PhpWord/Tests/_files/documents/reader.rtf rename to tests/PhpWord/_files/documents/reader.rtf index 400f43a5d9..4cecadeabd 100644 --- a/tests/PhpWord/Tests/_files/documents/reader.rtf +++ b/tests/PhpWord/_files/documents/reader.rtf @@ -16,6 +16,6 @@ \pard\nowidctlpar\qc\sa100{\cf0\f0\fs32\b\i I am styled by both font and paragraph style.}\par \pard\nowidctlpar{\cf1\f1\fs40\b\i\ul\strike\super I am inline styled.}\par \par -{\field {\*\fldinst {HYPERLINK "http://www.google.com"}}{\fldrslt {Google}}}\par +{\field {\*\fldinst {HYPERLINK "https://github.com/PHPOffice/PHPWord"}}{\fldrslt {PHPWord on GitHub}}}\par \par } \ No newline at end of file diff --git a/tests/PhpWord/Tests/_files/documents/sheet.xls b/tests/PhpWord/_files/documents/sheet.xls similarity index 100% rename from tests/PhpWord/Tests/_files/documents/sheet.xls rename to tests/PhpWord/_files/documents/sheet.xls diff --git a/tests/PhpWord/_files/documents/without_table_macros.docx b/tests/PhpWord/_files/documents/without_table_macros.docx new file mode 100644 index 0000000000..316a1df762 Binary files /dev/null and b/tests/PhpWord/_files/documents/without_table_macros.docx differ diff --git a/tests/PhpWord/Tests/_files/images/PhpWord.png b/tests/PhpWord/_files/images/PhpWord.png similarity index 100% rename from tests/PhpWord/Tests/_files/images/PhpWord.png rename to tests/PhpWord/_files/images/PhpWord.png diff --git a/tests/PhpWord/Tests/_files/images/alexz-johnson.pcx b/tests/PhpWord/_files/images/alexz-johnson.pcx similarity index 100% rename from tests/PhpWord/Tests/_files/images/alexz-johnson.pcx rename to tests/PhpWord/_files/images/alexz-johnson.pcx diff --git a/tests/PhpWord/Tests/_files/images/angela_merkel.tif b/tests/PhpWord/_files/images/angela_merkel.tif similarity index 100% rename from tests/PhpWord/Tests/_files/images/angela_merkel.tif rename to tests/PhpWord/_files/images/angela_merkel.tif diff --git a/tests/PhpWord/Tests/_files/images/duke_nukem.bmp b/tests/PhpWord/_files/images/duke_nukem.bmp similarity index 100% rename from tests/PhpWord/Tests/_files/images/duke_nukem.bmp rename to tests/PhpWord/_files/images/duke_nukem.bmp diff --git a/tests/PhpWord/Tests/_files/images/earth.jpg b/tests/PhpWord/_files/images/earth.jpg similarity index 100% rename from tests/PhpWord/Tests/_files/images/earth.jpg rename to tests/PhpWord/_files/images/earth.jpg diff --git a/tests/PhpWord/Tests/_files/images/firefox.png b/tests/PhpWord/_files/images/firefox.png similarity index 100% rename from tests/PhpWord/Tests/_files/images/firefox.png rename to tests/PhpWord/_files/images/firefox.png diff --git a/tests/PhpWord/Tests/_files/images/mario.gif b/tests/PhpWord/_files/images/mario.gif similarity index 100% rename from tests/PhpWord/Tests/_files/images/mario.gif rename to tests/PhpWord/_files/images/mario.gif diff --git a/tests/PhpWord/Tests/_files/images/mars.jpg b/tests/PhpWord/_files/images/mars.jpg similarity index 100% rename from tests/PhpWord/Tests/_files/images/mars.jpg rename to tests/PhpWord/_files/images/mars.jpg diff --git a/tests/PhpWord/Tests/_files/images/mars_noext_jpg b/tests/PhpWord/_files/images/mars_noext_jpg similarity index 100% rename from tests/PhpWord/Tests/_files/images/mars_noext_jpg rename to tests/PhpWord/_files/images/mars_noext_jpg diff --git a/tests/PhpWord/Tests/_files/templates/blank.docx b/tests/PhpWord/_files/templates/blank.docx similarity index 100% rename from tests/PhpWord/Tests/_files/templates/blank.docx rename to tests/PhpWord/_files/templates/blank.docx diff --git a/tests/PhpWord/Tests/_files/templates/clone-delete-block.docx b/tests/PhpWord/_files/templates/clone-delete-block.docx similarity index 100% rename from tests/PhpWord/Tests/_files/templates/clone-delete-block.docx rename to tests/PhpWord/_files/templates/clone-delete-block.docx diff --git a/tests/PhpWord/Tests/_files/templates/clone-merge.docx b/tests/PhpWord/_files/templates/clone-merge.docx similarity index 100% rename from tests/PhpWord/Tests/_files/templates/clone-merge.docx rename to tests/PhpWord/_files/templates/clone-merge.docx diff --git a/tests/PhpWord/Tests/_files/templates/corrupted_main_document_part.docx b/tests/PhpWord/_files/templates/corrupted_main_document_part.docx similarity index 100% rename from tests/PhpWord/Tests/_files/templates/corrupted_main_document_part.docx rename to tests/PhpWord/_files/templates/corrupted_main_document_part.docx diff --git a/tests/PhpWord/Tests/_files/templates/header-footer.docx b/tests/PhpWord/_files/templates/header-footer.docx similarity index 100% rename from tests/PhpWord/Tests/_files/templates/header-footer.docx rename to tests/PhpWord/_files/templates/header-footer.docx diff --git a/tests/PhpWord/_files/templates/with_table_macros.docx b/tests/PhpWord/_files/templates/with_table_macros.docx new file mode 100644 index 0000000000..4653c6f1f7 Binary files /dev/null and b/tests/PhpWord/_files/templates/with_table_macros.docx differ diff --git a/tests/PhpWord/Tests/_files/xsl/passthrough.xsl b/tests/PhpWord/_files/xsl/passthrough.xsl similarity index 76% rename from tests/PhpWord/Tests/_files/xsl/passthrough.xsl rename to tests/PhpWord/_files/xsl/passthrough.xsl index 4ab21dd745..b1d656a10f 100644 --- a/tests/PhpWord/Tests/_files/xsl/passthrough.xsl +++ b/tests/PhpWord/_files/xsl/passthrough.xsl @@ -1,6 +1,6 @@ +> diff --git a/tests/PhpWord/Tests/_files/xsl/remove_tables_by_needle.xsl b/tests/PhpWord/_files/xsl/remove_tables_by_needle.xsl similarity index 100% rename from tests/PhpWord/Tests/_files/xsl/remove_tables_by_needle.xsl rename to tests/PhpWord/_files/xsl/remove_tables_by_needle.xsl diff --git a/tests/PhpWord/Tests/_includes/TestHelperDOCX.php b/tests/PhpWord/_includes/TestHelperDOCX.php similarity index 83% rename from tests/PhpWord/Tests/_includes/TestHelperDOCX.php rename to tests/PhpWord/_includes/TestHelperDOCX.php index 2a0043d5c8..0307997427 100644 --- a/tests/PhpWord/Tests/_includes/TestHelperDOCX.php +++ b/tests/PhpWord/_includes/TestHelperDOCX.php @@ -11,16 +11,13 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; +namespace PhpOffice\PhpWord; use PhpOffice\PhpWord\Exception\CreateTemporaryFileException; -use PhpOffice\PhpWord\IOFactory; -use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Settings; /** * Test helper class @@ -41,7 +38,9 @@ class TestHelperDOCX * * @param \PhpOffice\PhpWord\PhpWord $phpWord * @param string $writerName - * @return \PhpOffice\PhpWord\Tests\XmlDocument + * + * @return \PhpOffice\PhpWord\XmlDocument + * * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException */ public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007') @@ -60,7 +59,7 @@ public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007') $zip = new \ZipArchive; $res = $zip->open(self::$file); - if ($res === true) { + if (true === $res) { $zip->extractTo(Settings::getTempDir() . '/PhpWord_Unit_Test/'); $zip->close(); } @@ -89,12 +88,12 @@ public static function clear() public static function deleteDir($dir) { foreach (scandir($dir) as $file) { - if ($file === '.' || $file === '..') { + if ('.' === $file || '..' === $file) { continue; - } elseif (is_file($dir . "/" . $file)) { - unlink($dir . "/" . $file); - } elseif (is_dir($dir . "/" . $file)) { - self::deleteDir($dir . "/" . $file); + } elseif (is_file($dir . '/' . $file)) { + unlink($dir . '/' . $file); + } elseif (is_dir($dir . '/' . $file)) { + self::deleteDir($dir . '/' . $file); } } diff --git a/tests/PhpWord/Tests/_includes/XmlDocument.php b/tests/PhpWord/_includes/XmlDocument.php similarity index 95% rename from tests/PhpWord/Tests/_includes/XmlDocument.php rename to tests/PhpWord/_includes/XmlDocument.php index 2e161bb1a5..72b18c29aa 100644 --- a/tests/PhpWord/Tests/_includes/XmlDocument.php +++ b/tests/PhpWord/_includes/XmlDocument.php @@ -11,11 +11,11 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ -namespace PhpOffice\PhpWord\Tests; +namespace PhpOffice\PhpWord; /** * DOM wrapper class @@ -90,7 +90,7 @@ public function getFileDom($file = 'word/document.xml') */ public function getNodeList($path, $file = 'word/document.xml') { - if ($this->dom === null || $file !== $this->file) { + if (null === $this->dom || $file !== $this->file) { $this->getFileDom($file); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4932a21b26..60ca5ae771 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,10 +11,12 @@ * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. test bootstrap * * @link https://github.com/PHPOffice/PHPWord - * @copyright 2010-2014 PHPWord contributors + * @copyright 2010-2016 PHPWord contributors * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 */ +require_once __DIR__ . '/../bootstrap.php'; + date_default_timezone_set('UTC'); // defining base dir for tests @@ -22,19 +24,12 @@ define('PHPWORD_TESTS_BASE_DIR', realpath(__DIR__)); } -$vendor = realpath(__DIR__ . '/../vendor'); -if (file_exists($vendor . '/autoload.php')) { - require $vendor . '/autoload.php'; -} else { - throw new Exception('Unable to load dependencies'); -} - spl_autoload_register(function ($class) { $class = ltrim($class, '\\'); - $prefix = 'PhpOffice\\PhpWord\\Tests'; + $prefix = 'PhpOffice\\PhpWord'; if (strpos($class, $prefix) === 0) { $class = str_replace('\\', DIRECTORY_SEPARATOR, $class); - $class = join(DIRECTORY_SEPARATOR, array('PhpWord', 'Tests', '_includes')) . + $class = join(DIRECTORY_SEPARATOR, array('PhpWord', '_includes')) . substr($class, strlen($prefix)); $file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php'; if (file_exists($file)) { @@ -42,6 +37,3 @@ } } }); - -require_once __DIR__ . '/../src/PhpWord/Autoloader.php'; -\PhpOffice\PhpWord\Autoloader::register();