Brak opisu

Font.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\RTF\Style;
  18. use PhpOffice\PhpWord\Style\Font as FontStyle;
  19. /**
  20. * RTF font style writer
  21. *
  22. * @since 0.11.0
  23. */
  24. class Font extends AbstractStyle
  25. {
  26. /**
  27. * @var int Font name index
  28. */
  29. private $nameIndex = 0;
  30. /**
  31. * @var int Font color index
  32. */
  33. private $colorIndex = 0;
  34. /**
  35. * Write style
  36. *
  37. * @return string
  38. */
  39. public function write()
  40. {
  41. $style = $this->getStyle();
  42. if (!$style instanceof FontStyle) {
  43. return '';
  44. }
  45. $content = '';
  46. $content .= '\cf' . $this->colorIndex;
  47. $content .= '\f' . $this->nameIndex;
  48. $size = $style->getSize();
  49. $content .= $this->getValueIf(is_numeric($size), '\fs' . ($size * 2));
  50. $content .= $this->getValueIf($style->isBold(), '\b');
  51. $content .= $this->getValueIf($style->isItalic(), '\i');
  52. $content .= $this->getValueIf($style->getUnderline() != FontStyle::UNDERLINE_NONE, '\ul');
  53. $content .= $this->getValueIf($style->isStrikethrough(), '\strike');
  54. $content .= $this->getValueIf($style->isSuperScript(), '\super');
  55. $content .= $this->getValueIf($style->isSubScript(), '\sub');
  56. return $content . ' ';
  57. }
  58. /**
  59. * Set font name index.
  60. *
  61. *
  62. * @param int $value
  63. * @return void
  64. */
  65. public function setNameIndex($value = 0)
  66. {
  67. $this->nameIndex = $value;
  68. }
  69. /**
  70. * Set font color index.
  71. *
  72. * @param int $value
  73. * @return void
  74. */
  75. public function setColorIndex($value = 0)
  76. {
  77. $this->colorIndex = $value;
  78. }
  79. }