[1] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * PHPExcel |
---|
| 4 | * |
---|
| 5 | * Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
---|
| 24 | * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
---|
| 25 | * @version 1.8.0, 2014-03-02 |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * PHPExcel_Writer_Excel5_Font |
---|
| 31 | * |
---|
| 32 | * @category PHPExcel |
---|
| 33 | * @package PHPExcel_Writer_Excel5 |
---|
| 34 | * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
---|
| 35 | */ |
---|
| 36 | class PHPExcel_Writer_Excel5_Font |
---|
| 37 | { |
---|
| 38 | /** |
---|
| 39 | * Color index |
---|
| 40 | * |
---|
| 41 | * @var int |
---|
| 42 | */ |
---|
| 43 | private $_colorIndex; |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * Font |
---|
| 47 | * |
---|
| 48 | * @var PHPExcel_Style_Font |
---|
| 49 | */ |
---|
| 50 | private $_font; |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Constructor |
---|
| 54 | * |
---|
| 55 | * @param PHPExcel_Style_Font $font |
---|
| 56 | */ |
---|
| 57 | public function __construct(PHPExcel_Style_Font $font = null) |
---|
| 58 | { |
---|
| 59 | $this->_colorIndex = 0x7FFF; |
---|
| 60 | $this->_font = $font; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * Set the color index |
---|
| 65 | * |
---|
| 66 | * @param int $colorIndex |
---|
| 67 | */ |
---|
| 68 | public function setColorIndex($colorIndex) |
---|
| 69 | { |
---|
| 70 | $this->_colorIndex = $colorIndex; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * Get font record data |
---|
| 75 | * |
---|
| 76 | * @return string |
---|
| 77 | */ |
---|
| 78 | public function writeFont() |
---|
| 79 | { |
---|
| 80 | $font_outline = 0; |
---|
| 81 | $font_shadow = 0; |
---|
| 82 | |
---|
| 83 | $icv = $this->_colorIndex; // Index to color palette |
---|
| 84 | if ($this->_font->getSuperScript()) { |
---|
| 85 | $sss = 1; |
---|
| 86 | } else if ($this->_font->getSubScript()) { |
---|
| 87 | $sss = 2; |
---|
| 88 | } else { |
---|
| 89 | $sss = 0; |
---|
| 90 | } |
---|
| 91 | $bFamily = 0; // Font family |
---|
| 92 | $bCharSet = PHPExcel_Shared_Font::getCharsetFromFontName($this->_font->getName()); // Character set |
---|
| 93 | |
---|
| 94 | $record = 0x31; // Record identifier |
---|
| 95 | $reserved = 0x00; // Reserved |
---|
| 96 | $grbit = 0x00; // Font attributes |
---|
| 97 | if ($this->_font->getItalic()) { |
---|
| 98 | $grbit |= 0x02; |
---|
| 99 | } |
---|
| 100 | if ($this->_font->getStrikethrough()) { |
---|
| 101 | $grbit |= 0x08; |
---|
| 102 | } |
---|
| 103 | if ($font_outline) { |
---|
| 104 | $grbit |= 0x10; |
---|
| 105 | } |
---|
| 106 | if ($font_shadow) { |
---|
| 107 | $grbit |= 0x20; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | $data = pack("vvvvvCCCC", |
---|
| 111 | $this->_font->getSize() * 20, // Fontsize (in twips) |
---|
| 112 | $grbit, |
---|
| 113 | $icv, // Colour |
---|
| 114 | self::_mapBold($this->_font->getBold()), // Font weight |
---|
| 115 | $sss, // Superscript/Subscript |
---|
| 116 | self::_mapUnderline($this->_font->getUnderline()), |
---|
| 117 | $bFamily, |
---|
| 118 | $bCharSet, |
---|
| 119 | $reserved |
---|
| 120 | ); |
---|
| 121 | $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($this->_font->getName()); |
---|
| 122 | |
---|
| 123 | $length = strlen($data); |
---|
| 124 | $header = pack("vv", $record, $length); |
---|
| 125 | |
---|
| 126 | return($header . $data); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * Map to BIFF5-BIFF8 codes for bold |
---|
| 131 | * |
---|
| 132 | * @param boolean $bold |
---|
| 133 | * @return int |
---|
| 134 | */ |
---|
| 135 | private static function _mapBold($bold) { |
---|
| 136 | if ($bold) { |
---|
| 137 | return 0x2BC; // 700 = Bold font weight |
---|
| 138 | } |
---|
| 139 | return 0x190; // 400 = Normal font weight |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /** |
---|
| 143 | * Map of BIFF2-BIFF8 codes for underline styles |
---|
| 144 | * @static array of int |
---|
| 145 | * |
---|
| 146 | */ |
---|
| 147 | private static $_mapUnderline = array( PHPExcel_Style_Font::UNDERLINE_NONE => 0x00, |
---|
| 148 | PHPExcel_Style_Font::UNDERLINE_SINGLE => 0x01, |
---|
| 149 | PHPExcel_Style_Font::UNDERLINE_DOUBLE => 0x02, |
---|
| 150 | PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING => 0x21, |
---|
| 151 | PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING => 0x22, |
---|
| 152 | ); |
---|
| 153 | /** |
---|
| 154 | * Map underline |
---|
| 155 | * |
---|
| 156 | * @param string |
---|
| 157 | * @return int |
---|
| 158 | */ |
---|
| 159 | private static function _mapUnderline($underline) { |
---|
| 160 | if (isset(self::$_mapUnderline[$underline])) |
---|
| 161 | return self::$_mapUnderline[$underline]; |
---|
| 162 | return 0x00; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | } |
---|