94 lines
4.4 KiB
PHP
94 lines
4.4 KiB
PHP
<?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.10.0
|
|
*/
|
|
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();
|
|
}
|
|
}
|