Nessuna descrizione

Font.php 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\Style;
  18. /**
  19. * Font style writer
  20. *
  21. * @since 0.10.0
  22. */
  23. class Font extends AbstractStyle
  24. {
  25. /**
  26. * Write style.
  27. *
  28. * @return void
  29. */
  30. public function write()
  31. {
  32. $style = $this->getStyle();
  33. if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
  34. return;
  35. }
  36. $xmlWriter = $this->getXmlWriter();
  37. $xmlWriter->startElement('style:style');
  38. $xmlWriter->writeAttribute('style:name', $style->getStyleName());
  39. $xmlWriter->writeAttribute('style:family', 'text');
  40. $xmlWriter->startElement('style:text-properties');
  41. // Name
  42. $font = $style->getName();
  43. $xmlWriter->writeAttributeIf($font != '', 'style:font-name', $font);
  44. $xmlWriter->writeAttributeIf($font != '', 'style:font-name-complex', $font);
  45. $size = $style->getSize();
  46. // Size
  47. $xmlWriter->writeAttributeIf(is_numeric($size), 'fo:font-size', $size . 'pt');
  48. $xmlWriter->writeAttributeIf(is_numeric($size), 'style:font-size-asian', $size . 'pt');
  49. $xmlWriter->writeAttributeIf(is_numeric($size), 'style:font-size-complex', $size . 'pt');
  50. // Color
  51. $color = $style->getColor();
  52. $xmlWriter->writeAttributeIf($color != '', 'fo:color', '#' . $color);
  53. // Bold & italic
  54. $xmlWriter->writeAttributeIf($style->isBold(), 'fo:font-weight', 'bold');
  55. $xmlWriter->writeAttributeIf($style->isBold(), 'style:font-weight-asian', 'bold');
  56. $xmlWriter->writeAttributeIf($style->isItalic(), 'fo:font-style', 'italic');
  57. $xmlWriter->writeAttributeIf($style->isItalic(), 'style:font-style-asian', 'italic');
  58. $xmlWriter->writeAttributeIf($style->isItalic(), 'style:font-style-complex', 'italic');
  59. // Underline
  60. // @todo Various mode of underline
  61. $underline = $style->getUnderline();
  62. $xmlWriter->writeAttributeIf($underline != 'none', 'style:text-underline-style', 'solid');
  63. // Strikethrough, double strikethrough
  64. $xmlWriter->writeAttributeIf($style->isStrikethrough(), 'style:text-line-through-type', 'single');
  65. $xmlWriter->writeAttributeIf($style->isDoubleStrikethrough(), 'style:text-line-through-type', 'double');
  66. // Small caps, all caps
  67. $xmlWriter->writeAttributeIf($style->isSmallCaps(), 'fo:font-variant', 'small-caps');
  68. $xmlWriter->writeAttributeIf($style->isAllCaps(), 'fo:text-transform', 'uppercase');
  69. // Superscript/subscript
  70. $xmlWriter->writeAttributeIf($style->isSuperScript(), 'style:text-position', 'super');
  71. $xmlWriter->writeAttributeIf($style->isSubScript(), 'style:text-position', 'sub');
  72. // @todo Foreground-Color
  73. // @todo Background color
  74. $xmlWriter->endElement(); // style:text-properties
  75. $xmlWriter->endElement(); // style:style
  76. }
  77. }