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

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