File Source for Font.php

PHPExcel_Writer_Excel5

# Source for file Font.php

Documentation is available at Font.php

1. <?php
2. /**
3. * PHPExcel
4. *
5. * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25. * @version 1.7.6, 2011-02-27
26. */
29. /**
30. * PHPExcel_Writer_Excel5_Font
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Writer_Excel5
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_Writer_Excel5_Font
37. {
38. /**
39. * BIFF version
40. *
41. * @var int
42. */
43. private $_BIFFVersion;
45. /**
46. * Color index
47. *
48. * @var int
49. */
50. private $_colorIndex;
52. /**
53. * Font
54. *
55. * @var PHPExcel_Style_Font
56. */
57. private $_font;
59. /**
60. * Constructor
61. *
62. * @param PHPExcel_Style_Font $font
63. */
64. public function __construct(PHPExcel_Style_Font $font = null)
65. {
66. $this->_BIFFVersion = 0x0600;
67. $this->_colorIndex = 0x7FFF;
68. $this->_font = $font;
69. }
71. /**
72. * Set the color index
73. *
74. * @param int $colorIndex
75. */
76. public function setColorIndex($colorIndex)
77. {
78. $this->_colorIndex = $colorIndex;
79. }
81. /**
82. * Get font record data
83. *
84. * @return string
85. */
86. public function writeFont()
87. {
88. $font_outline = 0;
89. $font_shadow = 0;
91. $icv = $this->_colorIndex; // Index to color palette
92. if ($this->_font->getSuperScript()) {
93. $sss = 1;
94. } else if ($this->_font->getSubScript()) {
95. $sss = 2;
96. } else {
97. $sss = 0;
98. }
99. $bFamily = 0; // Font family
100. $bCharSet = PHPExcel_Shared_Font:: getCharsetFromFontName($this->_font->getName()); // Character set
102. $record = 0x31; // Record identifier
103. $reserved = 0x00; // Reserved
104. $grbit = 0x00; // Font attributes
105. if ($this->_font->getItalic()) {
106. $grbit |= 0x02;
107. }
108. if ($this->_font->getStrikethrough()) {
109. $grbit |= 0x08;
110. }
111. if ($font_outline) {
112. $grbit |= 0x10;
113. }
114. if ($font_shadow) {
115. $grbit |= 0x20;
116. }
118. if ($this->_BIFFVersion == 0x0500) {
119. $data = pack("vvvvvCCCCC",
120. $this->_font->getSize() * 20,
121. $grbit,
122. $icv,
123. $this->_mapBold($this->_font->getBold()),
124. $sss,
125. $this->_mapUnderline($this->_font->getUnderline()),
126. $bFamily,
127. $bCharSet,
128. $reserved,
129. strlen($this->_font->getName())
130. );
131. $data .= $this->_font->getName();
132. } elseif ($this->_BIFFVersion == 0x0600) {
133. $data = pack("vvvvvCCCC",
134. $this->_font->getSize() * 20,
135. $grbit,
136. $icv,
137. $this->_mapBold($this->_font->getBold()),
138. $sss,
139. $this->_mapUnderline($this->_font->getUnderline()),
140. $bFamily,
141. $bCharSet,
142. $reserved
143. );
144. $data .= PHPExcel_Shared_String:: UTF8toBIFF8UnicodeShort($this->_font->getName());
145. }
147. $length = strlen($data);
148. $header = pack("vv", $record, $length);
150. return($header . $data);
151. }
153. /**
154. * Set BIFF version
155. *
156. * @param int $BIFFVersion
157. */
158. public function setBIFFVersion($BIFFVersion)
159. {
160. $this->_BIFFVersion = $BIFFVersion;
161. }
163. /**
164. * Map to BIFF5-BIFF8 codes for bold
165. *
166. * @param boolean $bold
167. * @return int
168. */
169. private function _mapBold($bold) {
170. if ($bold) {
171. return 0x2BC;
172. }
173. return 0x190;
174. }
176. /**
177. * Map underline
178. *
179. * @param string
180. * @return int
181. */
182. private function _mapUnderline($underline) {
183. switch ($underline) {
184. case PHPExcel_Style_Font:: UNDERLINE_NONE: return 0x00;
185. case PHPExcel_Style_Font:: UNDERLINE_SINGLE: return 0x01;
186. case PHPExcel_Style_Font:: UNDERLINE_DOUBLE: return 0x02;
187. case PHPExcel_Style_Font:: UNDERLINE_SINGLEACCOUNTING: return 0x21;
188. case PHPExcel_Style_Font:: UNDERLINE_DOUBLEACCOUNTING: return 0x22;
189. default: return 0x00;
190. }
191. }
193. }

Documentation generated on Sun, 27 Feb 2011 16:31:41 -0800 by phpDocumentor 1.4.3