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
|
|
|
|
2021-01-02 08:26:46 +01:00
|
|
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
2014-05-18 16:29:56 +07:00
|
|
|
use PhpOffice\PhpWord\Settings;
|
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
|
|
|
use PhpOffice\PhpWord\Shared\Converter;
|
2014-05-18 16:29:56 +07:00
|
|
|
use PhpOffice\PhpWord\Style;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
2014-05-18 16:29:56 +07:00
|
|
|
* ODText styles part writer: styles.xml
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-04-30 08:54:38 +07:00
|
|
|
class Styles extends AbstractPart
|
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-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
// XML header
|
|
|
|
|
$xmlWriter->startDocument('1.0', 'UTF-8');
|
|
|
|
|
$xmlWriter->startElement('office:document-styles');
|
2014-04-08 03:03:14 +07:00
|
|
|
$this->writeCommonRootAttributes($xmlWriter);
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-05-18 11:13:38 +07:00
|
|
|
// Font declarations
|
2014-04-08 03:03:14 +07:00
|
|
|
$this->writeFontFaces($xmlWriter);
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-05-18 11:13:38 +07:00
|
|
|
// Office styles
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('office:styles');
|
2014-05-18 16:29:56 +07:00
|
|
|
$this->writeDefault($xmlWriter);
|
|
|
|
|
$this->writeNamed($xmlWriter);
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->endElement();
|
|
|
|
|
|
2014-05-18 11:13:38 +07:00
|
|
|
// Automatic styles
|
2014-03-22 10:06:08 +04:00
|
|
|
$xmlWriter->startElement('office:automatic-styles');
|
2014-05-18 16:29:56 +07:00
|
|
|
$this->writePageLayout($xmlWriter);
|
2017-11-16 23:09:56 +01:00
|
|
|
$xmlWriter->endElement(); // office:automatic-styles
|
|
|
|
|
|
|
|
|
|
// Master style
|
2017-05-18 16:25:05 +02:00
|
|
|
$this->writeMaster($xmlWriter);
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-05-18 11:13:38 +07:00
|
|
|
$xmlWriter->endElement(); // office:document-styles
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
return $xmlWriter->getData();
|
|
|
|
|
}
|
2014-05-18 11:13:38 +07:00
|
|
|
|
|
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Write default styles.
|
|
|
|
|
*
|
2021-01-02 08:26:46 +01:00
|
|
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
2014-05-18 16:29:56 +07:00
|
|
|
*/
|
|
|
|
|
private function writeDefault(XMLWriter $xmlWriter)
|
|
|
|
|
{
|
|
|
|
|
$xmlWriter->startElement('style:default-style');
|
|
|
|
|
$xmlWriter->writeAttribute('style:family', 'paragraph');
|
|
|
|
|
|
|
|
|
|
// Paragraph
|
|
|
|
|
$xmlWriter->startElement('style:paragraph-properties');
|
|
|
|
|
$xmlWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
|
|
|
|
|
$xmlWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
|
|
|
|
|
$xmlWriter->writeAttribute('style:punctuation-wrap', 'hanging');
|
|
|
|
|
$xmlWriter->writeAttribute('style:line-break', 'strict');
|
|
|
|
|
$xmlWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
|
|
|
|
|
$xmlWriter->writeAttribute('style:writing-mode', 'page');
|
|
|
|
|
$xmlWriter->endElement(); // style:paragraph-properties
|
|
|
|
|
|
2017-09-27 00:40:08 +02:00
|
|
|
$language = $this->getParentWriter()->getPhpWord()->getSettings()->getThemeFontLang();
|
|
|
|
|
$latinLang = $language != null && is_string($language->getLatin()) ? explode('-', $language->getLatin()) : array('fr', 'FR');
|
|
|
|
|
$asianLang = $language != null && is_string($language->getEastAsia()) ? explode('-', $language->getEastAsia()) : array('zh', 'CN');
|
|
|
|
|
$complexLang = $language != null && is_string($language->getBidirectional()) ? explode('-', $language->getBidirectional()) : array('hi', 'IN');
|
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 ($this->getParentWriter()->getPhpWord()->getSettings()->hasHideGrammaticalErrors()) {
|
|
|
|
|
$latinLang = $asianLang = $complexLang = array('zxx', 'none');
|
|
|
|
|
}
|
2017-09-27 00:40:08 +02:00
|
|
|
|
2014-05-18 16:29:56 +07:00
|
|
|
// Font
|
|
|
|
|
$xmlWriter->startElement('style:text-properties');
|
|
|
|
|
$xmlWriter->writeAttribute('style:use-window-font-color', 'true');
|
|
|
|
|
$xmlWriter->writeAttribute('style:font-name', Settings::getDefaultFontName());
|
|
|
|
|
$xmlWriter->writeAttribute('fo:font-size', Settings::getDefaultFontSize() . 'pt');
|
2017-09-27 00:40:08 +02:00
|
|
|
$xmlWriter->writeAttribute('fo:language', $latinLang[0]);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:country', $latinLang[1]);
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->writeAttribute('style:letter-kerning', 'true');
|
|
|
|
|
$xmlWriter->writeAttribute('style:font-name-asian', Settings::getDefaultFontName() . '2');
|
|
|
|
|
$xmlWriter->writeAttribute('style:font-size-asian', Settings::getDefaultFontSize() . 'pt');
|
2017-09-27 00:40:08 +02:00
|
|
|
$xmlWriter->writeAttribute('style:language-asian', $asianLang[0]);
|
|
|
|
|
$xmlWriter->writeAttribute('style:country-asian', $asianLang[1]);
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->writeAttribute('style:font-name-complex', Settings::getDefaultFontName() . '2');
|
|
|
|
|
$xmlWriter->writeAttribute('style:font-size-complex', Settings::getDefaultFontSize() . 'pt');
|
2017-09-27 00:40:08 +02:00
|
|
|
$xmlWriter->writeAttribute('style:language-complex', $complexLang[0]);
|
|
|
|
|
$xmlWriter->writeAttribute('style:country-complex', $complexLang[1]);
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->writeAttribute('fo:hyphenate', 'false');
|
|
|
|
|
$xmlWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
|
|
|
|
|
$xmlWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
|
|
|
|
|
$xmlWriter->endElement(); // style:text-properties
|
|
|
|
|
|
|
|
|
|
$xmlWriter->endElement(); // style:default-style
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Write named styles.
|
|
|
|
|
*
|
2021-01-02 08:26:46 +01:00
|
|
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
2014-05-18 16:29:56 +07:00
|
|
|
*/
|
|
|
|
|
private function writeNamed(XMLWriter $xmlWriter)
|
|
|
|
|
{
|
|
|
|
|
$styles = Style::getStyles();
|
|
|
|
|
if (count($styles) > 0) {
|
|
|
|
|
foreach ($styles as $style) {
|
|
|
|
|
if ($style->isAuto() === false) {
|
|
|
|
|
$styleClass = str_replace('\\Style\\', '\\Writer\\ODText\\Style\\', get_class($style));
|
|
|
|
|
if (class_exists($styleClass)) {
|
|
|
|
|
/** @var $styleWriter \PhpOffice\PhpWord\Writer\ODText\Style\AbstractStyle Type hint */
|
|
|
|
|
$styleWriter = new $styleClass($xmlWriter, $style);
|
|
|
|
|
$styleWriter->write();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-04 22:44:12 +01: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
|
|
|
/**
|
|
|
|
|
* Convert int in twips to inches/cm then to string and append unit
|
|
|
|
|
*
|
2020-01-05 13:52:20 -08:00
|
|
|
* @param int|float $twips
|
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
|
|
|
* @param float $factor
|
|
|
|
|
* return string
|
|
|
|
|
*/
|
2020-01-05 13:52:20 -08:00
|
|
|
private static function cvttwiptostr($twips, $factor = 1.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
|
|
|
{
|
|
|
|
|
$ins = (string) ($twips * $factor / Converter::INCH_TO_TWIP) . 'in';
|
|
|
|
|
$cms = (string) ($twips * $factor * Converter::INCH_TO_CM / Converter::INCH_TO_TWIP) . 'cm';
|
|
|
|
|
|
|
|
|
|
return (strlen($ins) < strlen($cms)) ? $ins : $cms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* call writePageLayoutIndiv to write page layout styles for each page
|
|
|
|
|
*
|
2021-01-02 08:26:46 +01:00
|
|
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
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
|
|
|
private function writePageLayout(XMLWriter $xmlWriter)
|
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
|
|
|
{
|
|
|
|
|
$sections = $this->getParentWriter()->getPhpWord()->getSections();
|
2020-01-05 13:52:20 -08:00
|
|
|
$countsects = count($sections);
|
|
|
|
|
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
|
|
|
$this->writePageLayoutIndiv($xmlWriter, $sections[$i], $i + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-18 16:29:56 +07:00
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Write page layout styles.
|
|
|
|
|
*
|
2021-01-02 08:26:46 +01:00
|
|
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
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
|
|
|
* @param \PhpOffice\PhpWord\Element\Section $section
|
|
|
|
|
* @param int $sectionNbr
|
2014-05-18 16:29:56 +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
|
|
|
private function writePageLayoutIndiv(XMLWriter $xmlWriter, $section, $sectionNbr)
|
2014-05-18 16:29:56 +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
|
|
|
$sty = $section->getStyle();
|
|
|
|
|
if (count($section->getHeaders()) > 0) {
|
|
|
|
|
$topfactor = 0.5;
|
|
|
|
|
} else {
|
|
|
|
|
$topfactor = 1.0;
|
|
|
|
|
}
|
|
|
|
|
if (count($section->getFooters()) > 0) {
|
|
|
|
|
$botfactor = 0.5;
|
|
|
|
|
} else {
|
|
|
|
|
$botfactor = 1.0;
|
|
|
|
|
}
|
2020-01-05 13:52:20 -08:00
|
|
|
$orient = $sty->getOrientation();
|
|
|
|
|
$pwidth = self::cvttwiptostr($sty->getPageSizeW());
|
|
|
|
|
$pheight = self::cvttwiptostr($sty->getPageSizeH());
|
|
|
|
|
$mtop = self::cvttwiptostr($sty->getMarginTop(), $topfactor);
|
|
|
|
|
$mbottom = self::cvttwiptostr($sty->getMarginBottom(), $botfactor);
|
|
|
|
|
$mleft = self::cvttwiptostr($sty->getMarginRight());
|
|
|
|
|
$mright = self::cvttwiptostr($sty->getMarginLeft());
|
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
|
|
|
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->startElement('style:page-layout');
|
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->writeAttribute('style:name', "Mpm$sectionNbr");
|
2014-05-18 16:29:56 +07:00
|
|
|
|
|
|
|
|
$xmlWriter->startElement('style:page-layout-properties');
|
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->writeAttribute('fo:page-width', $pwidth);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:page-height', $pheight);
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->writeAttribute('style:num-format', '1');
|
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->writeAttribute('style:print-orientation', $orient);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:margin-top', $mtop);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:margin-bottom', $mbottom);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:margin-left', $mleft);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:margin-right', $mright);
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->writeAttribute('style:writing-mode', 'lr-tb');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-lines', '25199');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-base-height', '0.423cm');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-ruby-height', '0cm');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-mode', 'none');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-ruby-below', 'false');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-print', 'false');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-display', 'false');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-base-width', '0.37cm');
|
|
|
|
|
$xmlWriter->writeAttribute('style:layout-grid-snap-to', 'true');
|
|
|
|
|
$xmlWriter->writeAttribute('style:footnote-max-height', '0cm');
|
|
|
|
|
|
|
|
|
|
$xmlWriter->startElement('style:footnote-sep');
|
|
|
|
|
$xmlWriter->writeAttribute('style:width', '0.018cm');
|
|
|
|
|
$xmlWriter->writeAttribute('style:line-style', 'solid');
|
|
|
|
|
$xmlWriter->writeAttribute('style:adjustment', 'left');
|
|
|
|
|
$xmlWriter->writeAttribute('style:rel-width', '25%');
|
|
|
|
|
$xmlWriter->writeAttribute('style:color', '#000000');
|
|
|
|
|
$xmlWriter->endElement(); //style:footnote-sep
|
|
|
|
|
|
|
|
|
|
$xmlWriter->endElement(); // style:page-layout-properties
|
|
|
|
|
|
|
|
|
|
$xmlWriter->startElement('style:header-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
|
|
|
if ($topfactor < 1.0) {
|
|
|
|
|
$xmlWriter->startElement('style:header-footer-properties');
|
|
|
|
|
$xmlWriter->writeAttribute('fo:min-height', $mtop);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:margin-bottom', $mtop);
|
|
|
|
|
$xmlWriter->writeAttribute('style:dynamic-spacing', 'true');
|
|
|
|
|
$xmlWriter->endElement(); // style:header-footer-properties
|
|
|
|
|
}
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->endElement(); // style:header-style
|
|
|
|
|
|
|
|
|
|
$xmlWriter->startElement('style:footer-style');
|
2020-01-05 13:52:20 -08:00
|
|
|
if ($botfactor < 1.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
|
|
|
$xmlWriter->startElement('style:header-footer-properties');
|
|
|
|
|
$xmlWriter->writeAttribute('fo:min-height', $mbottom);
|
|
|
|
|
$xmlWriter->writeAttribute('fo:margin-top', $mbottom);
|
|
|
|
|
$xmlWriter->writeAttribute('style:dynamic-spacing', 'true');
|
|
|
|
|
$xmlWriter->endElement(); // style:header-footer-properties
|
|
|
|
|
}
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->endElement(); // style:footer-style
|
|
|
|
|
|
|
|
|
|
$xmlWriter->endElement(); // style:page-layout
|
|
|
|
|
}
|
2014-07-03 15:40:24 +04:00
|
|
|
|
2014-05-18 16:29:56 +07:00
|
|
|
/**
|
2014-07-03 15:40:24 +04:00
|
|
|
* Write master style.
|
|
|
|
|
*
|
2021-01-02 08:26:46 +01:00
|
|
|
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
|
2014-05-18 11:13:38 +07:00
|
|
|
*/
|
2014-05-18 16:29:56 +07:00
|
|
|
private function writeMaster(XMLWriter $xmlWriter)
|
2014-05-18 11:13:38 +07:00
|
|
|
{
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->startElement('office:master-styles');
|
|
|
|
|
|
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
|
|
|
$sections = $this->getParentWriter()->getPhpWord()->getSections();
|
2020-01-05 13:52:20 -08:00
|
|
|
$countsects = count($sections);
|
|
|
|
|
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;
|
|
|
|
|
$xmlWriter->startElement('style:master-page');
|
|
|
|
|
$xmlWriter->writeAttribute('style:name', "Standard$iplus1");
|
|
|
|
|
$xmlWriter->writeAttribute('style:page-layout-name', "Mpm$iplus1");
|
|
|
|
|
// Multiple headers and footers probably not supported,
|
|
|
|
|
// and, even if they are, I'm not sure how,
|
|
|
|
|
// so quit after generating one.
|
|
|
|
|
foreach ($sections[$i]->getHeaders() as $hdr) {
|
|
|
|
|
$xmlWriter->startElement('style:header');
|
|
|
|
|
foreach ($hdr->getElements() as $elem) {
|
|
|
|
|
$cl1 = get_class($elem);
|
|
|
|
|
$cl2 = str_replace('\\Element\\', '\\Writer\\ODText\\Element\\', $cl1);
|
|
|
|
|
if (class_exists($cl2)) {
|
|
|
|
|
$wtr = new $cl2($xmlWriter, $elem);
|
|
|
|
|
$wtr->write();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->endElement(); // style:header
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
foreach ($sections[$i]->getFooters() as $hdr) {
|
|
|
|
|
$xmlWriter->startElement('style:footer');
|
|
|
|
|
foreach ($hdr->getElements() as $elem) {
|
|
|
|
|
$cl1 = get_class($elem);
|
|
|
|
|
$cl2 = str_replace('\\Element\\', '\\Writer\\ODText\\Element\\', $cl1);
|
|
|
|
|
if (class_exists($cl2)) {
|
|
|
|
|
$wtr = new $cl2($xmlWriter, $elem);
|
|
|
|
|
$wtr->write();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->endElement(); // style:footer
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$xmlWriter->endElement(); // style:master-page
|
|
|
|
|
}
|
2014-05-18 16:29:56 +07:00
|
|
|
$xmlWriter->endElement(); // office:master-styles
|
2014-05-18 11:13:38 +07:00
|
|
|
}
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|