AbstractPart.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @see https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2018 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Writer\ODText\Part;
  18. use PhpOffice\PhpWord\Settings;
  19. use PhpOffice\PhpWord\Shared\XMLWriter;
  20. use PhpOffice\PhpWord\Style;
  21. use PhpOffice\PhpWord\Style\Font;
  22. use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart;
  23. /**
  24. * ODText writer part abstract
  25. */
  26. abstract class AbstractPart extends Word2007AbstractPart
  27. {
  28. /**
  29. * @var string Date format
  30. */
  31. protected $dateFormat = 'Y-m-d\TH:i:s.000';
  32. /**
  33. * Write common root attributes.
  34. *
  35. * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
  36. */
  37. protected function writeCommonRootAttributes(XMLWriter $xmlWriter)
  38. {
  39. $xmlWriter->writeAttribute('office:version', '1.2');
  40. $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
  41. $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
  42. $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
  43. $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
  44. $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
  45. $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
  46. $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  47. $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  48. $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
  49. $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
  50. $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
  51. $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
  52. $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
  53. $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
  54. $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
  55. $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
  56. $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
  57. $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
  58. $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
  59. $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
  60. $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
  61. $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
  62. $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
  63. $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
  64. $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
  65. $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
  66. }
  67. /**
  68. * Write font faces declaration.
  69. *
  70. * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
  71. */
  72. protected function writeFontFaces(XMLWriter $xmlWriter)
  73. {
  74. $xmlWriter->startElement('office:font-face-decls');
  75. $fontTable = array();
  76. $styles = Style::getStyles();
  77. $numFonts = 0;
  78. if (count($styles) > 0) {
  79. foreach ($styles as $style) {
  80. // Font
  81. if ($style instanceof Font) {
  82. $numFonts++;
  83. $name = $style->getName();
  84. if (!in_array($name, $fontTable)) {
  85. $fontTable[] = $name;
  86. // style:font-face
  87. $xmlWriter->startElement('style:font-face');
  88. $xmlWriter->writeAttribute('style:name', $name);
  89. $xmlWriter->writeAttribute('svg:font-family', $name);
  90. $xmlWriter->endElement();
  91. }
  92. }
  93. }
  94. }
  95. if (!in_array(Settings::getDefaultFontName(), $fontTable)) {
  96. $xmlWriter->startElement('style:font-face');
  97. $xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName());
  98. $xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName());
  99. $xmlWriter->endElement();
  100. }
  101. $xmlWriter->endElement();
  102. }
  103. }