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

Documentation generated on Wed, 22 Apr 2009 08:58:28 +0200 by phpDocumentor 1.4.1