Merge branch 'develop' into #140-bskrtich-pclzip
This commit is contained in:
commit
71b60e9bd5
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -7,15 +7,22 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
|
|||
### Features
|
||||
|
||||
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
|
||||
- Table: Add tblGrid element for Libre/Open Office table sizing - @gianis6 GH-183
|
||||
- Table: Add `tblGrid` element for Libre/Open Office table sizing - @gianis6 GH-183
|
||||
- Footnote: Ability to insert textbreak in footnote `$footnote->addTextBreak()` - @ivanlanin
|
||||
- Footnote: Ability to style footnote reference mark by using `FootnoteReference` style - @ivanlanin
|
||||
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
|
||||
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
|
||||
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
|
||||
|
||||
### Bugfixes
|
||||
|
||||
-
|
||||
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- Documentation: Simplify page level docblock - @ivanlanin GH-179
|
||||
- Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160
|
||||
- Reader: Rename AbstractReader > Reader - @ivanlanin
|
||||
|
||||
## 0.9.1 - 27 Mar 2014
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@
|
|||
{
|
||||
"name": "Ivan Lanin",
|
||||
"homepage": "http://ivan.lanin.org"
|
||||
},
|
||||
{
|
||||
"name": "Roman Syroeshko",
|
||||
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ Available font styles:
|
|||
- ``strikethrough`` 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*
|
||||
|
||||
Paragraph style
|
||||
^^^^^^^^^^^^^^^
|
||||
|
|
@ -201,27 +202,28 @@ 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
|
||||
- ``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*
|
||||
- ``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*
|
||||
|
||||
Cell span
|
||||
~~~~~~~~~
|
||||
|
|
@ -326,7 +328,8 @@ Footnotes
|
|||
---------
|
||||
|
||||
You can create footnotes in texts or textruns, but it's recommended to
|
||||
use textrun to have better layout.
|
||||
use textrun to have better layout. You can use ``addText``, ``addLink``,
|
||||
and ``addTextBreak`` on a footnote.
|
||||
|
||||
On textrun:
|
||||
|
||||
|
|
@ -335,7 +338,11 @@ On textrun:
|
|||
$textrun = $section->createTextRun();
|
||||
$textrun->addText('Lead text.');
|
||||
$footnote = $textrun->createFootnote();
|
||||
$footnote->addText('Footnote text.');
|
||||
$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.');
|
||||
|
||||
On text:
|
||||
|
|
@ -345,3 +352,23 @@ On text:
|
|||
$section->addText('Lead text.');
|
||||
$footnote = $section->createFootnote();
|
||||
$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``.
|
||||
|
||||
.. 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.
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ $footnote->addText(' No break is placed after adding an element.', 'BoldText');
|
|||
$footnote->addText(' All elements are placed inside a paragraph.', 'ColoredText');
|
||||
$footnote->addText(' The best search engine: ');
|
||||
$footnote->addLink('http://www.google.com', null, 'NLink');
|
||||
$footnote->addText('. Also not bad: ');
|
||||
$footnote->addText('. Also not bad:');
|
||||
$footnote->addTextBreak();
|
||||
$footnote->addLink('http://www.bing.com', null, 'NLink');
|
||||
|
||||
$textrun->addText('The trailing text in the paragraph.');
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ $section->addTextBreak(2);
|
|||
|
||||
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
||||
$section->addText("Remote image from: {$source}");
|
||||
$section->addMemoryImage($source);
|
||||
$section->addImage($source);
|
||||
// End code
|
||||
|
||||
// Save file
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", \EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
|
||||
$section->addText("This is some text highlighted using fgColor (limited to 15 colors) ", array("fgColor" => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW));
|
||||
$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
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", \EOL;
|
||||
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
|
||||
$xmlWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
include_once 'Sample_Footer.php';
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", \EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
|
||||
$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("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"));
|
||||
|
||||
$section->addTextBreak();
|
||||
$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:");
|
||||
|
||||
$table2 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
|
||||
$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"));
|
||||
|
||||
$section->addTextBreak();
|
||||
$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
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", \EOL;
|
||||
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
|
||||
$xmlWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
include_once 'Sample_Footer.php';
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", \EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->createSection();
|
||||
$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', 'Checkbox 2');
|
||||
|
||||
// Save file
|
||||
$name = basename(__FILE__, '.php');
|
||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||
foreach ($writers as $writer => $extension) {
|
||||
echo date('H:i:s'), " Write to {$writer} format", \EOL;
|
||||
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
|
||||
$xmlWriter->save("{$name}.{$extension}");
|
||||
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||
}
|
||||
|
||||
include_once 'Sample_Footer.php';
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* Footer file
|
||||
*/
|
||||
// Do not show execution time for index
|
||||
if (!$isIndexFile) {
|
||||
if (!IS_INDEX) {
|
||||
echo date('H:i:s'), " Done writing file(s)", EOL;
|
||||
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
|
||||
}
|
||||
|
|
@ -11,12 +11,12 @@ if (!$isIndexFile) {
|
|||
if (CLI) {
|
||||
echo 'The results are stored in the "results" subdirectory.', EOL;
|
||||
} else {
|
||||
if (!$isIndexFile) {
|
||||
if (!IS_INDEX) {
|
||||
$types = array('docx', 'odt', 'rtf');
|
||||
echo '<p> </p>';
|
||||
echo '<p>Results: ';
|
||||
foreach ($types as $type) {
|
||||
$result = "results/{$sampleFile}.{$type}";
|
||||
$result = 'results/' . SCRIPT_FILENAME . '.' . $type;
|
||||
if (file_exists($result)) {
|
||||
echo "<a href='{$result}' class='btn btn-primary'>{$type}</a> ";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
error_reporting(E_ALL);
|
||||
define('CLI', (PHP_SAPI == 'cli') ? true : false);
|
||||
define('EOL', CLI ? PHP_EOL : '<br />');
|
||||
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
|
||||
define('IS_INDEX', SCRIPT_FILENAME == 'index');
|
||||
|
||||
require_once '../src/PhpWord/Autoloader.php';
|
||||
PhpOffice\PhpWord\Autoloader::register();
|
||||
|
|
@ -15,12 +17,10 @@ if (CLI) {
|
|||
}
|
||||
|
||||
// Set titles and names
|
||||
$sampleFile = basename($_SERVER['SCRIPT_FILENAME'], '.php');
|
||||
$isIndexFile = ($sampleFile == 'index');
|
||||
$pageHeading = str_replace('_', ' ', $sampleFile);
|
||||
$pageTitle = $isIndexFile ? 'Welcome to ' : "{$pageHeading} - ";
|
||||
$pageHeading = str_replace('_', ' ', SCRIPT_FILENAME);
|
||||
$pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - ";
|
||||
$pageTitle .= 'PHPWord';
|
||||
$pageHeading = $isIndexFile ? '' : "<h1>{$pageHeading}</h1>";
|
||||
$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>";
|
||||
// Populate samples
|
||||
$files = '';
|
||||
if ($handle = opendir('.')) {
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ class DocumentProperties
|
|||
/**
|
||||
* Created
|
||||
*
|
||||
* @var datetime
|
||||
* @var datetime|int
|
||||
*/
|
||||
private $_created;
|
||||
|
||||
/**
|
||||
* Modified
|
||||
*
|
||||
* @var datetime
|
||||
* @var datetime|int
|
||||
*/
|
||||
private $_modified;
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ class DocumentProperties
|
|||
/**
|
||||
* Custom Properties
|
||||
*
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
private $_customProperties = array();
|
||||
|
||||
|
|
@ -476,41 +476,33 @@ class DocumentProperties
|
|||
switch ($propertyType) {
|
||||
case 'empty': // Empty
|
||||
return '';
|
||||
break;
|
||||
case 'null': // Null
|
||||
return null;
|
||||
break;
|
||||
case 'i1': // 1-Byte Signed Integer
|
||||
case 'i2': // 2-Byte Signed Integer
|
||||
case 'i4': // 4-Byte Signed Integer
|
||||
case 'i8': // 8-Byte Signed Integer
|
||||
case 'int': // Integer
|
||||
return (int) $propertyValue;
|
||||
break;
|
||||
case 'ui1': // 1-Byte Unsigned Integer
|
||||
case 'ui2': // 2-Byte Unsigned Integer
|
||||
case 'ui4': // 4-Byte Unsigned Integer
|
||||
case 'ui8': // 8-Byte Unsigned Integer
|
||||
case 'uint': // Unsigned Integer
|
||||
return abs((int) $propertyValue);
|
||||
break;
|
||||
case 'r4': // 4-Byte Real Number
|
||||
case 'r8': // 8-Byte Real Number
|
||||
case 'decimal': // Decimal
|
||||
return (float) $propertyValue;
|
||||
break;
|
||||
case 'lpstr': // LPSTR
|
||||
case 'lpwstr': // LPWSTR
|
||||
case 'bstr': // Basic String
|
||||
return $propertyValue;
|
||||
break;
|
||||
case 'date': // Date and Time
|
||||
case 'filetime': // File Time
|
||||
return strtotime($propertyValue);
|
||||
break;
|
||||
case 'bool': // Boolean
|
||||
return ($propertyValue == 'true') ? true : false;
|
||||
break;
|
||||
case 'cy': // Currency
|
||||
case 'error': // Error Status Code
|
||||
case 'vector': // Vector
|
||||
|
|
@ -525,7 +517,6 @@ class DocumentProperties
|
|||
case 'clsid': // Class ID
|
||||
case 'cf': // Clipboard Data
|
||||
return $propertyValue;
|
||||
break;
|
||||
}
|
||||
|
||||
return $propertyValue;
|
||||
|
|
@ -551,26 +542,21 @@ class DocumentProperties
|
|||
case 'ui8': // 8-Byte Unsigned Integer
|
||||
case 'uint': // Unsigned Integer
|
||||
return self::PROPERTY_TYPE_INTEGER;
|
||||
break;
|
||||
case 'r4': // 4-Byte Real Number
|
||||
case 'r8': // 8-Byte Real Number
|
||||
case 'decimal': // Decimal
|
||||
return self::PROPERTY_TYPE_FLOAT;
|
||||
break;
|
||||
case 'empty': // Empty
|
||||
case 'null': // Null
|
||||
case 'lpstr': // LPSTR
|
||||
case 'lpwstr': // LPWSTR
|
||||
case 'bstr': // Basic String
|
||||
return self::PROPERTY_TYPE_STRING;
|
||||
break;
|
||||
case 'date': // Date and Time
|
||||
case 'filetime': // File Time
|
||||
return self::PROPERTY_TYPE_DATE;
|
||||
break;
|
||||
case 'bool': // Boolean
|
||||
return self::PROPERTY_TYPE_BOOLEAN;
|
||||
break;
|
||||
case 'cy': // Currency
|
||||
case 'error': // Error Status Code
|
||||
case 'vector': // Vector
|
||||
|
|
@ -585,7 +571,6 @@ class DocumentProperties
|
|||
case 'clsid': // Class ID
|
||||
case 'cf': // Clipboard Data
|
||||
return self::PROPERTY_TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
return self::PROPERTY_TYPE_UNKNOWN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ class Media
|
|||
$cImg = self::countFooterMediaElements($key);
|
||||
$rID = $cImg + 1;
|
||||
$cImg++;
|
||||
$media = array();
|
||||
$isMemImage = false;
|
||||
if (!is_null($image)) {
|
||||
$isMemImage = $image->getIsMemImage();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use PhpOffice\PhpWord\Exceptions\Exception;
|
|||
*
|
||||
* @codeCoverageIgnore Abstract class
|
||||
*/
|
||||
abstract class AbstractReader implements IReader
|
||||
abstract class Reader implements IReader
|
||||
{
|
||||
/**
|
||||
* Read data only?
|
||||
|
|
@ -17,7 +17,7 @@ use PhpOffice\PhpWord\Exceptions\Exception;
|
|||
/**
|
||||
* Reader for Word2007
|
||||
*/
|
||||
class Word2007 extends AbstractReader implements IReader
|
||||
class Word2007 extends Reader implements IReader
|
||||
{
|
||||
/**
|
||||
* Can the current IReader read the file?
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use PhpOffice\PhpWord\Section\Text;
|
|||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Section\TextRun;
|
||||
use PhpOffice\PhpWord\Section\Title;
|
||||
use PhpOffice\PhpWord\Section\CheckBox;
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
|
||||
/**
|
||||
|
|
@ -115,7 +116,7 @@ class Section
|
|||
*/
|
||||
public function addText($text, $styleFont = null, $styleParagraph = null)
|
||||
{
|
||||
if (!String::IsUTF8($text)) {
|
||||
if (!String::isUTF8($text)) {
|
||||
$text = utf8_encode($text);
|
||||
}
|
||||
$text = new Text($text, $styleFont, $styleParagraph);
|
||||
|
|
@ -134,11 +135,11 @@ class Section
|
|||
*/
|
||||
public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
|
||||
{
|
||||
if (!String::IsUTF8($linkSrc)) {
|
||||
if (!String::isUTF8($linkSrc)) {
|
||||
$linkSrc = utf8_encode($linkSrc);
|
||||
}
|
||||
if (!is_null($linkName)) {
|
||||
if (!String::IsUTF8($linkName)) {
|
||||
if (!String::isUTF8($linkName)) {
|
||||
$linkName = utf8_encode($linkName);
|
||||
}
|
||||
}
|
||||
|
|
@ -413,4 +414,27 @@ class Section
|
|||
$this->_elementCollection[] = $footnote;
|
||||
return $footnote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a CheckBox Element
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $text
|
||||
* @param mixed $styleFont
|
||||
* @param mixed $styleParagraph
|
||||
* @return \PhpOffice\PhpWord\Section\CheckBox
|
||||
*/
|
||||
public function addCheckBox($name, $text, $styleFont = null, $styleParagraph = null)
|
||||
{
|
||||
if (!String::isUTF8($name)) {
|
||||
$name = utf8_encode($name);
|
||||
}
|
||||
if (!String::isUTF8($text)) {
|
||||
$text = utf8_encode($text);
|
||||
}
|
||||
$element = new CheckBox($name, $text, $styleFont, $styleParagraph);
|
||||
$this->_elementCollection[] = $element;
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Section;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
/**
|
||||
* Check box element
|
||||
*/
|
||||
class CheckBox
|
||||
{
|
||||
/**
|
||||
* Name content
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Text content
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $text;
|
||||
|
||||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var string|Font
|
||||
*/
|
||||
private $fontStyle;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $paragraphStyle;
|
||||
|
||||
/**
|
||||
* Create a new Text Element
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $text
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
$this->setName($name);
|
||||
$this->setText($text);
|
||||
$paragraphStyle = $this->setParagraphStyle($paragraphStyle);
|
||||
$this->setFontStyle($fontStyle, $paragraphStyle);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Text style
|
||||
*
|
||||
* @param mixed $style
|
||||
* @param mixed $paragraphStyle
|
||||
* @return string|Font
|
||||
*/
|
||||
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||
{
|
||||
if ($style instanceof Font) {
|
||||
$this->fontStyle = $style;
|
||||
$this->setParagraphStyle($paragraphStyle);
|
||||
} elseif (is_array($style)) {
|
||||
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||
$this->fontStyle->setArrayStyle($style);
|
||||
} elseif (null === $style) {
|
||||
$this->fontStyle = new Font('text', $paragraphStyle);
|
||||
} else {
|
||||
$this->fontStyle = $style;
|
||||
$this->setParagraphStyle($paragraphStyle);
|
||||
}
|
||||
return $this->fontStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
return $this->fontStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Paragraph style
|
||||
*
|
||||
* @param mixed $style
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function setParagraphStyle($style = null)
|
||||
{
|
||||
if (is_array($style)) {
|
||||
$this->paragraphStyle = new Paragraph;
|
||||
$this->paragraphStyle->setArrayStyle($style);
|
||||
} elseif ($style instanceof Paragraph) {
|
||||
$this->paragraphStyle = $style;
|
||||
} elseif (null === $style) {
|
||||
$this->paragraphStyle = new Paragraph;
|
||||
} else {
|
||||
$this->paragraphStyle = $style;
|
||||
}
|
||||
return $this->paragraphStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
return $this->paragraphStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name content
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text content
|
||||
*
|
||||
* @param string $text
|
||||
* @return $this
|
||||
*/
|
||||
public function setText($text)
|
||||
{
|
||||
$this->text = $text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,14 +27,14 @@ class PreserveText
|
|||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $_styleFont;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $_styleParagraph;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class PreserveText
|
|||
* @param string $text
|
||||
* @param mixed $styleFont
|
||||
* @param mixed $styleParagraph
|
||||
* @return PHPWord_Section_Footer_PreserveText
|
||||
* @return $this
|
||||
*/
|
||||
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
|
||||
{
|
||||
|
|
@ -88,7 +88,7 @@ class PreserveText
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -98,7 +98,7 @@ class PreserveText
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -77,6 +77,20 @@ class Footnote
|
|||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add TextBreak
|
||||
*
|
||||
* @param int $count
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Link Element
|
||||
*
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ class Link
|
|||
/**
|
||||
* Link style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $_styleFont;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $_styleParagraph;
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ class Link
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -150,7 +150,7 @@ class Link
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use PhpOffice\PhpWord\Section\Object;
|
|||
use PhpOffice\PhpWord\Section\Text;
|
||||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Section\TextRun;
|
||||
use PhpOffice\PhpWord\Section\CheckBox;
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
|
||||
/**
|
||||
|
|
@ -290,6 +291,28 @@ class Cell
|
|||
return $textRun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a CheckBox Element
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $text
|
||||
* @param mixed $styleFont
|
||||
* @param mixed $styleParagraph
|
||||
* @return \PhpOffice\PhpWord\Section\CheckBox
|
||||
*/
|
||||
public function addCheckBox($name, $text, $styleFont = null, $styleParagraph = null)
|
||||
{
|
||||
if (!String::isUTF8($name)) {
|
||||
$name = utf8_encode($name);
|
||||
}
|
||||
if (!String::isUTF8($text)) {
|
||||
$text = utf8_encode($text);
|
||||
}
|
||||
$text = new CheckBox($name, $text, $styleFont, $styleParagraph);
|
||||
$this->_elementCollection[] = $text;
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Elements
|
||||
*
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ class Text
|
|||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $fontStyle;
|
||||
|
||||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $paragraphStyle;
|
||||
|
||||
|
|
@ -42,8 +42,8 @@ class Text
|
|||
* Create a new Text Element
|
||||
*
|
||||
* @param string $text
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Font $fontStyle
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -55,9 +55,9 @@ class Text
|
|||
/**
|
||||
* Set Text style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @param string|array|Font $style
|
||||
* @param string|array|Paragraph $paragraphStyle
|
||||
* @return string|Font
|
||||
*/
|
||||
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -79,7 +79,7 @@ class Text
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -89,8 +89,8 @@ class Text
|
|||
/**
|
||||
* Set Paragraph style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
|
||||
* @return null|\PhpOffice\PhpWord\Style\Paragraph
|
||||
* @param string|array|Paragraph $style
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function setParagraphStyle($style = null)
|
||||
{
|
||||
|
|
@ -110,7 +110,7 @@ class Text
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ class TextBreak
|
|||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Pagaraph
|
||||
* @var string|Paragraph
|
||||
*/
|
||||
private $paragraphStyle = null;
|
||||
|
||||
/**
|
||||
* Text style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Font
|
||||
* @var string|Font
|
||||
*/
|
||||
private $fontStyle = null;
|
||||
|
||||
|
|
@ -50,9 +50,9 @@ class TextBreak
|
|||
/**
|
||||
* Set Text style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Font $style
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @param mixed $style
|
||||
* @param mixed $paragraphStyle
|
||||
* @return string|Font
|
||||
*/
|
||||
public function setFontStyle($style = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -72,7 +72,7 @@ class TextBreak
|
|||
/**
|
||||
* Get Text style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return string|Font
|
||||
*/
|
||||
public function getFontStyle()
|
||||
{
|
||||
|
|
@ -82,8 +82,8 @@ class TextBreak
|
|||
/**
|
||||
* Set Paragraph style
|
||||
*
|
||||
* @param null|array|\PhpOffice\PhpWord\Style\Paragraph $style
|
||||
* @return null|\PhpOffice\PhpWord\Style\Paragraph
|
||||
* @param string|array|Paragraph $style
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function setParagraphStyle($style = null)
|
||||
{
|
||||
|
|
@ -101,7 +101,7 @@ class TextBreak
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace PhpOffice\PhpWord\Section;
|
|||
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
|
||||
use PhpOffice\PhpWord\Media;
|
||||
use PhpOffice\PhpWord\Shared\String;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
||||
/**
|
||||
|
|
@ -22,7 +23,7 @@ class TextRun
|
|||
/**
|
||||
* Paragraph style
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @var Paragraph
|
||||
*/
|
||||
private $_styleParagraph;
|
||||
|
||||
|
|
@ -123,8 +124,8 @@ class TextRun
|
|||
* Add TextBreak
|
||||
*
|
||||
* @param int $count
|
||||
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
|
||||
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
|
||||
* @param mixed $fontStyle
|
||||
* @param mixed $paragraphStyle
|
||||
*/
|
||||
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
|
||||
{
|
||||
|
|
@ -161,7 +162,7 @@ class TextRun
|
|||
/**
|
||||
* Get Paragraph style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @return string|Paragraph
|
||||
*/
|
||||
public function getParagraphStyle()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ if (!defined('DATE_W3C')) {
|
|||
/**
|
||||
* XMLWriter wrapper
|
||||
*
|
||||
* @method bool writeElement(string $name, string $content = null)
|
||||
* @method bool startElement(string $name)
|
||||
* @method bool writeAttribute(string $name, string $value)
|
||||
* @method bool endElement()
|
||||
|
|
|
|||
|
|
@ -135,6 +135,18 @@ class Font
|
|||
*/
|
||||
private $_fgColor = null;
|
||||
|
||||
/**
|
||||
* Background color
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_bgColor = null;
|
||||
/**
|
||||
* Text line height
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
/**
|
||||
* Text line height
|
||||
*
|
||||
|
|
@ -454,6 +466,28 @@ class Font
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background color
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBgColor()
|
||||
{
|
||||
return $this->_bgColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background color
|
||||
*
|
||||
* @param string $pValue
|
||||
* @return $this
|
||||
*/
|
||||
public function setBgColor($pValue = null)
|
||||
{
|
||||
$this->_bgColor = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style type
|
||||
*
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@ class Row
|
|||
*/
|
||||
private $_cantSplit = false;
|
||||
|
||||
/**
|
||||
* Table row exact height
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_exactHeight = false;
|
||||
|
||||
/**
|
||||
* Create a new row style
|
||||
*/
|
||||
|
|
@ -50,7 +57,7 @@ class Row
|
|||
* Set tblHeader
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @return PHPWord_Style_Row
|
||||
* @return $this
|
||||
*/
|
||||
public function setTblHeader($pValue = false)
|
||||
{
|
||||
|
|
@ -75,7 +82,7 @@ class Row
|
|||
* Set cantSplit
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @return PHPWord_Style_Row
|
||||
* @return $this
|
||||
*/
|
||||
public function setCantSplit($pValue = false)
|
||||
{
|
||||
|
|
@ -95,4 +102,29 @@ class Row
|
|||
{
|
||||
return $this->_cantSplit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set exactHeight
|
||||
*
|
||||
* @param bool $pValue
|
||||
* @return $this
|
||||
*/
|
||||
public function setExactHeight($pValue = false)
|
||||
{
|
||||
if (!is_bool($pValue)) {
|
||||
$pValue = false;
|
||||
}
|
||||
$this->_exactHeight = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get exactHeight
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getExactHeight()
|
||||
{
|
||||
return $this->_exactHeight;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
namespace PhpOffice\PhpWord;
|
||||
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\TOC as TOCStyle;
|
||||
|
||||
/**
|
||||
* Table of contents
|
||||
|
|
@ -26,14 +27,14 @@ class TOC
|
|||
/**
|
||||
* TOC style
|
||||
*
|
||||
* @var PhpOffice\PhpWord\Style\TOC
|
||||
* @var TOCStyle
|
||||
*/
|
||||
private static $_styleTOC;
|
||||
|
||||
/**
|
||||
* Font style
|
||||
*
|
||||
* @var PhpOffice\PhpWord\Style\Font|array|string
|
||||
* @var Font|array|string
|
||||
*/
|
||||
private static $_styleFont;
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ class TOC
|
|||
*/
|
||||
public function __construct($styleFont = null, $styleTOC = null)
|
||||
{
|
||||
self::$_styleTOC = new \PhpOffice\PhpWord\Style\TOC();
|
||||
self::$_styleTOC = new TOCStyle();
|
||||
|
||||
if (!is_null($styleTOC) && is_array($styleTOC)) {
|
||||
foreach ($styleTOC as $key => $value) {
|
||||
|
|
@ -122,7 +123,7 @@ class TOC
|
|||
/**
|
||||
* Get TOC Style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\TOC
|
||||
* @return TOCStyle
|
||||
*/
|
||||
public static function getStyleTOC()
|
||||
{
|
||||
|
|
@ -132,7 +133,7 @@ class TOC
|
|||
/**
|
||||
* Get Font Style
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Style\Font
|
||||
* @return Font
|
||||
*/
|
||||
public static function getStyleFont()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,91 +22,48 @@ use PhpOffice\PhpWord\Writer\ODText\Styles;
|
|||
/**
|
||||
* ODText writer
|
||||
*/
|
||||
class ODText implements IWriter
|
||||
class ODText extends Writer implements IWriter
|
||||
{
|
||||
/**
|
||||
* PHPWord object
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
private $_document;
|
||||
|
||||
/**
|
||||
* Individual writers
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Writer\ODText\WriterPart[]
|
||||
*/
|
||||
private $_writerParts;
|
||||
|
||||
/**
|
||||
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\HashTable
|
||||
* @var HashTable
|
||||
*/
|
||||
private $_drawingHashTable;
|
||||
|
||||
/**
|
||||
* Use disk caching where possible?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_useDiskCaching = false;
|
||||
|
||||
/**
|
||||
* Disk caching directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_diskCachingDirectory;
|
||||
private $drawingHashTable;
|
||||
|
||||
/**
|
||||
* Create new ODText writer
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
{
|
||||
// Assign PhpWord
|
||||
$this->setPhpWord($phpWord);
|
||||
|
||||
// Set up disk caching location
|
||||
$this->_diskCachingDirectory = './';
|
||||
|
||||
// Initialise writer parts
|
||||
$this->_writerParts['content'] = new Content();
|
||||
$this->_writerParts['manifest'] = new Manifest();
|
||||
$this->_writerParts['meta'] = new Meta();
|
||||
$this->_writerParts['mimetype'] = new Mimetype();
|
||||
$this->_writerParts['styles'] = new Styles();
|
||||
|
||||
|
||||
// Assign parent IWriter
|
||||
foreach ($this->_writerParts as $writer) {
|
||||
// Set writer parts
|
||||
$this->writerParts['content'] = new Content();
|
||||
$this->writerParts['manifest'] = new Manifest();
|
||||
$this->writerParts['meta'] = new Meta();
|
||||
$this->writerParts['mimetype'] = new Mimetype();
|
||||
$this->writerParts['styles'] = new Styles();
|
||||
foreach ($this->writerParts as $writer) {
|
||||
$writer->setParentWriter($this);
|
||||
}
|
||||
|
||||
// Set HashTable variables
|
||||
$this->_drawingHashTable = new HashTable();
|
||||
$this->drawingHashTable = new HashTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save PhpWord to file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save($pFilename = null)
|
||||
{
|
||||
if (!is_null($this->_document)) {
|
||||
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
||||
$originalFilename = $pFilename;
|
||||
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
|
||||
$pFilename = @tempnam('./', 'phppttmp');
|
||||
if ($pFilename == '') {
|
||||
$pFilename = $originalFilename;
|
||||
}
|
||||
}
|
||||
|
||||
// Create drawing dictionary
|
||||
if (!is_null($this->phpWord)) {
|
||||
$pFilename = $this->getTempFile($pFilename);
|
||||
|
||||
// Create new ZIP file and open it for writing
|
||||
$zipClass = Settings::getZipClass();
|
||||
|
|
@ -132,19 +89,19 @@ class ODText implements IWriter
|
|||
|
||||
// Add mimetype to ZIP file
|
||||
//@todo Not in \ZipArchive::CM_STORE mode
|
||||
$objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype($this->_document));
|
||||
$objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->writeMimetype($this->phpWord));
|
||||
|
||||
// Add content.xml to ZIP file
|
||||
$objZip->addFromString('content.xml', $this->getWriterPart('content')->writeContent($this->_document));
|
||||
$objZip->addFromString('content.xml', $this->getWriterPart('content')->writeContent($this->phpWord));
|
||||
|
||||
// Add meta.xml to ZIP file
|
||||
$objZip->addFromString('meta.xml', $this->getWriterPart('meta')->writeMeta($this->_document));
|
||||
$objZip->addFromString('meta.xml', $this->getWriterPart('meta')->writeMeta($this->phpWord));
|
||||
|
||||
// Add styles.xml to ZIP file
|
||||
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document));
|
||||
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->writeStyles($this->phpWord));
|
||||
|
||||
// Add META-INF/manifest.xml
|
||||
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->_document));
|
||||
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->phpWord));
|
||||
|
||||
// Add media. Has not used yet. Legacy from PHPExcel.
|
||||
// @codeCoverageIgnoreStart
|
||||
|
|
@ -187,111 +144,19 @@ class ODText implements IWriter
|
|||
throw new Exception("Could not close zip file $pFilename.");
|
||||
}
|
||||
|
||||
// If a temporary file was used, copy it to the correct file stream
|
||||
if ($originalFilename != $pFilename) {
|
||||
if (copy($pFilename, $originalFilename) === false) {
|
||||
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
|
||||
}
|
||||
@unlink($pFilename);
|
||||
}
|
||||
|
||||
$this->cleanupTempFile();
|
||||
} else {
|
||||
throw new Exception("PhpWord object unassigned.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PhpWord object
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\PhpWord
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function getPhpWord()
|
||||
{
|
||||
if (!is_null($this->_document)) {
|
||||
return $this->_document;
|
||||
} else {
|
||||
throw new Exception("No PhpWord assigned.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PhpWord object
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @return \PhpOffice\PhpWord\Writer\ODText
|
||||
*/
|
||||
public function setPhpWord(PhpWord $phpWord = null)
|
||||
{
|
||||
$this->_document = $phpWord;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\HashTable
|
||||
* @return HashTable
|
||||
*/
|
||||
public function getDrawingHashTable()
|
||||
{
|
||||
return $this->_drawingHashTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get writer part
|
||||
*
|
||||
* @param string $pPartName Writer part name
|
||||
* @return \PhpOffice\PhpWord\Writer\ODText\WriterPart
|
||||
*/
|
||||
public function getWriterPart($pPartName = '')
|
||||
{
|
||||
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) {
|
||||
return $this->_writerParts[strtolower($pPartName)];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get use disk caching where possible?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseDiskCaching()
|
||||
{
|
||||
return $this->_useDiskCaching;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set use disk caching where possible?
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @param string $pDirectory Disk caching directory
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception Exception when directory does not exist
|
||||
* @return \PhpOffice\PhpWord\Writer\ODText
|
||||
*/
|
||||
public function setUseDiskCaching($pValue = false, $pDirectory = null)
|
||||
{
|
||||
$this->_useDiskCaching = $pValue;
|
||||
|
||||
if (!is_null($pDirectory)) {
|
||||
if (is_dir($pDirectory)) {
|
||||
$this->_diskCachingDirectory = $pDirectory;
|
||||
} else {
|
||||
throw new Exception("Directory does not exist: $pDirectory");
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get disk caching directory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDiskCachingDirectory()
|
||||
{
|
||||
return $this->_diskCachingDirectory;
|
||||
return $this->drawingHashTable;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,18 +35,13 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write content file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeContent(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8');
|
||||
|
|
@ -131,7 +126,7 @@ class Content extends WriterPart
|
|||
$numFonts = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
$numFonts++;
|
||||
$name = $style->getName();
|
||||
|
|
@ -163,7 +158,7 @@ class Content extends WriterPart
|
|||
if (preg_match('#^T[0-9]+$#', $styleName) != 0
|
||||
|| preg_match('#^P[0-9]+$#', $styleName) != 0
|
||||
) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
$xmlWriter->startElement('style:style');
|
||||
$xmlWriter->writeAttribute('style:name', $styleName);
|
||||
|
|
@ -249,11 +244,11 @@ class Content extends WriterPart
|
|||
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter);
|
||||
$this->writeTextBreak($xmlWriter);
|
||||
} elseif ($element instanceof Link) {
|
||||
$this->writeUnsupportedElement($xmlWriter, 'Link');
|
||||
} elseif ($element instanceof Title) {
|
||||
|
|
@ -276,9 +271,9 @@ class Content extends WriterPart
|
|||
}
|
||||
|
||||
if ($pSection == $countSections) {
|
||||
$this->_writeEndSection($xmlWriter, $section);
|
||||
$this->writeEndSection($xmlWriter, $section);
|
||||
} else {
|
||||
$this->_writeSection($xmlWriter, $section);
|
||||
$this->writeSection($xmlWriter, $section);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -293,11 +288,11 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write text
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param \PhpOffice\PhpWord\Section\Text $text
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Text $text
|
||||
* @param bool $withoutP
|
||||
*/
|
||||
protected function _writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
|
||||
protected function writeText(XMLWriter $xmlWriter, Text $text, $withoutP = false)
|
||||
{
|
||||
$styleFont = $text->getFontStyle();
|
||||
$styleParagraph = $text->getParagraphStyle();
|
||||
|
|
@ -341,18 +336,18 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write TextRun section
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param \PhpOffice\PhpWord\Section\TextRun $textrun
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param TextRun $textrun
|
||||
* @todo Enable all other section types
|
||||
*/
|
||||
protected function _writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
|
||||
protected function writeTextRun(XMLWriter $xmlWriter, TextRun $textrun)
|
||||
{
|
||||
$elements = $textrun->getElements();
|
||||
$xmlWriter->startElement('text:p');
|
||||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element, true);
|
||||
$this->writeText($xmlWriter, $element, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -362,9 +357,9 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write TextBreak
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
*/
|
||||
protected function _writeTextBreak(XMLWriter $xmlWriter = null)
|
||||
protected function writeTextBreak(XMLWriter $xmlWriter = null)
|
||||
{
|
||||
$xmlWriter->startElement('text:p');
|
||||
$xmlWriter->writeAttribute('text:style-name', 'Standard');
|
||||
|
|
@ -375,20 +370,20 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write end section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Write section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
private function writeSection(XMLWriter $xmlWriter = null, Section $section = null)
|
||||
{
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
|
@ -396,7 +391,7 @@ class Content extends WriterPart
|
|||
/**
|
||||
* Write unsupported element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param string $element
|
||||
*/
|
||||
private function writeUnsupportedElement($xmlWriter, $element)
|
||||
|
|
|
|||
|
|
@ -21,18 +21,13 @@ class Manifest extends WriterPart
|
|||
/**
|
||||
* Write Manifest file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeManifest(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8');
|
||||
|
|
@ -69,7 +64,7 @@ class Manifest extends WriterPart
|
|||
for ($i = 0; $i < $this->getParentWriter()->getDrawingHashTable()->count(); ++$i) {
|
||||
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
|
||||
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension());
|
||||
$mimeType = $this->_getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
|
||||
$mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath());
|
||||
|
||||
$xmlWriter->startElement('manifest:file-entry');
|
||||
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
|
||||
|
|
@ -102,9 +97,9 @@ class Manifest extends WriterPart
|
|||
*
|
||||
* @param string $pFile Filename
|
||||
* @return string Mime Type
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private function _getImageMimeType($pFile = '')
|
||||
private function getImageMimeType($pFile = '')
|
||||
{
|
||||
if (file_exists($pFile)) {
|
||||
$image = getimagesize($pFile);
|
||||
|
|
|
|||
|
|
@ -20,18 +20,13 @@ class Meta extends WriterPart
|
|||
/**
|
||||
* Write Meta file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeMeta(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8');
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Mimetype extends WriterPart
|
|||
/**
|
||||
* Write Mimetype to Text format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string Text Output
|
||||
*/
|
||||
public function writeMimetype(PhpWord $phpWord = null)
|
||||
|
|
|
|||
|
|
@ -24,18 +24,13 @@ class Styles extends WriterPart
|
|||
/**
|
||||
* Write Styles file to XML format
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
* @return string XML Output
|
||||
*/
|
||||
public function writeStyles(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8');
|
||||
|
|
@ -78,7 +73,7 @@ class Styles extends WriterPart
|
|||
$numFonts = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
$numFonts++;
|
||||
$name = $style->getName();
|
||||
|
|
@ -149,7 +144,7 @@ class Styles extends WriterPart
|
|||
if (preg_match('#^T[0-9]+$#', $styleName) == 0
|
||||
&& preg_match('#^P[0-9]+$#', $styleName) == 0
|
||||
) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
// style:style
|
||||
$xmlWriter->startElement('style:style');
|
||||
|
|
@ -173,7 +168,7 @@ class Styles extends WriterPart
|
|||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
} elseif ($style instanceof Paragraph) {
|
||||
// PhpOffice\PhpWord\Style\Paragraph
|
||||
// Paragraph
|
||||
// style:style
|
||||
$xmlWriter->startElement('style:style');
|
||||
$xmlWriter->writeAttribute('style:name', $styleName);
|
||||
|
|
@ -188,7 +183,7 @@ class Styles extends WriterPart
|
|||
|
||||
$xmlWriter->endElement();
|
||||
} elseif ($style instanceof Table) {
|
||||
// PhpOffice\PhpWord\Style\Table
|
||||
// Table
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,43 +9,9 @@
|
|||
|
||||
namespace PhpOffice\PhpWord\Writer\ODText;
|
||||
|
||||
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||
use PhpOffice\PhpWord\Writer\IWriter;
|
||||
|
||||
/**
|
||||
* ODText writer part abstract
|
||||
*/
|
||||
abstract class WriterPart
|
||||
abstract class WriterPart extends \PhpOffice\PhpWord\Writer\Word2007\WriterPart
|
||||
{
|
||||
/**
|
||||
* Parent IWriter object
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Writer\IWriter
|
||||
*/
|
||||
private $_parentWriter;
|
||||
|
||||
/**
|
||||
* Set parent IWriter object
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Writer\IWriter $pWriter
|
||||
*/
|
||||
public function setParentWriter(IWriter $pWriter = null)
|
||||
{
|
||||
$this->_parentWriter = $pWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent IWriter object
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\Writer\IWriter
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function getParentWriter()
|
||||
{
|
||||
if (!is_null($this->_parentWriter)) {
|
||||
return $this->_parentWriter;
|
||||
} else {
|
||||
throw new Exception("No parent IWriter assigned.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,46 +31,39 @@ use PhpOffice\PhpWord\TOC;
|
|||
/**
|
||||
* RTF writer
|
||||
*/
|
||||
class RTF implements IWriter
|
||||
class RTF extends Writer implements IWriter
|
||||
{
|
||||
/**
|
||||
* Private PhpWord
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
private $_document;
|
||||
|
||||
/**
|
||||
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\HashTable
|
||||
* @var HashTable
|
||||
*/
|
||||
private $_drawingHashTable;
|
||||
private $drawingHashTable;
|
||||
|
||||
/**
|
||||
* Color register
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_colorTable;
|
||||
private $colorTable;
|
||||
|
||||
/**
|
||||
* Font register
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_fontTable;
|
||||
private $fontTable;
|
||||
|
||||
/**
|
||||
* Last paragraph style
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_lastParagraphStyle;
|
||||
private $lastParagraphStyle;
|
||||
|
||||
/**
|
||||
* Create new RTF writer
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
{
|
||||
|
|
@ -78,79 +71,38 @@ class RTF implements IWriter
|
|||
$this->setPhpWord($phpWord);
|
||||
|
||||
// Set HashTable variables
|
||||
$this->_drawingHashTable = new HashTable();
|
||||
$this->drawingHashTable = new HashTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save PhpWord to file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save($pFilename = null)
|
||||
{
|
||||
if (!is_null($this->_document)) {
|
||||
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
||||
$originalFilename = $pFilename;
|
||||
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
|
||||
$pFilename = @tempnam('./', 'phppttmp');
|
||||
if ($pFilename == '') {
|
||||
$pFilename = $originalFilename;
|
||||
}
|
||||
}
|
||||
if (!is_null($this->phpWord)) {
|
||||
$pFilename = $this->getTempFile($pFilename);
|
||||
|
||||
$hFile = fopen($pFilename, 'w') or die("can't open file");
|
||||
fwrite($hFile, $this->getData());
|
||||
fclose($hFile);
|
||||
|
||||
// If a temporary file was used, copy it to the correct file stream
|
||||
if ($originalFilename != $pFilename) {
|
||||
if (copy($pFilename, $originalFilename) === false) {
|
||||
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
|
||||
}
|
||||
@unlink($pFilename);
|
||||
}
|
||||
|
||||
$this->cleanupTempFile();
|
||||
} else {
|
||||
throw new Exception("PhpWord object unassigned.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PhpWord object
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\PhpWord
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function getPhpWord()
|
||||
{
|
||||
if (!is_null($this->_document)) {
|
||||
return $this->_document;
|
||||
} else {
|
||||
throw new Exception("No PhpWord assigned.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PhpWord object
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @return \PhpOffice\PhpWord\Writer\RTF
|
||||
*/
|
||||
public function setPhpWord(PhpWord $phpWord = null)
|
||||
{
|
||||
$this->_document = $phpWord;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PHPWord_Worksheet_BaseDrawing HashTable
|
||||
*
|
||||
* @return \PhpOffice\PhpWord\HashTable
|
||||
* @return HashTable
|
||||
*/
|
||||
public function getDrawingHashTable()
|
||||
{
|
||||
return $this->_drawingHashTable;
|
||||
return $this->drawingHashTable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -160,9 +112,9 @@ class RTF implements IWriter
|
|||
*/
|
||||
private function getData()
|
||||
{
|
||||
// PhpWord object : $this->_document
|
||||
$this->_fontTable = $this->getDataFont();
|
||||
$this->_colorTable = $this->getDataColor();
|
||||
// PhpWord object : $this->phpWord
|
||||
$this->fontTable = $this->getDataFont();
|
||||
$this->colorTable = $this->getDataColor();
|
||||
|
||||
$sRTFContent = '{\rtf1';
|
||||
// Set the default character set
|
||||
|
|
@ -174,13 +126,13 @@ class RTF implements IWriter
|
|||
$sRTFContent .= \PHP_EOL;
|
||||
// Set the font tbl group
|
||||
$sRTFContent .= '{\fonttbl';
|
||||
foreach ($this->_fontTable as $idx => $font) {
|
||||
foreach ($this->fontTable as $idx => $font) {
|
||||
$sRTFContent .= '{\f' . $idx . '\fnil\fcharset0 ' . $font . ';}';
|
||||
}
|
||||
$sRTFContent .= '}' . \PHP_EOL;
|
||||
// Set the color tbl group
|
||||
$sRTFContent .= '{\colortbl ';
|
||||
foreach ($this->_colorTable as $idx => $color) {
|
||||
foreach ($this->colorTable as $idx => $color) {
|
||||
$arrColor = Drawing::htmlToRGB($color);
|
||||
$sRTFContent .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . '';
|
||||
}
|
||||
|
|
@ -218,19 +170,18 @@ class RTF implements IWriter
|
|||
*/
|
||||
private function getDataFont()
|
||||
{
|
||||
$phpWord = $this->_document;
|
||||
$phpWord = $this->phpWord;
|
||||
|
||||
$arrFonts = array();
|
||||
// Default font : PhpWord::DEFAULT_FONT_NAME
|
||||
$arrFonts[] = PhpWord::DEFAULT_FONT_NAME;
|
||||
// PhpWord object : $this->_document
|
||||
// PhpWord object : $this->phpWord
|
||||
|
||||
// Browse styles
|
||||
$styles = Style::getStyles();
|
||||
$numPStyles = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// PhpOffice\PhpWord\Style\Font
|
||||
// Font
|
||||
if ($style instanceof Font) {
|
||||
if (in_array($style->getName(), $arrFonts) == false) {
|
||||
$arrFonts[] = $style->getName();
|
||||
|
|
@ -273,14 +224,13 @@ class RTF implements IWriter
|
|||
*/
|
||||
private function getDataColor()
|
||||
{
|
||||
$phpWord = $this->_document;
|
||||
$phpWord = $this->phpWord;
|
||||
|
||||
$arrColors = array();
|
||||
// PhpWord object : $this->_document
|
||||
// PhpWord object : $this->phpWord
|
||||
|
||||
// Browse styles
|
||||
$styles = Style::getStyles();
|
||||
$numPStyles = 0;
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
// Font
|
||||
|
|
@ -334,7 +284,7 @@ class RTF implements IWriter
|
|||
*/
|
||||
private function getDataContent()
|
||||
{
|
||||
$phpWord = $this->_document;
|
||||
$phpWord = $this->phpWord;
|
||||
$sRTFBody = '';
|
||||
|
||||
$_sections = $phpWord->getSections();
|
||||
|
|
@ -400,7 +350,7 @@ class RTF implements IWriter
|
|||
}
|
||||
|
||||
if ($styleParagraph && !$withoutP) {
|
||||
if ($this->_lastParagraphStyle != $text->getParagraphStyle()) {
|
||||
if ($this->lastParagraphStyle != $text->getParagraphStyle()) {
|
||||
$sRTFText .= '\pard\nowidctlpar';
|
||||
if ($styleParagraph->getSpaceAfter() != null) {
|
||||
$sRTFText .= '\sa' . $styleParagraph->getSpaceAfter();
|
||||
|
|
@ -410,17 +360,17 @@ class RTF implements IWriter
|
|||
$sRTFText .= '\qc';
|
||||
}
|
||||
}
|
||||
$this->_lastParagraphStyle = $text->getParagraphStyle();
|
||||
$this->lastParagraphStyle = $text->getParagraphStyle();
|
||||
} else {
|
||||
$this->_lastParagraphStyle = '';
|
||||
$this->lastParagraphStyle = '';
|
||||
}
|
||||
} else {
|
||||
$this->_lastParagraphStyle = '';
|
||||
$this->lastParagraphStyle = '';
|
||||
}
|
||||
|
||||
if ($styleFont instanceof Font) {
|
||||
if ($styleFont->getColor() != null) {
|
||||
$idxColor = array_search($styleFont->getColor(), $this->_colorTable);
|
||||
$idxColor = array_search($styleFont->getColor(), $this->colorTable);
|
||||
if ($idxColor !== false) {
|
||||
$sRTFText .= '\cf' . ($idxColor + 1);
|
||||
}
|
||||
|
|
@ -428,7 +378,7 @@ class RTF implements IWriter
|
|||
$sRTFText .= '\cf0';
|
||||
}
|
||||
if ($styleFont->getName() != null) {
|
||||
$idxFont = array_search($styleFont->getName(), $this->_fontTable);
|
||||
$idxFont = array_search($styleFont->getName(), $this->fontTable);
|
||||
if ($idxFont !== false) {
|
||||
$sRTFText .= '\f' . $idxFont;
|
||||
}
|
||||
|
|
@ -438,14 +388,14 @@ class RTF implements IWriter
|
|||
if ($styleFont->getBold()) {
|
||||
$sRTFText .= '\b';
|
||||
}
|
||||
if ($styleFont->getBold()) {
|
||||
if ($styleFont->getItalic()) {
|
||||
$sRTFText .= '\i';
|
||||
}
|
||||
if ($styleFont->getSize()) {
|
||||
$sRTFText .= '\fs' . ($styleFont->getSize() * 2);
|
||||
}
|
||||
}
|
||||
if ($this->_lastParagraphStyle != '' || $styleFont) {
|
||||
if ($this->lastParagraphStyle != '' || $styleFont) {
|
||||
$sRTFText .= ' ';
|
||||
}
|
||||
$sRTFText .= $text->getText();
|
||||
|
|
@ -501,7 +451,7 @@ class RTF implements IWriter
|
|||
*/
|
||||
private function getDataContentTextBreak()
|
||||
{
|
||||
$this->_lastParagraphStyle = '';
|
||||
$this->lastParagraphStyle = '';
|
||||
|
||||
return '\par' . \PHP_EOL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,73 +28,44 @@ use PhpOffice\PhpWord\Writer\Word2007\Styles;
|
|||
/**
|
||||
* Word2007 writer
|
||||
*/
|
||||
class Word2007 implements IWriter
|
||||
class Word2007 extends Writer implements IWriter
|
||||
{
|
||||
/**
|
||||
* PHPWord object
|
||||
*
|
||||
* @var PhpOffice\PhpWord\PhpWord
|
||||
*/
|
||||
private $_document;
|
||||
|
||||
/**
|
||||
* Individual writers
|
||||
*
|
||||
* @var PhpOffice\PhpWord\Writer\Word2007\WriterPart
|
||||
*/
|
||||
private $_writerParts;
|
||||
|
||||
/**
|
||||
* Disk caching directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_diskCachingDirectory;
|
||||
|
||||
/**
|
||||
* Use disk caching
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_useDiskCaching = false;
|
||||
|
||||
/**
|
||||
* Types of images
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_imageTypes = array();
|
||||
private $imageTypes = array();
|
||||
|
||||
/**
|
||||
* Types of objects
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_objectTypes = array();
|
||||
private $objectTypes = array();
|
||||
|
||||
/**
|
||||
* Create new Word2007 writer
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord
|
||||
* @param PhpWord
|
||||
*/
|
||||
public function __construct(PhpWord $phpWord = null)
|
||||
{
|
||||
$this->_document = $phpWord;
|
||||
// Assign PhpWord
|
||||
$this->setPhpWord($phpWord);
|
||||
|
||||
$this->_diskCachingDirectory = './';
|
||||
|
||||
$this->_writerParts['contenttypes'] = new ContentTypes();
|
||||
$this->_writerParts['rels'] = new Rels();
|
||||
$this->_writerParts['docprops'] = new DocProps();
|
||||
$this->_writerParts['documentrels'] = new DocumentRels();
|
||||
$this->_writerParts['document'] = new Document();
|
||||
$this->_writerParts['styles'] = new Styles();
|
||||
$this->_writerParts['header'] = new Header();
|
||||
$this->_writerParts['footer'] = new Footer();
|
||||
$this->_writerParts['footnotes'] = new Footnotes();
|
||||
$this->_writerParts['footnotesrels'] = new FootnotesRels();
|
||||
|
||||
foreach ($this->_writerParts as $writer) {
|
||||
// Set writer parts
|
||||
$this->writerParts['contenttypes'] = new ContentTypes();
|
||||
$this->writerParts['rels'] = new Rels();
|
||||
$this->writerParts['docprops'] = new DocProps();
|
||||
$this->writerParts['documentrels'] = new DocumentRels();
|
||||
$this->writerParts['document'] = new Document();
|
||||
$this->writerParts['styles'] = new Styles();
|
||||
$this->writerParts['header'] = new Header();
|
||||
$this->writerParts['footer'] = new Footer();
|
||||
$this->writerParts['footnotes'] = new Footnotes();
|
||||
$this->writerParts['footnotesrels'] = new FootnotesRels();
|
||||
foreach ($this->writerParts as $writer) {
|
||||
$writer->setParentWriter($this);
|
||||
}
|
||||
}
|
||||
|
|
@ -106,16 +77,8 @@ class Word2007 implements IWriter
|
|||
*/
|
||||
public function save($pFilename = null)
|
||||
{
|
||||
if (!is_null($this->_document)) {
|
||||
|
||||
// If $pFilename is php://output or php://stdout, make it a temporary file...
|
||||
$originalFilename = $pFilename;
|
||||
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
|
||||
$pFilename = @tempnam('./', 'phppttmp');
|
||||
if ($pFilename == '') {
|
||||
$pFilename = $originalFilename;
|
||||
}
|
||||
}
|
||||
if (!is_null($this->phpWord)) {
|
||||
$pFilename = $this->getTempFile($pFilename);
|
||||
|
||||
// Create new ZIP file and open it for writing
|
||||
$zipClass = Settings::getZipClass();
|
||||
|
|
@ -143,7 +106,7 @@ class Word2007 implements IWriter
|
|||
$_secElements = Media::getSectionMediaElements();
|
||||
foreach ($_secElements as $element) { // loop through section media elements
|
||||
if ($element['type'] != 'hyperlink') {
|
||||
$this->_addFileToPackage($objZip, $element);
|
||||
$this->addFileToPackage($objZip, $element);
|
||||
}
|
||||
$sectionElements[] = $element;
|
||||
}
|
||||
|
|
@ -153,7 +116,7 @@ class Word2007 implements IWriter
|
|||
if (count($_hdrMedia) > 0) {
|
||||
$objZip->addFromString('word/_rels/' . $_headerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_hdrMedia));
|
||||
foreach ($_hdrMedia as $element) { // loop through header media elements
|
||||
$this->_addFileToPackage($objZip, $element);
|
||||
$this->addFileToPackage($objZip, $element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -163,7 +126,7 @@ class Word2007 implements IWriter
|
|||
if (count($_ftrMedia) > 0) {
|
||||
$objZip->addFromString('word/_rels/' . $_footerFile . '.xml.rels', $this->getWriterPart('documentrels')->writeHeaderFooterRels($_ftrMedia));
|
||||
foreach ($_ftrMedia as $element) { // loop through footers media elements
|
||||
$this->_addFileToPackage($objZip, $element);
|
||||
$this->addFileToPackage($objZip, $element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -178,7 +141,7 @@ class Word2007 implements IWriter
|
|||
$_cHdrs = 0;
|
||||
$_cFtrs = 0;
|
||||
$rID = Media::countSectionMediaElements() + 6;
|
||||
$_sections = $this->_document->getSections();
|
||||
$_sections = $this->phpWord->getSections();
|
||||
|
||||
$footers = array();
|
||||
foreach ($_sections as $section) {
|
||||
|
|
@ -217,18 +180,18 @@ class Word2007 implements IWriter
|
|||
$objZip->addFromString(
|
||||
'[Content_Types].xml',
|
||||
$this->getWriterPart('contenttypes')->writeContentTypes(
|
||||
$this->_imageTypes,
|
||||
$this->_objectTypes,
|
||||
$this->imageTypes,
|
||||
$this->objectTypes,
|
||||
$_cHdrs,
|
||||
$footers
|
||||
)
|
||||
);
|
||||
$objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->_document));
|
||||
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docprops')->writeDocPropsApp($this->_document));
|
||||
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('docprops')->writeDocPropsCore($this->_document));
|
||||
$objZip->addFromString('word/document.xml', $this->getWriterPart('document')->writeDocument($this->_document));
|
||||
$objZip->addFromString('_rels/.rels', $this->getWriterPart('rels')->writeRelationships($this->phpWord));
|
||||
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('docprops')->writeDocPropsApp($this->phpWord));
|
||||
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('docprops')->writeDocPropsCore($this->phpWord));
|
||||
$objZip->addFromString('word/document.xml', $this->getWriterPart('document')->writeDocument($this->phpWord));
|
||||
$objZip->addFromString('word/_rels/document.xml.rels', $this->getWriterPart('documentrels')->writeDocumentRels($sectionElements));
|
||||
$objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document));
|
||||
$objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->phpWord));
|
||||
|
||||
// Write static files
|
||||
$objZip->addFile(__DIR__ . '/../_staticDocParts/numbering.xml', 'word/numbering.xml');
|
||||
|
|
@ -237,19 +200,12 @@ class Word2007 implements IWriter
|
|||
$objZip->addFile(__DIR__ . '/../_staticDocParts/webSettings.xml', 'word/webSettings.xml');
|
||||
$objZip->addFile(__DIR__ . '/../_staticDocParts/fontTable.xml', 'word/fontTable.xml');
|
||||
|
||||
|
||||
// Close file
|
||||
if ($objZip->close() === false) {
|
||||
throw new Exception("Could not close zip file $pFilename.");
|
||||
}
|
||||
|
||||
// If a temporary file was used, copy it to the correct file stream
|
||||
if ($originalFilename != $pFilename) {
|
||||
if (copy($pFilename, $originalFilename) === false) {
|
||||
throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename.");
|
||||
}
|
||||
@unlink($pFilename);
|
||||
}
|
||||
$this->cleanupTempFile();
|
||||
} else {
|
||||
throw new Exception("PhpWord object unassigned.");
|
||||
}
|
||||
|
|
@ -292,79 +248,23 @@ class Word2007 implements IWriter
|
|||
if ($imageExtension === 'jpeg') {
|
||||
$imageExtension = 'jpg';
|
||||
}
|
||||
if (!in_array($imageType, $this->_imageTypes)) {
|
||||
$this->_imageTypes[$imageExtension] = $imageType;
|
||||
if (!in_array($imageType, $this->imageTypes)) {
|
||||
$this->imageTypes[$imageExtension] = $imageType;
|
||||
}
|
||||
} else {
|
||||
if (!in_array($extension, $this->_objectTypes)) {
|
||||
$this->_objectTypes[] = $extension;
|
||||
if (!in_array($extension, $this->objectTypes)) {
|
||||
$this->objectTypes[] = $extension;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get writer part
|
||||
*
|
||||
* @param string $pPartName Writer part name
|
||||
* @return \PhpOffice\PhpWord\Writer\ODText\WriterPart
|
||||
*/
|
||||
public function getWriterPart($pPartName = '')
|
||||
{
|
||||
if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) {
|
||||
return $this->_writerParts[strtolower($pPartName)];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get use disk caching status
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseDiskCaching()
|
||||
{
|
||||
return $this->_useDiskCaching;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set use disk caching status
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @param string $pDirectory
|
||||
*/
|
||||
public function setUseDiskCaching($pValue = false, $pDirectory = null)
|
||||
{
|
||||
$this->_useDiskCaching = $pValue;
|
||||
|
||||
if (!is_null($pDirectory)) {
|
||||
if (is_dir($pDirectory)) {
|
||||
$this->_diskCachingDirectory = $pDirectory;
|
||||
} else {
|
||||
throw new Exception("Directory does not exist: $pDirectory");
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get disk caching directory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDiskCachingDirectory()
|
||||
{
|
||||
return $this->_diskCachingDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check content types
|
||||
*
|
||||
* @param mixed $objZip
|
||||
* @param mixed $element
|
||||
*/
|
||||
private function _addFileToPackage($objZip, $element)
|
||||
private function addFileToPackage($objZip, $element)
|
||||
{
|
||||
if (isset($element['isMemImage']) && $element['isMemImage']) {
|
||||
$image = call_user_func($element['createfunction'], $element['source']);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -19,20 +19,15 @@ class ContentTypes extends WriterPart
|
|||
{
|
||||
/**
|
||||
* Write [Content_Types].xml
|
||||
* @param array $_imageTypes
|
||||
* @param array $_objectTypes
|
||||
* @param array $imageTypes
|
||||
* @param array $objectTypes
|
||||
* @param int $_cHdrs
|
||||
* @param array $footers
|
||||
*/
|
||||
public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers)
|
||||
public function writeContentTypes($imageTypes, $objectTypes, $_cHdrs, $footers)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -42,27 +37,27 @@ class ContentTypes extends WriterPart
|
|||
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
|
||||
|
||||
// Rels
|
||||
$this->_writeDefaultContentType(
|
||||
$this->writeDefaultContentType(
|
||||
$xmlWriter,
|
||||
'rels',
|
||||
'application/vnd.openxmlformats-package.relationships+xml'
|
||||
);
|
||||
|
||||
// XML
|
||||
$this->_writeDefaultContentType(
|
||||
$this->writeDefaultContentType(
|
||||
$xmlWriter,
|
||||
'xml',
|
||||
'application/xml'
|
||||
);
|
||||
|
||||
// Add media content-types
|
||||
foreach ($_imageTypes as $key => $value) {
|
||||
$this->_writeDefaultContentType($xmlWriter, $key, $value);
|
||||
foreach ($imageTypes as $key => $value) {
|
||||
$this->writeDefaultContentType($xmlWriter, $key, $value);
|
||||
}
|
||||
|
||||
// Add embedding content-types
|
||||
if (count($_objectTypes) > 0) {
|
||||
$this->_writeDefaultContentType(
|
||||
if (count($objectTypes) > 0) {
|
||||
$this->writeDefaultContentType(
|
||||
$xmlWriter,
|
||||
'bin',
|
||||
'application/vnd.openxmlformats-officedocument.oleObject'
|
||||
|
|
@ -70,76 +65,76 @@ class ContentTypes extends WriterPart
|
|||
}
|
||||
|
||||
// DocProps
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/docProps/app.xml',
|
||||
'application/vnd.openxmlformats-officedocument.extended-properties+xml'
|
||||
);
|
||||
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/docProps/core.xml',
|
||||
'application/vnd.openxmlformats-package.core-properties+xml'
|
||||
);
|
||||
|
||||
// Document
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/document.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
|
||||
);
|
||||
|
||||
// Styles
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/styles.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml'
|
||||
);
|
||||
|
||||
// Numbering
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/numbering.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml'
|
||||
);
|
||||
|
||||
// Settings
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/settings.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml'
|
||||
);
|
||||
|
||||
// Theme1
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/theme/theme1.xml',
|
||||
'application/vnd.openxmlformats-officedocument.theme+xml'
|
||||
);
|
||||
|
||||
// WebSettings
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/webSettings.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml'
|
||||
);
|
||||
|
||||
// Font Table
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/fontTable.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml'
|
||||
);
|
||||
|
||||
// Footnotes
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/footnotes.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml'
|
||||
);
|
||||
|
||||
for ($i = 1; $i <= $_cHdrs; $i++) {
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/header' . $i . '.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml'
|
||||
|
|
@ -148,7 +143,7 @@ class ContentTypes extends WriterPart
|
|||
|
||||
for ($i = 1; $i <= count($footers); $i++) {
|
||||
if (!is_null($footers[$i])) {
|
||||
$this->_writeOverrideContentType(
|
||||
$this->writeOverrideContentType(
|
||||
$xmlWriter,
|
||||
'/word/footer' . $i . '.xml',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml'
|
||||
|
|
@ -163,32 +158,15 @@ class ContentTypes extends WriterPart
|
|||
return $xmlWriter->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image mime type
|
||||
*
|
||||
* @param string $pFile Filename
|
||||
* @return string Mime Type
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
private function _getImageMimeType($pFile = '')
|
||||
{
|
||||
if (file_exists($pFile)) {
|
||||
$image = getimagesize($pFile);
|
||||
return image_type_to_mime_type($image[2]);
|
||||
} else {
|
||||
throw new Exception("File $pFile does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write Default XML element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
|
||||
* @param XMLWriter $xmlWriter XML Writer
|
||||
* @param string $pPartname Part name
|
||||
* @param string $pContentType Content type
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private function _writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
|
||||
private function writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
|
||||
{
|
||||
if ($pPartname != '' && $pContentType != '') {
|
||||
// Write content type
|
||||
|
|
@ -204,12 +182,12 @@ class ContentTypes extends WriterPart
|
|||
/**
|
||||
* Write Override XML element
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param string $pPartname Part name
|
||||
* @param string $pContentType Content type
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private function _writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
|
||||
private function writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '')
|
||||
{
|
||||
if ($pPartname != '' && $pContentType != '') {
|
||||
// Write content type
|
||||
|
|
@ -221,4 +199,21 @@ class ContentTypes extends WriterPart
|
|||
throw new Exception("Invalid parameters passed.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image mime type
|
||||
*
|
||||
* @param string $pFile Filename
|
||||
* @return string Mime Type
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getImageMimeType($pFile = '')
|
||||
{
|
||||
if (file_exists($pFile)) {
|
||||
$image = getimagesize($pFile);
|
||||
return image_type_to_mime_type($image[2]);
|
||||
} else {
|
||||
throw new Exception("File $pFile does not exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,12 +23,7 @@ class DocProps extends WriterPart
|
|||
public function writeDocPropsApp(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -115,17 +110,12 @@ class DocProps extends WriterPart
|
|||
/**
|
||||
* Write docProps/core.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeDocPropsCore(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use PhpOffice\PhpWord\Section\Text;
|
|||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Section\TextRun;
|
||||
use PhpOffice\PhpWord\Section\Title;
|
||||
use PhpOffice\PhpWord\Section\CheckBox;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
|
|
@ -35,16 +36,12 @@ class Document extends Base
|
|||
/**
|
||||
* Write word/document.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeDocument(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -73,39 +70,40 @@ class Document extends Base
|
|||
$pSection++;
|
||||
|
||||
$_elements = $section->getElements();
|
||||
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof Link) {
|
||||
$this->_writeLink($xmlWriter, $element);
|
||||
$this->writeLink($xmlWriter, $element);
|
||||
} elseif ($element instanceof Title) {
|
||||
$this->_writeTitle($xmlWriter, $element);
|
||||
$this->writeTitle($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter, $element);
|
||||
$this->writeTextBreak($xmlWriter, $element);
|
||||
} elseif ($element instanceof PageBreak) {
|
||||
$this->_writePageBreak($xmlWriter);
|
||||
$this->writePageBreak($xmlWriter);
|
||||
} elseif ($element instanceof Table) {
|
||||
$this->_writeTable($xmlWriter, $element);
|
||||
$this->writeTable($xmlWriter, $element);
|
||||
} elseif ($element instanceof ListItem) {
|
||||
$this->_writeListItem($xmlWriter, $element);
|
||||
$this->writeListItem($xmlWriter, $element);
|
||||
} elseif ($element instanceof Image) {
|
||||
$this->_writeImage($xmlWriter, $element);
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} elseif ($element instanceof Object) {
|
||||
$this->_writeObject($xmlWriter, $element);
|
||||
$this->writeObject($xmlWriter, $element);
|
||||
} elseif ($element instanceof TOC) {
|
||||
$this->_writeTOC($xmlWriter);
|
||||
$this->writeTOC($xmlWriter);
|
||||
} elseif ($element instanceof Footnote) {
|
||||
$this->_writeFootnoteReference($xmlWriter, $element);
|
||||
$this->writeFootnote($xmlWriter, $element);
|
||||
} elseif ($element instanceof CheckBox) {
|
||||
$this->writeCheckBox($xmlWriter, $element);
|
||||
}
|
||||
}
|
||||
|
||||
if ($pSection == $countSections) {
|
||||
$this->_writeEndSection($xmlWriter, $section);
|
||||
$this->writeEndSection($xmlWriter, $section);
|
||||
} else {
|
||||
$this->_writeSection($xmlWriter, $section);
|
||||
$this->writeSection($xmlWriter, $section);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -120,14 +118,14 @@ class Document extends Base
|
|||
/**
|
||||
* Write begin section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeSection(XMLWriter $xmlWriter, Section $section)
|
||||
private function writeSection(XMLWriter $xmlWriter, Section $section)
|
||||
{
|
||||
$xmlWriter->startElement('w:p');
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$this->_writeEndSection($xmlWriter, $section, 3);
|
||||
$this->writeEndSection($xmlWriter, $section, 3);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
|
@ -135,10 +133,10 @@ class Document extends Base
|
|||
/**
|
||||
* Write end section
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section $section
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Section $section
|
||||
*/
|
||||
private function _writeEndSection(XMLWriter $xmlWriter, Section $section)
|
||||
private function writeEndSection(XMLWriter $xmlWriter, Section $section)
|
||||
{
|
||||
$settings = $section->getSettings();
|
||||
$_headers = $section->getHeaders();
|
||||
|
|
@ -274,9 +272,9 @@ class Document extends Base
|
|||
/**
|
||||
* Write page break element
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
*/
|
||||
private function _writePageBreak(XMLWriter $xmlWriter)
|
||||
private function writePageBreak(XMLWriter $xmlWriter)
|
||||
{
|
||||
$xmlWriter->startElement('w:p');
|
||||
$xmlWriter->startElement('w:r');
|
||||
|
|
@ -287,122 +285,12 @@ class Document extends Base
|
|||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write list item element
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section\ListItem $listItem
|
||||
*/
|
||||
public function _writeListItem(XMLWriter $xmlWriter, ListItem $listItem)
|
||||
{
|
||||
$textObject = $listItem->getTextObject();
|
||||
$text = $textObject->getText();
|
||||
$styleParagraph = $textObject->getParagraphStyle();
|
||||
$SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false;
|
||||
|
||||
$depth = $listItem->getDepth();
|
||||
$listType = $listItem->getStyle()->getListType();
|
||||
|
||||
$xmlWriter->startElement('w:p');
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
|
||||
if ($SpIsObject) {
|
||||
$this->_writeParagraphStyle($xmlWriter, $styleParagraph, true);
|
||||
} elseif (!$SpIsObject && !is_null($styleParagraph)) {
|
||||
$xmlWriter->startElement('w:pStyle');
|
||||
$xmlWriter->writeAttribute('w:val', $styleParagraph);
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
$xmlWriter->startElement('w:numPr');
|
||||
|
||||
$xmlWriter->startElement('w:ilvl');
|
||||
$xmlWriter->writeAttribute('w:val', $depth);
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->startElement('w:numId');
|
||||
$xmlWriter->writeAttribute('w:val', $listType);
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$this->_writeText($xmlWriter, $textObject, true);
|
||||
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object element
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param PhpOffice\PhpWord\Section\Object $object
|
||||
*/
|
||||
protected function _writeObject(XMLWriter $xmlWriter, Object $object)
|
||||
{
|
||||
$rIdObject = $object->getRelationId();
|
||||
$rIdImage = $object->getImageRelationId();
|
||||
$shapeId = md5($rIdObject . '_' . $rIdImage);
|
||||
|
||||
$objectId = $object->getObjectId();
|
||||
|
||||
$style = $object->getStyle();
|
||||
$width = $style->getWidth();
|
||||
$height = $style->getHeight();
|
||||
$align = $style->getAlign();
|
||||
|
||||
|
||||
$xmlWriter->startElement('w:p');
|
||||
|
||||
if (!is_null($align)) {
|
||||
$xmlWriter->startElement('w:pPr');
|
||||
$xmlWriter->startElement('w:jc');
|
||||
$xmlWriter->writeAttribute('w:val', $align);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
$xmlWriter->startElement('w:r');
|
||||
|
||||
$xmlWriter->startElement('w:object');
|
||||
$xmlWriter->writeAttribute('w:dxaOrig', '249');
|
||||
$xmlWriter->writeAttribute('w:dyaOrig', '160');
|
||||
|
||||
$xmlWriter->startElement('v:shape');
|
||||
$xmlWriter->writeAttribute('id', $shapeId);
|
||||
$xmlWriter->writeAttribute('type', '#_x0000_t75');
|
||||
$xmlWriter->writeAttribute('style', 'width:104px;height:67px');
|
||||
$xmlWriter->writeAttribute('o:ole', '');
|
||||
|
||||
$xmlWriter->startElement('v:imagedata');
|
||||
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdImage);
|
||||
$xmlWriter->writeAttribute('o:title', '');
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->startElement('o:OLEObject');
|
||||
$xmlWriter->writeAttribute('Type', 'Embed');
|
||||
$xmlWriter->writeAttribute('ProgID', 'Package');
|
||||
$xmlWriter->writeAttribute('ShapeID', $shapeId);
|
||||
$xmlWriter->writeAttribute('DrawAspect', 'Icon');
|
||||
$xmlWriter->writeAttribute('ObjectID', '_' . $objectId);
|
||||
$xmlWriter->writeAttribute('r:id', 'rId' . $rIdObject);
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->endElement(); // w:r
|
||||
|
||||
$xmlWriter->endElement(); // w:p
|
||||
}
|
||||
|
||||
/**
|
||||
* Write TOC element
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
*/
|
||||
private function _writeTOC(XMLWriter $xmlWriter)
|
||||
private function writeTOC(XMLWriter $xmlWriter)
|
||||
{
|
||||
$titles = TOC::getTitles();
|
||||
$styleFont = TOC::getStyleFont();
|
||||
|
|
@ -423,7 +311,7 @@ class Document extends Base
|
|||
$xmlWriter->startElement('w:pPr');
|
||||
|
||||
if ($isObject && !is_null($styleFont->getParagraphStyle())) {
|
||||
$this->_writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
|
||||
$this->writeParagraphStyle($xmlWriter, $styleFont->getParagraphStyle());
|
||||
}
|
||||
|
||||
if ($indent > 0) {
|
||||
|
|
@ -481,7 +369,7 @@ class Document extends Base
|
|||
$xmlWriter->startElement('w:r');
|
||||
|
||||
if ($isObject) {
|
||||
$this->_writeTextStyle($xmlWriter, $styleFont);
|
||||
$this->writeFontStyle($xmlWriter, $styleFont);
|
||||
}
|
||||
|
||||
$xmlWriter->startElement('w:t');
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
/**
|
||||
* Word2007 document rels part writer
|
||||
*/
|
||||
class DocumentRels extends WriterPart
|
||||
class DocumentRels extends Base
|
||||
{
|
||||
/**
|
||||
* Write word/_rels/document.xml.rels
|
||||
|
|
@ -25,12 +25,7 @@ class DocumentRels extends WriterPart
|
|||
public function writeDocumentRels($_relsCollection)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -40,7 +35,7 @@ class DocumentRels extends WriterPart
|
|||
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
|
||||
|
||||
// Relationship word/document.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
1,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
|
||||
|
|
@ -48,7 +43,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/numbering.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
2,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
|
||||
|
|
@ -56,7 +51,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
3,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
|
||||
|
|
@ -64,7 +59,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
4,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
|
||||
|
|
@ -72,7 +67,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
5,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
|
||||
|
|
@ -80,7 +75,7 @@ class DocumentRels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship word/settings.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
6,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
|
||||
|
|
@ -94,7 +89,7 @@ class DocumentRels extends WriterPart
|
|||
$relationId = $relation['rID'];
|
||||
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
|
||||
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
|
||||
|
|
@ -118,12 +113,7 @@ class DocumentRels extends WriterPart
|
|||
public function writeHeaderFooterRels($_relsCollection)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -138,7 +128,7 @@ class DocumentRels extends WriterPart
|
|||
$relationName = $relation['target'];
|
||||
$relationId = $relation['rID'];
|
||||
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType,
|
||||
|
|
@ -152,36 +142,4 @@ class DocumentRels extends WriterPart
|
|||
// Return
|
||||
return $xmlWriter->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write individual rels entry
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param int $pId Relationship ID
|
||||
* @param string $pType Relationship type
|
||||
* @param string $pTarget Relationship target
|
||||
* @param string $pTargetMode Relationship target mode
|
||||
*/
|
||||
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
|
||||
{
|
||||
if ($pType != '' && $pTarget != '') {
|
||||
if (strpos($pId, 'rId') === false) {
|
||||
$pId = 'rId' . $pId;
|
||||
}
|
||||
|
||||
// Write relationship
|
||||
$xmlWriter->startElement('Relationship');
|
||||
$xmlWriter->writeAttribute('Id', $pId);
|
||||
$xmlWriter->writeAttribute('Type', $pType);
|
||||
$xmlWriter->writeAttribute('Target', $pTarget);
|
||||
|
||||
if ($pTargetMode != '') {
|
||||
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
|
||||
}
|
||||
|
||||
$xmlWriter->endElement();
|
||||
} else {
|
||||
throw new Exception("Invalid parameters passed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
|
|||
use PhpOffice\PhpWord\Section\Text;
|
||||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Section\TextRun;
|
||||
use PhpOffice\PhpWord\Section\Footer as FooterElement;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
|
|
@ -25,17 +26,12 @@ class Footer extends Base
|
|||
/**
|
||||
* Write word/footnotes.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Section\Footer $footer
|
||||
* @param FooterElement $footer
|
||||
*/
|
||||
public function writeFooter(\PhpOffice\PhpWord\Section\Footer $footer)
|
||||
public function writeFooter(FooterElement $footer)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -55,17 +51,17 @@ class Footer extends Base
|
|||
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter, $element);
|
||||
$this->writeTextBreak($xmlWriter, $element);
|
||||
} elseif ($element instanceof Table) {
|
||||
$this->_writeTable($xmlWriter, $element);
|
||||
$this->writeTable($xmlWriter, $element);
|
||||
} elseif ($element instanceof Image) {
|
||||
$this->_writeImage($xmlWriter, $element);
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} elseif ($element instanceof PreserveText) {
|
||||
$this->_writePreserveText($xmlWriter, $element);
|
||||
$this->writePreserveText($xmlWriter, $element);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@
|
|||
namespace PhpOffice\PhpWord\Writer\Word2007;
|
||||
|
||||
use PhpOffice\PhpWord\Section\Footnote;
|
||||
use PhpOffice\PhpWord\Section\Text;
|
||||
use PhpOffice\PhpWord\Section\Link;
|
||||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
|
|
@ -25,21 +29,20 @@ class Footnotes extends Base
|
|||
public function writeFootnotes($allFootnotesCollection)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
||||
$xmlWriter->startElement('w:footnotes');
|
||||
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
|
||||
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
|
||||
|
||||
// write separator and continuation separator
|
||||
$xmlWriter->writeAttribute(
|
||||
'xmlns:r',
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
|
||||
);
|
||||
$xmlWriter->writeAttribute(
|
||||
'xmlns:w',
|
||||
'http://schemas.openxmlformats.org/wordprocessingml/2006/main'
|
||||
);
|
||||
// Separator and continuation separator
|
||||
$xmlWriter->startElement('w:footnote');
|
||||
$xmlWriter->writeAttribute('w:id', 0);
|
||||
$xmlWriter->writeAttribute('w:type', 'separator');
|
||||
|
|
@ -50,7 +53,7 @@ class Footnotes extends Base
|
|||
$xmlWriter->endElement(); // w:r
|
||||
$xmlWriter->endElement(); // w:p
|
||||
$xmlWriter->endElement(); // w:footnote
|
||||
|
||||
// Content
|
||||
$xmlWriter->startElement('w:footnote');
|
||||
$xmlWriter->writeAttribute('w:id', 1);
|
||||
$xmlWriter->writeAttribute('w:type', 'continuationSeparator');
|
||||
|
|
@ -61,16 +64,61 @@ class Footnotes extends Base
|
|||
$xmlWriter->endElement(); // w:r
|
||||
$xmlWriter->endElement(); // w:p
|
||||
$xmlWriter->endElement(); // w:footnote
|
||||
|
||||
foreach ($allFootnotesCollection as $footnote) {
|
||||
if ($footnote instanceof Footnote) {
|
||||
$this->_writeFootnote($xmlWriter, $footnote);
|
||||
$this->writeFootnote($xmlWriter, $footnote);
|
||||
}
|
||||
}
|
||||
|
||||
$xmlWriter->endElement();
|
||||
|
||||
// Return
|
||||
return $xmlWriter->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write footnote content, overrides method in parent class
|
||||
*
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param Footnote $footnote
|
||||
* @param boolean $withoutP
|
||||
*/
|
||||
protected function writeFootnote(XMLWriter $xmlWriter, Footnote $footnote, $withoutP = false)
|
||||
{
|
||||
$xmlWriter->startElement('w:footnote');
|
||||
$xmlWriter->writeAttribute('w:id', $footnote->getReferenceId());
|
||||
$xmlWriter->startElement('w:p');
|
||||
// Paragraph style
|
||||
$styleParagraph = $footnote->getParagraphStyle();
|
||||
$this->writeInlineParagraphStyle($xmlWriter, $styleParagraph);
|
||||
// Reference symbol
|
||||
$xmlWriter->startElement('w:r');
|
||||
$xmlWriter->startElement('w:rPr');
|
||||
$xmlWriter->startElement('w:rStyle');
|
||||
$xmlWriter->writeAttribute('w:val', 'FootnoteReference');
|
||||
$xmlWriter->endElement(); // w:rStyle
|
||||
$xmlWriter->endElement(); // w:rPr
|
||||
$xmlWriter->writeElement('w:footnoteRef');
|
||||
$xmlWriter->endElement(); // w:r
|
||||
// Empty space after refence symbol
|
||||
$xmlWriter->startElement('w:r');
|
||||
$xmlWriter->startElement('w:t');
|
||||
$xmlWriter->writeAttribute('xml:space', 'preserve');
|
||||
$xmlWriter->writeRaw(' ');
|
||||
$xmlWriter->endElement(); // w:t
|
||||
$xmlWriter->endElement(); // w:r
|
||||
// Actual footnote contents
|
||||
$elements = $footnote->getElements();
|
||||
if (count($elements) > 0) {
|
||||
foreach ($elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->writeText($xmlWriter, $element, true);
|
||||
} elseif ($element instanceof Link) {
|
||||
$this->writeLink($xmlWriter, $element, true);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$xmlWriter->writeElement('w:br');
|
||||
}
|
||||
}
|
||||
}
|
||||
$xmlWriter->endElement(); // w:p
|
||||
$xmlWriter->endElement(); // w:footnote
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
/**
|
||||
* Word2007 footnotes rel part writer
|
||||
*/
|
||||
class FootnotesRels extends WriterPart
|
||||
class FootnotesRels extends Base
|
||||
{
|
||||
/**
|
||||
* Write word/_rels/footnotes.xml.rels
|
||||
|
|
@ -25,12 +25,7 @@ class FootnotesRels extends WriterPart
|
|||
public function writeFootnotesRels($_relsCollection)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -46,7 +41,7 @@ class FootnotesRels extends WriterPart
|
|||
$relationId = $relation['rID'];
|
||||
$targetMode = ($relationType == 'hyperlink') ? 'External' : '';
|
||||
|
||||
$this->_writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
|
||||
$this->writeRelationship($xmlWriter, $relationId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/' . $relationType, $relationName, $targetMode);
|
||||
}
|
||||
|
||||
$xmlWriter->endElement();
|
||||
|
|
@ -54,36 +49,4 @@ class FootnotesRels extends WriterPart
|
|||
// Return
|
||||
return $xmlWriter->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write individual rels entry
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param int $pId Relationship ID
|
||||
* @param string $pType Relationship type
|
||||
* @param string $pTarget Relationship target
|
||||
* @param string $pTargetMode Relationship target mode
|
||||
*/
|
||||
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
|
||||
{
|
||||
if ($pType != '' && $pTarget != '') {
|
||||
if (strpos($pId, 'rId') === false) {
|
||||
$pId = 'rId' . $pId;
|
||||
}
|
||||
|
||||
// Write relationship
|
||||
$xmlWriter->startElement('Relationship');
|
||||
$xmlWriter->writeAttribute('Id', $pId);
|
||||
$xmlWriter->writeAttribute('Type', $pType);
|
||||
$xmlWriter->writeAttribute('Target', $pTarget);
|
||||
|
||||
if ($pTargetMode != '') {
|
||||
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
|
||||
}
|
||||
|
||||
$xmlWriter->endElement();
|
||||
} else {
|
||||
throw new Exception("Invalid parameters passed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use PhpOffice\PhpWord\Section\Table;
|
|||
use PhpOffice\PhpWord\Section\Text;
|
||||
use PhpOffice\PhpWord\Section\TextBreak;
|
||||
use PhpOffice\PhpWord\Section\TextRun;
|
||||
use PhpOffice\PhpWord\Section\Header as HeaderElement;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
|
|
@ -25,16 +26,12 @@ class Header extends Base
|
|||
/**
|
||||
* Write word/headerx.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Section\Header $header
|
||||
* @param HeaderElement $header
|
||||
*/
|
||||
public function writeHeader(\PhpOffice\PhpWord\Section\Header $header)
|
||||
public function writeHeader(HeaderElement $header)
|
||||
{
|
||||
// Create XML writer
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -55,21 +52,21 @@ class Header extends Base
|
|||
|
||||
foreach ($_elements as $element) {
|
||||
if ($element instanceof Text) {
|
||||
$this->_writeText($xmlWriter, $element);
|
||||
$this->writeText($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextRun) {
|
||||
$this->_writeTextRun($xmlWriter, $element);
|
||||
$this->writeTextRun($xmlWriter, $element);
|
||||
} elseif ($element instanceof TextBreak) {
|
||||
$this->_writeTextBreak($xmlWriter, $element);
|
||||
$this->writeTextBreak($xmlWriter, $element);
|
||||
} elseif ($element instanceof Table) {
|
||||
$this->_writeTable($xmlWriter, $element);
|
||||
$this->writeTable($xmlWriter, $element);
|
||||
} elseif ($element instanceof Image) {
|
||||
if (!$element->getIsWatermark()) {
|
||||
$this->_writeImage($xmlWriter, $element);
|
||||
$this->writeImage($xmlWriter, $element);
|
||||
} else {
|
||||
$this->_writeWatermark($xmlWriter, $element);
|
||||
$this->writeWatermark($xmlWriter, $element);
|
||||
}
|
||||
} elseif ($element instanceof PreserveText) {
|
||||
$this->_writePreserveText($xmlWriter, $element);
|
||||
$this->writePreserveText($xmlWriter, $element);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,22 +16,17 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
/**
|
||||
* Word2007 rels part writer
|
||||
*/
|
||||
class Rels extends WriterPart
|
||||
class Rels extends Base
|
||||
{
|
||||
/**
|
||||
* Write _rels/.rels
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeRelationships(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
|
@ -43,7 +38,7 @@ class Rels extends WriterPart
|
|||
$relationId = 1;
|
||||
|
||||
// Relationship word/document.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
|
||||
|
|
@ -51,7 +46,7 @@ class Rels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship docProps/core.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
++$relationId,
|
||||
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
|
||||
|
|
@ -59,7 +54,7 @@ class Rels extends WriterPart
|
|||
);
|
||||
|
||||
// Relationship docProps/app.xml
|
||||
$this->_writeRelationship(
|
||||
$this->writeRelationship(
|
||||
$xmlWriter,
|
||||
++$relationId,
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
|
||||
|
|
@ -70,37 +65,4 @@ class Rels extends WriterPart
|
|||
|
||||
return $xmlWriter->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write Override content type
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param int $pId Relationship ID. rId will be prepended!
|
||||
* @param string $pType Relationship type
|
||||
* @param string $pTarget Relationship target
|
||||
* @param string $pTargetMode Relationship target mode
|
||||
* @throws \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
private function _writeRelationship(XMLWriter $xmlWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
|
||||
{
|
||||
if ($pType != '' && $pTarget != '') {
|
||||
if (strpos($pId, 'rId') === false) {
|
||||
$pId = 'rId' . $pId;
|
||||
}
|
||||
|
||||
// Write relationship
|
||||
$xmlWriter->startElement('Relationship');
|
||||
$xmlWriter->writeAttribute('Id', $pId);
|
||||
$xmlWriter->writeAttribute('Type', $pType);
|
||||
$xmlWriter->writeAttribute('Target', $pTarget);
|
||||
|
||||
if ($pTargetMode != '') {
|
||||
$xmlWriter->writeAttribute('TargetMode', $pTargetMode);
|
||||
}
|
||||
|
||||
$xmlWriter->endElement();
|
||||
} else {
|
||||
throw new Exception("Invalid parameters passed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,67 +14,37 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
|
|||
use PhpOffice\PhpWord\Style;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Style\Paragraph;
|
||||
use PhpOffice\PhpWord\Style\Table;
|
||||
|
||||
/**
|
||||
* Word2007 styles part writer
|
||||
*/
|
||||
class Styles extends Base
|
||||
{
|
||||
/**
|
||||
* PHPWord object
|
||||
*
|
||||
* @var PhpWord
|
||||
*/
|
||||
private $_document;
|
||||
|
||||
/**
|
||||
* Write word/styles.xml
|
||||
*
|
||||
* @param PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param PhpWord $phpWord
|
||||
*/
|
||||
public function writeStyles(PhpWord $phpWord = null)
|
||||
{
|
||||
// Create XML writer
|
||||
$xmlWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
|
||||
} else {
|
||||
$xmlWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
|
||||
$this->_document = $phpWord;
|
||||
$xmlWriter = $this->getXmlWriter();
|
||||
|
||||
// XML header
|
||||
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
||||
$xmlWriter->startElement('w:styles');
|
||||
|
||||
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
|
||||
$xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
|
||||
|
||||
// Write DocDefaults
|
||||
$this->_writeDocDefaults($xmlWriter);
|
||||
|
||||
// Write Style Definitions
|
||||
$xmlWriter->writeAttribute(
|
||||
'xmlns:r',
|
||||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
|
||||
);
|
||||
$xmlWriter->writeAttribute(
|
||||
'xmlns:w',
|
||||
'http://schemas.openxmlformats.org/wordprocessingml/2006/main'
|
||||
);
|
||||
// Write default styles
|
||||
$styles = Style::getStyles();
|
||||
|
||||
// Write normal paragraph style
|
||||
$normalStyle = null;
|
||||
if (array_key_exists('Normal', $styles)) {
|
||||
$normalStyle = $styles['Normal'];
|
||||
}
|
||||
$xmlWriter->startElement('w:style');
|
||||
$xmlWriter->writeAttribute('w:type', 'paragraph');
|
||||
$xmlWriter->writeAttribute('w:default', '1');
|
||||
$xmlWriter->writeAttribute('w:styleId', 'Normal');
|
||||
$xmlWriter->startElement('w:name');
|
||||
$xmlWriter->writeAttribute('w:val', 'Normal');
|
||||
$xmlWriter->endElement();
|
||||
if (!is_null($normalStyle)) {
|
||||
$this->_writeParagraphStyle($xmlWriter, $normalStyle);
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$this->writeDefaultStyles($xmlWriter, $phpWord, $styles);
|
||||
// Write other styles
|
||||
if (count($styles) > 0) {
|
||||
foreach ($styles as $styleName => $style) {
|
||||
|
|
@ -116,10 +86,10 @@ class Styles extends Base
|
|||
$xmlWriter->startElement('w:basedOn');
|
||||
$xmlWriter->writeAttribute('w:val', 'Normal');
|
||||
$xmlWriter->endElement();
|
||||
$this->_writeParagraphStyle($xmlWriter, $paragraphStyle);
|
||||
$this->writeParagraphStyle($xmlWriter, $paragraphStyle);
|
||||
}
|
||||
|
||||
$this->_writeTextStyle($xmlWriter, $style);
|
||||
$this->writeFontStyle($xmlWriter, $style);
|
||||
|
||||
$xmlWriter->endElement();
|
||||
|
||||
|
|
@ -149,10 +119,10 @@ class Styles extends Base
|
|||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
$this->_writeParagraphStyle($xmlWriter, $style);
|
||||
$this->writeParagraphStyle($xmlWriter, $style);
|
||||
$xmlWriter->endElement();
|
||||
|
||||
} elseif ($style instanceof \PhpOffice\PhpWord\Style\Table) {
|
||||
} elseif ($style instanceof Table) {
|
||||
$xmlWriter->startElement('w:style');
|
||||
$xmlWriter->writeAttribute('w:type', 'table');
|
||||
$xmlWriter->writeAttribute('w:customStyle', '1');
|
||||
|
|
@ -166,7 +136,7 @@ class Styles extends Base
|
|||
$xmlWriter->writeAttribute('w:val', '99');
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$this->_writeTableStyle($xmlWriter, $style);
|
||||
$this->writeTableStyle($xmlWriter, $style);
|
||||
|
||||
$xmlWriter->endElement(); // w:style
|
||||
}
|
||||
|
|
@ -180,36 +150,65 @@ class Styles extends Base
|
|||
}
|
||||
|
||||
/**
|
||||
* Write document defaults
|
||||
* Write default font and other default styles
|
||||
*
|
||||
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
||||
* @param XMLWriter $xmlWriter
|
||||
* @param array $styles
|
||||
*/
|
||||
private function _writeDocDefaults(XMLWriter $xmlWriter)
|
||||
private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles)
|
||||
{
|
||||
$fontName = $this->_document->getDefaultFontName();
|
||||
$fontSize = $this->_document->getDefaultFontSize();
|
||||
$fontName = $phpWord->getDefaultFontName();
|
||||
$fontSize = $phpWord->getDefaultFontSize();
|
||||
|
||||
// Default font
|
||||
$xmlWriter->startElement('w:docDefaults');
|
||||
$xmlWriter->startElement('w:rPrDefault');
|
||||
$xmlWriter->startElement('w:rPr');
|
||||
|
||||
$xmlWriter->startElement('w:rFonts');
|
||||
$xmlWriter->writeAttribute('w:ascii', $fontName);
|
||||
$xmlWriter->writeAttribute('w:hAnsi', $fontName);
|
||||
$xmlWriter->writeAttribute('w:eastAsia', $fontName);
|
||||
$xmlWriter->writeAttribute('w:cs', $fontName);
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->endElement(); // w:rFonts
|
||||
$xmlWriter->startElement('w:sz');
|
||||
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
|
||||
$xmlWriter->endElement();
|
||||
|
||||
$xmlWriter->endElement(); // w:sz
|
||||
$xmlWriter->startElement('w:szCs');
|
||||
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement(); // w:szCs
|
||||
$xmlWriter->endElement(); // w:rPr
|
||||
$xmlWriter->endElement(); // w:rPrDefault
|
||||
$xmlWriter->endElement(); // w:docDefaults
|
||||
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
$xmlWriter->endElement();
|
||||
// Normal style
|
||||
$xmlWriter->startElement('w:style');
|
||||
$xmlWriter->writeAttribute('w:type', 'paragraph');
|
||||
$xmlWriter->writeAttribute('w:default', '1');
|
||||
$xmlWriter->writeAttribute('w:styleId', 'Normal');
|
||||
$xmlWriter->startElement('w:name');
|
||||
$xmlWriter->writeAttribute('w:val', 'Normal');
|
||||
$xmlWriter->endElement(); // w:name
|
||||
if (array_key_exists('Normal', $styles)) {
|
||||
$this->writeParagraphStyle($xmlWriter, $styles['Normal']);
|
||||
}
|
||||
$xmlWriter->endElement(); // w:style
|
||||
|
||||
// FootnoteReference style
|
||||
if (!array_key_exists('FootnoteReference', $styles)) {
|
||||
$xmlWriter->startElement('w:style');
|
||||
$xmlWriter->writeAttribute('w:type', 'character');
|
||||
$xmlWriter->writeAttribute('w:styleId', 'FootnoteReference');
|
||||
$xmlWriter->startElement('w:name');
|
||||
$xmlWriter->writeAttribute('w:val', 'Footnote Reference');
|
||||
$xmlWriter->endElement(); // w:name
|
||||
$xmlWriter->writeElement('w:semiHidden');
|
||||
$xmlWriter->writeElement('w:unhideWhenUsed');
|
||||
$xmlWriter->startElement('w:rPr');
|
||||
$xmlWriter->startElement('w:vertAlign');
|
||||
$xmlWriter->writeAttribute('w:val', 'superscript');
|
||||
$xmlWriter->endElement(); // w:vertAlign
|
||||
$xmlWriter->endElement(); // w:rPr
|
||||
$xmlWriter->endElement(); // w:style
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace PhpOffice\PhpWord\Writer\Word2007;
|
|||
|
||||
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||
use PhpOffice\PhpWord\Writer\IWriter;
|
||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||
|
||||
/**
|
||||
* Word2007 writer part abstract class
|
||||
|
|
@ -22,7 +23,7 @@ abstract class WriterPart
|
|||
*
|
||||
* @var IWriter
|
||||
*/
|
||||
private $_parentWriter;
|
||||
protected $parentWriter;
|
||||
|
||||
/**
|
||||
* Set parent writer
|
||||
|
|
@ -31,20 +32,41 @@ abstract class WriterPart
|
|||
*/
|
||||
public function setParentWriter(IWriter $pWriter = null)
|
||||
{
|
||||
$this->_parentWriter = $pWriter;
|
||||
$this->parentWriter = $pWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parent writer
|
||||
*
|
||||
* @return IWriter
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getParentWriter()
|
||||
{
|
||||
if (!is_null($this->_parentWriter)) {
|
||||
return $this->_parentWriter;
|
||||
if (!is_null($this->parentWriter)) {
|
||||
return $this->parentWriter;
|
||||
} else {
|
||||
throw new Exception("No parent IWriter assigned.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get XML Writer
|
||||
*
|
||||
* @return XMLWriter
|
||||
*/
|
||||
protected function getXmlWriter()
|
||||
{
|
||||
$useDiskCaching = false;
|
||||
if (!is_null($this->parentWriter)) {
|
||||
if ($this->parentWriter->getUseDiskCaching()) {
|
||||
$useDiskCaching = true;
|
||||
}
|
||||
}
|
||||
if ($useDiskCaching) {
|
||||
return new XMLWriter(XMLWriter::STORAGE_DISK, $this->parentWriter->getDiskCachingDirectory());
|
||||
} else {
|
||||
return new XMLWriter(XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Writer;
|
||||
|
||||
use PhpOffice\PhpWord\Exceptions\Exception;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
|
||||
/**
|
||||
* Abstract writer class
|
||||
*
|
||||
* @since 0.9.2
|
||||
*/
|
||||
abstract class Writer implements IWriter
|
||||
{
|
||||
/**
|
||||
* PHPWord object
|
||||
*
|
||||
* @var PhpWord
|
||||
*/
|
||||
protected $phpWord = null;
|
||||
|
||||
/**
|
||||
* Individual writers
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $writerParts = array();
|
||||
|
||||
/**
|
||||
* Use disk caching
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $useDiskCaching = false;
|
||||
|
||||
/**
|
||||
* Disk caching directory
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $diskCachingDirectory = './';
|
||||
|
||||
/**
|
||||
* Original file name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $originalFilename;
|
||||
|
||||
/**
|
||||
* Temporary file name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $tempFilename;
|
||||
|
||||
/**
|
||||
* Get PhpWord object
|
||||
*
|
||||
* @return PhpWord
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getPhpWord()
|
||||
{
|
||||
if (!is_null($this->phpWord)) {
|
||||
return $this->phpWord;
|
||||
} else {
|
||||
throw new Exception("No PhpWord assigned.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PhpWord object
|
||||
*
|
||||
* @param PhpWord
|
||||
* @return $this
|
||||
*/
|
||||
public function setPhpWord(PhpWord $phpWord = null)
|
||||
{
|
||||
$this->phpWord = $phpWord;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get writer part
|
||||
*
|
||||
* @param string $pPartName Writer part name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWriterPart($pPartName = '')
|
||||
{
|
||||
if ($pPartName != '' && isset($this->writerParts[strtolower($pPartName)])) {
|
||||
return $this->writerParts[strtolower($pPartName)];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get use disk caching status
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUseDiskCaching()
|
||||
{
|
||||
return $this->useDiskCaching;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set use disk caching status
|
||||
*
|
||||
* @param boolean $pValue
|
||||
* @param string $pDirectory
|
||||
* @return $this
|
||||
*/
|
||||
public function setUseDiskCaching($pValue = false, $pDirectory = null)
|
||||
{
|
||||
$this->useDiskCaching = $pValue;
|
||||
|
||||
if (!is_null($pDirectory)) {
|
||||
if (is_dir($pDirectory)) {
|
||||
$this->diskCachingDirectory = $pDirectory;
|
||||
} else {
|
||||
throw new Exception("Directory does not exist: $pDirectory");
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get disk caching directory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDiskCachingDirectory()
|
||||
{
|
||||
return $this->diskCachingDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get temporary file name
|
||||
*
|
||||
* If $pFilename is php://output or php://stdout, make it a temporary file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return string
|
||||
*/
|
||||
protected function getTempFile($pFilename)
|
||||
{
|
||||
$this->originalFilename = $pFilename;
|
||||
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
|
||||
$pFilename = @tempnam(sys_get_temp_dir(), 'phpword_');
|
||||
if ($pFilename == '') {
|
||||
$pFilename = $this->originalFilename;
|
||||
}
|
||||
}
|
||||
$this->tempFilename = $pFilename;
|
||||
|
||||
return $this->tempFilename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup temporary file
|
||||
*
|
||||
* If a temporary file was used, copy it to the correct file stream
|
||||
*/
|
||||
protected function cleanupTempFile()
|
||||
{
|
||||
if ($this->originalFilename != $this->tempFilename) {
|
||||
if (copy($this->tempFilename, $this->originalFilename) === false) {
|
||||
throw new Exception("Could not copy temporary zip file {$this->tempFilename} to {$this->originalFilename}.");
|
||||
}
|
||||
@unlink($this->tempFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ use PhpOffice\PhpWord\Exceptions\Exception;
|
|||
class ExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Throw new exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @covers \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ use PhpOffice\PhpWord\Exceptions\InvalidImageException;
|
|||
class InvalidImageExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Throw new exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
|
||||
* @covers \PhpOffice\PhpWord\Exceptions\InvalidImageException
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
|
|||
class InvalidStyleExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Throw new exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidStyleException
|
||||
* @covers \PhpOffice\PhpWord\Exceptions\InvalidStyleException
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
|
|||
class UnsupportedImageTypeExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Throw new exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
|
||||
* @covers \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Can read exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function testCanReadFailed()
|
||||
|
|
@ -54,6 +56,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
$object = IOFactory::load($fqFilename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
$fqFilename = join(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Tests\Section;
|
||||
|
||||
use PhpOffice\PhpWord\Section\CheckBox;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\CheckBox
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class CheckBoxTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oCheckBox = new CheckBox();
|
||||
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\CheckBox', $oCheckBox);
|
||||
$this->assertEquals(null, $oCheckBox->getText());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name and text
|
||||
*/
|
||||
public function testCheckBox()
|
||||
{
|
||||
$oCheckBox = new CheckBox('chkBox', 'CheckBox');
|
||||
|
||||
$this->assertEquals($oCheckBox->getName(), 'chkBox');
|
||||
$this->assertEquals($oCheckBox->getText(), 'CheckBox');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get font style
|
||||
*/
|
||||
public function testFont()
|
||||
{
|
||||
$oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle');
|
||||
$this->assertEquals($oCheckBox->getFontStyle(), 'fontStyle');
|
||||
|
||||
$oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Font style as object
|
||||
*/
|
||||
public function testFontObject()
|
||||
{
|
||||
$font = new Font();
|
||||
$oCheckBox = new CheckBox('chkBox', 'CheckBox', $font);
|
||||
$this->assertEquals($oCheckBox->getFontStyle(), $font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paragraph style
|
||||
*/
|
||||
public function testParagraph()
|
||||
{
|
||||
$oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle', 'paragraphStyle');
|
||||
$this->assertEquals($oCheckBox->getParagraphStyle(), 'paragraphStyle');
|
||||
|
||||
$oCheckBox->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle());
|
||||
}
|
||||
}
|
||||
|
|
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Footer\PreserveText;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\Footer\PreserveText
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Footer\PreserveText
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class PreserveTextTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oPreserveText = new PreserveText();
|
||||
|
|
@ -29,6 +31,9 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oPreserveText->getParagraphStyle(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance with style name
|
||||
*/
|
||||
public function testConstructWithString()
|
||||
{
|
||||
$oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph');
|
||||
|
|
@ -37,6 +42,9 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance with array
|
||||
*/
|
||||
public function testConstructWithArray()
|
||||
{
|
||||
$oPreserveText = new PreserveText(
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Footer;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\Footer
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Footer
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class FooterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* New instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
@ -28,15 +30,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oFooter->getFooterCount(), $iVal);
|
||||
}
|
||||
|
||||
public function testRelationID()
|
||||
{
|
||||
$oFooter = new Footer(0);
|
||||
|
||||
$iVal = rand(1, 1000);
|
||||
$oFooter->setRelationId($iVal);
|
||||
$this->assertEquals($oFooter->getRelationId(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text
|
||||
*/
|
||||
public function testAddText()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -46,6 +42,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text non-UTF8
|
||||
*/
|
||||
public function testAddTextNotUTF8()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -56,6 +55,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), 'ééé');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text break
|
||||
*/
|
||||
public function testAddTextBreak()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -65,6 +67,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount($iVal, $oFooter->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text run
|
||||
*/
|
||||
public function testCreateTextRun()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -74,6 +79,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add table
|
||||
*/
|
||||
public function testAddTable()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -83,16 +91,23 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Table', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image
|
||||
*/
|
||||
public function testAddImage()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
$oFooter = new Footer(1);
|
||||
$element = $oFooter->addImage($src);
|
||||
$element1 = $oFooter->addImage($src);
|
||||
$element2 = $oFooter->addMemoryImage($src); // @deprecated
|
||||
|
||||
$this->assertCount(1, $oFooter->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
$this->assertCount(2, $oFooter->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image by URL
|
||||
*/
|
||||
public function testAddImageByUrl()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -104,6 +119,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text
|
||||
*/
|
||||
public function testAddPreserveText()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -113,6 +131,9 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text non-UTF8
|
||||
*/
|
||||
public function testAddPreserveTextNotUTF8()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
|
@ -123,10 +144,25 @@ class FooterTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), array('ééé'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*/
|
||||
public function testGetElements()
|
||||
{
|
||||
$oFooter = new Footer(1);
|
||||
|
||||
$this->assertInternalType('array', $oFooter->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get relation Id
|
||||
*/
|
||||
public function testRelationID()
|
||||
{
|
||||
$oFooter = new Footer(0);
|
||||
|
||||
$iVal = rand(1, 1000);
|
||||
$oFooter->setRelationId($iVal);
|
||||
$this->assertEquals($oFooter->getRelationId(), $iVal);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Footnote;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\Footnote
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Footnote
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class FootnoteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* New instance without parameter
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oFootnote = new Footnote();
|
||||
|
|
@ -28,6 +30,9 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oFootnote->getParagraphStyle(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance with string parameter
|
||||
*/
|
||||
public function testConstructString()
|
||||
{
|
||||
$oFootnote = new Footnote('pStyle');
|
||||
|
|
@ -35,6 +40,9 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle');
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance with array parameter
|
||||
*/
|
||||
public function testConstructArray()
|
||||
{
|
||||
$oFootnote = new Footnote(array('spacing' => 100));
|
||||
|
|
@ -45,6 +53,9 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text element
|
||||
*/
|
||||
public function testAddText()
|
||||
{
|
||||
$oFootnote = new Footnote();
|
||||
|
|
@ -54,6 +65,20 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text break element
|
||||
*/
|
||||
public function testAddTextBreak()
|
||||
{
|
||||
$oFootnote = new Footnote();
|
||||
$oFootnote->addTextBreak(2);
|
||||
|
||||
$this->assertCount(2, $oFootnote->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link element
|
||||
*/
|
||||
public function testAddLink()
|
||||
{
|
||||
$oFootnote = new Footnote();
|
||||
|
|
@ -63,6 +88,9 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get reference Id
|
||||
*/
|
||||
public function testReferenceId()
|
||||
{
|
||||
$oFootnote = new Footnote();
|
||||
|
|
@ -72,6 +100,9 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oFootnote->getReferenceId(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*/
|
||||
public function testGetElements()
|
||||
{
|
||||
$oFootnote = new Footnote();
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Header;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\Header
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Header
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* New instance
|
||||
*/
|
||||
public function testConstructDefault()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
@ -29,6 +31,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oHeader->getType(), Header::AUTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text
|
||||
*/
|
||||
public function testAddText()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -39,6 +44,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), 'text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text non-UTF8
|
||||
*/
|
||||
public function testAddTextNotUTF8()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -49,6 +57,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), 'ééé');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text break
|
||||
*/
|
||||
public function testAddTextBreak()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -56,6 +67,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount(1, $oHeader->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text break with params
|
||||
*/
|
||||
public function testAddTextBreakWithParams()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -64,6 +78,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount($iVal, $oHeader->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text run
|
||||
*/
|
||||
public function testCreateTextRun()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -72,6 +89,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount(1, $oHeader->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add table
|
||||
*/
|
||||
public function testAddTable()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -80,16 +100,23 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount(1, $oHeader->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image
|
||||
*/
|
||||
public function testAddImage()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
$oHeader = new Header(1);
|
||||
$element = $oHeader->addImage($src);
|
||||
$element1 = $oHeader->addImage($src);
|
||||
$element2 = $oHeader->addMemoryImage($src); // @deprecated
|
||||
|
||||
$this->assertCount(1, $oHeader->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
$this->assertCount(2, $oHeader->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image by URL
|
||||
*/
|
||||
public function testAddImageByUrl()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -101,6 +128,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text
|
||||
*/
|
||||
public function testAddPreserveText()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -110,6 +140,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text non-UTF8
|
||||
*/
|
||||
public function testAddPreserveTextNotUTF8()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -120,6 +153,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), array('ééé'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add watermark
|
||||
*/
|
||||
public function testAddWatermark()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
|
|
@ -130,6 +166,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*/
|
||||
public function testGetElements()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -137,6 +176,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInternalType('array', $oHeader->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get relation Id
|
||||
*/
|
||||
public function testRelationId()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -146,6 +188,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oHeader->getRelationId(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset type
|
||||
*/
|
||||
public function testResetType()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -155,6 +200,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oHeader->getType(), Header::AUTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* First page
|
||||
*/
|
||||
public function testFirstPage()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
@ -163,6 +211,9 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oHeader->getType(), Header::FIRST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Even page
|
||||
*/
|
||||
public function testEvenPage()
|
||||
{
|
||||
$oHeader = new Header(1);
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Image;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\Image
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Image
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class ImageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* New instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/firefox.png";
|
||||
|
|
@ -31,6 +33,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance with style
|
||||
*/
|
||||
public function testConstructWithStyle()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/firefox.png";
|
||||
|
|
@ -44,7 +49,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* Valid image types
|
||||
*/
|
||||
public function testValidImageTypes()
|
||||
{
|
||||
|
|
@ -57,8 +62,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Image not found
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testImageNotFound()
|
||||
{
|
||||
|
|
@ -66,14 +72,18 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Invalid image types
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testInvalidImageTypes()
|
||||
{
|
||||
new Image(__DIR__ . "/../_files/images/alexz-johnson.pcx");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style
|
||||
*/
|
||||
public function testStyle()
|
||||
{
|
||||
$oImage = new Image(
|
||||
|
|
@ -84,6 +94,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get relation Id
|
||||
*/
|
||||
public function testRelationID()
|
||||
{
|
||||
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
|
||||
|
|
@ -92,12 +105,19 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oImage->getRelationId(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get is watermark
|
||||
*/
|
||||
public function testWatermark()
|
||||
{
|
||||
$oImage = new Image(__DIR__ . "/../_files/images/earth.jpg");
|
||||
$oImage->setIsWatermark(true);
|
||||
$this->assertEquals($oImage->getIsWatermark(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test PNG
|
||||
*/
|
||||
public function testPNG()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/firefox.png";
|
||||
|
|
@ -112,6 +132,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oImage->getImageType(), 'image/png');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test GIF
|
||||
*/
|
||||
public function testGIF()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/mario.gif";
|
||||
|
|
@ -126,6 +149,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oImage->getImageType(), 'image/gif');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test JPG
|
||||
*/
|
||||
public function testJPG()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
|
|
@ -140,6 +166,9 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oImage->getImageType(), 'image/jpeg');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test BMP
|
||||
*/
|
||||
public function testBMP()
|
||||
{
|
||||
$oImage = new Image(__DIR__ . "/../_files/images/duke_nukem.bmp");
|
||||
|
|
@ -150,4 +179,17 @@ class ImageTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oImage->getImageExtension(), 'bmp');
|
||||
$this->assertEquals($oImage->getImageType(), 'image/bmp');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test TIFF
|
||||
*/
|
||||
public function testTIFF()
|
||||
{
|
||||
$oImage = new Image(__DIR__ . "/../_files/images/angela_merkel.tif");
|
||||
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
|
||||
$this->assertEquals($oImage->getImageCreateFunction(), null);
|
||||
$this->assertEquals($oImage->getImageFunction(), null);
|
||||
$this->assertEquals($oImage->getImageType(), 'image/tiff');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ use PhpOffice\PhpWord\Style\Font;
|
|||
*/
|
||||
class LinkTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
*/
|
||||
public function testConstructDefault()
|
||||
{
|
||||
$oLink = new Link('http://www.google.com');
|
||||
|
|
@ -31,6 +34,9 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oLink->getParagraphStyle(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance with array
|
||||
*/
|
||||
public function testConstructWithParamsArray()
|
||||
{
|
||||
$oLink = new Link(
|
||||
|
|
@ -47,6 +53,9 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance with style name string
|
||||
*/
|
||||
public function testConstructWithParamsString()
|
||||
{
|
||||
$oLink = new Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle');
|
||||
|
|
@ -55,6 +64,9 @@ class LinkTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get relation Id
|
||||
*/
|
||||
public function testRelationId()
|
||||
{
|
||||
$oLink = new Link('http://www.google.com');
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ use PhpOffice\PhpWord\Section\ListItem;
|
|||
*/
|
||||
class ListItemTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Get text object
|
||||
*/
|
||||
public function testText()
|
||||
{
|
||||
$oListItem = new ListItem('text');
|
||||
|
|
@ -26,6 +29,9 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $oListItem->getTextObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style
|
||||
*/
|
||||
public function testStyle()
|
||||
{
|
||||
$oListItem = new ListItem(
|
||||
|
|
@ -42,6 +48,9 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get depth
|
||||
*/
|
||||
public function testDepth()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ use PhpOffice\PhpWord\Section\Object;
|
|||
*/
|
||||
class ObjectTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Create new instance with supported files
|
||||
*/
|
||||
public function testConstructWithSupportedFiles()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/documents/sheet.xls";
|
||||
|
|
@ -29,6 +32,9 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oObject->getSource(), $src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance with non-supported files
|
||||
*/
|
||||
public function testConstructWithNotSupportedFiles()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/xsl/passthrough.xsl";
|
||||
|
|
@ -39,6 +45,9 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oObject->getStyle(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create with style
|
||||
*/
|
||||
public function testConstructWithSupportedFilesAndStyle()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/documents/sheet.xls";
|
||||
|
|
@ -49,6 +58,9 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oObject->getSource(), $src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get relation Id
|
||||
*/
|
||||
public function testRelationId()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/documents/sheet.xls";
|
||||
|
|
@ -59,6 +71,9 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oObject->getRelationId(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get image relation Id
|
||||
*/
|
||||
public function testImageRelationId()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/documents/sheet.xls";
|
||||
|
|
@ -69,6 +84,9 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oObject->getImageRelationId(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get object relation Id
|
||||
*/
|
||||
public function testObjectId()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/documents/sheet.xls";
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($iVal, $oSettings->getHeaderHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get margin
|
||||
*/
|
||||
public function testMargin()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -79,6 +82,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($iVal, $oSettings->getMarginRight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get landscape orientation
|
||||
*/
|
||||
public function testOrientationLandscape()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -90,6 +96,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(11906, $oSettings->getPageSizeH());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get portrait orientation
|
||||
*/
|
||||
public function testOrientationPortrait()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -101,6 +110,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(16838, $oSettings->getPageSizeH());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get border size
|
||||
*/
|
||||
public function testBorderSize()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -131,6 +143,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($iVal, $oSettings->getBorderTopSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get border color
|
||||
*/
|
||||
public function testBorderColor()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -156,6 +171,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('22FF33', $oSettings->getBorderTopColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get page numbering start
|
||||
*/
|
||||
public function testNumberingStart()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -171,9 +189,11 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertNull($oSettings->getPageNumberingStart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get header height
|
||||
*/
|
||||
public function testHeader()
|
||||
{
|
||||
// Section Settings
|
||||
$oSettings = new Settings();
|
||||
|
||||
$this->assertEquals(720, $oSettings->getHeaderHeight());
|
||||
|
|
@ -186,6 +206,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(720, $oSettings->getHeaderHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get footer height
|
||||
*/
|
||||
public function testFooter()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -201,6 +224,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(720, $oSettings->getFooterHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get column number
|
||||
*/
|
||||
public function testColumnsNum()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -217,6 +243,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(1, $oSettings->getColsNum());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get column spacing
|
||||
*/
|
||||
public function testColumnsSpace()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
@ -233,6 +262,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(720, $oSettings->getColsSpace());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get break type
|
||||
*/
|
||||
public function testBreakType()
|
||||
{
|
||||
// Section Settings
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\Table\Cell;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\Table\Cell
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Table\Cell
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class CellTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* New instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
@ -28,6 +30,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oCell->getWidth(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance with array
|
||||
*/
|
||||
public function testConstructWithStyleArray()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
@ -37,6 +42,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oCell->getWidth(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance with string
|
||||
*/
|
||||
public function testConstructWithStyleString()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
@ -45,6 +53,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oCell->getStyle(), 'cellStyle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text
|
||||
*/
|
||||
public function testAddText()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
|
|
@ -54,6 +65,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Text', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add non-UTF8
|
||||
*/
|
||||
public function testAddTextNotUTF8()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
|
|
@ -64,15 +78,31 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), 'ééé');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link
|
||||
*/
|
||||
public function testAddLink()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
$element = $oCell->addLink('http://www.google.fr', 'Nom');
|
||||
$element = $oCell->addLink(utf8_decode('ééé'), utf8_decode('ééé'));
|
||||
|
||||
$this->assertCount(1, $oCell->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Link', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link exception
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function testAddLinkException()
|
||||
{
|
||||
$oCell = new Cell('header', 1);
|
||||
$element = $oCell->addLink('http://google.com', 'Google');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text break
|
||||
*/
|
||||
public function testAddTextBreak()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
|
|
@ -81,6 +111,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount(1, $oCell->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add list item
|
||||
*/
|
||||
public function testAddListItem()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
|
|
@ -91,6 +124,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getTextObject()->getText(), 'text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add list item non-UTF8
|
||||
*/
|
||||
public function testAddListItemNotUTF8()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
|
|
@ -101,16 +137,23 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getTextObject()->getText(), 'ééé');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image section
|
||||
*/
|
||||
public function testAddImageSection()
|
||||
{
|
||||
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
||||
$oCell = new Cell('section', 1);
|
||||
$element = $oCell->addImage($src);
|
||||
$element1 = $oCell->addImage($src);
|
||||
$element2 = $oCell->addMemoryImage($src); // @deprecated
|
||||
|
||||
$this->assertCount(1, $oCell->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
$this->assertCount(2, $oCell->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image header
|
||||
*/
|
||||
public function testAddImageHeader()
|
||||
{
|
||||
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
||||
|
|
@ -121,6 +164,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image footer
|
||||
*/
|
||||
public function testAddImageFooter()
|
||||
{
|
||||
$src = __DIR__ . "/../../_files/images/earth.jpg";
|
||||
|
|
@ -131,7 +177,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
public function testAddSectionImageByUrl()
|
||||
/**
|
||||
* Add image section by URL
|
||||
*/
|
||||
public function testAddImageSectionByUrl()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
$element = $oCell->addImage(
|
||||
|
|
@ -142,7 +191,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
public function testAddHeaderImageByUrl()
|
||||
/**
|
||||
* Add image header by URL
|
||||
*/
|
||||
public function testAddImageHeaderByUrl()
|
||||
{
|
||||
$oCell = new Cell('header', 1);
|
||||
$element = $oCell->addImage(
|
||||
|
|
@ -153,7 +205,10 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
public function testAddFooterImageByUrl()
|
||||
/**
|
||||
* Add image footer by URL
|
||||
*/
|
||||
public function testAddImageFooterByUrl()
|
||||
{
|
||||
$oCell = new Cell('footer', 1);
|
||||
$element = $oCell->addImage(
|
||||
|
|
@ -164,6 +219,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add object
|
||||
*/
|
||||
public function testAddObjectXLS()
|
||||
{
|
||||
$src = __DIR__ . "/../../_files/documents/sheet.xls";
|
||||
|
|
@ -174,6 +232,21 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Object', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add object exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidObjectException
|
||||
*/
|
||||
public function testAddObjectException()
|
||||
{
|
||||
$src = __DIR__ . "/_files/xsl/passthrough.xsl";
|
||||
$oCell = new Cell('section', 1);
|
||||
$element = $oCell->addObject($src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text
|
||||
*/
|
||||
public function testAddPreserveText()
|
||||
{
|
||||
$oCell = new Cell('header', 1);
|
||||
|
|
@ -183,6 +256,9 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Footer\\PreserveText', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text non-UTF8
|
||||
*/
|
||||
public function testAddPreserveTextNotUTF8()
|
||||
{
|
||||
$oCell = new Cell('header', 1);
|
||||
|
|
@ -193,6 +269,20 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), array('ééé'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add preserve text exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function testAddPreserveTextException()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
$element = $oCell->addPreserveText('text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text run
|
||||
*/
|
||||
public function testCreateTextRun()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
|
|
@ -202,6 +292,21 @@ class CellTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\TextRun', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add check box
|
||||
*/
|
||||
public function testAddCheckBox()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
$element = $oCell->addCheckBox(utf8_decode('ééé'), utf8_decode('ééé'));
|
||||
|
||||
$this->assertCount(1, $oCell->getElements());
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\CheckBox', $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elements
|
||||
*/
|
||||
public function testGetElements()
|
||||
{
|
||||
$oCell = new Cell('section', 1);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ use PhpOffice\PhpWord\Section\Table\Row;
|
|||
*/
|
||||
class RowTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
@ -31,6 +34,9 @@ class RowTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new instance with parameters
|
||||
*/
|
||||
public function testConstructWithParams()
|
||||
{
|
||||
$iVal = rand(1, 1000);
|
||||
|
|
@ -46,6 +52,9 @@ class RowTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add cell
|
||||
*/
|
||||
public function testAddCell()
|
||||
{
|
||||
$oRow = new Row('section', 1);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ use PhpOffice\PhpWord\Section\Table;
|
|||
*/
|
||||
class TableTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oTable = new Table('section', 1);
|
||||
|
|
@ -30,6 +33,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount(0, $oTable->getRows());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style name
|
||||
*/
|
||||
public function testStyleText()
|
||||
{
|
||||
$oTable = new Table('section', 1, 'tableStyle');
|
||||
|
|
@ -37,6 +43,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTable->getStyle(), 'tableStyle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style array
|
||||
*/
|
||||
public function testStyleArray()
|
||||
{
|
||||
$oTable = new Table(
|
||||
|
|
@ -48,6 +57,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get width
|
||||
*/
|
||||
public function testWidth()
|
||||
{
|
||||
$oTable = new Table('section', 1);
|
||||
|
|
@ -56,6 +68,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTable->getWidth(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add/get row
|
||||
*/
|
||||
public function testRow()
|
||||
{
|
||||
$oTable = new Table('section', 1);
|
||||
|
|
@ -64,6 +79,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount(1, $oTable->getRows());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add cell
|
||||
*/
|
||||
public function testCell()
|
||||
{
|
||||
$oTable = new Table('section', 1);
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@ use PhpOffice\PhpWord\Section\TextRun;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\TextRun
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\TextRun
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class TextRunTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* New instance
|
||||
*/
|
||||
public function testConstructNull()
|
||||
{
|
||||
$oTextRun = new TextRun();
|
||||
|
|
@ -28,6 +30,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTextRun->getParagraphStyle(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance with string
|
||||
*/
|
||||
public function testConstructString()
|
||||
{
|
||||
$oTextRun = new TextRun('pStyle');
|
||||
|
|
@ -37,6 +42,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle');
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance with array
|
||||
*/
|
||||
public function testConstructArray()
|
||||
{
|
||||
$oTextRun = new TextRun(array('spacing' => 100));
|
||||
|
|
@ -46,6 +54,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oTextRun->getParagraphStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text
|
||||
*/
|
||||
public function testAddText()
|
||||
{
|
||||
$oTextRun = new TextRun();
|
||||
|
|
@ -56,6 +67,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), 'text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text non-UTF8
|
||||
*/
|
||||
public function testAddTextNotUTF8()
|
||||
{
|
||||
$oTextRun = new TextRun();
|
||||
|
|
@ -66,6 +80,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getText(), 'ééé');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link
|
||||
*/
|
||||
public function testAddLink()
|
||||
{
|
||||
$oTextRun = new TextRun();
|
||||
|
|
@ -76,6 +93,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getLinkSrc(), 'http://www.google.fr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link with name
|
||||
*/
|
||||
public function testAddLinkWithName()
|
||||
{
|
||||
$oTextRun = new TextRun();
|
||||
|
|
@ -87,6 +107,20 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($element->getLinkName(), 'ééé');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text break
|
||||
*/
|
||||
public function testAddTextBreak()
|
||||
{
|
||||
$oTextRun = new TextRun();
|
||||
$element = $oTextRun->addTextBreak(2);
|
||||
|
||||
$this->assertCount(2, $oTextRun->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add image
|
||||
*/
|
||||
public function testAddImage()
|
||||
{
|
||||
$src = __DIR__ . "/../_files/images/earth.jpg";
|
||||
|
|
@ -98,6 +132,9 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertCount(1, $oTextRun->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add footnote
|
||||
*/
|
||||
public function testCreateFootnote()
|
||||
{
|
||||
$oTextRun = new TextRun();
|
||||
|
|
|
|||
|
|
@ -10,15 +10,18 @@
|
|||
namespace PhpOffice\PhpWord\Tests\Section;
|
||||
|
||||
use PhpOffice\PhpWord\Section\Text;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Section\Text
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Section\Text
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class TextTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* New instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oText = new Text();
|
||||
|
|
@ -29,6 +32,9 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text
|
||||
*/
|
||||
public function testText()
|
||||
{
|
||||
$oText = new Text('text');
|
||||
|
|
@ -36,6 +42,9 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oText->getText(), 'text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get font style
|
||||
*/
|
||||
public function testFont()
|
||||
{
|
||||
$oText = new Text('text', 'fontStyle');
|
||||
|
|
@ -45,6 +54,19 @@ class TextTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get font style as object
|
||||
*/
|
||||
public function testFontObject()
|
||||
{
|
||||
$font = new Font();
|
||||
$oText = new Text('text', $font);
|
||||
$this->assertEquals($oText->getFontStyle(), $font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paragraph style
|
||||
*/
|
||||
public function testParagraph()
|
||||
{
|
||||
$oText = new Text('text', 'fontStyle', 'paragraphStyle');
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ use PhpOffice\PhpWord\Section\Title;
|
|||
*/
|
||||
class TitleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Create new instance
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$oTitle = new Title('text');
|
||||
|
|
@ -27,6 +30,9 @@ class TitleTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTitle->getText(), 'text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style null
|
||||
*/
|
||||
public function testStyleNull()
|
||||
{
|
||||
$oTitle = new Title('text');
|
||||
|
|
@ -34,6 +40,9 @@ class TitleTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTitle->getStyle(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style not null
|
||||
*/
|
||||
public function testStyleNotNull()
|
||||
{
|
||||
$oTitle = new Title('text', 1, 'style');
|
||||
|
|
@ -41,6 +50,9 @@ class TitleTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTitle->getStyle(), 'style');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get anchor
|
||||
*/
|
||||
public function testAnchor()
|
||||
{
|
||||
$oTitle = new Title('text');
|
||||
|
|
@ -50,6 +62,9 @@ class TitleTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($oTitle->getAnchor(), $iVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bookmark Id
|
||||
*/
|
||||
public function testBookmarkID()
|
||||
{
|
||||
$oTitle = new Title('text');
|
||||
|
|
|
|||
|
|
@ -88,12 +88,13 @@ class SectionTest extends \PHPUnit_Framework_TestCase
|
|||
$section->addTitle(utf8_decode('ä'), 1);
|
||||
$section->createTextRun();
|
||||
$section->createFootnote();
|
||||
$section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä'));
|
||||
$section->addTOC();
|
||||
|
||||
$elementCollection = $section->getElements();
|
||||
$elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
|
||||
'Table', 'ListItem', 'Object', 'Image', 'Image',
|
||||
'Title', 'TextRun', 'Footnote');
|
||||
'Title', 'TextRun', 'Footnote', 'CheckBox');
|
||||
$i = 0;
|
||||
foreach ($elementTypes as $elementType) {
|
||||
$this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$elementType}", $elementCollection[$i]);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ use PhpOffice\PhpWord\Shared\String;
|
|||
*/
|
||||
class StringTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Is UTF8
|
||||
*/
|
||||
public function testIsUTF8()
|
||||
{
|
||||
$this->assertTrue(String::isUTF8(''));
|
||||
|
|
@ -26,12 +29,18 @@ class StringTest extends \PHPUnit_Framework_TestCase
|
|||
$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(''));
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@ use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Style\Font
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Style\Font
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class FontTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Tear down after each test
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
TestHelperDOCX::clear();
|
||||
|
|
@ -55,6 +57,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
'strikethrough' => false,
|
||||
'color' => PhpWord::DEFAULT_FONT_COLOR,
|
||||
'fgColor' => null,
|
||||
'bgColor' => null,
|
||||
'hint' => PhpWord::DEFAULT_FONT_CONTENT_TYPE,
|
||||
);
|
||||
foreach ($attributes as $key => $default) {
|
||||
|
|
@ -83,7 +86,8 @@ class FontTest extends \PHPUnit_Framework_TestCase
|
|||
'underline' => Font::UNDERLINE_HEAVY,
|
||||
'strikethrough' => true,
|
||||
'color' => '999999',
|
||||
'fgColor' => '999999',
|
||||
'fgColor' => Font::FGCOLOR_YELLOW,
|
||||
'bgColor' => 'FFFF00',
|
||||
'hint' => 'eastAsia',
|
||||
);
|
||||
$object->setArrayStyle($attributes);
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@ use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Style\Paragraph
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Style\Paragraph
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class ParagraphTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Tear down after each test
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
TestHelperDOCX::clear();
|
||||
|
|
@ -97,6 +99,9 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Tabs', $object->getTabs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Line height
|
||||
*/
|
||||
public function testLineHeight()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class RowTest extends \PHPUnit_Framework_TestCase
|
|||
$properties = array(
|
||||
'tblHeader' => true,
|
||||
'cantSplit' => false,
|
||||
'exactHeight' => true,
|
||||
);
|
||||
foreach ($properties as $key => $value) {
|
||||
// set/get
|
||||
|
|
@ -56,6 +57,7 @@ class RowTest extends \PHPUnit_Framework_TestCase
|
|||
$properties = array(
|
||||
'tblHeader' => 'a',
|
||||
'cantSplit' => 'b',
|
||||
'exactHeight' => 'c',
|
||||
);
|
||||
foreach ($properties as $key => $value) {
|
||||
$set = "set{$key}";
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* XSL stylesheet can be applied
|
||||
*
|
||||
* @param string $actualDocumentFqfn
|
||||
* @covers ::applyXslStyleSheet
|
||||
* @depends testTemplateCanBeSavedInTemporaryLocation
|
||||
* @test
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@ use PhpOffice\PhpWord\Writer\ODText;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\ODText
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\ODText
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class ODTextTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test construct
|
||||
* Construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
|
|
@ -43,9 +42,10 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::getPhpWord
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage No PhpWord assigned.
|
||||
* Construct with null
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage No PhpWord assigned.
|
||||
*/
|
||||
public function testConstructWithNull()
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* Save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
|
|
@ -89,7 +89,8 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* Save php output
|
||||
*
|
||||
* @todo Haven't got any method to test this
|
||||
*/
|
||||
public function testSavePhpOutput()
|
||||
|
|
@ -102,8 +103,9 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
|
|
@ -113,7 +115,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::getWriterPart
|
||||
* Get writer part return null value
|
||||
*/
|
||||
public function testGetWriterPartNull()
|
||||
{
|
||||
|
|
@ -122,8 +124,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* @covers ::getUseDiskCaching
|
||||
* Set/get use disk caching
|
||||
*/
|
||||
public function testSetGetUseDiskCaching()
|
||||
{
|
||||
|
|
@ -134,7 +135,8 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* Use disk caching exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function testSetUseDiskCachingException()
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@ use PhpOffice\PhpWord\Writer\RTF;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\RTF
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\RTF
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class RTFTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* covers ::construct
|
||||
* Construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
|
|
@ -31,8 +30,9 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* covers ::__construct
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* Construct with null
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage No PhpWord assigned.
|
||||
*/
|
||||
public function testConstructWithNull()
|
||||
|
|
@ -42,32 +42,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @todo Haven't got any method to test this
|
||||
*/
|
||||
public function testSavePhpOutput()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test');
|
||||
$writer = new RTF($phpWord);
|
||||
$writer->save('php://output');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new RTF();
|
||||
$writer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* @covers ::<private>
|
||||
* Save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
|
|
@ -76,12 +51,12 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
$file = __DIR__ . "/../_files/temp.rtf";
|
||||
|
||||
$phpWord = new PhpWord();
|
||||
$phpWord->addFontStyle('Font', array('size' => 11));
|
||||
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000'));
|
||||
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test 1', 'Font');
|
||||
$section->addText('Test 1', 'Font', 'Paragraph');
|
||||
$section->addTextBreak();
|
||||
$section->addText('Test 2', null, 'Paragraph');
|
||||
$section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true));
|
||||
$section->addLink('http://test.com');
|
||||
$section->addTitle('Test', 1);
|
||||
$section->addPageBreak();
|
||||
|
|
@ -101,4 +76,30 @@ class RTFTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @todo Haven't got any method to test this
|
||||
*/
|
||||
public function testSavePhpOutput()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test');
|
||||
$writer = new RTF($phpWord);
|
||||
$writer->save('php://output');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new RTF();
|
||||
$writer->save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$textrun->addTextBreak();
|
||||
$textrun = $section->createTextRun($aStyle);
|
||||
$textrun->addLink('http://test.com');
|
||||
$textrun->addImage($imageSrc);
|
||||
$textrun->addImage($imageSrc, array('align' => 'top'));
|
||||
$textrun->createFootnote();
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
$parent = "/w:document/w:body/w:p";
|
||||
|
|
@ -79,9 +80,15 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$fontStyleArray = array('bold' => true);
|
||||
$fontStyleName = 'Font Style';
|
||||
$paragraphStyleArray = array('align' => '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);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t');
|
||||
|
|
@ -97,8 +104,14 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$footer = $section->createFooter();
|
||||
$fontStyleArray = array('bold' => true);
|
||||
$fontStyleName = 'Font';
|
||||
$paragraphStyleArray = array('align' => 'right');
|
||||
$paragraphStyleName = 'Paragraph';
|
||||
|
||||
$footer->addPreserveText('{PAGE}');
|
||||
$footer->addPreserveText('Page {PAGE}');
|
||||
$footer->addPreserveText('{PAGE}', $fontStyleArray, $paragraphStyleArray);
|
||||
$footer->addPreserveText('{PAGE}', $fontStyleName, $paragraphStyleName);
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
$preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml');
|
||||
|
|
@ -193,6 +206,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$styles['superScript'] = true;
|
||||
$styles['color'] = 'FF0000';
|
||||
$styles['fgColor'] = 'yellow';
|
||||
$styles['bgColor'] = 'FFFF00';
|
||||
$styles['hint'] = 'eastAsia';
|
||||
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test', $styles);
|
||||
|
|
@ -219,6 +234,10 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$tWidth = 120;
|
||||
$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;
|
||||
|
|
@ -236,6 +255,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$cStyles["borderBottomColor"] = 'FF0000';
|
||||
$cStyles["borderLeftColor"] = 'FF0000';
|
||||
$cStyles["borderRightColor"] = 'FF0000';
|
||||
$cStyles["vMerge"] = 'restart';
|
||||
|
||||
$section = $phpWord->createSection();
|
||||
$table = $section->addTable($tStyles);
|
||||
|
|
@ -246,6 +266,8 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$cell->addTextBreak();
|
||||
$cell->addLink('http://google.com');
|
||||
$cell->addListItem('Test');
|
||||
$cell->addImage($imageSrc);
|
||||
$cell->addObject($objectSrc);
|
||||
$textrun = $cell->createTextRun();
|
||||
$textrun->addText('Test');
|
||||
|
||||
|
|
@ -352,4 +374,23 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
|||
$element = "/w:document/w:body/w:p/w:r/w:fldChar";
|
||||
$this->assertEquals('end', $doc->getElementAttribute($element, 'w:fldCharType'));
|
||||
}
|
||||
|
||||
/**
|
||||
* covers ::_writeCheckbox
|
||||
*/
|
||||
public function testWriteCheckbox()
|
||||
{
|
||||
$rStyle = 'rStyle';
|
||||
$pStyle = 'pStyle';
|
||||
|
||||
$phpWord = new PhpWord();
|
||||
$phpWord->addFontStyle($rStyle, array('bold' => true));
|
||||
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
|
||||
$section = $phpWord->createSection();
|
||||
$section->addCheckbox('Check1', 'Test', $rStyle, $pStyle);
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
$element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name';
|
||||
$this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
namespace PhpOffice\PhpWord\Tests\Writer\Word2007;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Style\Font;
|
||||
use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
||||
|
||||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Document
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Document
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||
|
|
@ -27,11 +27,18 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||
TestHelperDOCX::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write end section page numbering
|
||||
*/
|
||||
public function testWriteEndSectionPageNumbering()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->getSettings()->setPageNumberingStart(2);
|
||||
$settings = $section->getSettings();
|
||||
$settings->setLandscape();
|
||||
$settings->setPageNumberingStart(2);
|
||||
$settings->setBorderSize(240);
|
||||
$settings->setBreakType('nextPage');
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType');
|
||||
|
|
@ -40,11 +47,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* covers ::_writeTOC
|
||||
* covers ::_writePageBreak
|
||||
* covers ::_writeListItem
|
||||
* covers ::_writeTitle
|
||||
* covers ::_writeObject
|
||||
* Write elements
|
||||
*/
|
||||
public function testElements()
|
||||
{
|
||||
|
|
@ -87,4 +90,39 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
|
|||
$element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject');
|
||||
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write element with some styles
|
||||
*/
|
||||
public function testElementStyles()
|
||||
{
|
||||
$objectSrc = __DIR__ . "/../../_files/documents/sheet.xls";
|
||||
|
||||
$phpWord = new PhpWord();
|
||||
$phpWord->addParagraphStyle('pStyle', array('align' => 'center'));
|
||||
$phpWord->addFontStyle('fStyle', array('size' => '20'));
|
||||
$phpWord->addTitleStyle(1, array('color' => '333333', 'bold' => true));
|
||||
$fontStyle = new Font('text', array('align' => 'center'));
|
||||
$section = $phpWord->createSection();
|
||||
$section->addListItem('List Item', 0, null, null, 'pStyle');
|
||||
$section->addObject($objectSrc, array('align' => 'center'));
|
||||
$section->addTOC($fontStyle);
|
||||
$section->addTitle('Title 1', 1);
|
||||
$section->addTOC('fStyle');
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
// List item
|
||||
$element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId');
|
||||
$this->assertEquals(3, $element->getAttribute('w:val'));
|
||||
|
||||
// Object
|
||||
$element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject');
|
||||
$this->assertEquals('Embed', $element->getAttribute('Type'));
|
||||
|
||||
// TOC
|
||||
$element = $doc->getElement('/w:document/w:body/w:p[3]/w:pPr/w:tabs/w:tab');
|
||||
$this->assertEquals('right', $element->getAttribute('w:val'));
|
||||
$this->assertEquals('dot', $element->getAttribute('w:leader'));
|
||||
$this->assertEquals(9062, $element->getAttribute('w:pos'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
|||
class FooterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Write footer
|
||||
*
|
||||
* @covers ::writeFooter
|
||||
*/
|
||||
public function testWriteFooter()
|
||||
|
|
|
|||
|
|
@ -27,14 +27,21 @@ class FootnotesTest extends \PHPUnit_Framework_TestCase
|
|||
TestHelperDOCX::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write footnotes
|
||||
*/
|
||||
public function testWriteFootnotes()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Text');
|
||||
$footnote = $section->createFootnote();
|
||||
$footnote->addText('Footnote');
|
||||
$footnote->addLink('http://google.com');
|
||||
$footnote1 = $section->createFootnote('pStyle');
|
||||
$footnote1->addText('Footnote');
|
||||
$footnote1->addTextBreak();
|
||||
$footnote1->addLink('http://google.com');
|
||||
$footnote2 = $section->createFootnote(array('align' => 'left'));
|
||||
$footnote2->addText('Footnote');
|
||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||
|
||||
$this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference"));
|
||||
|
|
|
|||
|
|
@ -15,13 +15,12 @@ use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Header
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Header
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class HeaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers ::writeHeader
|
||||
* Write header
|
||||
*/
|
||||
public function testWriteHeader()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,18 +15,20 @@ use PhpOffice\PhpWord\Tests\TestHelperDOCX;
|
|||
/**
|
||||
* Test class for PhpOffice\PhpWord\Writer\Word2007
|
||||
*
|
||||
* @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007
|
||||
* @runTestsInSeparateProcesses
|
||||
*/
|
||||
class Word2007Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Tear down after each test
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
TestHelperDOCX::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* covers ::__construct
|
||||
* Construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
|
|
@ -57,10 +59,12 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::save
|
||||
* Save
|
||||
*/
|
||||
public function testSave()
|
||||
{
|
||||
$localImage = __DIR__ . '/../_files/images/earth.jpg';
|
||||
$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'));
|
||||
|
|
@ -71,16 +75,57 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
$section = $phpWord->createSection();
|
||||
$textrun = $section->createTextRun();
|
||||
$textrun->addText('Test 3');
|
||||
$footnote = $textrun->createFootnote();
|
||||
$footnote->addLink('http://test.com');
|
||||
$header = $section->createHeader();
|
||||
$header->addImage($localImage);
|
||||
$footer = $section->createFooter();
|
||||
$footer->addImage($remoteImage);
|
||||
|
||||
$writer = new Word2007($phpWord);
|
||||
$file = __DIR__ . "/../_files/temp.docx";
|
||||
$writer->save($file);
|
||||
$this->assertTrue(\file_exists($file));
|
||||
|
||||
$this->assertTrue(file_exists($file));
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkContentTypes
|
||||
* Save using disk caching
|
||||
*/
|
||||
public function testSaveUseDiskCaching()
|
||||
{
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$section->addText('Test');
|
||||
$footnote = $section->createFootnote();
|
||||
$footnote->addText('Test');
|
||||
|
||||
$writer = new Word2007($phpWord);
|
||||
$writer->setUseDiskCaching(true);
|
||||
$file = __DIR__ . "/../_files/temp.docx";
|
||||
$writer->save($file);
|
||||
|
||||
$this->assertTrue(file_exists($file));
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save with no PhpWord object assigned
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* @expectedExceptionMessage PhpWord object unassigned.
|
||||
*/
|
||||
public function testSaveException()
|
||||
{
|
||||
$writer = new Word2007();
|
||||
$writer->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check content types
|
||||
*/
|
||||
public function testCheckContentTypes()
|
||||
{
|
||||
|
|
@ -110,20 +155,33 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* @covers ::getUseDiskCaching
|
||||
* Get writer part return null value
|
||||
*/
|
||||
public function testGetWriterPartNull()
|
||||
{
|
||||
$object = new Word2007();
|
||||
$this->assertNull($object->getWriterPart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set/get use disk caching
|
||||
*/
|
||||
public function testSetGetUseDiskCaching()
|
||||
{
|
||||
$object = new Word2007();
|
||||
$phpWord = new PhpWord();
|
||||
$section = $phpWord->createSection();
|
||||
$object = new Word2007($phpWord);
|
||||
$object->setUseDiskCaching(true, \PHPWORD_TESTS_BASE_DIR);
|
||||
$writer = new Word2007($phpWord);
|
||||
$writer->save('php://output');
|
||||
|
||||
$this->assertTrue($object->getUseDiskCaching());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setUseDiskCaching
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
* Use disk caching exception
|
||||
*
|
||||
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
|
||||
*/
|
||||
public function testSetUseDiskCachingException()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,15 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Tests;
|
||||
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\IOFactory;
|
||||
|
||||
/**
|
||||
* Test helper class
|
||||
*/
|
||||
class TestHelperDOCX
|
||||
{
|
||||
/** @var string $file */
|
||||
/**
|
||||
* Temporary file name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static protected $file;
|
||||
|
||||
/**
|
||||
* Get document content
|
||||
*
|
||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||
* @param string $writerName
|
||||
* @return \PhpOffice\PhpWord\Tests\XmlDocument
|
||||
|
|
@ -34,6 +51,9 @@ class TestHelperDOCX
|
|||
return new XmlDocument(sys_get_temp_dir() . '/PhpWord_Unit_Test/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear document
|
||||
*/
|
||||
public static function clear()
|
||||
{
|
||||
if (\file_exists(self::$file)) {
|
||||
|
|
@ -45,6 +65,8 @@ class TestHelperDOCX
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete directory
|
||||
*
|
||||
* @param string $dir
|
||||
*/
|
||||
public static function deleteDir($dir)
|
||||
|
|
@ -63,6 +85,8 @@ class TestHelperDOCX
|
|||
}
|
||||
|
||||
/**
|
||||
* Get file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getFile()
|
||||
|
|
|
|||
|
|
@ -1,21 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
namespace PhpOffice\PhpWord\Tests;
|
||||
|
||||
/**
|
||||
* DOM wrapper class
|
||||
*/
|
||||
class XmlDocument
|
||||
{
|
||||
/** @var string $path */
|
||||
/**
|
||||
* Path
|
||||
*
|
||||
* @var string $path
|
||||
*/
|
||||
private $path;
|
||||
|
||||
/** @var \DOMDocument $dom */
|
||||
/**
|
||||
* DOMDocument object
|
||||
*
|
||||
* @var \DOMDocument
|
||||
*/
|
||||
private $dom;
|
||||
|
||||
/** @var \DOMXpath $xpath */
|
||||
/**
|
||||
* DOMXpath object
|
||||
*
|
||||
* @var \DOMXpath
|
||||
*/
|
||||
private $xpath;
|
||||
|
||||
/** @var string $file */
|
||||
/**
|
||||
* File name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param string $path
|
||||
*/
|
||||
public function __construct($path)
|
||||
|
|
@ -24,6 +53,8 @@ class XmlDocument
|
|||
}
|
||||
|
||||
/**
|
||||
* Get DOM from file
|
||||
*
|
||||
* @param string $file
|
||||
* @return \DOMDocument
|
||||
*/
|
||||
|
|
@ -43,9 +74,11 @@ class XmlDocument
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @return \DOMNodeList
|
||||
* Get node list
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @return \DOMNodeList
|
||||
*/
|
||||
public function getNodeList($path, $file = 'word/document.xml')
|
||||
{
|
||||
|
|
@ -62,9 +95,11 @@ class XmlDocument
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @return \DOMElement
|
||||
* Get element
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @return \DOMElement
|
||||
*/
|
||||
public function getElement($path, $file = 'word/document.xml')
|
||||
{
|
||||
|
|
@ -74,6 +109,8 @@ class XmlDocument
|
|||
}
|
||||
|
||||
/**
|
||||
* Get file name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFile()
|
||||
|
|
@ -82,6 +119,8 @@ class XmlDocument
|
|||
}
|
||||
|
||||
/**
|
||||
* Get path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
|
|
@ -90,6 +129,8 @@ class XmlDocument
|
|||
}
|
||||
|
||||
/**
|
||||
* Get element attribute
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $attribute
|
||||
* @param string $file
|
||||
|
|
@ -101,6 +142,8 @@ class XmlDocument
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if element exists
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @return string
|
||||
|
|
|
|||
|
|
@ -1,4 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPWord test bootstrap
|
||||
*
|
||||
* @link https://github.com/PHPOffice/PHPWord
|
||||
* @copyright 2014 PHPWord
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
// defining base dir for tests
|
||||
|
|
@ -24,7 +32,8 @@ spl_autoload_register(function ($class) {
|
|||
$prefix = 'PhpOffice\\PhpWord\\Tests';
|
||||
if (strpos($class, $prefix) === 0) {
|
||||
$class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
|
||||
$class = 'PhpWord' . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR . '_includes' . substr($class, strlen($prefix));
|
||||
$class = join(DIRECTORY_SEPARATOR, array('PhpWord', 'Tests', '_includes')) .
|
||||
substr($class, strlen($prefix));
|
||||
$file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php';
|
||||
if (\file_exists($file)) {
|
||||
require_once $file;
|
||||
|
|
|
|||
Loading…
Reference in New Issue