No Description

AbstractPart.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 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. * @return void
  37. */
  38. protected function writeCommonRootAttributes(XMLWriter $xmlWriter)
  39. {
  40. $xmlWriter->writeAttribute('office:version', '1.2');
  41. $xmlWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
  42. $xmlWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
  43. $xmlWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
  44. $xmlWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
  45. $xmlWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
  46. $xmlWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
  47. $xmlWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  48. $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  49. $xmlWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
  50. $xmlWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
  51. $xmlWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
  52. $xmlWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
  53. $xmlWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
  54. $xmlWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
  55. $xmlWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
  56. $xmlWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
  57. $xmlWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
  58. $xmlWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
  59. $xmlWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
  60. $xmlWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
  61. $xmlWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
  62. $xmlWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
  63. $xmlWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
  64. $xmlWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
  65. $xmlWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
  66. $xmlWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
  67. }
  68. /**
  69. * Write font faces declaration.
  70. *
  71. * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
  72. * @return void
  73. */
  74. protected function writeFontFaces(XMLWriter $xmlWriter)
  75. {
  76. $xmlWriter->startElement('office:font-face-decls');
  77. $fontTable = array();
  78. $styles = Style::getStyles();
  79. $numFonts = 0;
  80. if (count($styles) > 0) {
  81. foreach ($styles as $style) {
  82. // Font
  83. if ($style instanceof Font) {
  84. $numFonts++;
  85. $name = $style->getName();
  86. if (!in_array($name, $fontTable)) {
  87. $fontTable[] = $name;
  88. // style:font-face
  89. $xmlWriter->startElement('style:font-face');
  90. $xmlWriter->writeAttribute('style:name', $name);
  91. $xmlWriter->writeAttribute('svg:font-family', $name);
  92. $xmlWriter->endElement();
  93. }
  94. }
  95. }
  96. }
  97. if (!in_array(Settings::getDefaultFontName(), $fontTable)) {
  98. $xmlWriter->startElement('style:font-face');
  99. $xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName());
  100. $xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName());
  101. $xmlWriter->endElement();
  102. }
  103. $xmlWriter->endElement();
  104. }
  105. }