PHPExcel_Writer_Excel5
[ class tree: PHPExcel_Writer_Excel5 ] [ index: PHPExcel_Writer_Excel5 ] [ all elements ]

Source for file Font.php

Documentation is available at Font.php

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

Documentation generated on Mon, 10 Aug 2009 08:04:22 +0200 by phpDocumentor 1.4.1