Merge pull request #187 from ivanlanin/#160-element-container

#160 Refactor folders: Element, Container, and Exception
This commit is contained in:
Ivan Lanin 2014-04-08 15:59:12 +07:00
commit cf7263b97c
167 changed files with 4067 additions and 5667 deletions

View File

@ -4,6 +4,8 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
## 0.9.2 - Not yet released
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`.
### Features
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
@ -17,16 +19,47 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
- Template: Ability to find & replace variables in headers & footers - @dgudgeon GH-190
- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira GH-191
- TOC: Ability to have two or more TOC in one document and to set min and max depth for TOC - @Pyreweb GH-189
- Table: Ability to add footnote in table cell - @ivanlanin GH-187
- Footnote: Ability to add image in footnote - @ivanlanin GH-187
- ListItem: Ability to add list item in header/footer - @ivanlanin GH-187
- CheckBox: Ability to add checkbox in header/footer - @ivanlanin GH-187
- Link: Ability to add link in header/footer - @ivanlanin GH-187
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
- Media: Add `Media::reset()` to reset all media data - @juzi GH-19
- Style: Add `Style::reset()` to reset all styles
- Footnote: Add `Footnote::reset()` to reset all footnotes
- TOC: Add `TOC::reset()` to reset all TOC
### Bugfixes
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
### Deprecated
- `createTextRun` replaced by `addTextRun`
- `createFootnote` replaced by `addFootnote`
- `createHeader` replaced by `addHeader`
- `createFooter` replaced by `addFooter`
- `createSection` replaced by `addSection`
- `Element\Footnote::getReferenceId` replaced by `Element\AbstractElement::getRelationId`
- `Element\Footnote::setReferenceId` replaced by `Element\AbstractElement::setRelationId`
- `Footnote::addFootnoteLinkElement` replaced by `Media::addElement`
- `Footnote::getFootnoteLinkElements` replaced by `Media::getElements`
- All current methods on `Media`
### 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
- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
## 0.9.1 - 27 Mar 2014

View File

@ -71,7 +71,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');

View File

@ -16,7 +16,7 @@ section, use the following code:
.. code-block:: php
$section = $phpWord->createSection($sectionSettings);
$section = $phpWord->addSection($sectionSettings);
The ``$sectionSettings`` is an optional associative array that sets the
section. Example:
@ -70,10 +70,10 @@ property of the section.
.. code-block:: php
// Method 1
$section = $phpWord->createSection(array('pageNumberingStart' => 1));
$section = $phpWord->addSection(array('pageNumberingStart' => 1));
// Method 2
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->getSettings()->setPageNumberingStart(1);
Multicolumn
@ -85,10 +85,10 @@ using the ``breakType`` and ``colsNum`` property of the section.
.. code-block:: php
// Method 1
$section = $phpWord->createSection(array('breakType' => 'continuous', 'colsNum' => 2));
$section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2));
// Method 2
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->getSettings()->setBreakType('continuous');
$section->getSettings()->setColsNum(2);
@ -96,11 +96,11 @@ Headers
-------
Each section can have its own header reference. To create a header use
the ``createHeader`` method:
the ``addHeader`` method:
.. code-block:: php
$header = $section->createHeader();
$header = $section->addHeader();
Be sure to save the result in a local object. You can use all elements
that are available for the footer. See "Footer" section for detail.
@ -111,11 +111,11 @@ Footers
-------
Each section can have its own footer reference. To create a footer, use
the ``createFooter`` method:
the ``addFooter`` method:
.. code-block:: php
$footer = $section->createFooter();
$footer = $section->addFooter();
Be sure to save the result in a local object to add elements to a
footer. You can add the following elements to footers:

View File

@ -3,12 +3,57 @@
Elements
========
Below are the matrix of element availability in each container. The column shows
the containers while the rows lists the elements.
+-----+---------------+---------+--------+--------+------+----------+----------+
| Num | Element | Section | Header | Footer | Cell | Text Run | Footnote |
+=====+===============+=========+========+========+======+==========+==========+
| 1 | Text | v | v | v | v | v | v |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 2 | Text Run | v | v | v | v | \- | \- |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 3 | Link | v | v | v | v | v | v |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 4 | Title | v | ? | ? | ? | ? | ? |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 5 | Preserve Text | ? | v | v | v\* | ? | ? |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 6 | Text Break | v | v | v | v | v | v |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 7 | Page Break | v | \- | \- | \- | \- | \- |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 8 | List | v | v | v | v | \- | \- |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 9 | Table | v | v | v | ? | \- | \- |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 10 | Image | v | v | v | v | v | v |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 11 | Watermark | \- | v | \- | \- | \- | \- |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 12 | Object | v | v | v | v | v | v |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 13 | TOC | v | \- | \- | \- | \- | \- |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 14 | Footnote | v | \- | \- | v\*\*| v\*\* | \- |
+-----+---------------+---------+--------+--------+------+----------+----------+
| 15 | CheckBox | v | v | v | v | ? | ? |
+-----+---------------+---------+--------+--------+------+----------+----------+
Legend:
- ``v`` Available
- ``v*`` Available only when inside header/footer
- ``v**`` Available only when inside section
- ``-`` Not available
- ``?`` Should be available
Texts
-----
Text can be added by using ``addText`` and ``createTextRun`` method.
Text can be added by using ``addText`` and ``addTextRun`` method.
``addText`` is used for creating simple paragraphs that only contain
texts with the same style. ``createTextRun`` is used for creating
texts with the same style. ``addTextRun`` is used for creating
complex paragraphs that contain text with different style (some bold,
other italics, etc) or other elements, e.g. images or links. The
syntaxes are as follow:
@ -16,7 +61,7 @@ syntaxes are as follow:
.. code-block:: php
$section->addText($text, [$fontStyle], [$paragraphStyle]);
$textrun = $section->createTextRun([$paragraphStyle]);
$textrun = $section->addTextRun([$paragraphStyle]);
Text styles
~~~~~~~~~~~
@ -34,7 +79,7 @@ Inline style examples:
$paragraphStyle = array('align' => 'both');
$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
$textrun = $section->createTextRun();
$textrun = $section->addTextRun();
$textrun->addText('I am bold', array('bold' => true));
$textrun->addText('I am italic', array('italic' => true));
$textrun->addText('I am colored, array('color' => 'AACC00'));
@ -255,7 +300,7 @@ Examples:
.. code-block:: php
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->addImage(
'mars.jpg',
array(
@ -266,9 +311,9 @@ Examples:
'wrappingStyle' => 'behind'
)
);
$footer = $section->createFooter();
$footer = $section->addFooter();
$footer->addImage('http://example.com/image.php');
$textrun = $section->createTextRun();
$textrun = $section->addTextRun();
$textrun->addImage('http://php.net/logo.jpg');
Image styles
@ -293,8 +338,8 @@ header reference. After creating a header, you can use the
.. code-block:: php
$section = $phpWord->createSection();
$header = $section->createHeader();
$section = $phpWord->addSection();
$header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
Objects
@ -342,9 +387,9 @@ On textrun:
.. code-block:: php
$textrun = $section->createTextRun();
$textrun = $section->addTextRun();
$textrun->addText('Lead text.');
$footnote = $textrun->createFootnote();
$footnote = $textrun->addFootnote();
$footnote->addText('Footnote text can have ');
$footnote->addLink('http://test.com', 'links');
$footnote->addText('.');
@ -357,7 +402,7 @@ On text:
.. code-block:: php
$section->addText('Lead text.');
$footnote = $section->createFootnote();
$footnote = $section->addFootnote();
$footnote->addText('Footnote text.');
The footnote reference number will be displayed with decimal number starting

View File

@ -19,7 +19,7 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
@ -136,7 +136,7 @@ points to twips.
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
);
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$sectionStyle = $section->getSettings();
// half inch left margin
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));

View File

@ -9,7 +9,7 @@ $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' =>
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
// New portrait section
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Simple text
$section->addTitle('Welcome to PhpWord', 1);

View File

@ -25,7 +25,7 @@ $phpWord->addParagraphStyle('centerTab', array(
));
// New portrait section
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Add listitem elements
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');

View File

@ -6,24 +6,24 @@ echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
$section = $phpWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section->addText('I am placed on a default section.');
// New landscape section
$section = $phpWord->createSection(array('orientation' => 'landscape'));
$section = $phpWord->addSection(array('orientation' => 'landscape'));
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
$section->addPageBreak();
$section->addPageBreak();
// New portrait section
$section = $phpWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section = $phpWord->addSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins.');
// New portrait section with Header & Footer
$section = $phpWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
$section = $phpWord->addSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
$section->addText('This section and we play with header/footer height.');
$section->createHeader()->addText('Header');
$section->createFooter()->addText('Footer');
$section->addHeader()->addText('Header');
$section->addFooter()->addText('Footer');
// Save file
$name = basename(__FILE__, '.php');

View File

@ -12,10 +12,10 @@ $phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// New portrait section
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Add text run
$textrun = $section->createTextRun('pStyle');
$textrun = $section->addTextRun('pStyle');
$textrun->addText('Each textrun can contain native text, link elements or an image.');
$textrun->addText(' No break is placed after adding an element.', 'BoldText');
@ -28,7 +28,9 @@ $textrun->addText(' All elements are placed inside a paragraph with the optional
$textrun->addText(' Sample Link: ');
$textrun->addLink('http://www.google.com', null, 'NLink');
$textrun->addText(' Sample Image: ');
$textrun->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
$textrun->addText(' Sample Object: ');
$textrun->addObject('resources/_sheet.xls');
$textrun->addText(' Here is some more text. ');
// Save file

View File

@ -10,29 +10,29 @@ $filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
'Suspendisse congue congue leo sed pellentesque.';
// Normal
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->addText('Normal paragraph. ' . $filler);
// Two columns
$section = $phpWord->createSection(array(
$section = $phpWord->addSection(array(
'colsNum' => 2,
'colsSpace' => 1440,
'breakType' => 'continuous'));
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
// Normal
$section = $phpWord->createSection(array('breakType' => 'continuous'));
$section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again. ' . $filler);
// Three columns
$section = $phpWord->createSection(array(
$section = $phpWord->addSection(array(
'colsNum' => 3,
'colsSpace' => 720,
'breakType' => 'continuous'));
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
// Normal
$section = $phpWord->createSection(array('breakType' => 'continuous'));
$section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again.');
// Save file

View File

@ -4,9 +4,10 @@ include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
\PhpOffice\PhpWord\Settings::setCompatibility(false);
// New portrait section
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Add style definitions
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
@ -15,23 +16,25 @@ $phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// Add text elements
$textrun = $section->createTextRun('pStyle');
$textrun = $section->addTextRun('pStyle');
$textrun->addText('This is some lead text in a paragraph with a following footnote. ','pStyle');
$footnote = $textrun->createFootnote();
$footnote->addText('Just like a textrun a footnote can contain native text and link elements.');
$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 = $textrun->addFootnote();
$footnote->addText('Just like a textrun, a footnote can contain native texts. ');
$footnote->addText('No break is placed after adding an element. ', 'BoldText');
$footnote->addText('All elements are placed inside a paragraph. ', 'ColoredText');
$footnote->addTextBreak();
$footnote->addLink('http://www.bing.com', null, 'NLink');
$textrun->addText('The trailing text in the paragraph.');
$footnote->addText('But you can insert a manual text break like above, ');
$footnote->addText('links like ');
$footnote->addLink('http://www.google.com', null, 'NLink');
$footnote->addText(', image like ');
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
$footnote->addText(', or object like ');
$footnote->addObject('resources/_sheet.xls');
$footnote->addText('But you can only put footnote in section, not in header or footer.');
$section->addText('You can also create the footnote directly from the section making it wrap in a paragraph like the footnote below this paragraph. But is is best used from within a textrun.');
$footnote = $section->createFootnote();
$footnote = $section->addFootnote();
$footnote->addText('The reference for this is wrapped in its own line');
// Save file

View File

@ -10,7 +10,7 @@ $document = $phpWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
// Variables on different parts of document
$document->setValue('weekday', date('l')); // On section/content
$document->setValue('time', date('H:i')); // On footer
$document->setValue('serverName', $_SERVER['SERVER_NAME']); // On header
$document->setValue('serverName', realpath(__DIR__)); // On header
// Simple table
$document->cloneRow('rowValue', 10);

View File

@ -11,7 +11,7 @@ $phpWord->setDefaultParagraphStyle(array(
));
// Sample
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->addText('Below are the samples on how to control your paragraph ' .
'pagination. See "Line and Page Break" tab on paragraph properties ' .

View File

@ -4,7 +4,7 @@ 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 = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
// 1. Basic table
@ -63,10 +63,21 @@ $cellVCentered = array('valign' => 'center');
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan');
$table->addRow();
$table->addCell(2000, $cellRowSpan)->addText('A', null, $cellHCentered);
$table->addCell(4000, $cellColSpan)->addText('B', null, $cellHCentered);
$cell1 = $table->addCell(2000, $cellRowSpan);
$textrun1 = $cell1->addTextRun($cellHCentered);
$textrun1->addText('A');
$textrun1->addFootnote()->addText('Row span');
$cell2 = $table->addCell(4000, $cellColSpan);
$textrun2 = $cell2->addTextRun($cellHCentered);
$textrun2->addText('B');
$textrun2->addFootnote()->addText('Colspan span');
$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered);
$table->addRow();
$table->addCell(null, $cellRowContinue);
$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);

View File

@ -4,7 +4,7 @@ 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 = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));

View File

@ -6,26 +6,30 @@ echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Add first page header
$header = $section->createHeader();
$header = $section->addHeader();
$header->firstPage();
$table = $header->addTable();
$table->addRow();
$table->addCell(4500)->addText('This is the header.');
$cell = $table->addCell(4500);
$textrun = $cell->addTextRun();
$textrun->addText('This is the header with ');
$textrun->addLink('http://google.com', 'link to Google');
$table->addCell(4500)->addImage(
'resources/PhpWord.png',
array('width' => 80, 'height' => 80, 'align' => 'right')
);
// Add header for all other pages
$subsequent = $section->createHeader();
$subsequent = $section->addHeader();
$subsequent->addText("Subsequent pages in Section 1 will Have this!");
// Add footer
$footer = $section->createFooter();
$footer = $section->addFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center'));
$footer->addLink('http://google.com', 'Direct Google');
// Write some text
$section->addTextBreak();
@ -46,9 +50,9 @@ $section->addTextBreak();
$section->addText('Some text...');
// New portrait section
$section2 = $phpWord->createSection();
$section2 = $phpWord->addSection();
$sec2Header = $section2->createHeader();
$sec2Header = $section2->addHeader();
$sec2Header->addText("All pages in Section 2 will Have this!");
// Write some text

View File

@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg');
$section->addTextBreak(2);

View File

@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Add listitem elements
$section->addListItem('List Item 1', 0);

View File

@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Add hyperlink elements
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));

View File

@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
$section->addObject('resources/_sheet.xls');

View File

@ -6,7 +6,7 @@ echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->createSection();
$section = $phpWord->addSection();
// Define the TOC font style
$fontStyle = array('spaceAfter' => 60, 'size' => 12);

View File

@ -7,8 +7,8 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->createSection();
$header = $section->createHeader();
$section = $phpWord->addSection();
$header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
$section->addText('The header reference to the current section includes a watermark image.');

View File

@ -12,7 +12,7 @@ $phpWord->addFontStyle('fontStyle', array('size' => 9));
$phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
$fontStyle = array('size' => 24);
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->addText('Text break with no style:');
$section->addTextBreak();
$section->addText('Text break with defined font style:');

View File

@ -4,7 +4,7 @@ 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 = $phpWord->addSection();
$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"));

View File

@ -4,7 +4,7 @@ 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 = $phpWord->addSection();
$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");

View File

@ -5,7 +5,7 @@ include_once 'Sample_Header.php';
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->createSection();
$section = $phpWord->addSection();
$section->addText('Check box in section');
$section->addCheckBox('chkBox1', 'Checkbox 1');
$section->addText('Check box in table cell');

View File

@ -3,7 +3,7 @@ include_once 'Sample_Header.php';
if (!CLI) {
?>
<div class="jumbotron">
<p>Welcome to PHPWord, a library written in pure PHP that provides a set of classes to write to and read from different document file formats, i.e. Word (.docx), WordPad (.rtf), and Libre/OpenOffice Writer (.odt).</p>
<p>Welcome to PHPWord, a pure PHP library for reading and writing word processing documents, i.e. Word (.docx), WordPad (.rtf), and Libre/OpenOffice Writer (.odt).</p>
<p>Please use the menu above to browse PHPWord samples.</p>
<p>
<a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPWord" role="button">Fork us on Github!</a>

View File

@ -27,101 +27,101 @@ class DocumentProperties
*
* @var string
*/
private $_creator;
private $creator;
/**
* LastModifiedBy
*
* @var string
*/
private $_lastModifiedBy;
private $lastModifiedBy;
/**
* Created
*
* @var datetime|int
* @var int
*/
private $_created;
private $created;
/**
* Modified
*
* @var datetime|int
* @var int
*/
private $_modified;
private $modified;
/**
* Title
*
* @var string
*/
private $_title;
private $title;
/**
* Description
*
* @var string
*/
private $_description;
private $description;
/**
* Subject
*
* @var string
*/
private $_subject;
private $subject;
/**
* Keywords
*
* @var string
*/
private $_keywords;
private $keywords;
/**
* Category
*
* @var string
*/
private $_category;
private $category;
/**
* Company
*
* @var string
*/
private $_company;
private $company;
/**
* Manager
*
* @var string
*/
private $_manager;
private $manager;
/**
* Custom Properties
*
* @var array
*/
private $_customProperties = array();
private $customProperties = array();
/**
* Create new DocumentProperties
*/
public function __construct()
{
$this->_creator = '';
$this->_lastModifiedBy = $this->_creator;
$this->_created = time();
$this->_modified = time();
$this->_title = '';
$this->_subject = '';
$this->_description = '';
$this->_keywords = '';
$this->_category = '';
$this->_company = '';
$this->_manager = '';
$this->creator = '';
$this->lastModifiedBy = $this->creator;
$this->created = time();
$this->modified = time();
$this->title = '';
$this->subject = '';
$this->description = '';
$this->keywords = '';
$this->category = '';
$this->company = '';
$this->manager = '';
}
/**
@ -131,7 +131,7 @@ class DocumentProperties
*/
public function getCreator()
{
return $this->_creator;
return $this->creator;
}
/**
@ -142,7 +142,7 @@ class DocumentProperties
*/
public function setCreator($pValue = '')
{
$this->_creator = $pValue;
$this->creator = $pValue;
return $this;
}
@ -153,7 +153,7 @@ class DocumentProperties
*/
public function getLastModifiedBy()
{
return $this->_lastModifiedBy;
return $this->lastModifiedBy;
}
/**
@ -164,24 +164,24 @@ class DocumentProperties
*/
public function setLastModifiedBy($pValue = '')
{
$this->_lastModifiedBy = $pValue;
$this->lastModifiedBy = $pValue;
return $this;
}
/**
* Get Created
*
* @return datetime
* @return int
*/
public function getCreated()
{
return $this->_created;
return $this->created;
}
/**
* Set Created
*
* @param datetime $pValue
* @param int $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCreated($pValue = null)
@ -189,24 +189,24 @@ class DocumentProperties
if (is_null($pValue)) {
$pValue = time();
}
$this->_created = $pValue;
$this->created = $pValue;
return $this;
}
/**
* Get Modified
*
* @return datetime
* @return int
*/
public function getModified()
{
return $this->_modified;
return $this->modified;
}
/**
* Set Modified
*
* @param datetime $pValue
* @param int $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setModified($pValue = null)
@ -214,7 +214,7 @@ class DocumentProperties
if (is_null($pValue)) {
$pValue = time();
}
$this->_modified = $pValue;
$this->modified = $pValue;
return $this;
}
@ -225,7 +225,7 @@ class DocumentProperties
*/
public function getTitle()
{
return $this->_title;
return $this->title;
}
/**
@ -236,7 +236,7 @@ class DocumentProperties
*/
public function setTitle($pValue = '')
{
$this->_title = $pValue;
$this->title = $pValue;
return $this;
}
@ -247,7 +247,7 @@ class DocumentProperties
*/
public function getDescription()
{
return $this->_description;
return $this->description;
}
/**
@ -258,7 +258,7 @@ class DocumentProperties
*/
public function setDescription($pValue = '')
{
$this->_description = $pValue;
$this->description = $pValue;
return $this;
}
@ -269,7 +269,7 @@ class DocumentProperties
*/
public function getSubject()
{
return $this->_subject;
return $this->subject;
}
/**
@ -280,7 +280,7 @@ class DocumentProperties
*/
public function setSubject($pValue = '')
{
$this->_subject = $pValue;
$this->subject = $pValue;
return $this;
}
@ -291,7 +291,7 @@ class DocumentProperties
*/
public function getKeywords()
{
return $this->_keywords;
return $this->keywords;
}
/**
@ -302,7 +302,7 @@ class DocumentProperties
*/
public function setKeywords($pValue = '')
{
$this->_keywords = $pValue;
$this->keywords = $pValue;
return $this;
}
@ -313,7 +313,7 @@ class DocumentProperties
*/
public function getCategory()
{
return $this->_category;
return $this->category;
}
/**
@ -324,7 +324,7 @@ class DocumentProperties
*/
public function setCategory($pValue = '')
{
$this->_category = $pValue;
$this->category = $pValue;
return $this;
}
@ -335,7 +335,7 @@ class DocumentProperties
*/
public function getCompany()
{
return $this->_company;
return $this->company;
}
/**
@ -346,7 +346,7 @@ class DocumentProperties
*/
public function setCompany($pValue = '')
{
$this->_company = $pValue;
$this->company = $pValue;
return $this;
}
@ -357,7 +357,7 @@ class DocumentProperties
*/
public function getManager()
{
return $this->_manager;
return $this->manager;
}
/**
@ -368,7 +368,7 @@ class DocumentProperties
*/
public function setManager($pValue = '')
{
$this->_manager = $pValue;
$this->manager = $pValue;
return $this;
}
@ -379,7 +379,7 @@ class DocumentProperties
*/
public function getCustomProperties()
{
return array_keys($this->_customProperties);
return array_keys($this->customProperties);
}
/**
@ -390,7 +390,7 @@ class DocumentProperties
*/
public function isCustomPropertySet($propertyName)
{
return isset($this->_customProperties[$propertyName]);
return isset($this->customProperties[$propertyName]);
}
/**
@ -401,8 +401,8 @@ class DocumentProperties
*/
public function getCustomPropertyValue($propertyName)
{
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['value'];
if (isset($this->customProperties[$propertyName])) {
return $this->customProperties[$propertyName]['value'];
}
}
@ -415,8 +415,8 @@ class DocumentProperties
*/
public function getCustomPropertyType($propertyName)
{
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['type'];
if (isset($this->customProperties[$propertyName])) {
return $this->customProperties[$propertyName]['type'];
}
}
@ -457,7 +457,7 @@ class DocumentProperties
}
}
$this->_customProperties[$propertyName] = array(
$this->customProperties[$propertyName] = array(
'value' => $propertyValue,
'type' => $propertyType
);
@ -465,11 +465,11 @@ class DocumentProperties
}
/**
* Convert document propery based on type
* Convert document property based on type
*
* @param mixed $propertyValue
* @param string $propertyType
* @return mixed
* @param string $propertyValue
* @param string $propertyType
* @return mixed
*/
public static function convertProperty($propertyValue, $propertyType)
{
@ -525,8 +525,8 @@ class DocumentProperties
/**
* Convert document property type
*
* @param string $propertyType
* @return mixed
* @param string $propertyType
* @return string
*/
public static function convertPropertyType($propertyType)
{

View File

@ -0,0 +1,563 @@
<?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\Element;
use PhpOffice\PhpWord\Exception\InvalidObjectException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\TOC;
use PhpOffice\PhpWord\Footnote as FootnoteCollection;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Element\Element;
use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\Link;
use PhpOffice\PhpWord\Element\Title;
use PhpOffice\PhpWord\Element\PreserveText;
use PhpOffice\PhpWord\Element\TextBreak;
use PhpOffice\PhpWord\Element\ListItem;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Element\Object;
use PhpOffice\PhpWord\Element\Footnote as FootnoteElement;
use PhpOffice\PhpWord\Element\CheckBox;
/**
* Container abstract class
*
* @since 0.9.2
*/
abstract class AbstractElement
{
/**
* Container type section|header|footer|cell|textrun|footnote
*
* @var string
*/
protected $container;
/**
* Section Id
*
* @var int
*/
protected $sectionId;
/**
* Document part type: section|header|footer
*
* Used by textrun and cell container to determine where the element is
* located because it will affect the availability of other element,
* e.g. footnote will not be available when $docPart is header or footer.
*
* @var string
*/
private $docPart = 'section';
/**
* Document part Id
*
* For header and footer, this will be = ($sectionId - 1) * 3 + $index
* because the max number of header/footer in every page is 3, i.e.
* AUTO, FIRST, and EVEN (AUTO = ODD)
*
* @var integer
*/
private $docPartId = 1;
/**
* Elements collection
*
* @var array
*/
protected $elements = array();
/**
* Relation Id
*
* @var int
*/
private $relationId;
/**
* Add text element
*
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return Text
*/
public function addText($text, $fontStyle = null, $paragraphStyle = null)
{
$this->checkValidity('text');
// Reset paragraph style for footnote and textrun. They have their own
if (in_array($this->container, array('footnote', 'textrun'))) {
$paragraphStyle = null;
}
$text = String::toUTF8($text);
$textObject = new Text($text, $fontStyle, $paragraphStyle);
$textObject->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->elements[] = $textObject;
return $textObject;
}
/**
* Add textrun element
*
* @param mixed $paragraphStyle
* @return TextRun
*/
public function addTextRun($paragraphStyle = null)
{
$this->checkValidity('textrun');
$textRun = new TextRun($paragraphStyle);
$textRun->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->elements[] = $textRun;
return $textRun;
}
/**
* Add link element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return Link
*/
public function addLink($linkSrc, $linkName = null, $fontStyle = null, $paragraphStyle = null)
{
$this->checkValidity('link');
$elementDocPart = $this->checkElementDocPart();
$link = new Link(String::toUTF8($linkSrc), String::toUTF8($linkName), $fontStyle, $paragraphStyle);
$link->setDocPart($this->getDocPart(), $this->getDocPartId());
$rID = Media::addElement($elementDocPart, 'link', $linkSrc);
$link->setRelationId($rID);
$this->elements[] = $link;
return $link;
}
/**
* Add a Title Element
*
* @param string $text
* @param int $depth
* @return Title
* @todo Enable title element in other containers
*/
public function addTitle($text, $depth = 1)
{
$this->checkValidity('title');
$styles = Style::getStyles();
if (array_key_exists('Heading_' . $depth, $styles)) {
$style = 'Heading' . $depth;
} else {
$style = null;
}
$text = String::toUTF8($text);
$title = new Title($text, $depth, $style);
$title->setDocPart($this->getDocPart(), $this->getDocPartId());
$data = TOC::addTitle($text, $depth);
$anchor = $data[0];
$bookmarkId = $data[1];
$title->setAnchor($anchor);
$title->setBookmarkId($bookmarkId);
$this->elements[] = $title;
return $title;
}
/**
* Add preserve text element
*
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return PreserveText
*/
public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null)
{
$this->checkValidity('preservetext');
$preserveText = new PreserveText(String::toUTF8($text), $fontStyle, $paragraphStyle);
$preserveText->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->elements[] = $preserveText;
return $preserveText;
}
/**
* Add text break element
*
* @param int $count
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
$this->checkValidity('textbreak');
for ($i = 1; $i <= $count; $i++) {
$textBreak = new TextBreak($fontStyle, $paragraphStyle);
$textBreak->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->elements[] = $textBreak;
}
}
/**
* Add listitem element
*
* @param string $text
* @param int $depth
* @param mixed $fontStyle
* @param mixed $styleList
* @param mixed $paragraphStyle
* @return ListItem
*/
public function addListItem($text, $depth = 0, $fontStyle = null, $styleList = null, $paragraphStyle = null)
{
$this->checkValidity('listitem');
$listItem = new ListItem(String::toUTF8($text), $depth, $fontStyle, $styleList, $paragraphStyle);
$listItem->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->elements[] = $listItem;
return $listItem;
}
/**
* Add table element
*
* @param mixed $style
* @return Table
*/
public function addTable($style = null)
{
$this->checkValidity('table');
$table = new Table($this->getDocPart(), $this->getDocPartId(), $style);
$this->elements[] = $table;
return $table;
}
/**
* Add image element
*
* @param string $src
* @param mixed $style Image style
* @param boolean $isWatermark
* @return Image
*/
public function addImage($src, $style = null, $isWatermark = false)
{
$this->checkValidity('image');
$elementDocPart = $this->checkElementDocPart();
$image = new Image($src, $style, $isWatermark);
$image->setDocPart($this->getDocPart(), $this->getDocPartId());
$rID = Media::addElement($elementDocPart, 'image', $src, $image);
$image->setRelationId($rID);
$this->elements[] = $image;
return $image;
}
/**
* Add OLE-object element
*
* All exceptions should be handled by PhpOffice\PhpWord\Element\Object
*
* @param string $src
* @param mixed $style
* @return Object
* @todo Enable OLE object element in header and footer
*/
public function addObject($src, $style = null)
{
$this->checkValidity('object');
$elementDocPart = $this->checkElementDocPart();
$object = new Object($src, $style);
$object->setDocPart($this->getDocPart(), $this->getDocPartId());
if (!is_null($object->getSource())) {
$inf = pathinfo($src);
$ext = $inf['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$icon = realpath(__DIR__ . "/../_staticDocParts/_{$ext}.png");
$rID = Media::addElement($elementDocPart, 'object', $src);
$object->setRelationId($rID);
$rIDimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));
$object->setImageRelationId($rIDimg);
$this->elements[] = $object;
return $object;
} else {
throw new InvalidObjectException();
}
}
/**
* Add footnote element
*
* @param mixed $paragraphStyle
* @return FootnoteElement
*/
public function addFootnote($paragraphStyle = null)
{
$this->checkValidity('footnote');
$footnote = new FootnoteElement($paragraphStyle);
$refID = FootnoteCollection::addFootnoteElement($footnote);
$footnote->setDocPart('footnote', $this->getDocPartId());
$footnote->setRelationId($refID);
$this->elements[] = $footnote;
return $footnote;
}
/**
* Add a CheckBox Element
*
* @param string $name
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return CheckBox
*/
public function addCheckBox($name, $text, $fontStyle = null, $paragraphStyle = null)
{
$this->checkValidity('checkbox');
$checkBox = new CheckBox(String::toUTF8($name), String::toUTF8($text), $fontStyle, $paragraphStyle);
$checkBox->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->elements[] = $checkBox;
return $checkBox;
}
/**
* Get section number
*
* @return integer
*/
public function getSectionId()
{
return $this->sectionId;
}
/**
* Set doc part
*
* @param string $docPart
* @param integer $docPartId
*/
public function setDocPart($docPart, $docPartId = 1)
{
$this->docPart = $docPart;
$this->docPartId = $docPartId;
}
/**
* Get doc part
*
* @return string
*/
public function getDocPart()
{
return $this->docPart;
}
/**
* Get doc part Id
*
* @return integer
*/
public function getDocPartId()
{
return $this->docPartId;
}
/**
* Get all elements
*
* @return array
*/
public function getElements()
{
return $this->elements;
}
/**
* Get relation Id
*
* @return int
*/
public function getRelationId()
{
$this->checkValidity('relationid');
return $this->relationId;
}
/**
* Set relation Id
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->checkValidity('relationid');
$this->relationId = $rId;
}
/**
* Check if element is located in section doc part (as opposed to header/footer)
*
* @return boolean
*/
public function isInSection()
{
return ($this->docPart == 'section');
}
/**
* Set style value
*
* @param mixed $styleObject Style object
* @param mixed $styleValue Style value
* @param boolean $returnObject Always return object
*/
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
{
if (!is_null($styleValue) && is_array($styleValue)) {
foreach ($styleValue as $key => $value) {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$styleObject->setStyleValue($key, $value);
}
$style = $styleObject;
} else {
$style = $returnObject ? $styleObject : $styleValue;
}
return $style;
}
/**
* Check if a method is allowed for the current container
*
* @param string $method
* @return boolean
*/
private function checkValidity($method)
{
// Valid containers for each element
$allContainers = array('section', 'header', 'footer', 'cell', 'textrun', 'footnote');
$validContainers = array(
'text' => $allContainers,
'link' => $allContainers,
'textbreak' => $allContainers,
'image' => $allContainers,
'object' => $allContainers,
'textrun' => array('section', 'header', 'footer', 'cell'),
'listitem' => array('section', 'header', 'footer', 'cell'),
'checkbox' => array('section', 'header', 'footer', 'cell'),
'table' => array('section', 'header', 'footer'),
'footnote' => array('section', 'textrun', 'cell'),
'preservetext' => array('header', 'footer', 'cell'),
'title' => array('section'),
);
// Special condition, e.g. preservetext can only exists in cell when
// the cell is located in header or footer
$validContainerInContainers = array(
'preservetext' => array(array('cell'), array('header', 'footer')),
'footnote' => array(array('cell', 'textrun'), array('section')),
);
// Check if a method is valid for current container
if (array_key_exists($method, $validContainers)) {
if (!in_array($this->container, $validContainers[$method])) {
throw new \BadMethodCallException();
}
}
// Check if a method is valid for current container, located in other container
if (array_key_exists($method, $validContainerInContainers)) {
$rules = $validContainerInContainers[$method];
$containers = $rules[0];
$allowedDocParts = $rules[1];
foreach ($containers as $container) {
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
throw new \BadMethodCallException();
}
}
}
return true;
}
/**
* Return element location in document: section, headerx, or footerx
*/
private function checkElementDocPart()
{
$isCellTextrun = in_array($this->container, array('cell', 'textrun'));
$docPart = $isCellTextrun ? $this->getDocPart() : $this->container;
$docPartId = $isCellTextrun ? $this->getDocPartId() : $this->sectionId;
$inHeaderFooter = ($docPart == 'header' || $docPart == 'footer');
return $inHeaderFooter ? $docPart . $docPartId : $docPart;
}
/**
* Add memory image element
*
* @param string $src
* @param mixed $style
* @deprecated 0.9.0
* @codeCoverageIgnore
*/
public function addMemoryImage($src, $style = null)
{
return $this->addImage($src, $style);
}
/**
* Create textrun element
*
* @param mixed $paragraphStyle
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function createTextRun($paragraphStyle = null)
{
return $this->addTextRun($paragraphStyle);
}
/**
* Create footnote element
*
* @param mixed $paragraphStyle
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function createFootnote($paragraphStyle = null)
{
return $this->addFootnote($paragraphStyle);
}
}

68
src/PhpWord/Element/Cell.php Executable file
View File

@ -0,0 +1,68 @@
<?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\Element;
use PhpOffice\PhpWord\Style\Cell as CellStyle;
/**
* Table cell element
*/
class Cell extends AbstractElement
{
/**
* Cell width
*
* @var int
*/
private $width = null;
/**
* Cell style
*
* @var CellStyle
*/
private $cellStyle;
/**
* Create new instance
*
* @param string $docPart section|header|footer
* @param int $docPartId
* @param int $width
* @param array|CellStyle $style
*/
public function __construct($docPart, $docPartId, $width = null, $style = null)
{
$this->container = 'cell';
$this->setDocPart($docPart, $docPartId);
$this->width = $width;
$this->cellStyle = $this->setStyle(new CellStyle(), $style, true);
}
/**
* Get cell style
*
* @return CellStyle
*/
public function getStyle()
{
return $this->cellStyle;
}
/**
* Get cell width
*
* @return int
*/
public function getWidth()
{
return $this->width;
}
}

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Check box element
*/
class CheckBox
class CheckBox extends AbstractElement
{
/**
* Name content

64
src/PhpWord/Element/Footer.php Executable file
View File

@ -0,0 +1,64 @@
<?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\Element;
/**
* Footer element
*/
class Footer extends AbstractElement
{
const AUTO = 'default'; // default and odd pages
const FIRST = 'first';
const EVEN = 'even';
/**
* Header type
*
* @var string
*/
private $type = self::AUTO;
/**
* Create new instance
*
* @param int $sectionId
* @param int $footerId
* @param string $type
*/
public function __construct($sectionId, $footerId = 1, $type = self::AUTO)
{
$this->container = 'footer';
$this->sectionId = $sectionId;
$this->setType($type);
$this->setDocPart($this->container, ($sectionId - 1) * 3 + $footerId);
}
/**
* Set type
*
* @param string $value
* @since 0.9.2
*/
public function setType($value = self::AUTO)
{
$this->type = $value;
}
/**
* Get type
*
* @return string
* @since 0.9.2
*/
public function getType()
{
return $this->type;
}
}

View File

@ -0,0 +1,70 @@
<?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\Element;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Footnote element
*/
class Footnote extends AbstractElement
{
/**
* Paragraph style
*
* @var string|Paragraph
*/
private $paragraphStyle;
/**
* Create new instance
*
* @param string|array|Paragraph $paragraphStyle
*/
public function __construct($paragraphStyle = null)
{
$this->container = 'footnote';
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
}
/**
* Get paragraph style
*
* @return string|Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
/**
* Get Footnote Reference ID
*
* @return int
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function getReferenceId()
{
return $this->getRelationId();
}
/**
* Set Footnote Reference ID
*
* @param int $refId
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function setReferenceId($refId)
{
$this->setRelationId($refId);
}
}

116
src/PhpWord/Element/Header.php Executable file
View File

@ -0,0 +1,116 @@
<?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\Element;
use PhpOffice\PhpWord\Element\Image;
/**
* Header element
*/
class Header extends AbstractElement
{
/**
* Header types constants
*
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-wtype-4.html Header or Footer Type
*/
const AUTO = 'default'; // default and odd pages
const FIRST = 'first';
const EVEN = 'even';
/**
* Header type
*
* @var string
*/
private $type = self::AUTO;
/**
* Create new instance
*
* @param int $sectionId
* @param int $headerId
* @param string $type
*/
public function __construct($sectionId, $headerId = 1, $type = self::AUTO)
{
$this->container = 'header';
$this->sectionId = $sectionId;
$this->setType($type);
$this->setDocPart($this->container, ($sectionId - 1) * 3 + $headerId);
}
/**
* Add a Watermark Element
*
* @param string $src
* @param mixed $style
* @return Image
*/
public function addWatermark($src, $style = null)
{
return $this->addImage($src, $style, true);
}
/**
* Set header type
*
* @param string $value
* @since 0.9.2
*/
public function setType($value = self::AUTO)
{
if (!in_array($value, array(self::AUTO, self::FIRST, self::EVEN))) {
$value = self::AUTO;
}
$this->type = $value;
}
/**
* Get header type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Reset type to default
*
* @return string
*/
public function resetType()
{
return $this->type = self::AUTO;
}
/**
* First page only header
*
* @return string
*/
public function firstPage()
{
return $this->type = self::FIRST;
}
/**
* Even numbered pages only
*
* @return string
*/
public function evenPage()
{
return $this->type = self::EVEN;
}
}

View File

@ -7,15 +7,16 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
use PhpOffice\PhpWord\Exception\InvalidImageException;
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Image element
*/
class Image
class Image extends AbstractElement
{
/**
* Image source
@ -27,21 +28,14 @@ class Image
/**
* Image style
*
* @var \PhpOffice\PhpWord\Style\Image
* @var ImageStyle
*/
private $style;
/**
* Image relation ID specific only for DOCX
*
* @var string
*/
private $rId;
/**
* Is watermark
*
* @var bool
* @var boolean
*/
private $isWatermark;
@ -76,7 +70,7 @@ class Image
/**
* Is memory image
*
* @var string
* @var boolean
*/
private $isMemImage;
@ -85,9 +79,9 @@ class Image
*
* @param string $source
* @param mixed $style
* @param bool $isWatermark
* @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
* @throws \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
* @param boolean $isWatermark
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
public function __construct($source, $style = null, $isWatermark = false)
{
@ -101,10 +95,13 @@ class Image
// Check supported types
if ($this->isMemImage) {
$supportedTypes = array('image/jpeg', 'image/gif', 'image/png');
$imgData = getimagesize($source);
$imgData = @getimagesize($source);
if (!is_array($imgData)) {
throw new InvalidImageException();
}
$this->imageType = $imgData['mime']; // string
if (!in_array($this->imageType, $supportedTypes)) {
throw new UnsupportedImageTypeException;
throw new UnsupportedImageTypeException();
}
} else {
$supportedTypes = array(
@ -113,17 +110,19 @@ class Image
\IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM
);
if (!file_exists($source)) {
throw new InvalidImageException;
throw new InvalidImageException();
}
$imgData = getimagesize($source);
if (function_exists('exif_imagetype')) {
$this->imageType = exif_imagetype($source);
} else {
// @codeCoverageIgnoreStart
$tmp = getimagesize($source);
$this->imageType = $tmp[2];
// @codeCoverageIgnoreEnd
}
if (!in_array($this->imageType, $supportedTypes)) {
throw new UnsupportedImageTypeException;
throw new UnsupportedImageTypeException();
}
$this->imageType = \image_type_to_mime_type($this->imageType);
}
@ -131,18 +130,7 @@ class Image
// Set private properties
$this->source = $source;
$this->isWatermark = $isWatermark;
$this->style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->style->setStyleValue($key, $value);
}
}
if (isset($style['wrappingStyle'])) {
$this->style->setWrappingStyle($style['wrappingStyle']);
}
$this->style = $this->setStyle(new ImageStyle(), $style, true);
if ($this->style->getWidth() == null && $this->style->getHeight() == null) {
$this->style->setWidth($imgData[0]);
$this->style->setHeight($imgData[1]);
@ -153,33 +141,13 @@ class Image
/**
* Get Image style
*
* @return \PhpOffice\PhpWord\Style\Image
* @return ImageStyle
*/
public function getStyle()
{
return $this->style;
}
/**
* Get image relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->rId;
}
/**
* Set image relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->rId = $rId;
}
/**
* Get image source
*
@ -203,7 +171,7 @@ class Image
/**
* Get is watermark
*
* @return int
* @return boolean
*/
public function getIsWatermark()
{
@ -213,7 +181,7 @@ class Image
/**
* Set is watermark
*
* @param bool $pValue
* @param boolean $pValue
*/
public function setIsWatermark($pValue)
{

View File

@ -0,0 +1,106 @@
<?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\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Link element
*/
class Link extends AbstractElement
{
/**
* Link source
*
* @var string
*/
private $source;
/**
* Link name
*
* @var string
*/
private $name;
/**
* Font style
*
* @var string|Font
*/
private $fontStyle;
/**
* Paragraph style
*
* @var string|Paragraph
*/
private $paragraphStyle;
/**
* Create a new Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $fontStyle
* @param mixed $paragraphStyle
*/
public function __construct($linkSrc, $linkName = null, $fontStyle = null, $paragraphStyle = null)
{
$this->source = $linkSrc;
$this->name = $linkName;
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
return $this;
}
/**
* Get Link source
*
* @return string
*/
public function getLinkSrc()
{
return $this->source;
}
/**
* Get Link name
*
* @return string
*/
public function getLinkName()
{
return $this->name;
}
/**
* Get Text style
*
* @return string|Font
*/
public function getFontStyle()
{
return $this->fontStyle;
}
/**
* Get Paragraph style
*
* @return string|Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
}

View File

@ -7,33 +7,35 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
/**
* List item element
*/
class ListItem
class ListItem extends AbstractElement
{
/**
* ListItem Style
*
* @var \PhpOffice\PhpWord\Style\ListItem
* @var ListItemStyle
*/
private $_style;
private $style;
/**
* Textrun
*
* @var \PhpOffice\PhpWord\Section\Text
* @var \PhpOffice\PhpWord\Element\Text
*/
private $_textObject;
private $textObject;
/**
* ListItem Depth
*
* @var int
*/
private $_depth;
private $depth;
/**
@ -47,18 +49,9 @@ class ListItem
*/
public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
{
$this->_style = new \PhpOffice\PhpWord\Style\ListItem();
$this->_textObject = new Text($text, $styleFont, $styleParagraph);
$this->_depth = $depth;
if (!is_null($styleList) && is_array($styleList)) {
foreach ($styleList as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
$this->textObject = new Text($text, $styleFont, $styleParagraph);
$this->depth = $depth;
$this->style = $this->setStyle(new ListItemStyle(), $styleList, true);
}
/**
@ -66,7 +59,7 @@ class ListItem
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
/**
@ -74,7 +67,7 @@ class ListItem
*/
public function getTextObject()
{
return $this->_textObject;
return $this->textObject;
}
/**
@ -82,6 +75,6 @@ class ListItem
*/
public function getDepth()
{
return $this->_depth;
return $this->depth;
}
}

View File

@ -7,48 +7,35 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Object element
*/
class Object
class Object extends AbstractElement
{
/**
* Ole-Object Src
*
* @var string
*/
private $_src;
private $source;
/**
* Image Style
*
* @var \PhpOffice\PhpWord\Style\Image
*/
private $_style;
/**
* Object Relation ID
*
* @var int
*/
private $_rId;
private $style;
/**
* Image Relation ID
*
* @var int
*/
private $_rIdImg;
/**
* Object ID
*
* @var int
*/
private $_objId;
private $imageRelationId;
/**
* Create a new Ole-Object Element
@ -58,22 +45,12 @@ class Object
*/
public function __construct($src, $style = null)
{
$_supportedObjectTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
$inf = pathinfo($src);
if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
$this->_src = $src;
$this->_style = new \PhpOffice\PhpWord\Style\Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
if (\file_exists($src) && in_array($inf['extension'], $supportedTypes)) {
$this->source = $src;
$this->style = $this->setStyle(new ImageStyle(), $style, true);
return $this;
} else {
return false;
@ -87,7 +64,7 @@ class Object
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
/**
@ -97,27 +74,7 @@ class Object
*/
public function getSource()
{
return $this->_src;
}
/**
* Get Object Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Object Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
return $this->source;
}
/**
@ -127,7 +84,7 @@ class Object
*/
public function getImageRelationId()
{
return $this->_rIdImg;
return $this->imageRelationId;
}
/**
@ -137,26 +94,30 @@ class Object
*/
public function setImageRelationId($rId)
{
$this->_rIdImg = $rId;
$this->imageRelationId = $rId;
}
/**
* Get Object ID
*
* @return int
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function getObjectId()
{
return $this->_objId;
return $this->relationId + 1325353440;
}
/**
* Set Object ID
*
* @param int $objId
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function setObjectId($objId)
{
$this->_objId = $objId;
$this->relationId = $objId;
}
}

View File

@ -7,12 +7,12 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
/**
* Page break element
*/
class PageBreak
class PageBreak extends AbstractElement
{
/**
* Create new page break

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section\Footer;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@ -15,28 +15,28 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Preserve text/field element
*/
class PreserveText
class PreserveText extends AbstractElement
{
/**
* Text content
*
* @var string
*/
private $_text;
private $text;
/**
* Text style
*
* @var string|Font
*/
private $_styleFont;
private $fontStyle;
/**
* Paragraph style
*
* @var string|Paragraph
*/
private $_styleParagraph;
private $paragraphStyle;
/**
@ -49,37 +49,12 @@ class PreserveText
*/
public function __construct($text = null, $styleFont = null, $styleParagraph = null)
{
// Set font style
if (is_array($styleFont)) {
$this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleFont->setStyleValue($key, $value);
}
} else {
$this->_styleFont = $styleFont;
}
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
$this->fontStyle = $this->setStyle(new Font('text'), $styleFont);
$this->paragraphStyle = $this->setStyle(new Paragraph(), $styleParagraph);
$matches = preg_split('/({.*?})/', $text, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
if (isset($matches[0])) {
$this->_text = $matches;
$this->text = $matches;
}
return $this;
@ -92,7 +67,7 @@ class PreserveText
*/
public function getFontStyle()
{
return $this->_styleFont;
return $this->fontStyle;
}
/**
@ -102,7 +77,7 @@ class PreserveText
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
return $this->paragraphStyle;
}
/**
@ -112,6 +87,6 @@ class PreserveText
*/
public function getText()
{
return $this->_text;
return $this->text;
}
}

View File

@ -0,0 +1,97 @@
<?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\Element;
use PhpOffice\PhpWord\Style\Row as RowStyle;
/**
* Table row element
*/
class Row extends AbstractElement
{
/**
* Row height
*
* @var int
*/
private $height = null;
/**
* Row style
*
* @var RowStyle
*/
private $style;
/**
* Row cells
*
* @var array
*/
private $cells = array();
/**
* Create a new table row
*
* @param string $docPart
* @param int $docPartId
* @param int $height
* @param mixed $style
*/
public function __construct($docPart, $docPartId, $height = null, $style = null)
{
$this->setDocPart($docPart, $docPartId);
$this->height = $height;
$this->style = $this->setStyle(new RowStyle(), $style, true);
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
*/
public function addCell($width = null, $style = null)
{
$cell = new Cell($this->getDocPart(), $this->getDocPartId(), $width, $style);
$this->cells[] = $cell;
return $cell;
}
/**
* Get all cells
*
* @return array
*/
public function getCells()
{
return $this->cells;
}
/**
* Get row style
*
* @return RowStyle
*/
public function getStyle()
{
return $this->style;
}
/**
* Get row height
*
* @return int
*/
public function getHeight()
{
return $this->height;
}
}

View File

@ -0,0 +1,238 @@
<?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\Element;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\TOC;
use PhpOffice\PhpWord\Element\Footer;
use PhpOffice\PhpWord\Element\Header;
use PhpOffice\PhpWord\Element\PageBreak;
use PhpOffice\PhpWord\Style\Section as SectionSettings;
/**
* Section
*/
class Section extends AbstractElement
{
/**
* Section settings
*
* @var SectionSettings
*/
private $settings;
/**
* Section headers, indexed from 1, not zero
*
* @var Header[]
*/
private $headers = array();
/**
* Section footers, indexed from 1, not zero
*
* @var Footer[]
*/
private $footers = array();
/**
* Create new instance
*
* @param int $sectionCount
* @param array $settings
*/
public function __construct($sectionCount, $settings = null)
{
$this->container = 'section';
$this->sectionId = $sectionCount;
$this->setDocPart($this->container, $this->sectionId);
$this->settings = new SectionSettings();
$this->setSettings($settings);
}
/**
* Set section settings
*
* @param array $settings
*/
public function setSettings($settings = null)
{
if (!is_null($settings) && is_array($settings)) {
foreach ($settings as $key => $value) {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$this->settings->setSettingValue($key, $value);
}
}
}
/**
* Get Section Settings
*
* @return SectionSettings
*/
public function getSettings()
{
return $this->settings;
}
/**
* Add a PageBreak Element
*/
public function addPageBreak()
{
$this->elements[] = new PageBreak();
}
/**
* Add a Table-of-Contents Element
*
* @param mixed $styleFont
* @param mixed $styleTOC
* @param integer $minDepth
* @param integer $maxDepth
* @return TOC
*/
public function addTOC($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
{
$toc = new TOC($styleFont, $styleTOC, $minDepth, $maxDepth);
$this->elements[] = $toc;
return $toc;
}
/**
* Add header
*
* @param string $type
* @return Header
* @since 0.9.2
*/
public function addHeader($type = Header::AUTO)
{
return $this->addHeaderFooter($type, true);
}
/**
* Add footer
*
* @param string $type
* @return Footer
* @since 0.9.2
*/
public function addFooter($type = Header::AUTO)
{
return $this->addHeaderFooter($type, false);
}
/**
* Get header elements
*
* @return Header[]
*/
public function getHeaders()
{
return $this->headers;
}
/**
* Get footer elements
*
* @return Footer[]
*/
public function getFooters()
{
return $this->footers;
}
/**
* Is there a header for this section that is for the first page only?
*
* If any of the Header instances have a type of Header::FIRST then this method returns true.
* False otherwise.
*
* @return boolean
*/
public function hasDifferentFirstPage()
{
foreach ($this->headers as $header) {
if ($header->getType() == Header::FIRST) {
return true;
}
}
return false;
}
/**
* Add header/footer
*
* @param string $type
* @param string $header
* @return Header|Footer
* @since 0.9.2
*/
private function addHeaderFooter($type = Header::AUTO, $header = true)
{
$collectionArray = $header ? 'headers' : 'footers';
$containerClass = 'PhpOffice\\PhpWord\\Element\\';
$containerClass .= ($header ? 'Header' : 'Footer');
$collection = &$this->$collectionArray;
if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
$index = count($collection);
$container = new $containerClass($this->sectionId, ++$index, $type);
$collection[$index] = $container;
return $container;
} else {
throw new Exception('Invalid header/footer type.');
}
}
/**
* Create header
*
* @return Header
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function createHeader()
{
return $this->addHeader();
}
/**
* Create footer
*
* @return Footer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function createFooter()
{
return $this->addFooter();
}
/**
* Get footer
*
* @return Footer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function getFooter()
{
if (empty($this->footers)) {
return null;
} else {
return $this->footers[1];
}
}
}

View File

@ -0,0 +1,121 @@
<?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\Element;
use PhpOffice\PhpWord\Element\Row;
use PhpOffice\PhpWord\Style\Table as TableStyle;
/**
* Table element
*/
class Table extends AbstractElement
{
/**
* Table style
*
* @var TableStyle
*/
private $style;
/**
* Table rows
*
* @var array
*/
private $rows = array();
/**
* Table width
*
* @var int
*/
private $width = null;
/**
* Create a new table
*
* @param string $docPart
* @param int $docPartId
* @param mixed $style
*/
public function __construct($docPart, $docPartId, $style = null)
{
$this->setDocPart($docPart, $docPartId);
$this->style = $this->setStyle(new TableStyle(), $style);
}
/**
* Add a row
*
* @param int $height
* @param mixed $style
*/
public function addRow($height = null, $style = null)
{
$row = new Row($this->getDocPart(), $this->getDocPartId(), $height, $style);
$this->rows[] = $row;
return $row;
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return \PhpOffice\PhpWord\Element\Cell
*/
public function addCell($width = null, $style = null)
{
$i = count($this->rows) - 1;
$cell = $this->rows[$i]->addCell($width, $style);
return $cell;
}
/**
* Get all rows
*
* @return array
*/
public function getRows()
{
return $this->rows;
}
/**
* Get table style
*
* @return TableStyle
*/
public function getStyle()
{
return $this->style;
}
/**
* Set table width
*
* @param int $width
*/
public function setWidth($width)
{
$this->width = $width;
}
/**
* Get table width
*
* @return int
*/
public function getWidth()
{
return $this->width;
}
}

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text element
*/
class Text
class Text extends AbstractElement
{
/**
* Text content

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@ -15,7 +15,7 @@ use PhpOffice\PhpWord\Style\Paragraph;
/**
* Text break element
*/
class TextBreak
class TextBreak extends AbstractElement
{
/**
* Paragraph style

46
src/PhpWord/Element/TextRun.php Executable file
View File

@ -0,0 +1,46 @@
<?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\Element;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Textrun/paragraph element
*/
class TextRun extends AbstractElement
{
/**
* Paragraph style
*
* @var string|Paragraph
*/
private $paragraphStyle;
/**
* Create new instance
*
* @param string|array|Paragraph $paragraphStyle
*/
public function __construct($paragraphStyle = null)
{
$this->container = 'textrun';
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
}
/**
* Get Paragraph style
*
* @return string|Paragraph
*/
public function getParagraphStyle()
{
return $this->paragraphStyle;
}
}

View File

@ -7,47 +7,47 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Element;
/**
* Title element
*/
class Title
class Title extends AbstractElement
{
/**
* Title Text content
*
* @var string
*/
private $_text;
private $text;
/**
* Title depth
*
* @var int
*/
private $_depth;
private $depth;
/**
* Title anchor
*
* @var int
*/
private $_anchor;
private $anchor;
/**
* Title Bookmark ID
*
* @var int
*/
private $_bookmarkId;
private $bookmarkId;
/**
* Title style
*
* @var string
*/
private $_style;
private $style;
/**
@ -55,16 +55,16 @@ class Title
*
* @param string $text
* @param int $depth
* @param mixed $style
* @param string $style Name of the heading style, e.g. 'Heading1'
*/
public function __construct($text, $depth = 1, $style = null)
{
if (!is_null($style)) {
$this->_style = $style;
$this->style = $style;
}
$this->_text = $text;
$this->_depth = $depth;
$this->text = $text;
$this->depth = $depth;
return $this;
}
@ -76,7 +76,7 @@ class Title
*/
public function setAnchor($anchor)
{
$this->_anchor = $anchor;
$this->anchor = $anchor;
}
/**
@ -86,7 +86,7 @@ class Title
*/
public function getAnchor()
{
return $this->_anchor;
return $this->anchor;
}
/**
@ -96,7 +96,7 @@ class Title
*/
public function setBookmarkId($bookmarkId)
{
$this->_bookmarkId = $bookmarkId;
$this->bookmarkId = $bookmarkId;
}
/**
@ -106,7 +106,7 @@ class Title
*/
public function getBookmarkId()
{
return $this->_bookmarkId;
return $this->bookmarkId;
}
/**
@ -116,7 +116,7 @@ class Title
*/
public function getText()
{
return $this->_text;
return $this->text;
}
/**
@ -126,6 +126,6 @@ class Title
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
}

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Exceptions;
namespace PhpOffice\PhpWord\Exception;
/**
* General exception

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Exceptions;
namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image is not found

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Exceptions;
namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image is not found

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Exceptions;
namespace PhpOffice\PhpWord\Exception;
use InvalidArgumentException;

View File

@ -7,7 +7,7 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Exceptions;
namespace PhpOffice\PhpWord\Exception;
/**
* Exception used for when an image type is unsupported

View File

@ -9,35 +9,32 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Element\Footnote as FootnoteElement;
/**
* Footnote
*/
class Footnote
{
/**
* Footnote Elements
* Footnote elements
*
* @var array
*/
private static $_footnoteCollection = array();
private static $elements = array();
/**
* Footnote Link Elements
*
* @var array
*/
private static $_footnoteLink = array();
/**
* Add new Footnote Element
* Add new footnote
*
* @param FootnoteElement $footnote
* @return int Reference ID
*/
public static function addFootnoteElement(\PhpOffice\PhpWord\Section\Footnote $footnote)
public static function addFootnoteElement(FootnoteElement $footnote)
{
$refID = self::countFootnoteElements() + 2;
$refID = self::countFootnoteElements() + 1;
self::$_footnoteCollection[] = $footnote;
self::$elements[] = $footnote;
return $refID;
}
@ -49,7 +46,7 @@ class Footnote
*/
public static function getFootnoteElements()
{
return self::$_footnoteCollection;
return self::$elements;
}
/**
@ -59,47 +56,39 @@ class Footnote
*/
public static function countFootnoteElements()
{
return count(self::$_footnoteCollection);
return count(self::$elements);
}
/**
* Reset footer elements
*/
public static function reset()
{
self::$elements = array();
}
/**
* Add new Footnote Link Element
*
* @param string $linkSrc
*
* @return int Reference ID
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function addFootnoteLinkElement($linkSrc)
{
$rID = self::countFootnoteLinkElements() + 1;
$link = array();
$link['target'] = $linkSrc;
$link['rID'] = $rID;
$link['type'] = 'hyperlink';
self::$_footnoteLink[] = $link;
return $rID;
return Media::addElement('footnotes', 'link', $linkSrc);
}
/**
* Get Footnote Link Elements
*
* @return array
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function getFootnoteLinkElements()
{
return self::$_footnoteLink;
}
/**
* Get Footnote Link Elements Count
*
* @return int
*/
public static function countFootnoteLinkElements()
{
return count(self::$_footnoteLink);
return Media::getElements('footnotes', 'link');
}
}

View File

@ -1,203 +0,0 @@
<?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;
use PhpOffice\PhpWord\Exceptions\Exception;
/**
* Hash table
*
* @codeCoverageIgnore Legacy from PHPExcel
*/
class HashTable
{
/**
* HashTable elements
*
* @var array
*/
public $_items = array();
/**
* HashTable key map
*
* @var array
*/
public $_keyMap = array();
/**
* Create new
*
* @param \PhpOffice\PhpWord\IComparable[] $pSource Optional source array to create HashTable from
*/
public function __construct($pSource = null)
{
if (!is_null($pSource)) {
$this->addFromSource($pSource);
}
}
/**
* Add HashTable items from source
*
* @param \PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
public function addFromSource($pSource = null)
{
// Check if an array was passed
if ($pSource == null) {
return;
} elseif (!is_array($pSource)) {
throw new Exception('Invalid array parameter passed.');
}
foreach ($pSource as $item) {
$this->add($item);
}
}
/**
* Add HashTable item
*
* @param \PhpOffice\PhpWord\IComparable $pSource Item to add
*/
public function add(IComparable $pSource = null)
{
// Determine hashcode
$hashCode = null;
$hashIndex = $pSource->getHashIndex();
if (is_null($hashIndex)) {
$hashCode = $pSource->getHashCode();
} elseif (isset ($this->_keyMap[$hashIndex])) {
$hashCode = $this->_keyMap[$hashIndex];
} else {
$hashCode = $pSource->getHashCode();
}
// Add value
if (!isset($this->_items[$hashCode])) {
$this->_items[$hashCode] = $pSource;
$index = count($this->_items) - 1;
$this->_keyMap[$index] = $hashCode;
$pSource->setHashIndex($index);
} else {
$pSource->setHashIndex($this->_items[$hashCode]->getHashIndex());
}
}
/**
* Remove HashTable item
*
* @param \PhpOffice\PhpWord\IComparable $pSource Item to remove
*/
public function remove(IComparable $pSource = null)
{
if (isset($this->_items[$pSource->getHashCode()])) {
unset($this->_items[$pSource->getHashCode()]);
$deleteKey = -1;
foreach ($this->_keyMap as $key => $value) {
if ($deleteKey >= 0) {
$this->_keyMap[$key - 1] = $value;
}
if ($value == $pSource->getHashCode()) {
$deleteKey = $key;
}
}
unset($this->_keyMap[count($this->_keyMap) - 1]);
}
}
/**
* Clear HashTable
*
*/
public function clear()
{
$this->_items = array();
$this->_keyMap = array();
}
/**
* Get item count
*
* @return int
*/
public function count()
{
return count($this->_items);
}
/**
* Get hash code index
*
* @param string $pHashCode
* @return int Index
*/
public function getIndexForHashCode($pHashCode = '')
{
return array_search($pHashCode, $this->_keyMap);
}
/**
* Get by index
*
* @param int $pIndex
* @return \PhpOffice\PhpWord\IComparable
*/
public function getByIndex($pIndex = 0)
{
if (isset($this->_keyMap[$pIndex])) {
return $this->getByHashCode($this->_keyMap[$pIndex]);
}
return null;
}
/**
* Get by hashcode
* @param string $pHashCode
* @return \PhpOffice\PhpWord\IComparable
*
*/
public function getByHashCode($pHashCode = '')
{
if (isset($this->_items[$pHashCode])) {
return $this->_items[$pHashCode];
}
return null;
}
/**
* Convert to array
*
* @return \PhpOffice\PhpWord\IComparable[]
*/
public function toArray()
{
return $this->_items;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/
public function __clone()
{
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (is_object($value)) {
$this->$key = clone $value;
}
}
}
}

View File

@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exception\Exception;
/**
* IO factory
@ -21,12 +21,12 @@ abstract class IOFactory
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param string $name
* @return \PhpOffice\PhpWord\Writer\IWriter
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @return \PhpOffice\PhpWord\Writer\WriterInterface
* @throws Exception
*/
public static function createWriter(PhpWord $phpWord, $name)
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
{
if ($name !== 'IWriter' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
if ($name !== 'WriterInterface' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') {
throw new Exception("\"{$name}\" is not a valid writer.");
}
@ -38,12 +38,12 @@ abstract class IOFactory
* Create new reader
*
* @param string $name
* @return \PhpOffice\PhpWord\Reader\IReader
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
* @throws Exception
*/
public static function createReader($name)
public static function createReader($name = 'Word2007')
{
if ($name !== 'IReader' && $name !== 'Word2007') {
if ($name !== 'ReaderInterface' && $name !== 'Word2007') {
throw new Exception("\"{$name}\" is not a valid reader.");
}

View File

@ -9,7 +9,8 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Element\Image;
/**
* Media
@ -17,111 +18,172 @@ use PhpOffice\PhpWord\Section\Image;
class Media
{
/**
* Section Media Elements
* Media elements
*
* @var array
*/
private static $_sectionMedia = array(
'images' => array(),
'embeddings' => array(),
'links' => array()
);
private static $elements = array();
/**
* Header Media Elements
* Add new media element
*
* @var array
* @param string $container section|headerx|footerx|footnote
* @param string $mediaType image|object|link
* @param string $source
* @param Image $image
* @return integer
* @since 0.9.2
*/
private static $_headerMedia = array();
public static function addElement($container, $mediaType, $source, Image $image = null)
{
// Assign unique media Id and initiate media container if none exists
$mediaId = md5($container . $source);
if (!array_key_exists($container, self::$elements)) {
self::$elements[$container]= array();
}
// Add media if not exists or point to existing media
if (!array_key_exists($mediaId, self::$elements[$container])) {
$mediaCount = self::countElements($container);
$mediaTypeCount = self::countElements($container, $mediaType);
$mediaData = array();
$relId = ++$mediaCount;
$target = null;
$mediaTypeCount++;
// Images
if ($mediaType == 'image') {
if (is_null($image)) {
throw new Exception('Image object not assigned.');
}
$isMemImage = $image->getIsMemImage();
$ext = $image->getImageExtension();
$mediaData['imageExtension'] = $ext;
$mediaData['imageType'] = $image->getImageType();
if ($isMemImage) {
$mediaData['isMemImage'] = true;
$mediaData['createFunction'] = $image->getImageCreateFunction();
$mediaData['imageFunction'] = $image->getImageFunction();
}
$target = "media/{$container}_image{$mediaTypeCount}.{$ext}";
// Objects
} elseif ($mediaType == 'object') {
$file = "oleObject{$mediaTypeCount}.bin";
$target = "embeddings/{$container}_oleObject{$mediaTypeCount}.bin";
// Links
} elseif ($mediaType == 'link') {
$target = $source;
}
$mediaData['source'] = $source;
$mediaData['target'] = $target;
$mediaData['type'] = $mediaType;
$mediaData['rID'] = $relId;
self::$elements[$container][$mediaId] = $mediaData;
return $relId;
} else {
return self::$elements[$container][$mediaId]['rID'];
}
}
/**
* Footer Media Elements
* Get media elements count
*
* @var array
* @param string $container section|headerx|footerx|footnote
* @param string $mediaType image|object|link
* @return integer
* @since 0.9.2
*/
private static $_footerMedia = array();
public static function countElements($container, $mediaType = null)
{
$mediaCount = 0;
if (array_key_exists($container, self::$elements)) {
foreach (self::$elements[$container] as $mediaKey => $mediaData) {
if (!is_null($mediaType)) {
if ($mediaType == $mediaData['type']) {
$mediaCount++;
}
} else {
$mediaCount++;
}
}
}
return $mediaCount;
}
/**
* ObjectID Counter
* Get media elements
*
* @var int
* @param string $container section|headerx|footerx|footnote
* @param string $mediaType image|object|link
* @return array
* @since 0.9.2
*/
private static $_objectId = 1325353440;
public static function getElements($container, $mediaType = null)
{
$mediaElements = array();
// If header/footer, search for headerx and footerx where x is number
if ($container == 'header' || $container == 'footer') {
foreach (self::$elements as $key => $val) {
if (substr($key, 0, 6) == $container) {
$mediaElements[$key] = $val;
}
}
} else {
if (!array_key_exists($container, self::$elements)) {
return $mediaElements;
}
foreach (self::$elements[$container] as $mediaKey => $mediaData) {
if (!is_null($mediaType)) {
if ($mediaType == $mediaData['type']) {
$mediaElements[$mediaKey] = $mediaData;
}
} else {
$mediaElements[$mediaKey] = $mediaData;
}
}
}
return $mediaElements;
}
/**
* Reset media elements
*/
public static function reset()
{
self::$elements = array();
}
/**
* Add new Section Media Element
*
* @param string $src
* @param string $type
* @param \PhpOffice\PhpWord\Section\Image $image
* @return mixed
* @param Image $image
* @return integer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function addSectionMediaElement($src, $type, Image $image = null)
{
$mediaId = md5($src);
$key = ($type === 'image') ? 'images' : 'embeddings';
if (!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
$cImg = self::countSectionMediaElements('images');
$cObj = self::countSectionMediaElements('embeddings');
$rID = self::countSectionMediaElements() + 7;
$media = array();
$folder = null;
$file = null;
if ($type === 'image') {
$cImg++;
$isMemImage = false;
if (!is_null($image)) {
$isMemImage = $image->getIsMemImage();
$extension = $image->getImageExtension();
}
if ($isMemImage) {
$media['isMemImage'] = true;
$media['createfunction'] = $image->getImageCreateFunction();
$media['imagefunction'] = $image->getImageFunction();
}
$folder = 'media';
$file = $type . $cImg . '.' . strtolower($extension);
} elseif ($type === 'oleObject') {
$cObj++;
$folder = 'embedding';
$file = $type . $cObj . '.bin';
}
$media['source'] = $src;
$media['target'] = "$folder/section_$file";
$media['type'] = $type;
$media['rID'] = $rID;
self::$_sectionMedia[$key][$mediaId] = $media;
if ($type === 'oleObject') {
return array($rID, ++self::$_objectId);
}
return $rID;
} else {
if ($type === 'oleObject') {
$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
return array($rID, ++self::$_objectId);
}
return self::$_sectionMedia[$key][$mediaId]['rID'];
}
return self::addElement('section', $type, $src, $image);
}
/**
* Add new Section Link Element
*
* @param string $linkSrc
* @return mixed
* @return integer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function addSectionLinkElement($linkSrc)
{
$rID = self::countSectionMediaElements() + 7;
$link = array();
$link['target'] = $linkSrc;
$link['rID'] = $rID;
$link['type'] = 'hyperlink';
self::$_sectionMedia['links'][] = $link;
return $rID;
return self::addElement('section', 'link', $linkSrc);
}
/**
@ -129,160 +191,104 @@ class Media
*
* @param string $key
* @return array
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function getSectionMediaElements($key = null)
{
if (!is_null($key)) {
return self::$_sectionMedia[$key];
}
$arrImages = self::$_sectionMedia['images'];
$arrObjects = self::$_sectionMedia['embeddings'];
$arrLinks = self::$_sectionMedia['links'];
return array_merge($arrImages, $arrObjects, $arrLinks);
return self::getElements('section', $key);
}
/**
* Get Section Media Elements Count
*
* @param string $key
* @return int
* @return integer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function countSectionMediaElements($key = null)
{
if (!is_null($key)) {
return count(self::$_sectionMedia[$key]);
}
$cImages = count(self::$_sectionMedia['images']);
$cObjects = count(self::$_sectionMedia['embeddings']);
$cLinks = count(self::$_sectionMedia['links']);
return ($cImages + $cObjects + $cLinks);
return self::countElements('section', $key);
}
/**
* Add new Header Media Element
*
* @param int $headerCount
* @param integer $headerCount
* @param string $src
* @param \PhpOffice\PhpWord\Section\Image $image
* @return int
* @param Image $image
* @return integer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function addHeaderMediaElement($headerCount, $src, Image $image = null)
{
$mediaId = md5($src);
$key = 'header' . $headerCount;
if (!array_key_exists($key, self::$_headerMedia)) {
self::$_headerMedia[$key] = array();
}
if (!array_key_exists($mediaId, self::$_headerMedia[$key])) {
$cImg = self::countHeaderMediaElements($key);
$rID = $cImg + 1;
$cImg++;
$media = array();
$isMemImage = false;
if (!is_null($image)) {
$isMemImage = $image->getIsMemImage();
$extension = $image->getImageExtension();
}
if ($isMemImage) {
$media['isMemImage'] = true;
$media['createfunction'] = $image->getImageCreateFunction();
$media['imagefunction'] = $image->getImageFunction();
}
$file = 'image' . $cImg . '.' . strtolower($extension);
$media['source'] = $src;
$media['target'] = 'media/' . $key . '_' . $file;
$media['type'] = 'image';
$media['rID'] = $rID;
self::$_headerMedia[$key][$mediaId] = $media;
return $rID;
} else {
return self::$_headerMedia[$key][$mediaId]['rID'];
}
return self::addElement("header{$headerCount}", 'image', $src, $image);
}
/**
* Get Header Media Elements Count
*
* @param string $key
* @return int
* @return integer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function countHeaderMediaElements($key)
{
return count(self::$_headerMedia[$key]);
return self::countElements($key);
}
/**
* Get Header Media Elements
*
* @return int
* @return array
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function getHeaderMediaElements()
{
return self::$_headerMedia;
return self::getElements('header');
}
/**
* Add new Footer Media Element
*
* @param int $footerCount
* @param integer $footerCount
* @param string $src
* @param \PhpOffice\PhpWord\Section\Image $image
* @return int
* @param Image $image
* @return integer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function addFooterMediaElement($footerCount, $src, Image $image = null)
{
$mediaId = md5($src);
$key = 'footer' . $footerCount;
if (!array_key_exists($key, self::$_footerMedia)) {
self::$_footerMedia[$key] = array();
}
if (!array_key_exists($mediaId, self::$_footerMedia[$key])) {
$cImg = self::countFooterMediaElements($key);
$rID = $cImg + 1;
$cImg++;
$media = array();
$isMemImage = false;
if (!is_null($image)) {
$isMemImage = $image->getIsMemImage();
$extension = $image->getImageExtension();
}
if ($isMemImage) {
$media['isMemImage'] = true;
$media['createfunction'] = $image->getImageCreateFunction();
$media['imagefunction'] = $image->getImageFunction();
}
$file = 'image' . $cImg . '.' . strtolower($extension);
$media['source'] = $src;
$media['target'] = 'media/' . $key . '_' . $file;
$media['type'] = 'image';
$media['rID'] = $rID;
self::$_footerMedia[$key][$mediaId] = $media;
return $rID;
} else {
return self::$_footerMedia[$key][$mediaId]['rID'];
}
return self::addElement("footer{$footerCount}", 'image', $src, $image);
}
/**
* Get Footer Media Elements Count
*
* @param string $key
* @return int
* @return integer
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function countFooterMediaElements($key)
{
return count(self::$_footerMedia[$key]);
return self::countElements($key);
}
/**
* Get Footer Media Elements
*
* @return int
* @return array
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public static function getFooterMediaElements()
{
return self::$_footerMedia;
return self::getElements('footer');
}
}

View File

@ -10,8 +10,8 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Template;
@ -23,6 +23,7 @@ class PhpWord
const DEFAULT_FONT_COLOR = '000000'; // HEX
const DEFAULT_FONT_CONTENT_TYPE = 'default'; // default|eastAsia|cs
const DEFAULT_FONT_NAME = 'Arial';
/**
* Default font size, in points.
*
@ -34,48 +35,48 @@ class PhpWord
/**
* Document properties object
*
* @var \PhpOffice\PhpWord\DocumentProperties
* @var DocumentProperties
*/
private $_documentProperties;
private $documentProperties;
/**
* Default font name
*
* @var string
*/
private $_defaultFontName;
private $defaultFontName;
/**
* Default font size
* @var int
*/
private $_defaultFontSize;
private $defaultFontSize;
/**
* Collection of sections
*
* @var \PhpOffice\PhpWord\Section[]
* @var Section[]
*/
private $_sections = array();
private $sections = array();
/**
* Create new
*/
public function __construct()
{
$this->_documentProperties = new DocumentProperties();
$this->_defaultFontName = self::DEFAULT_FONT_NAME;
$this->_defaultFontSize = self::DEFAULT_FONT_SIZE;
$this->documentProperties = new DocumentProperties();
$this->defaultFontName = self::DEFAULT_FONT_NAME;
$this->defaultFontSize = self::DEFAULT_FONT_SIZE;
}
/**
* Get document properties object
*
* @return \PhpOffice\PhpWord\DocumentProperties
* @return DocumentProperties
*/
public function getDocumentProperties()
{
return $this->_documentProperties;
return $this->documentProperties;
}
/**
@ -86,7 +87,7 @@ class PhpWord
*/
public function setDocumentProperties(DocumentProperties $documentProperties)
{
$this->_documentProperties = $documentProperties;
$this->documentProperties = $documentProperties;
return $this;
}
@ -94,13 +95,13 @@ class PhpWord
/**
* Create new section
*
* @param \PhpOffice\PhpWord\Section\Settings $settings
* @return \PhpOffice\PhpWord\Section
* @param array $settings
* @return Section
*/
public function createSection($settings = null)
public function addSection($settings = null)
{
$section = new Section(\count($this->_sections) + 1, $settings);
$this->_sections[] = $section;
$section = new Section(\count($this->sections) + 1, $settings);
$this->sections[] = $section;
return $section;
}
@ -112,7 +113,7 @@ class PhpWord
*/
public function getDefaultFontName()
{
return $this->_defaultFontName;
return $this->defaultFontName;
}
/**
@ -122,17 +123,17 @@ class PhpWord
*/
public function setDefaultFontName($fontName)
{
$this->_defaultFontName = $fontName;
$this->defaultFontName = $fontName;
}
/**
* Get default font size
*
* @return string
* @return integer
*/
public function getDefaultFontSize()
{
return $this->_defaultFontSize;
return $this->defaultFontSize;
}
/**
@ -142,7 +143,7 @@ class PhpWord
*/
public function setDefaultFontSize($fontSize)
{
$this->_defaultFontSize = $fontSize;
$this->defaultFontSize = $fontSize;
}
/**
@ -158,8 +159,8 @@ class PhpWord
/**
* Adds a paragraph style definition to styles.xml
*
* @param $styleName string
* @param $styles array
* @param string $styleName
* @param array $styles
*/
public function addParagraphStyle($styleName, $styles)
{
@ -169,7 +170,7 @@ class PhpWord
/**
* Adds a font style definition to styles.xml
*
* @param $styleName string
* @param string $styleName
* @param mixed $styleFont
* @param mixed $styleParagraph
*/
@ -216,19 +217,19 @@ class PhpWord
/**
* Get all sections
*
* @return \PhpOffice\PhpWord\Section[]
* @return \PhpOffice\PhpWord\Element\Section[]
*/
public function getSections()
{
return $this->_sections;
return $this->sections;
}
/**
* Load template by filename
*
* @param string $filename Fully qualified filename.
* @return \PhpOffice\PhpWord\Template
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @return Template
* @throws Exception
*/
public function loadTemplate($filename)
{
@ -238,4 +239,17 @@ class PhpWord
throw new Exception("Template file {$filename} not found.");
}
}
/**
* Create new section
*
* @param array $settings
* @return Section
* @deprecated 0.9.2
* @codeCoverageIgnore
*/
public function createSection($settings = null)
{
return $this->addSection($settings);
}
}

View File

@ -9,14 +9,14 @@
namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exception\Exception;
/**
* Reader abstract class
*
* @codeCoverageIgnore Abstract class
*/
abstract class Reader implements IReader
abstract class AbstractReader implements ReaderInterface
{
/**
* Read data only?
@ -47,7 +47,7 @@ abstract class Reader implements IReader
* Set read data only
*
* @param bool $pValue
* @return \PhpOffice\PhpWord\Reader\IReader
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
*/
public function setReadDataOnly($pValue = true)
{
@ -60,7 +60,7 @@ abstract class Reader implements IReader
*
* @param string $pFilename
* @return resource
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
protected function openFile($pFilename)
{
@ -77,7 +77,7 @@ abstract class Reader implements IReader
}
/**
* Can the current IReader read the file?
* Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return bool
@ -90,7 +90,10 @@ abstract class Reader implements IReader
} catch (Exception $e) {
return false;
}
fclose($this->fileHandle);
if (is_resource($this->fileHandle)) {
fclose($this->fileHandle);
}
return true;
}
}

View File

@ -12,10 +12,10 @@ namespace PhpOffice\PhpWord\Reader;
/**
* Reader interface
*/
interface IReader
interface ReaderInterface
{
/**
* Can the current IReader read the file?
* Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return boolean

View File

@ -12,19 +12,19 @@ namespace PhpOffice\PhpWord\Reader;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\DocumentProperties;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exception\Exception;
/**
* Reader for Word2007
*/
class Word2007 extends Reader implements IReader
class Word2007 extends AbstractReader implements ReaderInterface
{
/**
* Can the current IReader read the file?
* Can the current ReaderInterface read the file?
*
* @param string $pFilename
* @return bool
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
public function canRead($pFilename)
{
@ -64,7 +64,7 @@ class Word2007 extends Reader implements IReader
* @param mixed $archive
* @param string $fileName
* @param bool $removeNamespace
* @return mixed
* @return string
*/
public function getFromZipArchive($archive, $fileName = '', $removeNamespace = false)
{
@ -173,7 +173,7 @@ class Word2007 extends Reader implements IReader
);
$xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}", true));
if (is_object($xmlDoc)) {
$section = $word->createSection();
$section = $word->addSection();
foreach ($xmlDoc->body->children() as $elm) {
$elmName = $elm->getName();
@ -181,7 +181,7 @@ class Word2007 extends Reader implements IReader
// Create new section if section setting found
if ($elm->pPr->sectPr) {
$section->setSettings($this->loadSectionSettings($elm->pPr));
$section = $word->createSection();
$section = $word->addSection();
continue;
}
// Has w:r? It's either text or textrun
@ -194,7 +194,7 @@ class Word2007 extends Reader implements IReader
);
// w:r more than 1? It's a textrun
} else {
$textRun = $section->createTextRun();
$textRun = $section->addTextRun();
foreach ($elm->r as $r) {
$textRun->addText(
$r->t,
@ -234,7 +234,7 @@ class Word2007 extends Reader implements IReader
$styleName = (string)$elm->name['val'];
if ($hasParagraphStyle) {
$pStyle = $this->loadParagraphStyle($elm);
if (!$hasFontStyle) {
if (is_array($pStyle) && !$hasFontStyle) {
$word->addParagraphStyle($styleName, $pStyle);
}
}
@ -428,8 +428,8 @@ class Word2007 extends Reader implements IReader
* Return item of array
*
* @param array $array
* @param mixed $key
* @return mixed|null
* @param integer $key
* @return string
*/
private static function arrayItem($array, $key = 0)
{

View File

@ -1,442 +0,0 @@
<?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;
use PhpOffice\PhpWord\Exceptions\InvalidObjectException;
use PhpOffice\PhpWord\Section\Footer;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Header;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Section\CheckBox;
use PhpOffice\PhpWord\Shared\String;
/**
* Section
*/
class Section
{
/**
* Section count
*
* @var int
*/
private $_sectionCount;
/**
* Section settings
*
* @var \PhpOffice\PhpWord\Section\Settings
*/
private $_settings;
/**
* Section Element Collection
*
* @var array
*/
private $_elementCollection = array();
/**
* Section Headers
*
* @var array
*/
private $_headers = array();
/**
* Section Footer
*
* @var \PhpOffice\PhpWord\Section\Footer
*/
private $_footer = null;
/**
* Create a new Section
*
* @param int $sectionCount
* @param mixed $settings
*/
public function __construct($sectionCount, $settings = null)
{
$this->_sectionCount = $sectionCount;
$this->_settings = new \PhpOffice\PhpWord\Section\Settings();
$this->setSettings($settings);
}
/**
* Set Section Settings
*
* @param array $settings
*/
public function setSettings($settings = null)
{
if (!is_null($settings) && is_array($settings)) {
foreach ($settings as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_settings->setSettingValue($key, $value);
}
}
}
/**
* Get Section Settings
*
* @return \PhpOffice\PhpWord\Section\Settings
*/
public function getSettings()
{
return $this->_settings;
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add a Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($linkSrc)) {
$linkSrc = utf8_encode($linkSrc);
}
if (!is_null($linkName)) {
if (!String::isUTF8($linkName)) {
$linkName = utf8_encode($linkName);
}
}
$link = new Link($linkSrc, $linkName, $styleFont, $styleParagraph);
$rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
}
/**
* Add a TextBreak Element
*
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Add a PageBreak Element
*/
public function addPageBreak()
{
$this->_elementCollection[] = new PageBreak();
}
/**
* Add a Table Element
*
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new Table('section', $this->_sectionCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
/**
* Add a ListItem Element
*
* @param string $text
* @param int $depth
* @param mixed $styleFont
* @param mixed $styleList
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\ListItem
*/
public function addListItem($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$listItem = new ListItem($text, $depth, $styleFont, $styleList, $styleParagraph);
$this->_elementCollection[] = $listItem;
return $listItem;
}
/**
* Add a OLE-Object Element
*
* All exceptions should be handled by PhpOffice\PhpWord\Section\Object
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Object
*/
public function addObject($src, $style = null)
{
$object = new Object($src, $style);
if (!is_null($object->getSource())) {
$inf = pathinfo($src);
$ext = $inf['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$icon = __DIR__ . "/_staticDocParts/_{$ext}.png";
$rIDimg = Media::addSectionMediaElement($icon, 'image', new Image($icon));
$data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0];
$objectId = $data[1];
$object->setRelationId($rID);
$object->setObjectId($objectId);
$object->setImageRelationId($rIDimg);
$this->_elementCollection[] = $object;
return $object;
} else {
throw new InvalidObjectException();
}
}
/**
* Add image element
*
* All exceptions should be handled by PhpOffice\PhpWord\Section\Image
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
$rID = Media::addSectionMediaElement($src, 'image', $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
}
/**
* Add memory image element
*
* @deprecated
*
* @param string $src
* @param mixed $style
*/
public function addMemoryImage($src, $style = null)
{
return $this->addImage($src, $style);
}
/**
* Add a Table-of-Contents Element
*
* @param mixed $styleFont
* @param mixed $styleTOC
* @param int $minDepth
* @param int $maxDepth
* @return \PhpOffice\PhpWord\TOC
*/
public function addTOC($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
{
$toc = new TOC($styleFont, $styleTOC, $minDepth, $maxDepth);
$this->_elementCollection[] = $toc;
return $toc;
}
/**
* Add a Title Element
*
* @param string $text
* @param int $depth
* @return \PhpOffice\PhpWord\Section\Title
*/
public function addTitle($text, $depth = 1)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$styles = Style::getStyles();
if (array_key_exists('Heading_' . $depth, $styles)) {
$style = 'Heading' . $depth;
} else {
$style = null;
}
$title = new Title($text, $depth, $style);
$data = TOC::addTitle($text, $depth);
$anchor = $data[0];
$bookmarkId = $data[1];
$title->setAnchor($anchor);
$title->setBookmarkId($bookmarkId);
$this->_elementCollection[] = $title;
return $title;
}
/**
* Create a new TextRun
*
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Get all Elements
*
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Create a new Header
*
* @return \PhpOffice\PhpWord\Section\Header
*/
public function createHeader()
{
$header = new Header($this->_sectionCount);
$this->_headers[] = $header;
return $header;
}
/**
* Get Headers
*
* @return array
*/
public function getHeaders()
{
return $this->_headers;
}
/**
* Is there a header for this section that is for the first page only?
*
* If any of the Header instances have a type of Header::FIRST then this method returns true.
* False otherwise.
*
* @return Boolean
*/
public function hasDifferentFirstPage()
{
$value = array_filter($this->_headers, function (Header &$header) {
return $header->getType() == Header::FIRST;
});
return count($value) > 0;
}
/**
* Create a new Footer
*
* @return \PhpOffice\PhpWord\Section\Footer
*/
public function createFooter()
{
$footer = new Footer($this->_sectionCount);
$this->_footer = $footer;
return $footer;
}
/**
* Get footer element
*
* @return \PhpOffice\PhpWord\Section\Footer
*/
public function getFooter()
{
return $this->_footer;
}
/**
* Create a new Footnote Element
*
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Footnote
*/
public function createFootnote($styleParagraph = null)
{
$footnote = new \PhpOffice\PhpWord\Section\Footnote($styleParagraph);
$refID = Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID);
$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;
}
}

View File

@ -1,195 +0,0 @@
<?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\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
/**
* Footer element
*/
class Footer
{
/**
* Footer Count
*
* @var int
*/
private $_footerCount;
/**
* Footer Relation ID
*
* @var int
*/
private $_rId;
/**
* Footer Element Collection
*
* @var int
*/
private $_elementCollection = array();
/**
* Create a new Footer
*
* @param int $sectionCount
*/
public function __construct($sectionCount)
{
$this->_footerCount = $sectionCount;
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new TextRun
*
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Add a Table Element
*
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new Table('footer', $this->_footerCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addFooterMediaElement($this->_footerCount, $src, $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new InvalidImageException;
}
}
/**
* Add a by PHP created Image Element
*
* @param string $src
* @param mixed $style
* @deprecated
*/
public function addMemoryImage($src, $style = null)
{
return $this->addImage($src, $style);
}
/**
* Add a PreserveText Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
}
/**
* Get Footer Relation ID
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Footer Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get all Footer Elements
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Footer Count
*/
public function getFooterCount()
{
return $this->_footerCount;
}
}

View File

@ -1,152 +0,0 @@
<?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\Paragraph;
/**
* Footnote element
*/
class Footnote
{
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $_styleParagraph;
/**
* Footnote Reference ID
*
* @var string
*/
private $_refId;
/**
* Text collection
*
* @var array
*/
private $_elementCollection;
/**
* Create a new Footnote Element
*
* @param mixed $styleParagraph
*/
public function __construct($styleParagraph = null)
{
$this->_elementCollection = array();
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text = null, $styleFont = null)
{
$givenText = $text;
$text = new Text($givenText, $styleFont);
$this->_elementCollection[] = $text;
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
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @return \PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
$link = new Link($linkSrc, $linkName, $styleFont);
$rID = \PhpOffice\PhpWord\Footnote::addFootnoteLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
}
/**
* Get Footnote content
*
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get paragraph style
*
* @return \PhpOffice\PhpWord\Style\Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
/**
* Get Footnote Reference ID
*
* @return int
*/
public function getReferenceId()
{
return $this->_refId;
}
/**
* Set Footnote Reference ID
*
* @param int $refId
*/
public function setReferenceId($refId)
{
$this->_refId = $refId;
}
}

View File

@ -1,275 +0,0 @@
<?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\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
/**
* Header element
*/
class Header
{
/**
* Header Count
*
* @var int
*/
private $_headerCount;
/**
* Header Relation ID
*
* @var int
*/
private $_rId;
/**
* Header type
*
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
private $_type = self::AUTO;
/**
* Even Numbered Pages Only
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
const EVEN = 'even';
/**
* Default Header or Footer
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
const AUTO = 'default'; // Did not use DEFAULT because it is a PHP keyword
/**
* First Page Only
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-w_type-4.html Header or Footer Type
*/
const FIRST = 'first';
/**
* Header Element Collection
*
* @var int
*/
private $_elementCollection = array();
/**
* Create a new Header
*
* @param int $sectionCount
*/
public function __construct($sectionCount)
{
$this->_headerCount = $sectionCount;
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Create a new TextRun
*
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
return $textRun;
}
/**
* Add a Table Element
*
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Table
*/
public function addTable($style = null)
{
$table = new Table('header', $this->_headerCount, $style);
$this->_elementCollection[] = $table;
return $table;
}
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $src, $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new InvalidImageException;
}
}
/**
* Add a by PHP created Image Element
*
* @param string $src
* @param mixed $style
* @deprecated
*/
public function addMemoryImage($src, $style = null)
{
return $this->addImage($src, $style);
}
/**
* Add a PreserveText Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
}
/**
* Add a Watermark Element
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addWatermark($src, $style = null)
{
$image = new Image($src, $style, true);
if (!is_null($image->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $src, $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new InvalidImageException;
}
}
/**
* Get Header Relation ID
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Header Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get all Header Elements
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Header Count
*/
public function getHeaderCount()
{
return $this->_headerCount;
}
/**
* Get Header Type
*/
public function getType()
{
return $this->_type;
}
/**
* Reset back to default
*/
public function resetType()
{
return $this->_type = self::AUTO;
}
/**
* First page only header
*/
public function firstPage()
{
return $this->_type = self::FIRST;
}
/**
* Even numbered Pages only
*/
public function evenPage()
{
return $this->_type = self::EVEN;
}
}

View File

@ -1,159 +0,0 @@
<?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;
/**
* Link element
*/
class Link
{
/**
* Link source
*
* @var string
*/
private $_linkSrc;
/**
* Link name
*
* @var string
*/
private $_linkName;
/**
* Link Relation ID
*
* @var string
*/
private $_rId;
/**
* Link style
*
* @var string|Font
*/
private $_styleFont;
/**
* Paragraph style
*
* @var string|Paragraph
*/
private $_styleParagraph;
/**
* Create a new Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @param mixed $styleParagraph
*/
public function __construct($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null)
{
$this->_linkSrc = $linkSrc;
$this->_linkName = $linkName;
// Set font style
if (is_array($styleFont)) {
$this->_styleFont = new Font('text');
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleFont->setStyleValue($key, $value);
}
} else {
$this->_styleFont = $styleFont;
}
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
return $this;
}
/**
* Get Link Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Link Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get Link source
*
* @return string
*/
public function getLinkSrc()
{
return $this->_linkSrc;
}
/**
* Get Link name
*
* @return string
*/
public function getLinkName()
{
return $this->_linkName;
}
/**
* Get Text style
*
* @return string|Font
*/
public function getFontStyle()
{
return $this->_styleFont;
}
/**
* Get Paragraph style
*
* @return string|Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
}

View File

@ -1,149 +0,0 @@
<?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\Section\Table\Row;
/**
* Table element
*/
class Table
{
/**
* Table style
*
* @var \PhpOffice\PhpWord\Style\Table
*/
private $_style;
/**
* Table rows
*
* @var array
*/
private $_rows = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf = null;
/**
* Table holder count
*
* @var array
*/
private $_pCount;
/**
* Table width
*
* @var int
*/
private $_width = null;
/**
* Create a new table
*
* @param string $insideOf
* @param int $pCount
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
if (!is_null($style)) {
if (is_array($style)) {
$this->_style = new \PhpOffice\PhpWord\Style\Table();
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
} else {
$this->_style = $style;
}
}
}
/**
* Add a row
*
* @param int $height
* @param mixed $style
*/
public function addRow($height = null, $style = null)
{
$row = new Row($this->_insideOf, $this->_pCount, $height, $style);
$this->_rows[] = $row;
return $row;
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Table\Cell
*/
public function addCell($width = null, $style = null)
{
$i = count($this->_rows) - 1;
$cell = $this->_rows[$i]->addCell($width, $style);
return $cell;
}
/**
* Get all rows
*
* @return array
*/
public function getRows()
{
return $this->_rows;
}
/**
* Get table style
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getStyle()
{
return $this->_style;
}
/**
* Set table width
*
* @param int $width
*/
public function setWidth($width)
{
$this->_width = $width;
}
/**
* Get table width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}
}

View File

@ -1,345 +0,0 @@
<?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\Table;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exceptions\InvalidObjectException;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\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;
/**
* Table cell element
*/
class Cell
{
/**
* Cell Width
*
* @var int
*/
private $_width = null;
/**
* Cell Style
*
* @var \PhpOffice\PhpWord\Style\Cell
*/
private $_style;
/**
* Cell Element Collection
*
* @var array
*/
private $_elementCollection = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf;
/**
* Section/Header/Footer count
*
* @var int
*/
private $_pCount;
/**
* Create a new Table Cell
*
* @param string $insideOf
* @param int $pCount
* @param int $width
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $width = null, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
$this->_width = $width;
$this->_style = new \PhpOffice\PhpWord\Style\Cell();
if (!is_null($style)) {
if (is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
} else {
$this->_style = $style;
}
}
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text, $styleFont = null, $styleParagraph = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add a Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $style = null)
{
if ($this->_insideOf == 'section') {
if (!String::isUTF8($linkSrc)) {
$linkSrc = utf8_encode($linkSrc);
}
if (!is_null($linkName)) {
if (!String::isUTF8($linkName)) {
$linkName = utf8_encode($linkName);
}
}
$link = new Link($linkSrc, $linkName, $style);
$rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
} else {
throw new Exception('Unsupported Link header / footer reference');
return false;
}
}
/**
* Add TextBreak
*
* @param int $count
* @param null|string|array|\PhpOffice\PhpWord\Style\Font $fontStyle
* @param null|string|array|\PhpOffice\PhpWord\Style\Paragraph $paragraphStyle
*/
public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null)
{
for ($i = 1; $i <= $count; $i++) {
$this->_elementCollection[] = new TextBreak($fontStyle, $paragraphStyle);
}
}
/**
* Add a ListItem Element
*
* @param string $text
* @param int $depth
* @param mixed $styleText
* @param mixed $styleList
* @return \PhpOffice\PhpWord\Section\ListItem
*/
public function addListItem($text, $depth = 0, $styleText = null, $styleList = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$listItem = new ListItem($text, $depth, $styleText, $styleList);
$this->_elementCollection[] = $listItem;
return $listItem;
}
/**
* Add a Image Element
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
if ($this->_insideOf == 'section') {
$rID = Media::addSectionMediaElement($src, 'image', $image);
} elseif ($this->_insideOf == 'header') {
$rID = Media::addHeaderMediaElement($this->_pCount, $src, $image);
} elseif ($this->_insideOf == 'footer') {
$rID = Media::addFooterMediaElement($this->_pCount, $src, $image);
}
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new InvalidImageException;
}
}
/**
* Add a by PHP created Image Element
*
* @param string $src
* @param mixed $style
* @deprecated
*/
public function addMemoryImage($src, $style = null)
{
return $this->addImage($src, $style);
}
/**
* Add a OLE-Object Element
*
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Object
*/
public function addObject($src, $style = null)
{
$object = new Object($src, $style);
if (!is_null($object->getSource())) {
$inf = pathinfo($src);
$ext = $inf['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$iconSrc = __DIR__ . '/../../_staticDocParts/';
if (!file_exists($iconSrc . '_' . $ext . '.png')) {
$iconSrc = $iconSrc . '_default.png';
} else {
$iconSrc .= '_' . $ext . '.png';
}
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image', new Image($iconSrc));
$data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0];
$objectId = $data[1];
$object->setRelationId($rID);
$object->setObjectId($objectId);
$object->setImageRelationId($rIDimg);
$this->_elementCollection[] = $object;
return $object;
} else {
throw new InvalidObjectException;
}
}
/**
* Add a PreserveText Element
*
* @param string $text
* @param mixed $styleFont
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Footer\PreserveText
*/
public function addPreserveText($text, $styleFont = null, $styleParagraph = null)
{
if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') {
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$ptext = new PreserveText($text, $styleFont, $styleParagraph);
$this->_elementCollection[] = $ptext;
return $ptext;
} else {
throw new Exception('addPreserveText only supported in footer/header.');
}
}
/**
* Create a new TextRun
*
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\TextRun
*/
public function createTextRun($styleParagraph = null)
{
$textRun = new TextRun($styleParagraph);
$this->_elementCollection[] = $textRun;
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
*
* @return array
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Cell Style
*
* @return \PhpOffice\PhpWord\Style\Cell
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get Cell width
*
* @return int
*/
public function getWidth()
{
return $this->_width;
}
}

View File

@ -1,124 +0,0 @@
<?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\Table;
/**
* Table row element
*/
class Row
{
/**
* Row height
*
* @var int
*/
private $_height = null;
/**
* Row style
*
* @var \PhpOffice\PhpWord\Style\Row
*/
private $_style;
/**
* Row cells
*
* @var array
*/
private $_cells = array();
/**
* Table holder
*
* @var string
*/
private $_insideOf;
/**
* Section/Header/Footer count
*
* @var int
*/
private $_pCount;
/**
* Create a new table row
*
* @param string $insideOf
* @param int $pCount
* @param int $height
* @param mixed $style
*/
public function __construct($insideOf, $pCount, $height = null, $style = null)
{
$this->_insideOf = $insideOf;
$this->_pCount = $pCount;
$this->_height = $height;
$this->_style = new \PhpOffice\PhpWord\Style\Row();
if (!is_null($style)) {
if (is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
}
}
/**
* Add a cell
*
* @param int $width
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Table\Cell
*/
public function addCell($width = null, $style = null)
{
$cell = new Cell($this->_insideOf, $this->_pCount, $width, $style);
$this->_cells[] = $cell;
return $cell;
}
/**
* Get all cells
*
* @return array
*/
public function getCells()
{
return $this->_cells;
}
/**
* Get row style
*
* @return \PhpOffice\PhpWord\Style\Row
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get row height
*
* @return int
*/
public function getHeight()
{
return $this->_height;
}
}

View File

@ -1,171 +0,0 @@
<?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\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Textrun/paragraph element
*/
class TextRun
{
/**
* Paragraph style
*
* @var Paragraph
*/
private $_styleParagraph;
/**
* Text collection
*
* @var array
*/
private $_elementCollection;
/**
* Create a new TextRun Element
*
* @param mixed $styleParagraph
*/
public function __construct($styleParagraph = null)
{
$this->_elementCollection = array();
// Set paragraph style
if (is_array($styleParagraph)) {
$this->_styleParagraph = new Paragraph();
foreach ($styleParagraph as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_styleParagraph->setStyleValue($key, $value);
}
} else {
$this->_styleParagraph = $styleParagraph;
}
}
/**
* Add a Text Element
*
* @param string $text
* @param mixed $styleFont
* @return \PhpOffice\PhpWord\Section\Text
*/
public function addText($text = null, $styleFont = null)
{
if (!String::isUTF8($text)) {
$text = utf8_encode($text);
}
$text = new Text($text, $styleFont);
$this->_elementCollection[] = $text;
return $text;
}
/**
* Add a Link Element
*
* @param string $linkSrc
* @param string $linkName
* @param mixed $styleFont
* @return \PhpOffice\PhpWord\Section\Link
*/
public function addLink($linkSrc, $linkName = null, $styleFont = null)
{
$linkSrc = utf8_encode($linkSrc);
if (!is_null($linkName)) {
$linkName = utf8_encode($linkName);
}
$link = new Link($linkSrc, $linkName, $styleFont);
$rID = Media::addSectionLinkElement($linkSrc);
$link->setRelationId($rID);
$this->_elementCollection[] = $link;
return $link;
}
/**
* Add a Image Element
*
* @param string $imageSrc
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Image
*/
public function addImage($imageSrc, $style = null)
{
$image = new Image($imageSrc, $style);
if (!is_null($image->getSource())) {
$rID = Media::addSectionMediaElement($imageSrc, 'image', $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new InvalidImageException;
}
}
/**
* 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);
}
}
/**
* Create a new Footnote Element
*
* @param mixed $styleParagraph
* @return \PhpOffice\PhpWord\Section\Footnote
*/
public function createFootnote($styleParagraph = null)
{
$footnote = new \PhpOffice\PhpWord\Section\Footnote($styleParagraph);
$refID = \PhpOffice\PhpWord\Footnote::addFootnoteElement($footnote);
$footnote->setReferenceId($refID);
$this->_elementCollection[] = $footnote;
return $footnote;
}
/**
* Get TextRun content
*
* @return string
*/
public function getElements()
{
return $this->_elementCollection;
}
/**
* Get Paragraph style
*
* @return string|Paragraph
*/
public function getParagraphStyle()
{
return $this->_styleParagraph;
}
}

View File

@ -23,7 +23,7 @@ class Settings
*
* @var boolean
*/
private static $_xmlWriterCompatibility = true;
private static $xmlWriterCompatibility = true;
/**
* Name of the class used for Zip file management
@ -32,7 +32,7 @@ class Settings
*
* @var string
*/
private static $_zipClass = self::ZIPARCHIVE;
private static $zipClass = self::ZIPARCHIVE;
/**
* Set the compatibility option used by the XMLWriter
@ -43,7 +43,7 @@ class Settings
public static function setCompatibility($compatibility)
{
if (is_bool($compatibility)) {
self::$_xmlWriterCompatibility = $compatibility;
self::$xmlWriterCompatibility = $compatibility;
return true;
}
return false;
@ -56,7 +56,7 @@ class Settings
*/
public static function getCompatibility()
{
return self::$_xmlWriterCompatibility;
return self::$xmlWriterCompatibility;
}
/**
@ -70,7 +70,7 @@ class Settings
{
if (($zipClass === self::PCLZIP) ||
($zipClass === self::ZIPARCHIVE)) {
self::$_zipClass = $zipClass;
self::$zipClass = $zipClass;
return true;
}
return false;
@ -86,6 +86,6 @@ class Settings
*/
public static function getZipClass()
{
return self::$_zipClass;
return self::$zipClass;
} // function getZipClass()
}

View File

@ -17,8 +17,8 @@ class Drawing
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int Value in EMU
* @param integer $pValue Value in pixels
* @return double Value in EMU
*/
public static function pixelsToEMU($pValue = 0)
{
@ -28,8 +28,8 @@ class Drawing
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int Value in pixels
* @param integer $pValue Value in EMU
* @return integer Value in pixels
*/
public static function EMUToPixels($pValue = 0)
{
@ -43,8 +43,8 @@ class Drawing
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return int Value in points
* @param integer $pValue Value in pixels
* @return double Value in points
*/
public static function pixelsToPoints($pValue = 0)
{
@ -54,8 +54,8 @@ class Drawing
/**
* Convert points width to pixels
*
* @param int $pValue Value in points
* @return int Value in pixels
* @param integer $pValue Value in points
* @return integer Value in pixels
*/
public static function pointsToPixels($pValue = 0)
{
@ -69,19 +69,19 @@ class Drawing
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int Angle
* @param integer $pValue Degrees
* @return integer Angle
*/
public static function degreesToAngle($pValue = 0)
{
return (int)round($pValue * 60000);
return (integer)round($pValue * 60000);
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int Degrees
* @param integer $pValue Angle
* @return integer Degrees
*/
public static function angleToDegrees($pValue = 0)
{
@ -95,8 +95,8 @@ class Drawing
/**
* Convert pixels to centimeters
*
* @param int $pValue Value in pixels
* @return int Value in centimeters
* @param integer $pValue Value in pixels
* @return double Value in centimeters
*/
public static function pixelsToCentimeters($pValue = 0)
{
@ -106,8 +106,8 @@ class Drawing
/**
* Convert centimeters width to pixels
*
* @param int $pValue Value in centimeters
* @return int Value in pixels
* @param integer $pValue Value in centimeters
* @return integer Value in pixels
*/
public static function centimetersToPixels($pValue = 0)
{
@ -121,8 +121,8 @@ class Drawing
/**
* Convert HTML hexadecimal to RGB
*
* @param str $pValue HTML Color in hexadecimal
* @return array Value in RGB
* @param string $pValue HTML Color in hexadecimal
* @return array Value in RGB
*/
public static function htmlToRGB($pValue)
{

View File

@ -17,8 +17,8 @@ class Font
/**
* Calculate an (approximate) pixel size, based on a font points size
*
* @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels)
* @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels)
*/
public static function fontSizeToPixels($fontSizeInPoints = 12)
{
@ -40,7 +40,7 @@ class Font
* Calculate an (approximate) pixel size, based on centimeter size
*
* @param int $sizeInCm Font size (in centimeters)
* @return int Size (in pixels)
* @return double Size (in pixels)
*/
public static function centimeterSizeToPixels($sizeInCm = 1)
{
@ -51,7 +51,7 @@ class Font
* Convert centimeter to twip
*
* @param int $sizeInCm
* @return int
* @return double
*/
public static function centimeterSizeToTwips($sizeInCm = 1)
{
@ -62,7 +62,7 @@ class Font
* Convert inch to twip
*
* @param int $sizeInInch
* @return int
* @return double
*/
public static function inchSizeToTwips($sizeInInch = 1)
{
@ -73,7 +73,7 @@ class Font
* Convert pixel to twip
*
* @param int $sizeInPixel
* @return int
* @return double
*/
public static function pixelSizeToTwips($sizeInPixel = 1)
{
@ -83,8 +83,8 @@ class Font
/**
* Calculate twip based on point size, used mainly for paragraph spacing
*
* @param int|float $sizeInPoint Size in point
* @return int|float Size (in twips)
* @param integer $sizeInPoint Size in point
* @return integer Size (in twips)
*/
public static function pointSizeToTwips($sizeInPoint = 1)
{

View File

@ -19,66 +19,36 @@ class String
*
* @var string[]
*/
private static $_controlCharacters = array();
/**
* Build control characters array
*/
private static function _buildControlCharacters()
{
for ($i = 0; $i <= 19; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$_controlCharacters[$find] = $replace;
}
}
}
private static $controlCharacters = array();
/**
* Convert from OpenXML escaped control character to PHP control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to unescape
* @return string
* @param string $value Value to unescape
* @return string
*/
public static function controlCharacterOOXML2PHP($value = '')
{
if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value);
return str_replace(array_keys(self::$controlCharacters), array_values(self::$controlCharacters), $value);
}
/**
* Convert from PHP control character to OpenXML escaped control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to escape
* @return string
* @param string $value Value to escape
* @return string
*/
public static function controlCharacterPHP2OOXML($value = '')
{
if (empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
if (empty(self::$controlCharacters)) {
self::buildControlCharacters();
}
return str_replace(array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value);
return str_replace(array_values(self::$controlCharacters), array_keys(self::$controlCharacters), $value);
}
/**
@ -91,4 +61,33 @@ class String
{
return $value === '' || preg_match('/^./su', $value) === 1;
}
/**
* Return UTF8 encoded value
*
* @param string $value
* @return string
*/
public static function toUTF8($value = '')
{
if (!is_null($value) && !self::isUTF8($value)) {
$value = utf8_encode($value);
}
return $value;
}
/**
* Build control characters array
*/
private static function buildControlCharacters()
{
for ($i = 0; $i <= 19; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s', strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$controlCharacters[$find] = $replace;
}
}
}
}

View File

@ -24,6 +24,8 @@ if (!defined('DATE_W3C')) {
* @method bool startElement(string $name)
* @method bool writeAttribute(string $name, string $value)
* @method bool endElement()
* @method bool startDocument(string $version = 1.0, string $encoding = null, string $standalone = null)
* @method bool text(string $content)
*/
class XMLWriter
{
@ -36,14 +38,14 @@ class XMLWriter
*
* @var \XMLWriter
*/
private $_xmlWriter;
private $xmlWriter;
/**
* Temporary filename
*
* @var string
*/
private $_tempFileName = '';
private $tempFile = '';
/**
* Create new XMLWriter
@ -54,30 +56,30 @@ class XMLWriter
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './')
{
// Create internal XMLWriter
$this->_xmlWriter = new \XMLWriter();
$this->xmlWriter = new \XMLWriter();
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->_xmlWriter->openMemory();
$this->xmlWriter->openMemory();
} else {
// Create temporary filename
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
$this->tempFile = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
if ($this->xmlWriter->openUri($this->tempFile) === false) {
// Fallback to memory...
$this->_xmlWriter->openMemory();
$this->xmlWriter->openMemory();
}
}
// Set xml Compatibility
$compatibility = Settings::getCompatibility();
if ($compatibility) {
$this->_xmlWriter->setIndent(false);
$this->_xmlWriter->setIndentString('');
$this->xmlWriter->setIndent(false);
$this->xmlWriter->setIndentString('');
} else {
$this->_xmlWriter->setIndent(true);
$this->_xmlWriter->setIndentString(' ');
$this->xmlWriter->setIndent(true);
$this->xmlWriter->setIndentString(' ');
}
}
@ -87,26 +89,11 @@ class XMLWriter
public function __destruct()
{
// Desctruct XMLWriter
unset($this->_xmlWriter);
unset($this->xmlWriter);
// Unlink temporary files
if ($this->_tempFileName != '') {
@unlink($this->_tempFileName);
}
}
/**
* Get written data
*
* @return string XML data
*/
public function getData()
{
if ($this->_tempFileName == '') {
return $this->_xmlWriter->outputMemory(true);
} else {
$this->_xmlWriter->flush();
return file_get_contents($this->_tempFileName);
if ($this->tempFile != '') {
@unlink($this->tempFile);
}
}
@ -119,22 +106,37 @@ class XMLWriter
public function __call($function, $args)
{
try {
@call_user_func_array(array($this->_xmlWriter, $function), $args);
@call_user_func_array(array($this->xmlWriter, $function), $args);
} catch (\Exception $ex) {
// Do nothing!
}
}
/**
* Get written data
*
* @return string XML data
*/
public function getData()
{
if ($this->tempFile == '') {
return $this->xmlWriter->outputMemory(true);
} else {
$this->xmlWriter->flush();
return file_get_contents($this->tempFile);
}
}
/**
* Fallback method for writeRaw, introduced in PHP 5.2
*
* @param string $text
* @return string
* @return bool
*/
public function writeRaw($text)
{
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
return $this->_xmlWriter->writeRaw($text);
if (isset($this->xmlWriter) && is_object($this->xmlWriter) && (method_exists($this->xmlWriter, 'writeRaw'))) {
return $this->xmlWriter->writeRaw($text);
}
return $this->text($text);

View File

@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord\Shared;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exception\Exception;
// @codeCoverageIgnoreStart
if (!defined('PCLZIP_TEMPORARY_DIR')) {
@ -36,14 +36,14 @@ class ZipArchive
*
* @var string
*/
private $_tempDir;
private $tempDir;
/**
* Zip Archive Stream Handle
*
* @var string
*/
private $_zip;
private $zip;
/**
* Open a new zip archive
@ -53,8 +53,8 @@ class ZipArchive
*/
public function open($fileName)
{
$this->_tempDir = sys_get_temp_dir();
$this->_zip = new \PclZip($fileName);
$this->tempDir = sys_get_temp_dir();
$this->zip = new \PclZip($fileName);
return true;
}
@ -83,13 +83,13 @@ class ZipArchive
// To Rename the file while adding it to the zip we
// need to create a temp file with the correct name
if ($filenameParts['basename'] != $localnameParts['basename']) {
$temppath = $this->_tempDir . '/' . $localnameParts['basename'];
$temppath = $this->tempDir . '/' . $localnameParts['basename'];
copy($filename, $temppath);
$filename = $temppath;
$filenameParts = pathinfo($temppath);
}
$res = $this->_zip->add(
$res = $this->zip->add(
$filename,
PCLZIP_OPT_REMOVE_PATH,
$filenameParts['dirname'],
@ -98,8 +98,7 @@ class ZipArchive
);
if ($res == 0) {
throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
return false;
throw new Exception("Error zipping files : " . $this->zip->errorInfo(true));
}
return true;
@ -116,25 +115,24 @@ class ZipArchive
$filenameParts = pathinfo($localname);
// Write $contents to a temp file
$handle = fopen($this->_tempDir . '/' . $filenameParts["basename"], "wb");
$handle = fopen($this->tempDir . '/' . $filenameParts["basename"], "wb");
fwrite($handle, $contents);
fclose($handle);
// Add temp file to zip
$res = $this->_zip->add(
$this->_tempDir . '/' . $filenameParts["basename"],
$res = $this->zip->add(
$this->tempDir . '/' . $filenameParts["basename"],
PCLZIP_OPT_REMOVE_PATH,
$this->_tempDir,
$this->tempDir,
PCLZIP_OPT_ADD_PATH,
$filenameParts["dirname"]
);
if ($res == 0) {
throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true));
return false;
throw new Exception("Error zipping files : " . $this->zip->errorInfo(true));
}
// Remove temp file
unlink($this->_tempDir . '/' . $filenameParts["basename"]);
unlink($this->tempDir . '/' . $filenameParts["basename"]);
return true;
}
@ -147,18 +145,18 @@ class ZipArchive
*/
public function locateName($fileName)
{
$list = $this->_zip->listContent();
$list = $this->zip->listContent();
$listCount = count($list);
$list_index = -1;
$listIndex = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
$listIndex = $i;
break;
}
}
return ($list_index > -1);
return ($listIndex > -1);
}
/**
@ -169,31 +167,32 @@ class ZipArchive
*/
public function getFromName($fileName)
{
$list = $this->_zip->listContent();
$list = $this->zip->listContent();
$listCount = count($list);
$list_index = -1;
$listIndex = -1;
$contents = null;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
$listIndex = $i;
break;
}
}
$extracted = "";
if ($list_index != -1) {
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
if ($listIndex != -1) {
$extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
} else {
$filename = substr($fileName, 1);
$list_index = -1;
$fileName = substr($fileName, 1);
$listIndex = -1;
for ($i = 0; $i < $listCount; ++$i) {
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
$list_index = $i;
$listIndex = $i;
break;
}
}
$extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
$extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING);
}
if ((is_array($extracted)) && ($extracted != 0)) {
$contents = $extracted[0]["content"];

View File

@ -1,181 +0,0 @@
<?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\Shared;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Settings;
/**
* Zip stream wrapper
*
* @codeCoverageIgnore Legacy from PHPExcel
*/
class ZipStreamWrapper
{
/**
* Internal ZipAcrhive
*
* @var \ZipAcrhive
*/
private $_archive;
/**
* Filename in ZipAcrhive
*
* @var string
*/
private $_fileNameInArchive = '';
/**
* Position in file
*
* @var int
*/
private $_position = 0;
/**
* Data
*
* @var mixed
*/
private $_data = '';
/**
* Register wrapper
*/
public static function register()
{
@stream_wrapper_unregister("zip");
@stream_wrapper_register("zip", __CLASS__);
}
/**
* Open stream
*
* @param string $path
* @param string $mode
* @param string $options
* @param string $opened_path
*/
public function streamOpen($path, $mode, $options, &$opened_path)
{
// Check for mode
if ($mode{0} != 'r') {
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
}
// Parse URL
$url = @parse_url($path);
// Fix URL
if (!is_array($url)) {
$url['host'] = substr($path, strlen('zip://'));
$url['path'] = '';
}
if (strpos($url['host'], '#') !== false) {
if (!isset($url['fragment'])) {
$url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path'];
$url['host'] = substr($url['host'], 0, strpos($url['host'], '#'));
unset($url['path']);
}
} else {
$url['host'] = $url['host'] . $url['path'];
unset($url['path']);
}
// Open archive
$zipClass = Settings::getZipClass();
$this->_archive = new $zipClass();
$this->_archive->open($url['host']);
$this->_fileNameInArchive = $url['fragment'];
$this->_position = 0;
$this->_data = $this->_archive->getFromName($this->_fileNameInArchive);
return true;
}
/**
* Stat stream
*/
public function streamStat()
{
return $this->_archive->statName($this->_fileNameInArchive);
}
/**
* Read stream
*
* @param int $count
*/
public function streamRead($count)
{
$ret = substr($this->_data, $this->_position, $count);
$this->_position += strlen($ret);
return $ret;
}
/**
* Tell stream
*/
public function streamTell()
{
return $this->_position;
}
/**
* EOF stream
*/
public function streamEof()
{
return $this->_position >= strlen($this->_data);
}
/**
* Seek stream
*
* @param int $offset
* @param mixed $whence
*/
public function streamSeek($offset, $whence)
{
switch ($whence) {
case \SEEK_SET:
if ($offset < strlen($this->_data) && $offset >= 0) {
$this->_position = $offset;
return true;
} else {
return false;
}
break;
case \SEEK_CUR:
if ($offset >= 0) {
$this->_position += $offset;
return true;
} else {
return false;
}
break;
case \SEEK_END:
if (strlen($this->_data) + $offset >= 0) {
$this->_position = strlen($this->_data) + $offset;
return true;
} else {
return false;
}
break;
default:
return false;
}
}
}

View File

@ -23,7 +23,7 @@ class Style
*
* @var array
*/
private static $_styleElements = array();
private static $styles = array();
/**
* Add paragraph style
@ -33,17 +33,7 @@ class Style
*/
public static function addParagraphStyle($styleName, $styles)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new Paragraph();
foreach ($styles as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$style->setStyleValue($key, $value);
}
self::$_styleElements[$styleName] = $style;
}
self::setStyleValues($styleName, $styles, new Paragraph());
}
/**
@ -55,16 +45,7 @@ class Style
*/
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$font = new Font('text', $styleParagraph);
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$font->setStyleValue($key, $value);
}
self::$_styleElements[$styleName] = $font;
}
self::setStyleValues($styleName, $styleFont, new Font('text', $styleParagraph));
}
/**
@ -75,17 +56,7 @@ class Style
*/
public static function addLinkStyle($styleName, $styles)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new Font('link');
foreach ($styles as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$style->setStyleValue($key, $value);
}
self::$_styleElements[$styleName] = $style;
}
self::setStyleValues($styleName, $styles, new Font('link'));
}
/**
@ -97,10 +68,10 @@ class Style
*/
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
if (!array_key_exists($styleName, self::$styles)) {
$style = new Table($styleTable, $styleFirstRow);
self::$_styleElements[$styleName] = $style;
self::$styles[$styleName] = $style;
}
}
@ -114,17 +85,15 @@ class Style
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
{
$styleName = 'Heading_' . $titleCount;
if (!array_key_exists($styleName, self::$_styleElements)) {
$font = new Font('title', $styleParagraph);
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$font->setStyleValue($key, $value);
}
self::setStyleValues("Heading_{$titleCount}", $styleFont, new Font('title', $styleParagraph));
}
self::$_styleElements[$styleName] = $font;
}
/**
* Reset styles
*/
public static function reset()
{
self::$styles = array();
}
/**
@ -144,7 +113,7 @@ class Style
*/
public static function getStyles()
{
return self::$_styleElements;
return self::$styles;
}
/**
@ -154,10 +123,31 @@ class Style
*/
public static function getStyle($styleName)
{
if (array_key_exists($styleName, self::$_styleElements)) {
return self::$_styleElements[$styleName];
if (array_key_exists($styleName, self::$styles)) {
return self::$styles[$styleName];
} else {
return null;
}
}
/**
* Set style values
*
* @param string $styleName
* @param array $styleValues
* @param mixed $styleObject
*/
private static function setStyleValues($styleName, $styleValues, $styleObject)
{
if (!array_key_exists($styleName, self::$styles)) {
foreach ($styleValues as $key => $value) {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$styleObject->setStyleValue($key, $value);
}
self::$styles[$styleName] = $styleObject;
}
}
}

View File

@ -0,0 +1,43 @@
<?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\Style;
/**
* Abstract style class
*
* @since 0.9.2
*/
abstract class AbstractStyle
{
/**
* Set style value template method
*
* Some child classes have their own specific overrides
*
* @param string $key
* @param string $value
*
* @todo Implement type check mechanism, e.g. boolean, integer, enum, defaults
*/
public function setStyleValue($key, $value)
{
// Backward compability check for versions < 0.9.2 which use underscore
// prefix for their private properties
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
// Check if the set method is exists. Throws an exception?
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
}
}

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* Table cell style
*/
class Cell
class Cell extends AbstractStyle
{
const TEXT_DIR_BTLR = 'btLr';
const TEXT_DIR_TBRL = 'tbRl';
@ -22,91 +22,91 @@ class Cell
*
* @var string
*/
private $_valign;
private $valign;
/**
* Text Direction
*
* @var string
*/
private $_textDirection;
private $textDirection;
/**
* Background-Color
*
* @var string
*/
private $_bgColor;
private $bgColor;
/**
* Border Top Size
*
* @var int
*/
private $_borderTopSize;
private $borderTopSize;
/**
* Border Top Color
*
* @var string
*/
private $_borderTopColor;
private $borderTopColor;
/**
* Border Left Size
*
* @var int
*/
private $_borderLeftSize;
private $borderLeftSize;
/**
* Border Left Color
*
* @var string
*/
private $_borderLeftColor;
private $borderLeftColor;
/**
* Border Right Size
*
* @var int
*/
private $_borderRightSize;
private $borderRightSize;
/**
* Border Right Color
*
* @var string
*/
private $_borderRightColor;
private $borderRightColor;
/**
* Border Bottom Size
*
* @var int
*/
private $_borderBottomSize;
private $borderBottomSize;
/**
* Border Bottom Color
*
* @var string
*/
private $_borderBottomColor;
private $borderBottomColor;
/**
* Border Default Color
*
* @var string
*/
private $_defaultBorderColor;
private $defaultBorderColor;
/**
* colspan
*
* @var integer
*/
private $_gridSpan = null;
private $gridSpan = null;
/**
* rowspan (restart, continue)
@ -116,25 +116,25 @@ class Cell
*
* @var string
*/
private $_vMerge = null;
private $vMerge = null;
/**
* Create a new Cell Style
*/
public function __construct()
{
$this->_valign = null;
$this->_textDirection = null;
$this->_bgColor = null;
$this->_borderTopSize = null;
$this->_borderTopColor = null;
$this->_borderLeftSize = null;
$this->_borderLeftColor = null;
$this->_borderRightSize = null;
$this->_borderRightColor = null;
$this->_borderBottomSize = null;
$this->_borderBottomColor = null;
$this->_defaultBorderColor = '000000';
$this->valign = null;
$this->textDirection = null;
$this->bgColor = null;
$this->borderTopSize = null;
$this->borderTopColor = null;
$this->borderLeftSize = null;
$this->borderLeftColor = null;
$this->borderRightSize = null;
$this->borderRightColor = null;
$this->borderBottomSize = null;
$this->borderBottomColor = null;
$this->defaultBorderColor = '000000';
}
/**
@ -145,9 +145,12 @@ class Cell
*/
public function setStyleValue($key, $value)
{
if ($key == '_borderSize') {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
if ($key == 'borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
} elseif ($key == 'borderColor') {
$this->setBorderColor($value);
} else {
$this->$key = $value;
@ -159,7 +162,7 @@ class Cell
*/
public function getVAlign()
{
return $this->_valign;
return $this->valign;
}
/**
@ -169,7 +172,7 @@ class Cell
*/
public function setVAlign($pValue = null)
{
$this->_valign = $pValue;
$this->valign = $pValue;
}
/**
@ -177,7 +180,7 @@ class Cell
*/
public function getTextDirection()
{
return $this->_textDirection;
return $this->textDirection;
}
/**
@ -187,7 +190,7 @@ class Cell
*/
public function setTextDirection($pValue = null)
{
$this->_textDirection = $pValue;
$this->textDirection = $pValue;
}
/**
@ -195,7 +198,7 @@ class Cell
*/
public function getBgColor()
{
return $this->_bgColor;
return $this->bgColor;
}
/**
@ -205,7 +208,7 @@ class Cell
*/
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
$this->bgColor = $pValue;
}
/**
@ -215,10 +218,10 @@ class Cell
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->borderTopSize = $pValue;
$this->borderLeftSize = $pValue;
$this->borderRightSize = $pValue;
$this->borderBottomSize = $pValue;
}
/**
@ -241,10 +244,10 @@ class Cell
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->borderTopColor = $pValue;
$this->borderLeftColor = $pValue;
$this->borderRightColor = $pValue;
$this->borderBottomColor = $pValue;
}
/**
@ -267,7 +270,7 @@ class Cell
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->borderTopSize = $pValue;
}
/**
@ -275,7 +278,7 @@ class Cell
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
return $this->borderTopSize;
}
/**
@ -285,7 +288,7 @@ class Cell
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->borderTopColor = $pValue;
}
/**
@ -293,7 +296,7 @@ class Cell
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
return $this->borderTopColor;
}
/**
@ -303,7 +306,7 @@ class Cell
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
$this->borderLeftSize = $pValue;
}
/**
@ -311,7 +314,7 @@ class Cell
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
return $this->borderLeftSize;
}
/**
@ -321,7 +324,7 @@ class Cell
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
$this->borderLeftColor = $pValue;
}
/**
@ -329,7 +332,7 @@ class Cell
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
return $this->borderLeftColor;
}
/**
@ -339,7 +342,7 @@ class Cell
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
$this->borderRightSize = $pValue;
}
/**
@ -347,7 +350,7 @@ class Cell
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
return $this->borderRightSize;
}
/**
@ -357,7 +360,7 @@ class Cell
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
$this->borderRightColor = $pValue;
}
/**
@ -365,7 +368,7 @@ class Cell
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
return $this->borderRightColor;
}
/**
@ -375,7 +378,7 @@ class Cell
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
$this->borderBottomSize = $pValue;
}
/**
@ -383,7 +386,7 @@ class Cell
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
return $this->borderBottomSize;
}
/**
@ -393,7 +396,7 @@ class Cell
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
$this->borderBottomColor = $pValue;
}
/**
@ -401,7 +404,7 @@ class Cell
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
return $this->borderBottomColor;
}
/**
@ -409,7 +412,7 @@ class Cell
*/
public function getDefaultBorderColor()
{
return $this->_defaultBorderColor;
return $this->defaultBorderColor;
}
/**
@ -419,7 +422,7 @@ class Cell
*/
public function setGridSpan($pValue = null)
{
$this->_gridSpan = $pValue;
$this->gridSpan = $pValue;
}
/**
@ -427,7 +430,7 @@ class Cell
*/
public function getGridSpan()
{
return $this->_gridSpan;
return $this->gridSpan;
}
/**
@ -437,7 +440,7 @@ class Cell
*/
public function setVMerge($pValue = null)
{
$this->_vMerge = $pValue;
$this->vMerge = $pValue;
}
/**
@ -445,6 +448,6 @@ class Cell
*/
public function getVMerge()
{
return $this->_vMerge;
return $this->vMerge;
}
}

View File

@ -10,12 +10,12 @@
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
use PhpOffice\PhpWord\Exception\InvalidStyleException;
/**
* Font style
*/
class Font
class Font extends AbstractStyle
{
const UNDERLINE_NONE = 'none';
const UNDERLINE_DASH = 'dash';
@ -56,91 +56,91 @@ class Font
*
* @var string
*/
private $_type;
private $type;
/**
* Paragraph style
*
* @var \PhpOffice\PhpWord\Style\Paragraph
*/
private $_paragraphStyle;
private $paragraphStyle;
/**
* Font name
*
* @var int|float
*/
private $_name = PhpWord::DEFAULT_FONT_NAME;
private $name = PhpWord::DEFAULT_FONT_NAME;
/**
* Font size
*
* @var int|float
*/
private $_size = PhpWord::DEFAULT_FONT_SIZE;
private $size = PhpWord::DEFAULT_FONT_SIZE;
/**
* Bold
*
* @var bool
*/
private $_bold = false;
private $bold = false;
/**
* Italic
*
* @var bool
*/
private $_italic = false;
private $italic = false;
/**
* Superscript
*
* @var bool
*/
private $_superScript = false;
private $superScript = false;
/**
* Subscript
*
* @var bool
*/
private $_subScript = false;
private $subScript = false;
/**
* Undeline
*
* @var string
*/
private $_underline = self::UNDERLINE_NONE;
private $underline = self::UNDERLINE_NONE;
/**
* Strikethrough
*
* @var bool
*/
private $_strikethrough = false;
private $strikethrough = false;
/**
* Font color
*
* @var string
*/
private $_color = PhpWord::DEFAULT_FONT_COLOR;
private $color = PhpWord::DEFAULT_FONT_COLOR;
/**
* Foreground/highlight
*
* @var string
*/
private $_fgColor = null;
private $fgColor = null;
/**
* Background color
*
* @var string
*/
private $_bgColor = null;
private $bgColor = null;
/**
* Text line height
*
@ -159,7 +159,7 @@ class Font
*
* @var string
*/
private $_hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
private $hint = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
/**
* Create new font style
@ -169,15 +169,15 @@ class Font
*/
public function __construct($type = 'text', $paragraphStyle = null)
{
$this->_type = $type;
$this->type = $type;
if ($paragraphStyle instanceof Paragraph) {
$this->_paragraphStyle = $paragraphStyle;
$this->paragraphStyle = $paragraphStyle;
} elseif (is_array($paragraphStyle)) {
$this->_paragraphStyle = new Paragraph;
$this->_paragraphStyle->setArrayStyle($paragraphStyle);
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle->setArrayStyle($paragraphStyle);
} else {
$this->_paragraphStyle = $paragraphStyle;
$this->paragraphStyle = $paragraphStyle;
}
}
@ -193,8 +193,8 @@ class Font
if ($key === 'line-height') {
$this->setLineHeight($value);
null;
} elseif (substr($key, 0, 1) !== '_') {
$key = '_' . $key;
} elseif (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$this->setStyleValue($key, $value);
}
@ -202,20 +202,6 @@ class Font
return $this;
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
$method = 'set' . substr($key, 1);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
/**
* Get font name
*
@ -223,7 +209,7 @@ class Font
*/
public function getName()
{
return $this->_name;
return $this->name;
}
/**
@ -237,7 +223,7 @@ class Font
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_NAME;
}
$this->_name = $pValue;
$this->name = $pValue;
return $this;
}
@ -249,7 +235,7 @@ class Font
*/
public function getSize()
{
return $this->_size;
return $this->size;
}
/**
@ -263,7 +249,7 @@ class Font
if (!is_numeric($pValue)) {
$pValue = PhpWord::DEFAULT_FONT_SIZE;
}
$this->_size = $pValue;
$this->size = $pValue;
return $this;
}
@ -274,7 +260,7 @@ class Font
*/
public function getBold()
{
return $this->_bold;
return $this->bold;
}
/**
@ -288,7 +274,7 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_bold = $pValue;
$this->bold = $pValue;
return $this;
}
@ -299,7 +285,7 @@ class Font
*/
public function getItalic()
{
return $this->_italic;
return $this->italic;
}
/**
@ -313,7 +299,7 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_italic = $pValue;
$this->italic = $pValue;
return $this;
}
@ -324,7 +310,7 @@ class Font
*/
public function getSuperScript()
{
return $this->_superScript;
return $this->superScript;
}
/**
@ -338,8 +324,8 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_superScript = $pValue;
$this->_subScript = !$pValue;
$this->superScript = $pValue;
$this->subScript = !$pValue;
return $this;
}
@ -350,7 +336,7 @@ class Font
*/
public function getSubScript()
{
return $this->_subScript;
return $this->subScript;
}
/**
@ -364,8 +350,8 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_subScript = $pValue;
$this->_superScript = !$pValue;
$this->subScript = $pValue;
$this->superScript = !$pValue;
return $this;
}
@ -376,7 +362,7 @@ class Font
*/
public function getUnderline()
{
return $this->_underline;
return $this->underline;
}
/**
@ -390,7 +376,7 @@ class Font
if ($pValue == '') {
$pValue = self::UNDERLINE_NONE;
}
$this->_underline = $pValue;
$this->underline = $pValue;
return $this;
}
@ -401,7 +387,7 @@ class Font
*/
public function getStrikethrough()
{
return $this->_strikethrough;
return $this->strikethrough;
}
/**
@ -415,7 +401,7 @@ class Font
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_strikethrough = $pValue;
$this->strikethrough = $pValue;
return $this;
}
@ -426,7 +412,7 @@ class Font
*/
public function getColor()
{
return $this->_color;
return $this->color;
}
/**
@ -440,18 +426,18 @@ class Font
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_COLOR;
}
$this->_color = $pValue;
$this->color = $pValue;
return $this;
}
/**
* Get foreground/highlight color
*
* @return bool
* @return string
*/
public function getFgColor()
{
return $this->_fgColor;
return $this->fgColor;
}
/**
@ -462,7 +448,7 @@ class Font
*/
public function setFgColor($pValue = null)
{
$this->_fgColor = $pValue;
$this->fgColor = $pValue;
return $this;
}
@ -473,7 +459,7 @@ class Font
*/
public function getBgColor()
{
return $this->_bgColor;
return $this->bgColor;
}
/**
@ -484,7 +470,7 @@ class Font
*/
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
$this->bgColor = $pValue;
return $this;
}
@ -495,7 +481,7 @@ class Font
*/
public function getStyleType()
{
return $this->_type;
return $this->type;
}
/**
@ -505,7 +491,7 @@ class Font
*/
public function getParagraphStyle()
{
return $this->_paragraphStyle;
return $this->paragraphStyle;
}
/**
@ -513,7 +499,7 @@ class Font
*
* @param int|float|string $lineHeight
* @return $this
* @throws \PhpOffice\PhpWord\Exceptions\InvalidStyleException
* @throws \PhpOffice\PhpWord\Exception\InvalidStyleException
*/
public function setLineHeight($lineHeight)
{
@ -543,11 +529,11 @@ class Font
/**
* Get Font Content Type
*
* @return bool
* @return string
*/
public function getHint()
{
return $this->_hint;
return $this->hint;
}
/**
@ -561,7 +547,7 @@ class Font
if (is_null($pValue) || $pValue == '') {
$pValue = PhpWord::DEFAULT_FONT_CONTENT_TYPE;
}
$this->_hint = $pValue;
$this->hint = $pValue;
return $this;
}
}

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* Image and memory image style
*/
class Image
class Image extends AbstractStyle
{
const WRAPPING_STYLE_INLINE = 'inline';
const WRAPPING_STYLE_SQUARE = 'square';
@ -25,21 +25,35 @@ class Image
*
* @var int
*/
private $_width;
private $width;
/**
* Image width
*
* @var int
*/
private $_height;
private $height;
/**
* Alignment
*
* @var string
*/
private $_align;
private $align;
/**
* Margin Top
*
* @var int
*/
private $marginTop;
/**
* Margin Left
*
* @var int
*/
private $marginLeft;
/**
* Wrapping style
@ -48,50 +62,25 @@ class Image
*/
private $wrappingStyle;
/**
* Margin Top
*
* @var int
*/
private $_marginTop;
/**
* Margin Left
*
* @var int
*/
private $_marginLeft;
/**
* Create new image style
*/
public function __construct()
{
$this->_width = null;
$this->_height = null;
$this->_align = null;
$this->_marginTop = null;
$this->_marginLeft = null;
$this->width = null;
$this->height = null;
$this->align = null;
$this->marginTop = null;
$this->marginLeft = null;
$this->setWrappingStyle(self::WRAPPING_STYLE_INLINE);
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
/**
* Get width
*/
public function getWidth()
{
return $this->_width;
return $this->width;
}
/**
@ -101,7 +90,7 @@ class Image
*/
public function setWidth($pValue = null)
{
$this->_width = $pValue;
$this->width = $pValue;
}
/**
@ -109,7 +98,7 @@ class Image
*/
public function getHeight()
{
return $this->_height;
return $this->height;
}
/**
@ -119,7 +108,7 @@ class Image
*/
public function setHeight($pValue = null)
{
$this->_height = $pValue;
$this->height = $pValue;
}
/**
@ -127,7 +116,7 @@ class Image
*/
public function getAlign()
{
return $this->_align;
return $this->align;
}
/**
@ -137,7 +126,7 @@ class Image
*/
public function setAlign($pValue = null)
{
$this->_align = $pValue;
$this->align = $pValue;
}
/**
@ -147,7 +136,7 @@ class Image
*/
public function getMarginTop()
{
return $this->_marginTop;
return $this->marginTop;
}
/**
@ -158,7 +147,7 @@ class Image
*/
public function setMarginTop($pValue = null)
{
$this->_marginTop = $pValue;
$this->marginTop = $pValue;
return $this;
}
@ -169,7 +158,7 @@ class Image
*/
public function getMarginLeft()
{
return $this->_marginLeft;
return $this->marginLeft;
}
/**
@ -180,7 +169,7 @@ class Image
*/
public function setMarginLeft($pValue = null)
{
$this->_marginLeft = $pValue;
$this->marginLeft = $pValue;
return $this;
}

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* List item style
*/
class ListItem
class ListItem extends AbstractStyle
{
const TYPE_NUMBER = 7;
const TYPE_NUMBER_NESTED = 8;
@ -24,25 +24,14 @@ class ListItem
/**
* List Type
*/
private $_listType;
private $listType;
/**
* Create a new ListItem Style
*/
public function __construct()
{
$this->_listType = self::TYPE_BULLET_FILLED;
}
/**
* Set style value
*
* @param string $key
* @param string $value
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
$this->listType = self::TYPE_BULLET_FILLED;
}
/**
@ -52,7 +41,7 @@ class ListItem
*/
public function setListType($pValue = self::TYPE_BULLET_FILLED)
{
$this->_listType = $pValue;
$this->listType = $pValue;
}
/**
@ -60,6 +49,6 @@ class ListItem
*/
public function getListType()
{
return $this->_listType;
return $this->listType;
}
}

View File

@ -9,12 +9,12 @@
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Exceptions\InvalidStyleException;
use PhpOffice\PhpWord\Exception\InvalidStyleException;
/**
* Paragraph style
*/
class Paragraph
class Paragraph extends AbstractStyle
{
const LINE_HEIGHT = 240;
@ -30,91 +30,91 @@ class Paragraph
*
* @var string
*/
private $_align;
private $align;
/**
* Space before Paragraph
*
* @var int
*/
private $_spaceBefore;
private $spaceBefore;
/**
* Space after Paragraph
*
* @var int
*/
private $_spaceAfter;
private $spaceAfter;
/**
* Spacing between breaks
*
* @var int
*/
private $_spacing;
private $spacing;
/**
* Set of Custom Tab Stops
*
* @var array
*/
private $_tabs;
private $tabs;
/**
* Indent by how much
*
* @var int
*/
private $_indent;
private $indent;
/**
* Hanging by how much
*
* @var int
*/
private $_hanging;
private $hanging;
/**
* Parent style
*
* @var string
*/
private $_basedOn = 'Normal';
private $basedOn = 'Normal';
/**
* Style for next paragraph
*
* @var string
*/
private $_next;
private $next;
/**
* Allow first/last line to display on a separate page
*
* @var bool
*/
private $_widowControl = true;
private $widowControl = true;
/**
* Keep paragraph with next paragraph
*
* @var bool
*/
private $_keepNext = false;
private $keepNext = false;
/**
* Keep all lines on one page
*
* @var bool
*/
private $_keepLines = false;
private $keepLines = false;
/**
* Start paragraph on next page
*
* @var bool
*/
private $_pageBreakBefore = false;
private $pageBreakBefore = false;
/**
* Set style by array
@ -127,8 +127,8 @@ class Paragraph
foreach ($style as $key => $value) {
if ($key === 'line-height') {
null;
} elseif (substr($key, 0, 1) !== '_') {
$key = '_' . $key;
} elseif (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$this->setStyleValue($key, $value);
}
@ -144,16 +144,18 @@ class Paragraph
*/
public function setStyleValue($key, $value)
{
if ($key == '_indent' || $key == '_hanging') {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
if ($key == 'indent' || $key == 'hanging') {
$value = $value * 720;
} elseif ($key == '_spacing') {
} elseif ($key == 'spacing') {
$value += 240; // because line height of 1 matches 240 twips
} elseif ($key === 'line-height') {
$this->setLineHeight($value);
return;
}
$this->$key = $value;
$method = 'set' . substr($key, 1);
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($value);
}
@ -166,7 +168,7 @@ class Paragraph
*/
public function getAlign()
{
return $this->_align;
return $this->align;
}
/**
@ -181,18 +183,18 @@ class Paragraph
// justify becames both
$pValue = 'both';
}
$this->_align = $pValue;
$this->align = $pValue;
return $this;
}
/**
* Get Space before Paragraph
*
* @return string
* @return integer
*/
public function getSpaceBefore()
{
return $this->_spaceBefore;
return $this->spaceBefore;
}
/**
@ -203,18 +205,18 @@ class Paragraph
*/
public function setSpaceBefore($pValue = null)
{
$this->_spaceBefore = $pValue;
$this->spaceBefore = $pValue;
return $this;
}
/**
* Get Space after Paragraph
*
* @return string
* @return integer
*/
public function getSpaceAfter()
{
return $this->_spaceAfter;
return $this->spaceAfter;
}
/**
@ -225,7 +227,7 @@ class Paragraph
*/
public function setSpaceAfter($pValue = null)
{
$this->_spaceAfter = $pValue;
$this->spaceAfter = $pValue;
return $this;
}
@ -236,7 +238,7 @@ class Paragraph
*/
public function getSpacing()
{
return $this->_spacing;
return $this->spacing;
}
/**
@ -247,7 +249,7 @@ class Paragraph
*/
public function setSpacing($pValue = null)
{
$this->_spacing = $pValue;
$this->spacing = $pValue;
return $this;
}
@ -258,7 +260,7 @@ class Paragraph
*/
public function getIndent()
{
return $this->_indent;
return $this->indent;
}
/**
@ -269,7 +271,7 @@ class Paragraph
*/
public function setIndent($pValue = null)
{
$this->_indent = $pValue;
$this->indent = $pValue;
return $this;
}
@ -280,7 +282,7 @@ class Paragraph
*/
public function getHanging()
{
return $this->_hanging;
return $this->hanging;
}
/**
@ -291,7 +293,7 @@ class Paragraph
*/
public function setHanging($pValue = null)
{
$this->_hanging = $pValue;
$this->hanging = $pValue;
return $this;
}
@ -302,7 +304,7 @@ class Paragraph
*/
public function getTabs()
{
return $this->_tabs;
return $this->tabs;
}
/**
@ -314,7 +316,7 @@ class Paragraph
public function setTabs($pValue = null)
{
if (is_array($pValue)) {
$this->_tabs = new Tabs($pValue);
$this->tabs = new Tabs($pValue);
}
return $this;
}
@ -326,7 +328,7 @@ class Paragraph
*/
public function getBasedOn()
{
return $this->_basedOn;
return $this->basedOn;
}
/**
@ -337,7 +339,7 @@ class Paragraph
*/
public function setBasedOn($pValue = 'Normal')
{
$this->_basedOn = $pValue;
$this->basedOn = $pValue;
return $this;
}
@ -348,7 +350,7 @@ class Paragraph
*/
public function getNext()
{
return $this->_next;
return $this->next;
}
/**
@ -359,7 +361,7 @@ class Paragraph
*/
public function setNext($pValue = null)
{
$this->_next = $pValue;
$this->next = $pValue;
return $this;
}
@ -370,7 +372,7 @@ class Paragraph
*/
public function getWidowControl()
{
return $this->_widowControl;
return $this->widowControl;
}
/**
@ -384,7 +386,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = true;
}
$this->_widowControl = $pValue;
$this->widowControl = $pValue;
return $this;
}
@ -395,7 +397,7 @@ class Paragraph
*/
public function getKeepNext()
{
return $this->_keepNext;
return $this->keepNext;
}
/**
@ -409,7 +411,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_keepNext = $pValue;
$this->keepNext = $pValue;
return $this;
}
@ -420,7 +422,7 @@ class Paragraph
*/
public function getKeepLines()
{
return $this->_keepLines;
return $this->keepLines;
}
/**
@ -434,7 +436,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_keepLines = $pValue;
$this->keepLines = $pValue;
return $this;
}
@ -445,7 +447,7 @@ class Paragraph
*/
public function getPageBreakBefore()
{
return $this->_pageBreakBefore;
return $this->pageBreakBefore;
}
/**
@ -459,7 +461,7 @@ class Paragraph
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_pageBreakBefore = $pValue;
$this->pageBreakBefore = $pValue;
return $this;
}
@ -468,7 +470,7 @@ class Paragraph
*
* @param int|float|string $lineHeight
* @return $this
* @throws \PhpOffice\PhpWord\Exceptions\InvalidStyleException
* @throws \PhpOffice\PhpWord\Exception\InvalidStyleException
*/
public function setLineHeight($lineHeight)
{

View File

@ -12,28 +12,28 @@ namespace PhpOffice\PhpWord\Style;
/**
* Table row style
*/
class Row
class Row extends AbstractStyle
{
/**
* Repeat table row on every new page
*
* @var bool
*/
private $_tblHeader = false;
private $tblHeader = false;
/**
* Table row cannot break across pages
*
* @var bool
*/
private $_cantSplit = false;
private $cantSplit = false;
/**
* Table row exact height
*
* @var bool
*/
private $_exactHeight = false;
private $exactHeight = false;
/**
* Create a new row style
@ -42,17 +42,6 @@ class Row
{
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
/**
* Set tblHeader
*
@ -64,7 +53,7 @@ class Row
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_tblHeader = $pValue;
$this->tblHeader = $pValue;
return $this;
}
@ -75,7 +64,7 @@ class Row
*/
public function getTblHeader()
{
return $this->_tblHeader;
return $this->tblHeader;
}
/**
@ -89,7 +78,7 @@ class Row
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_cantSplit = $pValue;
$this->cantSplit = $pValue;
return $this;
}
@ -100,7 +89,7 @@ class Row
*/
public function getCantSplit()
{
return $this->_cantSplit;
return $this->cantSplit;
}
/**
@ -114,7 +103,7 @@ class Row
if (!is_bool($pValue)) {
$pValue = false;
}
$this->_exactHeight = $pValue;
$this->exactHeight = $pValue;
return $this;
}
@ -125,6 +114,6 @@ class Row
*/
public function getExactHeight()
{
return $this->_exactHeight;
return $this->exactHeight;
}
}

View File

@ -7,131 +7,131 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord\Section;
namespace PhpOffice\PhpWord\Style;
/**
* Section settings
*/
class Settings
class Section extends AbstractStyle
{
/**
* Default Page Size Width
*
* @var int
*/
private $_defaultPageSizeW = 11906;
private $defaultPageSizeW = 11906;
/**
* Default Page Size Height
*
* @var int
*/
private $_defaultPageSizeH = 16838;
private $defaultPageSizeH = 16838;
/**
* Page Orientation
*
* @var string
*/
private $_orientation;
private $orientation;
/**
* Page Margin Top
*
* @var int
*/
private $_marginTop;
private $marginTop;
/**
* Page Margin Left
*
* @var int
*/
private $_marginLeft;
private $marginLeft;
/**
* Page Margin Right
*
* @var int
*/
private $_marginRight;
private $marginRight;
/**
* Page Margin Bottom
*
* @var int
*/
private $_marginBottom;
private $marginBottom;
/**
* Page Size Width
*
* @var int
*/
private $_pageSizeW;
private $pageSizeW;
/**
* Page Size Height
*
* @var int
*/
private $_pageSizeH;
private $pageSizeH;
/**
* Page Border Top Size
*
* @var int
*/
private $_borderTopSize;
private $borderTopSize;
/**
* Page Border Top Color
*
* @var int
*/
private $_borderTopColor;
private $borderTopColor;
/**
* Page Border Left Size
*
* @var int
*/
private $_borderLeftSize;
private $borderLeftSize;
/**
* Page Border Left Color
*
* @var int
*/
private $_borderLeftColor;
private $borderLeftColor;
/**
* Page Border Right Size
*
* @var int
*/
private $_borderRightSize;
private $borderRightSize;
/**
* Page Border Right Color
*
* @var int
*/
private $_borderRightColor;
private $borderRightColor;
/**
* Page Border Bottom Size
*
* @var int
*/
private $_borderBottomSize;
private $borderBottomSize;
/**
* Page Border Bottom Color
*
* @var int
*/
private $_borderBottomColor;
private $borderBottomColor;
/**
* Page Numbering Start
@ -159,14 +159,14 @@ class Settings
*
* @var int
*/
private $_colsNum;
private $colsNum;
/**
* Section spacing between columns
*
* @var int
*/
private $_colsSpace;
private $colsSpace;
/**
* Section break type
@ -180,33 +180,33 @@ class Settings
*
* @var string
*/
private $_breakType;
private $breakType;
/**
* Create new Section Settings
*/
public function __construct()
{
$this->_orientation = null;
$this->_marginTop = 1418;
$this->_marginLeft = 1418;
$this->_marginRight = 1418;
$this->_marginBottom = 1134;
$this->_pageSizeW = $this->_defaultPageSizeW;
$this->_pageSizeH = $this->_defaultPageSizeH;
$this->_borderTopSize = null;
$this->_borderTopColor = null;
$this->_borderLeftSize = null;
$this->_borderLeftColor = null;
$this->_borderRightSize = null;
$this->_borderRightColor = null;
$this->_borderBottomSize = null;
$this->_borderBottomColor = null;
$this->orientation = null;
$this->marginTop = 1418;
$this->marginLeft = 1418;
$this->marginRight = 1418;
$this->marginBottom = 1134;
$this->pageSizeW = $this->defaultPageSizeW;
$this->pageSizeH = $this->defaultPageSizeH;
$this->borderTopSize = null;
$this->borderTopColor = null;
$this->borderLeftSize = null;
$this->borderLeftColor = null;
$this->borderRightSize = null;
$this->borderRightColor = null;
$this->borderBottomSize = null;
$this->borderBottomColor = null;
$this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches)
$this->footerHeight = 720;
$this->_colsNum = 1;
$this->_colsSpace = 720;
$this->_breakType = null;
$this->colsNum = 1;
$this->colsSpace = 720;
$this->breakType = null;
}
/**
@ -217,13 +217,16 @@ class Settings
*/
public function setSettingValue($key, $value)
{
if ($key == '_orientation' && $value == 'landscape') {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
if ($key == 'orientation' && $value == 'landscape') {
$this->setLandscape();
} elseif ($key == '_orientation' && is_null($value)) {
} elseif ($key == 'orientation' && is_null($value)) {
$this->setPortrait();
} elseif ($key == '_borderSize') {
} elseif ($key == 'borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
} elseif ($key == 'borderColor') {
$this->setBorderColor($value);
} else {
$this->$key = $value;
@ -237,7 +240,7 @@ class Settings
*/
public function getMarginTop()
{
return $this->_marginTop;
return $this->marginTop;
}
/**
@ -247,7 +250,7 @@ class Settings
*/
public function setMarginTop($pValue = '')
{
$this->_marginTop = $pValue;
$this->marginTop = $pValue;
return $this;
}
@ -258,7 +261,7 @@ class Settings
*/
public function getMarginLeft()
{
return $this->_marginLeft;
return $this->marginLeft;
}
/**
@ -268,7 +271,7 @@ class Settings
*/
public function setMarginLeft($pValue = '')
{
$this->_marginLeft = $pValue;
$this->marginLeft = $pValue;
return $this;
}
@ -279,7 +282,7 @@ class Settings
*/
public function getMarginRight()
{
return $this->_marginRight;
return $this->marginRight;
}
/**
@ -289,7 +292,7 @@ class Settings
*/
public function setMarginRight($pValue = '')
{
$this->_marginRight = $pValue;
$this->marginRight = $pValue;
return $this;
}
@ -300,7 +303,7 @@ class Settings
*/
public function getMarginBottom()
{
return $this->_marginBottom;
return $this->marginBottom;
}
/**
@ -310,7 +313,7 @@ class Settings
*/
public function setMarginBottom($pValue = '')
{
$this->_marginBottom = $pValue;
$this->marginBottom = $pValue;
return $this;
}
@ -319,9 +322,9 @@ class Settings
*/
public function setLandscape()
{
$this->_orientation = 'landscape';
$this->_pageSizeW = $this->_defaultPageSizeH;
$this->_pageSizeH = $this->_defaultPageSizeW;
$this->orientation = 'landscape';
$this->pageSizeW = $this->defaultPageSizeH;
$this->pageSizeH = $this->defaultPageSizeW;
}
/**
@ -329,9 +332,9 @@ class Settings
*/
public function setPortrait()
{
$this->_orientation = null;
$this->_pageSizeW = $this->_defaultPageSizeW;
$this->_pageSizeH = $this->_defaultPageSizeH;
$this->orientation = null;
$this->pageSizeW = $this->defaultPageSizeW;
$this->pageSizeH = $this->defaultPageSizeH;
}
/**
@ -341,7 +344,7 @@ class Settings
*/
public function getPageSizeW()
{
return $this->_pageSizeW;
return $this->pageSizeW;
}
/**
@ -351,7 +354,7 @@ class Settings
*/
public function getPageSizeH()
{
return $this->_pageSizeH;
return $this->pageSizeH;
}
/**
@ -361,7 +364,7 @@ class Settings
*/
public function getOrientation()
{
return $this->_orientation;
return $this->orientation;
}
/**
@ -371,10 +374,10 @@ class Settings
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->borderTopSize = $pValue;
$this->borderLeftSize = $pValue;
$this->borderRightSize = $pValue;
$this->borderBottomSize = $pValue;
}
/**
@ -399,10 +402,10 @@ class Settings
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->borderTopColor = $pValue;
$this->borderLeftColor = $pValue;
$this->borderRightColor = $pValue;
$this->borderBottomColor = $pValue;
}
/**
@ -427,7 +430,7 @@ class Settings
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->borderTopSize = $pValue;
}
/**
@ -437,7 +440,7 @@ class Settings
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
return $this->borderTopSize;
}
/**
@ -447,7 +450,7 @@ class Settings
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->borderTopColor = $pValue;
}
/**
@ -457,7 +460,7 @@ class Settings
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
return $this->borderTopColor;
}
/**
@ -467,7 +470,7 @@ class Settings
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
$this->borderLeftSize = $pValue;
}
/**
@ -477,7 +480,7 @@ class Settings
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
return $this->borderLeftSize;
}
/**
@ -487,7 +490,7 @@ class Settings
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
$this->borderLeftColor = $pValue;
}
/**
@ -497,7 +500,7 @@ class Settings
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
return $this->borderLeftColor;
}
/**
@ -507,7 +510,7 @@ class Settings
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
$this->borderRightSize = $pValue;
}
/**
@ -517,7 +520,7 @@ class Settings
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
return $this->borderRightSize;
}
/**
@ -527,7 +530,7 @@ class Settings
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
$this->borderRightColor = $pValue;
}
/**
@ -537,7 +540,7 @@ class Settings
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
return $this->borderRightColor;
}
/**
@ -547,7 +550,7 @@ class Settings
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
$this->borderBottomSize = $pValue;
}
/**
@ -557,7 +560,7 @@ class Settings
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
return $this->borderBottomSize;
}
/**
@ -567,7 +570,7 @@ class Settings
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
$this->borderBottomColor = $pValue;
}
/**
@ -577,7 +580,7 @@ class Settings
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
return $this->borderBottomColor;
}
/**
@ -660,7 +663,7 @@ class Settings
if (!is_numeric($pValue)) {
$pValue = 1;
}
$this->_colsNum = $pValue;
$this->colsNum = $pValue;
return $this;
}
@ -671,7 +674,7 @@ class Settings
*/
public function getColsNum()
{
return $this->_colsNum;
return $this->colsNum;
}
/**
@ -684,7 +687,7 @@ class Settings
if (!is_numeric($pValue)) {
$pValue = 720;
}
$this->_colsSpace = $pValue;
$this->colsSpace = $pValue;
return $this;
}
@ -695,7 +698,7 @@ class Settings
*/
public function getColsSpace()
{
return $this->_colsSpace;
return $this->colsSpace;
}
/**
@ -705,7 +708,7 @@ class Settings
*/
public function setBreakType($pValue = null)
{
$this->_breakType = $pValue;
$this->breakType = $pValue;
return $this;
}
@ -716,6 +719,6 @@ class Settings
*/
public function getBreakType()
{
return $this->_breakType;
return $this->breakType;
}
}

View File

@ -12,7 +12,7 @@ namespace PhpOffice\PhpWord\Style;
/**
* TOC style
*/
class TOC
class TOC extends AbstractStyle
{
const TABLEADER_DOT = 'dot';
const TABLEADER_UNDERSCORE = 'underscore';
@ -24,21 +24,21 @@ class TOC
*
* @var string
*/
private $_tabLeader;
private $tabLeader;
/**
* Tab Position
*
* @var int
*/
private $_tabPos;
private $tabPos;
/**
* Indent
*
* @var int
*/
private $_indent;
private $indent;
/**
@ -46,9 +46,9 @@ class TOC
*/
public function __construct()
{
$this->_tabPos = 9062;
$this->_tabLeader = self::TABLEADER_DOT;
$this->_indent = 200;
$this->tabPos = 9062;
$this->tabLeader = self::TABLEADER_DOT;
$this->indent = 200;
}
/**
@ -58,7 +58,7 @@ class TOC
*/
public function getTabPos()
{
return $this->_tabPos;
return $this->tabPos;
}
/**
@ -68,7 +68,7 @@ class TOC
*/
public function setTabPos($pValue)
{
$this->_tabPos = $pValue;
$this->tabPos = $pValue;
}
/**
@ -78,7 +78,7 @@ class TOC
*/
public function getTabLeader()
{
return $this->_tabLeader;
return $this->tabLeader;
}
/**
@ -88,7 +88,7 @@ class TOC
*/
public function setTabLeader($pValue = self::TABLEADER_DOT)
{
$this->_tabLeader = $pValue;
$this->tabLeader = $pValue;
}
/**
@ -98,7 +98,7 @@ class TOC
*/
public function getIndent()
{
return $this->_indent;
return $this->indent;
}
/**
@ -108,7 +108,7 @@ class TOC
*/
public function setIndent($pValue)
{
$this->_indent = $pValue;
$this->indent = $pValue;
}
/**

View File

@ -14,28 +14,28 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Tab style
*/
class Tab
class Tab extends AbstractStyle
{
/**
* Tab Stop Type
*
* @var string
*/
private $_val;
private $val;
/**
* Tab Leader Character
*
* @var string
*/
private $_leader;
private $leader;
/**
* Tab Stop Position
*
* @var int
*/
private $_position;
private $position;
/**
* Tab Stop Type
@ -43,7 +43,7 @@ class Tab
* @var array
* @link http://www.schemacentral.com/sc/ooxml/a-w_val-26.html Tab Stop Type
*/
private static $_possibleStopTypes = array(
private static $possibleStopTypes = array(
'clear', // No Tab Stop
'left', // Left Tab Stop
'center', // Center Tab Stop
@ -59,7 +59,7 @@ class Tab
* @var array
* @link http://www.schemacentral.com/sc/ooxml/a-w_leader-1.html Tab Leader Character
*/
private static $_possibleLeaders = array(
private static $possibleLeaders = array(
'none', // No tab stop leader
'dot', // Dotted leader line
'hyphen', // Dashed tab stop leader line
@ -80,13 +80,13 @@ class Tab
public function __construct($val = null, $position = 0, $leader = null)
{
// Default to clear if the stop type is not matched
$this->_val = (self::isStopType($val)) ? $val : 'clear';
$this->val = (self::isStopType($val)) ? $val : 'clear';
// Default to 0 if the position is non-numeric
$this->_position = (is_numeric($position)) ? intval($position) : 0;
$this->position = (is_numeric($position)) ? intval($position) : 0;
// Default to NULL if no tab leader
$this->_leader = (self::isLeaderType($leader)) ? $leader : null;
$this->leader = (self::isLeaderType($leader)) ? $leader : null;
}
/**
@ -98,11 +98,11 @@ class Tab
{
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tab");
$xmlWriter->writeAttribute("w:val", $this->_val);
if (!is_null($this->_leader)) {
$xmlWriter->writeAttribute("w:leader", $this->_leader);
$xmlWriter->writeAttribute("w:val", $this->val);
if (!is_null($this->leader)) {
$xmlWriter->writeAttribute("w:leader", $this->leader);
}
$xmlWriter->writeAttribute("w:pos", $this->_position);
$xmlWriter->writeAttribute("w:pos", $this->position);
$xmlWriter->endElement();
}
}
@ -115,7 +115,7 @@ class Tab
*/
private static function isStopType($attribute)
{
return in_array($attribute, self::$_possibleStopTypes);
return in_array($attribute, self::$possibleStopTypes);
}
/**
@ -126,6 +126,6 @@ class Tab
*/
private static function isLeaderType($attribute)
{
return in_array($attribute, self::$_possibleLeaders);
return in_array($attribute, self::$possibleLeaders);
}
}

View File

@ -12,133 +12,133 @@ namespace PhpOffice\PhpWord\Style;
/**
* Table style
*/
class Table
class Table extends AbstractStyle
{
/**
* Style for first row
*
* @var \PhpOffice\PhpWord\Style\Table
*/
private $_firstRow = null;
private $firstRow = null;
/**
* Cell margin top
*
* @var int
*/
private $_cellMarginTop = null;
private $cellMarginTop = null;
/**
* Cell margin left
*
* @var int
*/
private $_cellMarginLeft = null;
private $cellMarginLeft = null;
/**
* Cell margin right
*
* @var int
*/
private $_cellMarginRight = null;
private $cellMarginRight = null;
/**
* Cell margin bottom
*
* @var int
*/
private $_cellMarginBottom = null;
private $cellMarginBottom = null;
/**
* Background color
*
* @var string
*/
private $_bgColor;
private $bgColor;
/**
* Border size top
*
* @var int
*/
private $_borderTopSize;
private $borderTopSize;
/**
* Border color
*
* @var string top
*/
private $_borderTopColor;
private $borderTopColor;
/**
* Border size left
*
* @var int
*/
private $_borderLeftSize;
private $borderLeftSize;
/**
* Border color left
*
* @var string
*/
private $_borderLeftColor;
private $borderLeftColor;
/**
* Border size right
*
* @var int
*/
private $_borderRightSize;
private $borderRightSize;
/**
* Border color right
*
* @var string
*/
private $_borderRightColor;
private $borderRightColor;
/**
* Border size bottom
*
* @var int
*/
private $_borderBottomSize;
private $borderBottomSize;
/**
* Border color bottom
*
* @var string
*/
private $_borderBottomColor;
private $borderBottomColor;
/**
* Border size inside horizontal
*
* @var int
*/
private $_borderInsideHSize;
private $borderInsideHSize;
/**
* Border color inside horizontal
*
* @var string
*/
private $_borderInsideHColor;
private $borderInsideHColor;
/**
* Border size inside vertical
*
* @var int
*/
private $_borderInsideVSize;
private $borderInsideVSize;
/**
* Border color inside vertical
*
* @var string
*/
private $_borderInsideVColor;
private $borderInsideVColor;
/**
* Create new table style
@ -149,30 +149,29 @@ class Table
public function __construct($styleTable = null, $styleFirstRow = null)
{
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->_firstRow = clone $this;
$this->firstRow = clone $this;
unset($this->_firstRow->_firstRow);
unset($this->_firstRow->_cellMarginBottom);
unset($this->_firstRow->_cellMarginTop);
unset($this->_firstRow->_cellMarginLeft);
unset($this->_firstRow->_cellMarginRight);
unset($this->_firstRow->_borderInsideVColor);
unset($this->_firstRow->_borderInsideVSize);
unset($this->_firstRow->_borderInsideHColor);
unset($this->_firstRow->_borderInsideHSize);
unset($this->firstRow->firstRow);
unset($this->firstRow->cellMarginBottom);
unset($this->firstRow->cellMarginTop);
unset($this->firstRow->cellMarginLeft);
unset($this->firstRow->cellMarginRight);
unset($this->firstRow->borderInsideVColor);
unset($this->firstRow->borderInsideVSize);
unset($this->firstRow->borderInsideHColor);
unset($this->firstRow->borderInsideHSize);
foreach ($styleFirstRow as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$this->_firstRow->setStyleValue($key, $value);
$this->firstRow->setStyleValue($key, $value);
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
$this->setStyleValue($key, $value);
}
@ -187,11 +186,14 @@ class Table
*/
public function setStyleValue($key, $value)
{
if ($key == '_borderSize') {
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
if ($key == 'borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
} elseif ($key == 'borderColor') {
$this->setBorderColor($value);
} elseif ($key == '_cellMargin') {
} elseif ($key == 'cellMargin') {
$this->setCellMargin($value);
} else {
$this->$key = $value;
@ -205,17 +207,17 @@ class Table
*/
public function getFirstRow()
{
return $this->_firstRow;
return $this->firstRow;
}
/**
* Get background
*
* @return \PhpOffice\PhpWord\Style\Table
* @return string
*/
public function getBgColor()
{
return $this->_bgColor;
return $this->bgColor;
}
/**
@ -226,7 +228,7 @@ class Table
*/
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
$this->bgColor = $pValue;
}
/**
@ -236,12 +238,12 @@ class Table
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
$this->borderTopSize = $pValue;
$this->borderLeftSize = $pValue;
$this->borderRightSize = $pValue;
$this->borderBottomSize = $pValue;
$this->borderInsideHSize = $pValue;
$this->borderInsideVSize = $pValue;
}
/**
@ -267,12 +269,12 @@ class Table
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->_borderInsideHColor = $pValue;
$this->_borderInsideVColor = $pValue;
$this->borderTopColor = $pValue;
$this->borderLeftColor = $pValue;
$this->borderRightColor = $pValue;
$this->borderBottomColor = $pValue;
$this->borderInsideHColor = $pValue;
$this->borderInsideVColor = $pValue;
}
/**
@ -299,7 +301,7 @@ class Table
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->borderTopSize = $pValue;
}
/**
@ -309,7 +311,7 @@ class Table
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
return $this->borderTopSize;
}
/**
@ -319,7 +321,7 @@ class Table
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->borderTopColor = $pValue;
}
/**
@ -329,7 +331,7 @@ class Table
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
return $this->borderTopColor;
}
/**
@ -339,7 +341,7 @@ class Table
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
$this->borderLeftSize = $pValue;
}
/**
@ -349,7 +351,7 @@ class Table
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
return $this->borderLeftSize;
}
/**
@ -359,7 +361,7 @@ class Table
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
$this->borderLeftColor = $pValue;
}
/**
@ -369,7 +371,7 @@ class Table
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
return $this->borderLeftColor;
}
/**
@ -379,7 +381,7 @@ class Table
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
$this->borderRightSize = $pValue;
}
/**
@ -389,7 +391,7 @@ class Table
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
return $this->borderRightSize;
}
/**
@ -399,7 +401,7 @@ class Table
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
$this->borderRightColor = $pValue;
}
/**
@ -409,7 +411,7 @@ class Table
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
return $this->borderRightColor;
}
/**
@ -419,7 +421,7 @@ class Table
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
$this->borderBottomSize = $pValue;
}
/**
@ -429,7 +431,7 @@ class Table
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
return $this->borderBottomSize;
}
/**
@ -439,7 +441,7 @@ class Table
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
$this->borderBottomColor = $pValue;
}
/**
@ -449,7 +451,7 @@ class Table
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
return $this->borderBottomColor;
}
/**
@ -459,7 +461,7 @@ class Table
*/
public function setBorderInsideHColor($pValue = null)
{
$this->_borderInsideHColor = $pValue;
$this->borderInsideHColor = $pValue;
}
/**
@ -469,7 +471,7 @@ class Table
*/
public function getBorderInsideHColor()
{
return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null;
return (isset($this->borderInsideHColor)) ? $this->borderInsideHColor : null;
}
/**
@ -479,7 +481,7 @@ class Table
*/
public function setBorderInsideVColor($pValue = null)
{
$this->_borderInsideVColor = $pValue;
$this->borderInsideVColor = $pValue;
}
/**
@ -489,7 +491,7 @@ class Table
*/
public function getBorderInsideVColor()
{
return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null;
return (isset($this->borderInsideVColor)) ? $this->borderInsideVColor : null;
}
/**
@ -499,7 +501,7 @@ class Table
*/
public function setBorderInsideHSize($pValue = null)
{
$this->_borderInsideHSize = $pValue;
$this->borderInsideHSize = $pValue;
}
/**
@ -509,7 +511,7 @@ class Table
*/
public function getBorderInsideHSize()
{
return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
return (isset($this->borderInsideHSize)) ? $this->borderInsideHSize : null;
}
/**
@ -519,7 +521,7 @@ class Table
*/
public function setBorderInsideVSize($pValue = null)
{
$this->_borderInsideVSize = $pValue;
$this->borderInsideVSize = $pValue;
}
/**
@ -529,7 +531,7 @@ class Table
*/
public function getBorderInsideVSize()
{
return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null;
return (isset($this->borderInsideVSize)) ? $this->borderInsideVSize : null;
}
/**
@ -539,7 +541,7 @@ class Table
*/
public function setCellMarginTop($pValue = null)
{
$this->_cellMarginTop = $pValue;
$this->cellMarginTop = $pValue;
}
/**
@ -549,7 +551,7 @@ class Table
*/
public function getCellMarginTop()
{
return $this->_cellMarginTop;
return $this->cellMarginTop;
}
/**
@ -559,7 +561,7 @@ class Table
*/
public function setCellMarginLeft($pValue = null)
{
$this->_cellMarginLeft = $pValue;
$this->cellMarginLeft = $pValue;
}
/**
@ -569,7 +571,7 @@ class Table
*/
public function getCellMarginLeft()
{
return $this->_cellMarginLeft;
return $this->cellMarginLeft;
}
/**
@ -579,7 +581,7 @@ class Table
*/
public function setCellMarginRight($pValue = null)
{
$this->_cellMarginRight = $pValue;
$this->cellMarginRight = $pValue;
}
/**
@ -589,7 +591,7 @@ class Table
*/
public function getCellMarginRight()
{
return $this->_cellMarginRight;
return $this->cellMarginRight;
}
/**
@ -599,7 +601,7 @@ class Table
*/
public function setCellMarginBottom($pValue = null)
{
$this->_cellMarginBottom = $pValue;
$this->cellMarginBottom = $pValue;
}
/**
@ -609,7 +611,7 @@ class Table
*/
public function getCellMarginBottom()
{
return $this->_cellMarginBottom;
return $this->cellMarginBottom;
}
/**
@ -619,10 +621,10 @@ class Table
*/
public function setCellMargin($pValue = null)
{
$this->_cellMarginTop = $pValue;
$this->_cellMarginLeft = $pValue;
$this->_cellMarginRight = $pValue;
$this->_cellMarginBottom = $pValue;
$this->cellMarginTop = $pValue;
$this->cellMarginLeft = $pValue;
$this->cellMarginRight = $pValue;
$this->cellMarginBottom = $pValue;
}
/**
@ -632,6 +634,6 @@ class Table
*/
public function getCellMargin()
{
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom);
return array($this->cellMarginTop, $this->cellMarginLeft, $this->cellMarginRight, $this->cellMarginBottom);
}
}

View File

@ -14,14 +14,14 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Tabs style
*/
class Tabs
class Tabs extends AbstractStyle
{
/**
* Tabs
*
* @var array
*/
private $_tabs;
private $tabs;
/**
* Create new tab collection style
@ -30,7 +30,7 @@ class Tabs
*/
public function __construct(array $tabs)
{
$this->_tabs = $tabs;
$this->tabs = $tabs;
}
/**
@ -42,7 +42,7 @@ class Tabs
{
if (isset($xmlWriter)) {
$xmlWriter->startElement("w:tabs");
foreach ($this->_tabs as &$tab) {
foreach ($this->tabs as &$tab) {
$tab->toXml($xmlWriter);
}
$xmlWriter->endElement();

View File

@ -29,7 +29,7 @@ class TOC
*
* @var TOCStyle
*/
private static $tocStyle;
private static $TOCStyle;
/**
* Font style
@ -52,6 +52,7 @@ class TOC
*/
private static $bookmarkId = 0;
/**
* Min title depth to show
*
@ -66,24 +67,25 @@ class TOC
*/
private $maxDepth = 9;
/**
* Create a new Table-of-Contents Element
*
* @param mixed $styleFont
* @param array $styleTOC
* @param int $minDepth
* @param int $maxDepth
* @param integer $minDepth
* @param integer $maxDepth
*/
public function __construct($styleFont = null, $styleTOC = null, $minDepth = 1, $maxDepth = 9)
{
self::$tocStyle = new TOCStyle();
self::$TOCStyle = new TOCStyle();
if (!is_null($styleTOC) && is_array($styleTOC)) {
foreach ($styleTOC as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
self::$tocStyle->setStyleValue($key, $value);
self::$TOCStyle->setStyleValue($key, $value);
}
}
@ -91,8 +93,8 @@ class TOC
if (is_array($styleFont)) {
self::$fontStyle = new Font();
foreach ($styleFont as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
if (substr($key, 0, 1) == '_') {
$key = substr($key, 1);
}
self::$fontStyle->setStyleValue($key, $value);
}
@ -149,6 +151,14 @@ class TOC
return $titles;
}
/**
* Reset footnotes
*/
public static function reset()
{
self::$titles = array();
}
/**
* Get TOC Style
*
@ -156,7 +166,7 @@ class TOC
*/
public static function getStyleTOC()
{
return self::$tocStyle;
return self::$TOCStyle;
}
/**
@ -172,7 +182,7 @@ class TOC
/**
* Set max depth
*
* @param integer $value
* @param int $value
*/
public function setMaxDepth($value)
{
@ -192,7 +202,7 @@ class TOC
/**
* Set min depth
*
* @param integer $value
* @param int $value
*/
public function setMinDepth($value)
{

View File

@ -9,7 +9,7 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Shared\String;
@ -222,7 +222,7 @@ class Template
* @param string $blockname
* @param integer $clones
* @param boolean $replace
* @return null
* @return string|null
*/
public function cloneBlock($blockname, $clones = 1, $replace = true)
{
@ -263,7 +263,6 @@ class Template
* Delete a block of text
*
* @param string $blockname
* @param string $replacement
*/
public function deleteBlock($blockname)
{
@ -317,7 +316,7 @@ class Template
*
* @param string $documentPartXML
* @param string $search
* @param mixed $replace
* @param string $replace
* @param integer $limit
* @return string
*/
@ -335,16 +334,10 @@ class Template
$search = '${' . $search . '}';
}
if (!is_array($replace)) {
if (!String::isUTF8($replace)) {
$replace = utf8_encode($replace);
}
$replace = htmlspecialchars($replace);
} else {
foreach ($replace as $key => $value) {
$replace[$key] = htmlspecialchars($value);
}
if (!String::isUTF8($replace)) {
$replace = utf8_encode($replace);
}
$replace = htmlspecialchars($replace);
$regExpDelim = '/';
$escapedSearch = preg_quote($search, $regExpDelim);

View File

@ -9,15 +9,16 @@
namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
/**
* Abstract writer class
*
* @since 0.9.2
*/
abstract class Writer implements IWriter
abstract class AbstractWriter implements WriterInterface
{
/**
* PHPWord object
@ -148,21 +149,21 @@ abstract class Writer implements IWriter
/**
* Get temporary file name
*
* If $pFilename is php://output or php://stdout, make it a temporary file
* If $filename is php://output or php://stdout, make it a temporary file
*
* @param string $pFilename
* @param string $filename
* @return string
*/
protected function getTempFile($pFilename)
protected function getTempFile($filename)
{
$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->originalFilename = $filename;
if (strtolower($filename) == 'php://output' || strtolower($filename) == 'php://stdout') {
$filename = @tempnam(sys_get_temp_dir(), 'phpword_');
if ($filename == '') {
$filename = $this->originalFilename;
}
}
$this->tempFilename = $pFilename;
$this->tempFilename = $filename;
return $this->tempFilename;
}
@ -181,4 +182,37 @@ abstract class Writer implements IWriter
@unlink($this->tempFilename);
}
}
/**
* Get ZipArchive object
*
* @param string $filename
* @return mixed ZipArchive object
*/
protected function getZipArchive($filename)
{
// Create new ZIP file and open it for writing
$zipClass = Settings::getZipClass();
$objZip = new $zipClass();
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
$ro = new \ReflectionObject($objZip);
$zipOverWrite = $ro->getConstant('OVERWRITE');
$zipCreate = $ro->getConstant('CREATE');
// Remove any existing file
if (file_exists($filename)) {
unlink($filename);
}
// Try opening the ZIP file
if ($objZip->open($filename, $zipOverWrite) !== true) {
if ($objZip->open($filename, $zipCreate) !== true) {
throw new Exception("Could not open " . $filename . " for writing.");
}
}
return $objZip;
}
}

View File

@ -9,10 +9,8 @@
namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\HashTable;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\ODText\Content;
use PhpOffice\PhpWord\Writer\ODText\Manifest;
use PhpOffice\PhpWord\Writer\ODText\Meta;
@ -22,17 +20,11 @@ use PhpOffice\PhpWord\Writer\ODText\Styles;
/**
* ODText writer
*/
class ODText extends Writer implements IWriter
class ODText extends AbstractWriter implements WriterInterface
{
/**
* Private unique PHPWord_Worksheet_BaseDrawing HashTable
*
* @var HashTable
*/
private $drawingHashTable;
/**
* Create new ODText writer
*
* @param PhpWord $phpWord
*/
public function __construct(PhpWord $phpWord = null)
@ -49,43 +41,19 @@ class ODText extends Writer implements IWriter
foreach ($this->writerParts as $writer) {
$writer->setParentWriter($this);
}
// Set HashTable variables
$this->drawingHashTable = new HashTable();
}
/**
* Save PhpWord to file
*
* @param string $pFilename
* @param string $filename
* @throws Exception
*/
public function save($pFilename = null)
public function save($filename = null)
{
if (!is_null($this->phpWord)) {
$pFilename = $this->getTempFile($pFilename);
// Create new ZIP file and open it for writing
$zipClass = Settings::getZipClass();
$objZip = new $zipClass();
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP
$ro = new \ReflectionObject($objZip);
$zipOverWrite = $ro->getConstant('OVERWRITE');
$zipCreate = $ro->getConstant('CREATE');
// Remove any existing file
if (file_exists($pFilename)) {
unlink($pFilename);
}
// Try opening the ZIP file
if ($objZip->open($pFilename, $zipOverWrite) !== true) {
if ($objZip->open($pFilename, $zipCreate) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
}
}
$filename = $this->getTempFile($filename);
$objZip = $this->getZipArchive($filename);
// Add mimetype to ZIP file
//@todo Not in \ZipArchive::CM_STORE mode
@ -103,45 +71,9 @@ class ODText extends Writer implements IWriter
// Add META-INF/manifest.xml
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('manifest')->writeManifest($this->phpWord));
// Add media. Has not used yet. Legacy from PHPExcel.
// @codeCoverageIgnoreStart
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_Drawing) {
$imageContents = null;
$imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath();
if (strpos($imagePath, 'zip://') !== false) {
$imagePath = substr($imagePath, 6);
$imagePathSplitted = explode('#', $imagePath);
$zipClass = Settings::getZipClass();
$imageZip = new $zipClass();
$imageZip->open($imagePathSplitted[0]);
$imageContents = $imageZip->getFromName($imagePathSplitted[1]);
$imageZip->close();
unset($imageZip);
} else {
$imageContents = file_get_contents($imagePath);
}
$objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
} elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
ob_start();
call_user_func(
$this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(),
$this->getDrawingHashTable()->getByIndex($i)->getImageResource()
);
$imageContents = ob_get_contents();
ob_end_clean();
$objZip->addFromString('Pictures/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
}
}
// @codeCoverageIgnoreEnd
// Close file
if ($objZip->close() === false) {
throw new Exception("Could not close zip file $pFilename.");
throw new Exception("Could not close zip file $filename.");
}
$this->cleanupTempFile();
@ -149,14 +81,4 @@ class ODText extends Writer implements IWriter
throw new Exception("PhpWord object unassigned.");
}
}
/**
* Get PHPWord_Worksheet_BaseDrawing HashTable
*
* @return HashTable
*/
public function getDrawingHashTable()
{
return $this->drawingHashTable;
}
}

View File

@ -12,6 +12,6 @@ namespace PhpOffice\PhpWord\Writer\ODText;
/**
* ODText writer part abstract
*/
abstract class WriterPart extends \PhpOffice\PhpWord\Writer\Word2007\WriterPart
abstract class AbstractWriterPart extends \PhpOffice\PhpWord\Writer\Word2007\AbstractWriterPart
{
}

View File

@ -0,0 +1,93 @@
<?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\ODText;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* ODT base part writer
*
* @since 0.9.2
*/
class Base extends AbstractWriterPart
{
/**
* Write common root attributes
*/
protected function writeCommonRootAttributes(XMLWriter $xmlWriter)
{
$xmlWriter->writeAttribute('office:version', '1.2');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
}
/**
* Write font faces declaration
*/
protected function writeFontFaces(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
}
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
}

View File

@ -10,17 +10,16 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
use PhpOffice\PhpWord\Section\TextRun;
use PhpOffice\PhpWord\Section\Title;
use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Element\Link;
use PhpOffice\PhpWord\Element\ListItem;
use PhpOffice\PhpWord\Element\Object;
use PhpOffice\PhpWord\Element\PageBreak;
use PhpOffice\PhpWord\Element\Table;
use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextBreak;
use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Element\Title;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
@ -30,7 +29,7 @@ use PhpOffice\PhpWord\TOC;
/**
* ODText content part writer
*/
class Content extends WriterPart
class Content extends Base
{
/**
* Write content file to XML format
@ -40,6 +39,10 @@ class Content extends WriterPart
*/
public function writeContent(PhpWord $phpWord = null)
{
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@ -48,52 +51,26 @@ class Content extends WriterPart
// office:document-content
$xmlWriter->startElement('office:document-content');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$this->writeCommonRootAttributes($xmlWriter);
$xmlWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$xmlWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
$xmlWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$xmlWriter->writeAttribute('office:version', '1.2');
// We firstly search all fonts used
$_sections = $phpWord->getSections();
$countSections = count($_sections);
$sections = $phpWord->getSections();
$countSections = count($sections);
if ($countSections > 0) {
$pSection = 0;
$numPStyles = 0;
$numFStyles = 0;
foreach ($_sections as $section) {
foreach ($sections as $section) {
$pSection++;
$_elements = $section->getElements();
$elements = $section->getElements();
foreach ($_elements as $element) {
foreach ($elements as $element) {
if ($element instanceof Text) {
$fStyle = $element->getFontStyle();
$pStyle = $element->getParagraphStyle();
@ -119,37 +96,9 @@ class Content extends WriterPart
}
// office:font-face-decls
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
}
$xmlWriter->endElement();
$this->writeFontFaces($xmlWriter);
// office:automatic-styles
$xmlWriter->startElement('office:automatic-styles');
$styles = Style::getStyles();
$numPStyles = 0;
@ -232,17 +181,13 @@ class Content extends WriterPart
$xmlWriter->endElement();
$xmlWriter->endElement();
$_sections = $phpWord->getSections();
$countSections = count($_sections);
$pSection = 0;
$sections = $phpWord->getSections();
$countSections = count($sections);
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
foreach ($sections as $section) {
$elements = $section->getElements();
$_elements = $section->getElements();
foreach ($_elements as $element) {
foreach ($elements as $element) {
if ($element instanceof Text) {
$this->writeText($xmlWriter, $element);
} elseif ($element instanceof TextRun) {
@ -269,12 +214,6 @@ class Content extends WriterPart
$this->writeUnsupportedElement($xmlWriter, 'Element');
}
}
if ($pSection == $countSections) {
$this->writeEndSection($xmlWriter, $section);
} else {
$this->writeSection($xmlWriter, $section);
}
}
}
$xmlWriter->endElement();
@ -311,19 +250,21 @@ class Content extends WriterPart
if (empty($styleFont)) {
if (empty($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', 'P1');
} else {
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
} elseif (is_string($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', $styleParagraph);
}
$xmlWriter->writeRaw($text->getText());
} else {
if (empty($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', 'Standard');
} else {
$xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
} elseif (is_string($styleParagraph)) {
$xmlWriter->writeAttribute('text:style-name', $styleParagraph);
}
// text:span
$xmlWriter->startElement('text:span');
$xmlWriter->writeAttribute('text:style-name', $styleFont);
if (is_string($styleFont)) {
$xmlWriter->writeAttribute('text:style-name', $styleFont);
}
$xmlWriter->writeRaw($text->getText());
$xmlWriter->endElement();
}
@ -359,35 +300,13 @@ class Content extends WriterPart
*
* @param XMLWriter $xmlWriter
*/
protected function writeTextBreak(XMLWriter $xmlWriter = null)
protected function writeTextBreak(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('text:p');
$xmlWriter->writeAttribute('text:style-name', 'Standard');
$xmlWriter->endElement();
}
// @codeCoverageIgnoreStart
/**
* Write end section
*
* @param XMLWriter $xmlWriter
* @param Section $section
*/
private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
/**
* Write section
*
* @param XMLWriter $xmlWriter
* @param Section $section
*/
private function writeSection(XMLWriter $xmlWriter = null, Section $section = null)
{
}
// @codeCoverageIgnoreEnd
/**
* Write unsupported element
*

View File

@ -9,14 +9,12 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* ODText manifest part writer
*/
class Manifest extends WriterPart
class Manifest extends AbstractWriterPart
{
/**
* Write Manifest file to XML format
@ -34,8 +32,8 @@ class Manifest extends WriterPart
// manifest:manifest
$xmlWriter->startElement('manifest:manifest');
$xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
$xmlWriter->writeAttribute('manifest:version', '1.2');
$xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0');
// manifest:file-entry
$xmlWriter->startElement('manifest:file-entry');
@ -59,53 +57,9 @@ class Manifest extends WriterPart
$xmlWriter->writeAttribute('manifest:full-path', 'styles.xml');
$xmlWriter->endElement();
// Not used yet. Legacy from PHPExcel
// @codeCoverageIgnoreStart
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());
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
$xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$xmlWriter->endElement();
} elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPWord_Shape_MemoryDrawing) {
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType());
$extension = explode('/', $extension);
$extension = $extension[1];
$mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType();
$xmlWriter->startElement('manifest:file-entry');
$xmlWriter->writeAttribute('manifest:media-type', $mimeType);
$xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . str_replace(' ', '_', $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()));
$xmlWriter->endElement();
}
}
// @codeCoverageIgnoreEnd
$xmlWriter->endElement();
$xmlWriter->endElement(); // manifest:manifest
// Return
return $xmlWriter->getData();
}
/**
* 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");
}
}
}

View File

@ -10,12 +10,11 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* ODText meta part writer
*/
class Meta extends WriterPart
class Meta extends AbstractWriterPart
{
/**
* Write Meta file to XML format
@ -25,6 +24,10 @@ class Meta extends WriterPart
*/
public function writeMeta(PhpWord $phpWord = null)
{
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@ -33,13 +36,13 @@ class Meta extends WriterPart
// office:document-meta
$xmlWriter->startElement('office:document-meta');
$xmlWriter->writeAttribute('office:version', '1.2');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('office:version', '1.2');
// office:meta
$xmlWriter->startElement('office:meta');

View File

@ -14,7 +14,7 @@ use PhpOffice\PhpWord\PhpWord;
/**
* ODText mimetype part writer
*/
class Mimetype extends WriterPart
class Mimetype extends AbstractWriterPart
{
/**
* Write Mimetype to Text format

View File

@ -10,7 +10,6 @@
namespace PhpOffice\PhpWord\Writer\ODText;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
@ -19,7 +18,7 @@ use PhpOffice\PhpWord\Style\Table;
/**
* ODText styloes part writer
*/
class Styles extends WriterPart
class Styles extends Base
{
/**
* Write Styles file to XML format
@ -29,6 +28,10 @@ class Styles extends WriterPart
*/
public function writeStyles(PhpWord $phpWord = null)
{
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
// Create XML writer
$xmlWriter = $this->getXmlWriter();
@ -37,65 +40,10 @@ class Styles extends WriterPart
// Styles:Styles
$xmlWriter->startElement('office:document-styles');
$xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$xmlWriter->writeAttribute('office:version', '1.2');
$this->writeCommonRootAttributes($xmlWriter);
// office:font-face-decls
$xmlWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
}
if (!in_array(PhpWord::DEFAULT_FONT_NAME, $arrFonts)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->writeAttribute('svg:font-family', PhpWord::DEFAULT_FONT_NAME);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
$this->writeFontFaces($xmlWriter);
// office:styles
$xmlWriter->startElement('office:styles');

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