File Source for Font.php

PHPExcel_Shared

# 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_Shared
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_Shared_Font
31. *
32. * @category PHPExcel
33. * @package PHPExcel_Shared
34. * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35. */
36. class PHPExcel_Shared_Font
37. {
38. /* Methods for resolving autosize value */
39. const AUTOSIZE_METHOD_APPROX = 'approx';
40. const AUTOSIZE_METHOD_EXACT = 'exact';
42. /** Character set codes used by BIFF5-8 in Font records */
43. const CHARSET_ANSI_LATIN = 0x00;
44. const CHARSET_SYSTEM_DEFAULT = 0x01;
45. const CHARSET_SYMBOL = 0x02;
46. const CHARSET_APPLE_ROMAN = 0x4D;
47. const CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80;
48. const CHARSET_ANSI_KOREAN_HANGUL = 0x81;
49. const CHARSET_ANSI_KOREAN_JOHAB = 0x82;
50. const CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86;
51. const CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88;
52. const CHARSET_ANSI_GREEK = 0xA1;
53. const CHARSET_ANSI_TURKISH = 0xA2;
54. const CHARSET_ANSI_VIETNAMESE = 0xA3;
55. const CHARSET_ANSI_HEBREW = 0xB1;
56. const CHARSET_ANSI_ARABIC = 0xB2;
57. const CHARSET_ANSI_BALTIC = 0xBA;
58. const CHARSET_ANSI_CYRILLIC = 0xCC;
59. const CHARSET_ANSI_THAI = 0xDE;
60. const CHARSET_ANSI_LATIN_II = 0xEE;
61. const CHARSET_OEM_LATIN_I = 0xFF;
63. // XXX: Constants created!
64. /** Font filenames */
65. const ARIAL = 'arial.ttf';
66. const ARIAL_BOLD = 'arialbd.ttf';
67. const ARIAL_ITALIC = 'ariali.ttf';
68. const ARIAL_BOLD_ITALIC = 'arialbi.ttf';
70. const CALIBRI = 'CALIBRI.TTF';
71. const CALIBRI_BOLD = 'CALIBRIB.TTF';
72. const CALIBRI_ITALIC = 'CALIBRII.TTF';
73. const CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF';
75. const COMIC_SANS_MS = 'comic.ttf';
76. const COMIC_SANS_MS_BOLD = 'comicbd.ttf';
78. const COURIER_NEW = 'cour.ttf';
79. const COURIER_NEW_BOLD = 'courbd.ttf';
80. const COURIER_NEW_ITALIC = 'couri.ttf';
81. const COURIER_NEW_BOLD_ITALIC = 'courbi.ttf';
83. const GEORGIA = 'georgia.ttf';
84. const GEORGIA_BOLD = 'georgiab.ttf';
85. const GEORGIA_ITALIC = 'georgiai.ttf';
86. const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf';
88. const IMPACT = 'impact.ttf';
90. const LIBERATION_SANS = 'LiberationSans-Regular.ttf';
91. const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf';
92. const LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf';
93. const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf';
95. const LUCIDA_CONSOLE = 'lucon.ttf';
96. const LUCIDA_SANS_UNICODE = 'l_10646.ttf';
98. const MICROSOFT_SANS_SERIF = 'micross.ttf';
100. const PALATINO_LINOTYPE = 'pala.ttf';
101. const PALATINO_LINOTYPE_BOLD = 'palab.ttf';
102. const PALATINO_LINOTYPE_ITALIC = 'palai.ttf';
103. const PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf';
105. const SYMBOL = 'symbol.ttf';
107. const TAHOMA = 'tahoma.ttf';
108. const TAHOMA_BOLD = 'tahomabd.ttf';
110. const TIMES_NEW_ROMAN = 'times.ttf';
111. const TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf';
112. const TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf';
113. const TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf';
115. const TREBUCHET_MS = 'trebuc.ttf';
116. const TREBUCHET_MS_BOLD = 'trebucbd.ttf';
117. const TREBUCHET_MS_ITALIC = 'trebucit.ttf';
118. const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf';
120. const VERDANA = 'verdana.ttf';
121. const VERDANA_BOLD = 'verdanab.ttf';
122. const VERDANA_ITALIC = 'verdanai.ttf';
123. const VERDANA_BOLD_ITALIC = 'verdanaz.ttf';
125. /**
126. * AutoSize method
127. *
128. * @var string
129. */
130. private static $autoSizeMethod = self:: AUTOSIZE_METHOD_APPROX;
132. /**
133. * Path to folder containing TrueType font .ttf files
134. *
135. * @var string
136. */
137. private static $trueTypeFontPath = null;
139. /**
140. * How wide is a default column for a given default font and size?
141. * Empirical data found by inspecting real Excel files and reading off the pixel width
142. * in Microsoft Office Excel 2007.
143. *
144. * @var array
145. */
146. public static $defaultColumnWidths = array(
147. 'Arial' => array(
148. 1 => array('px' => 24, 'width' => 12.00000000),
149. 2 => array('px' => 24, 'width' => 12.00000000),
150. 3 => array('px' => 32, 'width' => 10.66406250),
151. 4 => array('px' => 32, 'width' => 10.66406250),
152. 5 => array('px' => 40, 'width' => 10.00000000),
153. 6 => array('px' => 48, 'width' => 9.59765625),
154. 7 => array('px' => 48, 'width' => 9.59765625),
155. 8 => array('px' => 56, 'width' => 9.33203125),
156. 9 => array('px' => 64, 'width' => 9.14062500),
157. 10 => array('px' => 64, 'width' => 9.14062500),
158. ),
159. 'Calibri' => array(
160. 1 => array('px' => 24, 'width' => 12.00000000),
161. 2 => array('px' => 24, 'width' => 12.00000000),
162. 3 => array('px' => 32, 'width' => 10.66406250),
163. 4 => array('px' => 32, 'width' => 10.66406250),
164. 5 => array('px' => 40, 'width' => 10.00000000),
165. 6 => array('px' => 48, 'width' => 9.59765625),
166. 7 => array('px' => 48, 'width' => 9.59765625),
167. 8 => array('px' => 56, 'width' => 9.33203125),
168. 9 => array('px' => 56, 'width' => 9.33203125),
169. 10 => array('px' => 64, 'width' => 9.14062500),
170. 11 => array('px' => 64, 'width' => 9.14062500),
171. ),
172. 'Verdana' => array(
173. 1 => array('px' => 24, 'width' => 12.00000000),
174. 2 => array('px' => 24, 'width' => 12.00000000),
175. 3 => array('px' => 32, 'width' => 10.66406250),
176. 4 => array('px' => 32, 'width' => 10.66406250),
177. 5 => array('px' => 40, 'width' => 10.00000000),
178. 6 => array('px' => 48, 'width' => 9.59765625),
179. 7 => array('px' => 48, 'width' => 9.59765625),
180. 8 => array('px' => 64, 'width' => 9.14062500),
181. 9 => array('px' => 72, 'width' => 9.00000000),
182. 10 => array('px' => 72, 'width' => 9.00000000),
183. ),
184. );
186. /**
187. * Set autoSize method
188. *
189. * @param string $pValue
190. */
191. public static function setAutoSizeMethod($pValue = 'approx')
192. {
193. self::$autoSizeMethod = $pValue;
194. }
196. /**
197. * Get autoSize method
198. *
199. * @return string
200. */
201. public static function getAutoSizeMethod()
202. {
203. return self::$autoSizeMethod;
204. }
206. /**
207. * Set the path to the folder containing .ttf files. There should be a trailing slash.
208. * Typical locations on variout some platforms:
209. * <ul>
210. * <li>C:/Windows/Fonts/</li>
211. * <li>/usr/share/fonts/truetype/</li>
212. * <li>~/.fonts/</li>
213. * </ul>
214. *
215. * @param string $pValue
216. */
217. public static function setTrueTypeFontPath($pValue = '')
218. {
219. self::$trueTypeFontPath = $pValue;
220. }
222. /**
223. * Get the path to the folder containing .ttf files.
224. *
225. * @return string
226. */
227. public static function getTrueTypeFontPath()
228. {
229. return self::$trueTypeFontPath;
230. }
232. /**
233. * Calculate an (approximate) OpenXML column width, based on font size and text contained
234. *
235. * @param int $fontSize Font size (in pixels or points)
236. * @param bool $fontSizeInPixels Is the font size specified in pixels (true) or in points (false) ?
237. * @param string $cellText Text to calculate width
238. * @param int $rotation Rotation angle
239. * @return int Column width
240. */
241. public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null) {
243. // If it is rich text, use plain text
244. if ($cellText instanceof PHPExcel_RichText) {
245. $cellText = $cellText->getPlainText();
246. }
248. // Special case if there are one or more newline characters ("\n")
249. if ( strpos($cellText, "\n") !== false) {
250. $lineTexts = explode("\n", $cellText);
251. $lineWitdhs = array();
252. foreach ($lineTexts as $lineText) {
253. $lineWidths[] = self:: calculateColumnWidth($font, $lineText, $rotation = 0, $defaultFont);
254. }
255. return max($lineWidths); // width of longest line in cell
256. }
258. // Try to get the exact text width in pixels
259. try {
260. // If autosize method is set to 'approx', use approximation
261. if (self::$autoSizeMethod == self:: AUTOSIZE_METHOD_APPROX) {
262. throw new Exception('AutoSize method is set to approx');
263. }
265. // Width of text in pixels excl. padding
266. $columnWidth = self:: getTextWidthPixelsExact($cellText, $font, $rotation);
268. // Excel adds some padding, use 1.07 of the width of an 'n' glyph
269. $columnWidth += ceil(self:: getTextWidthPixelsExact('0', $font, 0) * 1.07); // pixels incl. padding
271. } catch (Exception $e) {
272. // Width of text in pixels excl. padding, approximation
273. $columnWidth = self:: getTextWidthPixelsApprox($cellText, $font, $rotation);
275. // Excel adds some padding, just use approx width of 'n' glyph
276. $columnWidth += self:: getTextWidthPixelsApprox('n', $font, 0);
277. }
279. // Convert from pixel width to column width
280. $columnWidth = PHPExcel_Shared_Drawing:: pixelsToCellDimension($columnWidth, $defaultFont);
282. // Return
283. return round($columnWidth, 6);
284. }
286. /**
287. * Get GD text width in pixels for a string of text in a certain font at a certain rotation angle
288. *
289. * @param string $text
290. * @param PHPExcel_Style_Font
291. * @param int $rotation
292. * @return int
293. * @throws Exception
294. */
295. public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) {
296. if (! function_exists('imagettfbbox')) {
297. throw new Exception('GD library needs to be enabled');
298. }
300. // font size should really be supplied in pixels in GD2,
301. // but since GD2 seems to assume 72dpi, pixels and points are the same
302. $fontFile = self:: getTrueTypeFontFileFromFont($font);
303. $textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text);
305. // Get corners positions
306. $lowerLeftCornerX = $textBox[0];
307. $lowerLeftCornerY = $textBox[1];
308. $lowerRightCornerX = $textBox[2];
309. $lowerRightCornerY = $textBox[3];
310. $upperRightCornerX = $textBox[4];
311. $upperRightCornerY = $textBox[5];
312. $upperLeftCornerX = $textBox[6];
313. $upperLeftCornerY = $textBox[7];
315. // Consider the rotation when calculating the width
316. $textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX);
318. return $textWidth;
319. }
321. /**
322. * Get approximate width in pixels for a string of text in a certain font at a certain rotation angle
323. *
324. * @param string $columnText
325. * @param PHPExcel_Style_Font $font
326. * @param int $rotation
327. * @return int Text width in pixels (no padding added)
328. */
329. public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0)
330. {
331. $fontName = $font->getName();
332. $fontSize = $font->getSize();
334. // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.
335. switch ($fontName) {
336. case 'Calibri':
337. // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.
338. $columnWidth = (int) (8.26 * PHPExcel_Shared_String:: CountCharacters($columnText));
339. $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
340. break;
342. case 'Arial':
343. // value 7 was found via interpolation by inspecting real Excel files with Arial 10 font.
344. $columnWidth = (int) (7 * PHPExcel_Shared_String:: CountCharacters($columnText));
345. $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
346. break;
348. case 'Verdana':
349. // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.
350. $columnWidth = (int) (8 * PHPExcel_Shared_String:: CountCharacters($columnText));
351. $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
352. break;
354. default:
355. // just assume Calibri
356. $columnWidth = (int) (8.26 * PHPExcel_Shared_String:: CountCharacters($columnText));
357. $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
358. break;
359. }
361. // Calculate approximate rotated column width
362. if ($rotation !== 0) {
363. if ($rotation == -165) {
364. // stacked text
365. $columnWidth = 4; // approximation
366. } else {
367. // rotated text
368. $columnWidth = $columnWidth * cos( deg2rad($rotation))
369. + $fontSize * abs( sin( deg2rad($rotation))) / 5; // approximation
370. }
371. }
373. // pixel width is an integer
374. $columnWidth = (int) $columnWidth;
375. return $columnWidth;
376. }
378. /**
379. * Calculate an (approximate) pixel size, based on a font points size
380. *
381. * @param int $fontSizeInPoints Font size (in points)
382. * @return int Font size (in pixels)
383. */
384. public static function fontSizeToPixels($fontSizeInPoints = 11) {
385. return (int) ((4 / 3) * $fontSizeInPoints);
386. }
388. /**
389. * Calculate an (approximate) pixel size, based on inch size
390. *
391. * @param int $sizeInInch Font size (in inch)
392. * @return int Size (in pixels)
393. */
394. public static function inchSizeToPixels($sizeInInch = 1) {
395. return ($sizeInInch * 96);
396. }
398. /**
399. * Calculate an (approximate) pixel size, based on centimeter size
400. *
401. * @param int $sizeInCm Font size (in centimeters)
402. * @return int Size (in pixels)
403. */
404. public static function centimeterSizeToPixels($sizeInCm = 1) {
405. return ($sizeInCm * 37.795275591);
406. }
408. /**
409. * Returns the font path given the font
410. *
411. * @param PHPExcel_Style_Font
412. * @return string Path to TrueType font file
413. */
414. public static function getTrueTypeFontFileFromFont($font) {
415. if (! file_exists(self::$trueTypeFontPath) || ! is_dir(self::$trueTypeFontPath)) {
416. throw new Exception('Valid directory to TrueType Font files not specified');
417. }
419. $name = $font->getName();
420. $bold = $font->getBold();
421. $italic = $font->getItalic();
423. // Check if we can map font to true type font file
424. switch ($name) {
425. case 'Arial':
426. $fontFile = (
427. $bold ? ($italic ? self:: ARIAL_BOLD_ITALIC : self:: ARIAL_BOLD)
428. : ($italic ? self:: ARIAL_ITALIC : self:: ARIAL)
429. );
430. break;
432. case 'Calibri':
433. $fontFile = (
434. $bold ? ($italic ? self:: CALIBRI_BOLD_ITALIC : self:: CALIBRI_BOLD)
435. : ($italic ? self:: CALIBRI_ITALIC : self:: CALIBRI)
436. );
437. break;
439. case 'Courier New':
440. $fontFile = (
441. $bold ? ($italic ? self:: COURIER_NEW_BOLD_ITALIC : self:: COURIER_NEW_BOLD)
442. : ($italic ? self:: COURIER_NEW_ITALIC : self:: COURIER_NEW)
443. );
444. break;
446. case 'Comic Sans MS':
447. $fontFile = (
448. $bold ? self:: COMIC_SANS_MS_BOLD : self:: COMIC_SANS_MS
449. );
450. break;
452. case 'Georgia':
453. $fontFile = (
454. $bold ? ($italic ? self:: GEORGIA_BOLD_ITALIC : self:: GEORGIA_BOLD)
455. : ($italic ? self:: GEORGIA_ITALIC : self:: GEORGIA)
456. );
457. break;
459. case 'Impact':
460. $fontFile = self:: IMPACT;
461. break;
463. case 'Liberation Sans':
464. $fontFile = (
465. $bold ? ($italic ? self:: LIBERATION_SANS_BOLD_ITALIC : self:: LIBERATION_SANS_BOLD)
466. : ($italic ? self:: LIBERATION_SANS_ITALIC : self:: LIBERATION_SANS)
467. );
468. break;
470. case 'Lucida Console':
471. $fontFile = self:: LUCIDA_CONSOLE;
472. break;
474. case 'Lucida Sans Unicode':
475. $fontFile = self:: LUCIDA_SANS_UNICODE;
476. break;
478. case 'Microsoft Sans Serif':
479. $fontFile = self:: MICROSOFT_SANS_SERIF;
480. break;
482. case 'Palatino Linotype':
483. $fontFile = (
484. $bold ? ($italic ? self:: PALATINO_LINOTYPE_BOLD_ITALIC : self:: PALATINO_LINOTYPE_BOLD)
485. : ($italic ? self:: PALATINO_LINOTYPE_ITALIC : self:: PALATINO_LINOTYPE)
486. );
487. break;
489. case 'Symbol':
490. $fontFile = self:: SYMBOL;
491. break;
493. case 'Tahoma':
494. $fontFile = (
495. $bold ? self:: TAHOMA_BOLD : self:: TAHOMA
496. );
497. break;
499. case 'Times New Roman':
500. $fontFile = (
501. $bold ? ($italic ? self:: TIMES_NEW_ROMAN_BOLD_ITALIC : self:: TIMES_NEW_ROMAN_BOLD)
502. : ($italic ? self:: TIMES_NEW_ROMAN_ITALIC : self:: TIMES_NEW_ROMAN)
503. );
504. break;
506. case 'Trebuchet MS':
507. $fontFile = (
508. $bold ? ($italic ? self:: TREBUCHET_MS_BOLD_ITALIC : self:: TREBUCHET_MS_BOLD)
509. : ($italic ? self:: TREBUCHET_MS_ITALIC : self:: TREBUCHET_MS)
510. );
511. break;
513. case 'Verdana':
514. $fontFile = (
515. $bold ? ($italic ? self:: VERDANA_BOLD_ITALIC : self:: VERDANA_BOLD)
516. : ($italic ? self:: VERDANA_ITALIC : self:: VERDANA)
517. );
518. break;
520. default:
521. throw new Exception('Unknown font name "'. $name .'". Cannot map to TrueType font file');
522. break;
523. }
525. $fontFile = self::$trueTypeFontPath . $fontFile;
527. // Check if file actually exists
528. if (! file_exists($fontFile)) {
529. throw New Exception('TrueType Font file not found');
530. }
532. return $fontFile;
533. }
535. /**
536. * Returns the associated charset for the font name.
537. *
538. * @param string $name Font name
539. * @return int Character set code
540. */
541. public static function getCharsetFromFontName($name)
542. {
543. switch ($name) {
544. // Add more cases. Check FONT records in real Excel files.
545. case 'EucrosiaUPC': return self:: CHARSET_ANSI_THAI;
546. case 'Wingdings': return self:: CHARSET_SYMBOL;
547. case 'Wingdings 2': return self:: CHARSET_SYMBOL;
548. case 'Wingdings 3': return self:: CHARSET_SYMBOL;
549. default: return self:: CHARSET_ANSI_LATIN;
550. }
551. }
553. /**
554. * Get the effective column width for columns without a column dimension or column with width -1
555. * For example, for Calibri 11 this is 9.140625 (64 px)
556. *
557. * @param PHPExcel_Style_Font $font The workbooks default font
558. * @param boolean $pPixels true = return column width in pixels, false = return in OOXML units
559. * @return mixed Column width
560. */
561. public static function getDefaultColumnWidthByFont(PHPExcel_Style_Font $font, $pPixels = false)
562. {
563. if (isset(self::$defaultColumnWidths[$font->getName()][$font->getSize()])) {
564. // Exact width can be determined
565. $columnWidth = $pPixels ?
566. self::$defaultColumnWidths[$font->getName()][$font->getSize()]['px']
567. : self::$defaultColumnWidths[$font->getName()][$font->getSize()]['width'];
569. } else {
570. // We don't have data for this particular font and size, use approximation by
571. // extrapolating from Calibri 11
572. $columnWidth = $pPixels ?
573. self::$defaultColumnWidths['Calibri'][11]['px']
574. : self::$defaultColumnWidths['Calibri'][11]['width'];
575. $columnWidth = $columnWidth * $font->getSize() / 11;
577. // Round pixels to closest integer
578. if ($pPixels) {
579. $columnWidth = (int) round($columnWidth);
580. }
581. }
583. return $columnWidth;
584. }
586. /**
587. * Get the effective row height for rows without a row dimension or rows with height -1
588. * For example, for Calibri 11 this is 15 points
589. *
590. * @param PHPExcel_Style_Font $font The workbooks default font
591. * @return float Row height in points
592. */
593. public static function getDefaultRowHeightByFont(PHPExcel_Style_Font $font)
594. {
595. switch ($font->getName()) {
596. case 'Arial':
597. switch ($font->getSize()) {
598. case 10:
599. // inspection of Arial 10 workbook says 12.75pt ~17px
600. $rowHeight = 12.75;
601. break;
603. case 9:
604. // inspection of Arial 9 workbook says 12.00pt ~16px
605. $rowHeight = 12;
606. break;
608. case 8:
609. // inspection of Arial 8 workbook says 11.25pt ~15px
610. $rowHeight = 11.25;
611. break;
613. case 7:
614. // inspection of Arial 7 workbook says 9.00pt ~12px
615. $rowHeight = 9;
616. break;
618. case 6:
619. case 5:
620. // inspection of Arial 5,6 workbook says 8.25pt ~11px
621. $rowHeight = 8.25;
622. break;
624. case 4:
625. // inspection of Arial 4 workbook says 6.75pt ~9px
626. $rowHeight = 6.75;
627. break;
629. case 3:
630. // inspection of Arial 3 workbook says 6.00pt ~8px
631. $rowHeight = 6;
632. break;
634. case 2:
635. case 1:
636. // inspection of Arial 1,2 workbook says 5.25pt ~7px
637. $rowHeight = 5.25;
638. break;
640. default:
641. // use Arial 10 workbook as an approximation, extrapolation
642. $rowHeight = 12.75 * $font->getSize() / 10;
643. break;
644. }
645. break;
647. case 'Calibri':
648. switch ($font->getSize()) {
649. case 11:
650. // inspection of Calibri 11 workbook says 15.00pt ~20px
651. $rowHeight = 15;
652. break;
654. case 10:
655. // inspection of Calibri 10 workbook says 12.75pt ~17px
656. $rowHeight = 12.75;
657. break;
659. case 9:
660. // inspection of Calibri 9 workbook says 12.00pt ~16px
661. $rowHeight = 12;
662. break;
664. case 8:
665. // inspection of Calibri 8 workbook says 11.25pt ~15px
666. $rowHeight = 11.25;
667. break;
669. case 7:
670. // inspection of Calibri 7 workbook says 9.00pt ~12px
671. $rowHeight = 9;
672. break;
674. case 6:
675. case 5:
676. // inspection of Calibri 5,6 workbook says 8.25pt ~11px
677. $rowHeight = 8.25;
678. break;
680. case 4:
681. // inspection of Calibri 4 workbook says 6.75pt ~9px
682. $rowHeight = 6.75;
683. break;
685. case 3:
686. // inspection of Calibri 3 workbook says 6.00pt ~8px
687. $rowHeight = 6.00;
688. break;
690. case 2:
691. case 1:
692. // inspection of Calibri 1,2 workbook says 5.25pt ~7px
693. $rowHeight = 5.25;
694. break;
696. default:
697. // use Calibri 11 workbook as an approximation, extrapolation
698. $rowHeight = 15 * $font->getSize() / 11;
699. break;
700. }
701. break;
703. case 'Verdana':
704. switch ($font->getSize()) {
705. case 10:
706. // inspection of Verdana 10 workbook says 12.75pt ~17px
707. $rowHeight = 12.75;
708. break;
710. case 9:
711. // inspection of Verdana 9 workbook says 11.25pt ~15px
712. $rowHeight = 11.25;
713. break;
715. case 8:
716. // inspection of Verdana 8 workbook says 10.50pt ~14px
717. $rowHeight = 10.50;
718. break;
720. case 7:
721. // inspection of Verdana 7 workbook says 9.00pt ~12px
722. $rowHeight = 9.00;
723. break;
725. case 6:
726. case 5:
727. // inspection of Verdana 5,6 workbook says 8.25pt ~11px
728. $rowHeight = 8.25;
729. break;
731. case 4:
732. // inspection of Verdana 4 workbook says 6.75pt ~9px
733. $rowHeight = 6.75;
734. break;
736. case 3:
737. // inspection of Verdana 3 workbook says 6.00pt ~8px
738. $rowHeight = 6;
739. break;
741. case 2:
742. case 1:
743. // inspection of Verdana 1,2 workbook says 5.25pt ~7px
744. $rowHeight = 5.25;
745. break;
747. default:
748. // use Verdana 10 workbook as an approximation, extrapolation
749. $rowHeight = 12.75 * $font->getSize() / 10;
750. break;
751. }
752. break;
754. default:
755. // just use Calibri as an approximation
756. $rowHeight = 15 * $font->getSize() / 11;
757. break;
758. }
760. return $rowHeight;
761. }
763. }

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