PHPExcel_Shared
[ class tree: PHPExcel_Shared ] [ index: PHPExcel_Shared ] [ 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_Shared
  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.5, 2009-01-05
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Shared_Font
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Shared
  34.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. {
  37.     /**
  38.      * Calculate an (approximate) OpenXML column width, based on font size and text contained
  39.      *
  40.      * @param     int        $fontSize            Font size (in pixels or points)
  41.      * @param     bool    $fontSizeInPixels    Is the font size specified in pixels (true) or in points (false) ?
  42.      * @param     string    $columnText            Text to calculate width
  43.      * @return     int        Column width
  44.      */
  45.     public static function calculateColumnWidth($fontSize 9$fontSizeInPixels false$columnText ''{
  46.         if (!$fontSizeInPixels{
  47.             // Translate points size to pixel size
  48.             $fontSize PHPExcel_Shared_Font::fontSizeToPixels($fontSize);
  49.         }
  50.         
  51.         // If it is rich text, use rich text...
  52.         if ($columnText instanceof PHPExcel_RichText{
  53.             $columnText $columnText->getPlainText();
  54.         }
  55.         
  56.         // Only measure the part before the first newline character
  57.         if (strpos($columnText"\r"!== false{
  58.             $columnText substr($columnText0strpos($columnText"\r"));
  59.         }
  60.         if (strpos($columnText"\n"!== false{
  61.             $columnText substr($columnText0strpos($columnText"\n"));
  62.         }
  63.         
  64.         // Calculate column width
  65.         return round( ( (strlen($columnText$fontSize 5$fontSize 256 2566);
  66.     }
  67.     
  68.     /**
  69.      * Calculate an (approximate) pixel size, based on a font points size
  70.      *
  71.      * @param     int        $fontSizeInPoints    Font size (in points)
  72.      * @return     int        Font size (in pixels)
  73.      */
  74.     public static function fontSizeToPixels($fontSizeInPoints 12{
  75.         return ((16 12$fontSizeInPoints);
  76.     }
  77. }

Documentation generated on Mon, 05 Jan 2009 20:37:13 +0100 by phpDocumentor 1.4.1