For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.4 KiB

  1. <?php
  2. /**
  3. * PHPExcel_Writer_Excel5_Font
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Writer_Excel5
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Writer_Excel5_Font
  28. {
  29. /**
  30. * Color index
  31. *
  32. * @var int
  33. */
  34. private $colorIndex;
  35. /**
  36. * Font
  37. *
  38. * @var PHPExcel_Style_Font
  39. */
  40. private $font;
  41. /**
  42. * Constructor
  43. *
  44. * @param PHPExcel_Style_Font $font
  45. */
  46. public function __construct(PHPExcel_Style_Font $font = null)
  47. {
  48. $this->colorIndex = 0x7FFF;
  49. $this->font = $font;
  50. }
  51. /**
  52. * Set the color index
  53. *
  54. * @param int $colorIndex
  55. */
  56. public function setColorIndex($colorIndex)
  57. {
  58. $this->colorIndex = $colorIndex;
  59. }
  60. /**
  61. * Get font record data
  62. *
  63. * @return string
  64. */
  65. public function writeFont()
  66. {
  67. $font_outline = 0;
  68. $font_shadow = 0;
  69. $icv = $this->colorIndex; // Index to color palette
  70. if ($this->font->getSuperScript()) {
  71. $sss = 1;
  72. } elseif ($this->font->getSubScript()) {
  73. $sss = 2;
  74. } else {
  75. $sss = 0;
  76. }
  77. $bFamily = 0; // Font family
  78. $bCharSet = PHPExcel_Shared_Font::getCharsetFromFontName($this->font->getName()); // Character set
  79. $record = 0x31; // Record identifier
  80. $reserved = 0x00; // Reserved
  81. $grbit = 0x00; // Font attributes
  82. if ($this->font->getItalic()) {
  83. $grbit |= 0x02;
  84. }
  85. if ($this->font->getStrikethrough()) {
  86. $grbit |= 0x08;
  87. }
  88. if ($font_outline) {
  89. $grbit |= 0x10;
  90. }
  91. if ($font_shadow) {
  92. $grbit |= 0x20;
  93. }
  94. $data = pack(
  95. "vvvvvCCCC",
  96. // Fontsize (in twips)
  97. $this->font->getSize() * 20,
  98. $grbit,
  99. // Colour
  100. $icv,
  101. // Font weight
  102. self::mapBold($this->font->getBold()),
  103. // Superscript/Subscript
  104. $sss,
  105. self::mapUnderline($this->font->getUnderline()),
  106. $bFamily,
  107. $bCharSet,
  108. $reserved
  109. );
  110. $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($this->font->getName());
  111. $length = strlen($data);
  112. $header = pack("vv", $record, $length);
  113. return($header . $data);
  114. }
  115. /**
  116. * Map to BIFF5-BIFF8 codes for bold
  117. *
  118. * @param boolean $bold
  119. * @return int
  120. */
  121. private static function mapBold($bold)
  122. {
  123. if ($bold) {
  124. return 0x2BC; // 700 = Bold font weight
  125. }
  126. return 0x190; // 400 = Normal font weight
  127. }
  128. /**
  129. * Map of BIFF2-BIFF8 codes for underline styles
  130. * @static array of int
  131. *
  132. */
  133. private static $mapUnderline = array(
  134. PHPExcel_Style_Font::UNDERLINE_NONE => 0x00,
  135. PHPExcel_Style_Font::UNDERLINE_SINGLE => 0x01,
  136. PHPExcel_Style_Font::UNDERLINE_DOUBLE => 0x02,
  137. PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING => 0x21,
  138. PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING => 0x22,
  139. );
  140. /**
  141. * Map underline
  142. *
  143. * @param string
  144. * @return int
  145. */
  146. private static function mapUnderline($underline)
  147. {
  148. if (isset(self::$mapUnderline[$underline])) {
  149. return self::$mapUnderline[$underline];
  150. }
  151. return 0x00;
  152. }
  153. }