2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2017-11-04 22:44:12 +01:00
|
|
|
* @see https://github.com/PHPOffice/PHPWord
|
2018-03-08 23:52:25 +01:00
|
|
|
* @copyright 2010-2018 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
|
2014-04-30 08:54:38 +07:00
|
|
|
namespace PhpOffice\PhpWord\Writer\ODText\Part;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2016-01-23 19:16:34 +04:00
|
|
|
use PhpOffice\Common\XMLWriter;
|
2018-02-09 21:49:11 +01:00
|
|
|
use PhpOffice\PhpWord\Element\AbstractContainer;
|
2014-05-18 21:06:10 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Image;
|
2014-04-25 23:57:43 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Table;
|
2014-05-04 21:03:28 +04:00
|
|
|
use PhpOffice\PhpWord\Element\Text;
|
2014-05-18 11:13:38 +07:00
|
|
|
use PhpOffice\PhpWord\Element\TextRun;
|
2018-02-09 21:49:11 +01:00
|
|
|
use PhpOffice\PhpWord\Element\TrackChange;
|
2014-05-04 21:03:28 +04:00
|
|
|
use PhpOffice\PhpWord\PhpWord;
|
2014-07-03 16:11:15 +04:00
|
|
|
use PhpOffice\PhpWord\Style;
|
2014-03-22 10:06:08 +04:00
|
|
|
use PhpOffice\PhpWord\Style\Font;
|
2014-05-14 19:41:44 +07:00
|
|
|
use PhpOffice\PhpWord\Style\Paragraph;
|
2014-05-18 21:06:10 +07:00
|
|
|
use PhpOffice\PhpWord\Style\Table as TableStyle;
|
2014-05-07 09:47:02 +07:00
|
|
|
use PhpOffice\PhpWord\Writer\ODText\Element\Container;
|
2014-05-18 16:29:56 +07:00
|
|
|
use PhpOffice\PhpWord\Writer\ODText\Style\Paragraph as ParagraphStyleWriter;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
2014-05-06 08:50:55 +07:00
|
|
|
* ODText content part writer: content.xml
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-04-30 08:54:38 +07:00
|
|
|
class Content extends AbstractPart
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-18 21:06:10 +07:00
|
|
|
/**
|
|
|
|
|
* Auto style collection
|
|
|
|
|
*
|
|
|
|
|
* Collect inline style information from section, image, and table elements
|
|
|
|
|
*
|
|
|
|
|
* @todo Merge font and paragraph styles
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
private $autoStyles = array('Section' => array(), 'Image' => array(), 'Table' => array());
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
private $imageParagraphStyles = array();
|
2014-05-18 21:06:10 +07:00
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
/**
|
2014-05-06 08:50:55 +07:00
|
|
|
* Write part
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-05-06 08:50:55 +07:00
|
|
|
* @return string
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-06 08:50:55 +07:00
|
|
|
public function write()
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-03-30 16:31:01 +07:00
|
|
|
$xmlWriter = $this->getXmlWriter();
|
2014-05-18 11:13:38 +07:00
|
|
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
|
|
|
|
|
|
|
|
|
$this->getAutoStyles($phpWord);
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
$xmlWriter->startDocument('1.0', 'UTF-8');
|
|
|
|
|
$xmlWriter->startElement('office:document-content');
|
2014-04-08 03:03:14 +07:00
|
|
|
$this->writeCommonRootAttributes($xmlWriter);
|
2014-03-22 10:06:08 +04:00
|
|
|
$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: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');
|
|
|
|
|
|
2014-05-18 21:06:10 +07:00
|
|
|
// Font declarations and automatic styles
|
2014-04-11 23:02:05 +07:00
|
|
|
$this->writeFontFaces($xmlWriter); // office:font-face-decls
|
2014-05-18 21:06:10 +07:00
|
|
|
$this->writeAutoStyles($xmlWriter); // office:automatic-styles
|
2014-05-18 11:13:38 +07:00
|
|
|
|
|
|
|
|
// Body
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('office:body');
|
|
|
|
|
$xmlWriter->startElement('office:text');
|
2014-04-23 14:09:41 +07:00
|
|
|
|
2018-02-09 21:49:11 +01:00
|
|
|
// Tracked changes declarations
|
|
|
|
|
$trackedChanges = array();
|
|
|
|
|
$sections = $phpWord->getSections();
|
|
|
|
|
foreach ($sections as $section) {
|
|
|
|
|
$this->collectTrackedChanges($section, $trackedChanges);
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->startElement('text:tracked-changes');
|
|
|
|
|
foreach ($trackedChanges as $trackedElement) {
|
|
|
|
|
$trackedChange = $trackedElement->getTrackChange();
|
|
|
|
|
$xmlWriter->startElement('text:changed-region');
|
|
|
|
|
$trackedChange->setElementId();
|
|
|
|
|
$xmlWriter->writeAttribute('text:id', $trackedChange->getElementId());
|
|
|
|
|
|
|
|
|
|
if (($trackedChange->getChangeType() == TrackChange::INSERTED)) {
|
|
|
|
|
$xmlWriter->startElement('text:insertion');
|
|
|
|
|
} elseif ($trackedChange->getChangeType() == TrackChange::DELETED) {
|
|
|
|
|
$xmlWriter->startElement('text:deletion');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$xmlWriter->startElement('office:change-info');
|
|
|
|
|
$xmlWriter->writeElement('dc:creator', $trackedChange->getAuthor());
|
|
|
|
|
if ($trackedChange->getDate() != null) {
|
|
|
|
|
$xmlWriter->writeElement('dc:date', $trackedChange->getDate()->format('Y-m-d\TH:i:s\Z'));
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->endElement(); // office:change-info
|
|
|
|
|
if ($trackedChange->getChangeType() == TrackChange::DELETED) {
|
|
|
|
|
$xmlWriter->writeElement('text:p', $trackedElement->getText());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$xmlWriter->endElement(); // text:insertion|text:deletion
|
|
|
|
|
$xmlWriter->endElement(); // text:changed-region
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->endElement(); // text:tracked-changes
|
|
|
|
|
|
2014-05-18 11:13:38 +07:00
|
|
|
// Sequence declarations
|
2014-05-01 14:37:58 +07:00
|
|
|
$sequences = array('Illustration', 'Table', 'Text', 'Drawing');
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('text:sequence-decls');
|
2014-05-01 14:37:58 +07:00
|
|
|
foreach ($sequences as $sequence) {
|
|
|
|
|
$xmlWriter->startElement('text:sequence-decl');
|
|
|
|
|
$xmlWriter->writeAttribute('text:display-outline-level', 0);
|
|
|
|
|
$xmlWriter->writeAttribute('text:name', $sequence);
|
|
|
|
|
$xmlWriter->endElement();
|
|
|
|
|
}
|
2014-04-23 14:09:41 +07:00
|
|
|
$xmlWriter->endElement(); // text:sequence-decl
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-05-18 11:13:38 +07:00
|
|
|
// Sections
|
2014-04-03 11:34:06 +07:00
|
|
|
$sections = $phpWord->getSections();
|
2014-05-18 11:13:38 +07:00
|
|
|
foreach ($sections as $section) {
|
2014-05-18 16:29:56 +07:00
|
|
|
$name = 'Section' . $section->getSectionId();
|
|
|
|
|
$xmlWriter->startElement('text:section');
|
|
|
|
|
$xmlWriter->writeAttribute('text:name', $name);
|
|
|
|
|
$xmlWriter->writeAttribute('text:style-name', $name);
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$xmlWriter->startElement('text:p');
|
|
|
|
|
$xmlWriter->writeAttribute('text:style-name', 'SB' . $section->getSectionId());
|
|
|
|
|
$xmlWriter->endElement();
|
2014-05-18 11:13:38 +07:00
|
|
|
$containerWriter = new Container($xmlWriter, $section);
|
|
|
|
|
$containerWriter->write();
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->endElement(); // text:section
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
2014-05-18 11:13:38 +07:00
|
|
|
|
2014-04-23 14:09:41 +07:00
|
|
|
$xmlWriter->endElement(); // office:text
|
|
|
|
|
$xmlWriter->endElement(); // office:body
|
2014-05-18 11:13:38 +07:00
|
|
|
|
2014-04-23 14:09:41 +07:00
|
|
|
$xmlWriter->endElement(); // office:document-content
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
return $xmlWriter->getData();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-18 16:29:56 +07:00
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Write automatic styles other than fonts and paragraphs.
|
2014-05-18 16:29:56 +07:00
|
|
|
*
|
|
|
|
|
* @since 0.11.0
|
2014-07-03 15:40:24 +04:00
|
|
|
*
|
2016-01-23 19:16:34 +04:00
|
|
|
* @param \PhpOffice\Common\XMLWriter $xmlWriter
|
2014-05-18 16:29:56 +07:00
|
|
|
*/
|
2014-05-18 21:06:10 +07:00
|
|
|
private function writeAutoStyles(XMLWriter $xmlWriter)
|
2014-05-18 16:29:56 +07:00
|
|
|
{
|
2014-05-18 21:06:10 +07:00
|
|
|
$xmlWriter->startElement('office:automatic-styles');
|
|
|
|
|
|
|
|
|
|
$this->writeTextStyles($xmlWriter);
|
2014-05-24 00:11:06 +07:00
|
|
|
foreach ($this->autoStyles as $element => $styles) {
|
2014-05-18 21:06:10 +07:00
|
|
|
$writerClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . $element;
|
2014-05-24 00:11:06 +07:00
|
|
|
foreach ($styles as $style) {
|
|
|
|
|
/** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */
|
|
|
|
|
$styleWriter = new $writerClass($xmlWriter, $style);
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
}
|
2014-05-18 16:29:56 +07:00
|
|
|
}
|
2014-05-18 21:06:10 +07:00
|
|
|
|
|
|
|
|
$xmlWriter->endElement(); // office:automatic-styles
|
2014-05-18 16:29:56 +07:00
|
|
|
}
|
|
|
|
|
|
2014-04-11 23:02:05 +07:00
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Write automatic styles.
|
|
|
|
|
*
|
2016-01-23 19:16:34 +04:00
|
|
|
* @param \PhpOffice\Common\XMLWriter $xmlWriter
|
2014-04-11 23:02:05 +07:00
|
|
|
*/
|
2014-05-18 16:29:56 +07:00
|
|
|
private function writeTextStyles(XMLWriter $xmlWriter)
|
2014-04-11 23:02:05 +07:00
|
|
|
{
|
|
|
|
|
$styles = Style::getStyles();
|
2014-05-01 14:37:58 +07:00
|
|
|
$paragraphStyleCount = 0;
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
|
|
|
|
|
$style = new Paragraph();
|
|
|
|
|
$style->setStyleName('PB');
|
|
|
|
|
$style->setAuto();
|
|
|
|
|
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
|
|
|
|
|
$sects = $this->getParentWriter()->getPhpWord()->getSections();
|
2020-01-05 13:52:20 -08:00
|
|
|
$countsects = count($sects);
|
|
|
|
|
for ($i = 0; $i < $countsects; ++$i) {
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$iplus1 = $i + 1;
|
|
|
|
|
$style = new Paragraph();
|
|
|
|
|
$style->setStyleName("SB$iplus1");
|
|
|
|
|
$style->setAuto();
|
|
|
|
|
$pnstart = $sects[$i]->getStyle()->getPageNumberingStart();
|
|
|
|
|
$style->setNumLevel($pnstart);
|
|
|
|
|
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($styles as $style) {
|
|
|
|
|
$sty = $style->getStyleName();
|
|
|
|
|
if (substr($sty, 0, 8) === 'Heading_') {
|
2014-04-26 19:06:44 +07:00
|
|
|
$style = new Paragraph();
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$style->setStyleName('HD' . substr($sty, 8));
|
|
|
|
|
$style->setAuto();
|
|
|
|
|
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
$style = new Paragraph();
|
|
|
|
|
$style->setStyleName('HE' . substr($sty, 8));
|
2014-05-18 11:13:38 +07:00
|
|
|
$style->setAuto();
|
2014-05-18 16:29:56 +07:00
|
|
|
$styleWriter = new ParagraphStyleWriter($xmlWriter, $style);
|
2014-04-26 19:06:44 +07:00
|
|
|
$styleWriter->write();
|
2014-04-11 23:02:05 +07:00
|
|
|
}
|
|
|
|
|
}
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
|
|
|
|
|
foreach ($styles as $style) {
|
|
|
|
|
if ($style->isAuto() === true) {
|
|
|
|
|
$styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style));
|
|
|
|
|
if (class_exists($styleClass)) {
|
|
|
|
|
/** @var \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle $styleWriter Type hint */
|
|
|
|
|
$styleWriter = new $styleClass($xmlWriter, $style);
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
}
|
|
|
|
|
if ($style instanceof Paragraph) {
|
|
|
|
|
$paragraphStyleCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ($this->imageParagraphStyles as $style) {
|
|
|
|
|
$styleWriter = new \PhpOffice\PhpWord\Writer\ODText\Style\Paragraph($xmlWriter, $style);
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
}
|
2014-05-18 11:13:38 +07:00
|
|
|
}
|
2014-04-18 23:12:51 +07:00
|
|
|
|
2014-04-23 14:09:41 +07:00
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Get automatic styles.
|
|
|
|
|
*
|
|
|
|
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
2014-04-23 14:09:41 +07:00
|
|
|
*/
|
2014-05-18 11:13:38 +07:00
|
|
|
private function getAutoStyles(PhpWord $phpWord)
|
2014-04-23 14:09:41 +07:00
|
|
|
{
|
|
|
|
|
$sections = $phpWord->getSections();
|
2014-05-18 11:13:38 +07:00
|
|
|
$paragraphStyleCount = 0;
|
|
|
|
|
$fontStyleCount = 0;
|
|
|
|
|
foreach ($sections as $section) {
|
2014-06-08 16:44:46 +07:00
|
|
|
$style = $section->getStyle();
|
2014-05-18 21:06:10 +07:00
|
|
|
$style->setStyleName("Section{$section->getSectionId()}");
|
|
|
|
|
$this->autoStyles['Section'][] = $style;
|
2014-05-18 11:13:38 +07:00
|
|
|
$this->getContainerStyle($section, $paragraphStyleCount, $fontStyleCount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all styles of each elements in container recursively
|
|
|
|
|
*
|
2014-05-18 21:06:10 +07:00
|
|
|
* Table style can be null or string of the style name
|
|
|
|
|
*
|
2014-05-18 11:13:38 +07:00
|
|
|
* @param \PhpOffice\PhpWord\Element\AbstractContainer $container
|
2018-03-06 22:19:40 +01:00
|
|
|
* @param int $paragraphStyleCount
|
|
|
|
|
* @param int $fontStyleCount
|
2014-05-18 21:06:10 +07:00
|
|
|
* @todo Simplify the logic
|
2014-05-18 11:13:38 +07:00
|
|
|
*/
|
|
|
|
|
private function getContainerStyle($container, &$paragraphStyleCount, &$fontStyleCount)
|
|
|
|
|
{
|
|
|
|
|
$elements = $container->getElements();
|
|
|
|
|
foreach ($elements as $element) {
|
|
|
|
|
if ($element instanceof TextRun) {
|
2020-01-05 15:05:00 -08:00
|
|
|
$this->getElementStyleTextRun($element, $paragraphStyleCount);
|
2014-05-18 11:13:38 +07:00
|
|
|
$this->getContainerStyle($element, $paragraphStyleCount, $fontStyleCount);
|
|
|
|
|
} elseif ($element instanceof Text) {
|
|
|
|
|
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
|
2014-05-18 21:06:10 +07:00
|
|
|
} elseif ($element instanceof Image) {
|
|
|
|
|
$style = $element->getStyle();
|
|
|
|
|
$style->setStyleName('fr' . $element->getMediaIndex());
|
|
|
|
|
$this->autoStyles['Image'][] = $style;
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$sty = new \PhpOffice\PhpWord\Style\Paragraph();
|
|
|
|
|
$sty->setStyleName('IM' . $element->getMediaIndex());
|
|
|
|
|
$sty->setAuto();
|
|
|
|
|
$sty->setAlignment($style->getAlignment());
|
|
|
|
|
$this->imageParagraphStyles[] = $sty;
|
2014-05-18 21:06:10 +07:00
|
|
|
} elseif ($element instanceof Table) {
|
2018-06-03 00:22:08 +02:00
|
|
|
/** @var \PhpOffice\PhpWord\Style\Table $style */
|
2014-05-18 21:06:10 +07:00
|
|
|
$style = $element->getStyle();
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
if (is_string($style)) {
|
|
|
|
|
$style = Style::getStyle($style);
|
|
|
|
|
}
|
2014-05-18 21:06:10 +07:00
|
|
|
if ($style === null) {
|
|
|
|
|
$style = new TableStyle();
|
|
|
|
|
}
|
|
|
|
|
$style->setStyleName($element->getElementId());
|
2018-04-18 22:34:53 +02:00
|
|
|
$style->setColumnWidths($element->findFirstDefinedCellWidths());
|
2014-05-18 21:06:10 +07:00
|
|
|
$this->autoStyles['Table'][] = $style;
|
2014-04-23 14:09:41 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-18 11:13:38 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get style of individual element
|
|
|
|
|
*
|
2020-01-05 15:05:00 -08:00
|
|
|
* @param \PhpOffice\PhpWord\Element\Text $element
|
2018-03-06 22:19:40 +01:00
|
|
|
* @param int $paragraphStyleCount
|
|
|
|
|
* @param int $fontStyleCount
|
2014-05-18 11:13:38 +07:00
|
|
|
*/
|
|
|
|
|
private function getElementStyle(&$element, &$paragraphStyleCount, &$fontStyleCount)
|
|
|
|
|
{
|
|
|
|
|
$fontStyle = $element->getFontStyle();
|
|
|
|
|
$paragraphStyle = $element->getParagraphStyle();
|
|
|
|
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
|
|
|
|
|
|
|
|
|
if ($fontStyle instanceof Font) {
|
2017-11-04 22:44:12 +01:00
|
|
|
// Font
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$name = $fontStyle->getStyleName();
|
|
|
|
|
if (!$name) {
|
|
|
|
|
$fontStyleCount++;
|
|
|
|
|
$style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle, null);
|
|
|
|
|
$style->setAuto();
|
|
|
|
|
$style->setParagraph(null);
|
|
|
|
|
$element->setFontStyle("T{$fontStyleCount}");
|
|
|
|
|
} else {
|
|
|
|
|
$element->setFontStyle($name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($paragraphStyle instanceof Paragraph) {
|
2017-11-04 22:44:12 +01:00
|
|
|
// Paragraph
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$name = $paragraphStyle->getStyleName();
|
|
|
|
|
if (!$name) {
|
|
|
|
|
$paragraphStyleCount++;
|
|
|
|
|
$style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", $paragraphStyle);
|
|
|
|
|
$style->setAuto();
|
|
|
|
|
$element->setParagraphStyle("P{$paragraphStyleCount}");
|
|
|
|
|
} else {
|
|
|
|
|
$element->setParagraphStyle($name);
|
2020-01-05 15:05:00 -08:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$paragraphStyleCount++;
|
|
|
|
|
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
|
|
|
|
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
|
|
|
|
$style->setAuto();
|
|
|
|
|
$element->setParagraphStyle($parstylename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get style of individual element
|
|
|
|
|
*
|
|
|
|
|
* @param \PhpOffice\PhpWord\Element\TextRun $element
|
|
|
|
|
* @param int $paragraphStyleCount
|
|
|
|
|
*/
|
|
|
|
|
private function getElementStyleTextRun(&$element, &$paragraphStyleCount)
|
|
|
|
|
{
|
|
|
|
|
$paragraphStyle = $element->getParagraphStyle();
|
|
|
|
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
|
|
|
|
|
|
|
|
|
if ($paragraphStyle instanceof Paragraph) {
|
|
|
|
|
// Paragraph
|
|
|
|
|
$name = $paragraphStyle->getStyleName();
|
|
|
|
|
if (!$name) {
|
|
|
|
|
$paragraphStyleCount++;
|
|
|
|
|
$style = $phpWord->addParagraphStyle("P{$paragraphStyleCount}", $paragraphStyle);
|
|
|
|
|
$style->setAuto();
|
|
|
|
|
$element->setParagraphStyle("P{$paragraphStyleCount}");
|
|
|
|
|
} else {
|
|
|
|
|
$element->setParagraphStyle($name);
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
}
|
2020-01-05 13:52:20 -08:00
|
|
|
} else {
|
2014-05-18 11:13:38 +07:00
|
|
|
$paragraphStyleCount++;
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
|
|
|
|
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
2014-05-18 11:13:38 +07:00
|
|
|
$style->setAuto();
|
ODT Changes
Implement a number of features implemented in PhpWord,
but not yet supported in PhpWord ODT Writer.
1. Add default file to tests/PhpWord/_includes/XmlDocument.php to make it
considerably easier to test ODT changes (and Word2007 changes involving
files other that document.xml).
2. Page break before each section.
3. Page numbering start.
4. Font style for Headings.
5. Alignment for images.
6. Paragraph style for TextRun.
7. "Hide grammatical errors" for whole document.
8. Page layout for each section.
9. For each page layout, support user-specified page width, page height,
orientation, margin top, margin bottom, margin left, margin right.
10. Page header and footer.
11. Named colors.
12. NoProof font style.
13. Paragraph Style - spaceBefore, spaceAfter, lineHeight, pageBreakBefore,
indentation, text alignment.
14. Tab stops.
15. Basic support for some Fields (DATE, PAGE, NUMPAGES).
16. Link had an error in how it was handling internal links (needs leading #).
17. In addition to tests for all the above, added some tests for Tables.
Item 11 above needs 1 module from Pull Request 1775, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Item 15 above needs 1 module from Pull Request 1774, which is targeted
for v0.18.0 but not yet merged, so the relevant module is also here.
Testing change from Pull Request 1771 is included here, but was
merged after my fork.
2020-01-05 10:27:45 -08:00
|
|
|
$element->setParagraphStyle($parstylename);
|
2014-05-18 11:13:38 +07:00
|
|
|
}
|
|
|
|
|
}
|
2018-02-09 21:49:11 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Finds all tracked changes
|
|
|
|
|
*
|
|
|
|
|
* @param AbstractContainer $container
|
|
|
|
|
* @param \PhpOffice\PhpWord\Element\AbstractElement[] $trackedChanges
|
|
|
|
|
*/
|
|
|
|
|
private function collectTrackedChanges(AbstractContainer $container, &$trackedChanges = array())
|
|
|
|
|
{
|
|
|
|
|
$elements = $container->getElements();
|
|
|
|
|
foreach ($elements as $element) {
|
|
|
|
|
if ($element->getTrackChange() != null) {
|
|
|
|
|
$trackedChanges[] = $element;
|
|
|
|
|
}
|
|
|
|
|
if (is_callable(array($element, 'getElements'))) {
|
|
|
|
|
$this->collectTrackedChanges($element, $trackedChanges);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-23 17:37:26 +07:00
|
|
|
}
|