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

Source for file Drawing.php

Documentation is available at Drawing.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.2, 2010-01-11
  26.  */
  27.  
  28.  
  29. /** PHPExcel root */
  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/Font.php';
  39.  
  40.  
  41. /**
  42.  * PHPExcel_Shared_Drawing
  43.  *
  44.  * @category   PHPExcel
  45.  * @package    PHPExcel_Shared
  46.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  47.  */
  48. {
  49.     /**
  50.      * Convert pixels to EMU
  51.      *
  52.      * @param     int $pValue    Value in pixels
  53.      * @return     int            Value in EMU
  54.      */
  55.     public static function pixelsToEMU($pValue 0{
  56.         return round($pValue 9525);
  57.     }
  58.     
  59.     /**
  60.      * Convert EMU to pixels
  61.      *
  62.      * @param     int $pValue    Value in EMU
  63.      * @return     int            Value in pixels
  64.      */
  65.     public static function EMUToPixels($pValue 0{
  66.         if ($pValue != 0{
  67.             return round($pValue 9525);
  68.         else {
  69.             return 0;
  70.         }
  71.     }
  72.     
  73.     /**
  74.      * Convert pixels to column width. Exact algorithm not known.
  75.      * By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875
  76.      * This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
  77.      *
  78.      * @param     int $pValue    Value in pixels
  79.      * @param     PHPExcel_Style_Font $pDefaultFont    Default font of the workbook
  80.      * @return     int            Value in cell dimension
  81.      */
  82.     public static function pixelsToCellDimension($pValue 0PHPExcel_Style_Font $pDefaultFont{
  83.         // Font name and size
  84.         $name $pDefaultFont->getName();
  85.         $size $pDefaultFont->getSize();
  86.  
  87.         if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
  88.             // Exact width can be determined
  89.             $colWidth $pValue
  90.                 * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width']
  91.                 / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
  92.         else {
  93.             // We don't have data for this particular font and size, use approximation by
  94.             // extrapolating from Calibri 11
  95.             $colWidth $pValue 11
  96.                 * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width']
  97.                 / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'$size;
  98.         }
  99.  
  100.         return $colWidth;
  101.     }
  102.  
  103.     /**
  104.      * Convert column width from (intrinsic) Excel units to pixels
  105.      *
  106.      * @param     float    $pValue        Value in cell dimension
  107.      * @param     PHPExcel_Style_Font $pDefaultFont    Default font of the workbook
  108.      * @return     int        Value in pixels
  109.      */
  110.     public static function cellDimensionToPixels($pValue 0PHPExcel_Style_Font $pDefaultFont{
  111.         // Font name and size
  112.         $name $pDefaultFont->getName();
  113.         $size $pDefaultFont->getSize();
  114.  
  115.         if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
  116.             // Exact width can be determined
  117.             $colWidth $pValue
  118.                 * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px']
  119.                 / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'];
  120.  
  121.         else {
  122.             // We don't have data for this particular font and size, use approximation by
  123.             // extrapolating from Calibri 11
  124.             $colWidth $pValue $size
  125.                 * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px']
  126.                 / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'11;
  127.         }
  128.  
  129.         // Round pixels to closest integer
  130.         $colWidth = (int) round($colWidth);
  131.  
  132.         return $colWidth;
  133.     }
  134.  
  135.     /**
  136.      * Convert pixels to points
  137.      *
  138.      * @param     int $pValue    Value in pixels
  139.      * @return     int            Value in points
  140.      */
  141.     public static function pixelsToPoints($pValue 0{
  142.         return $pValue 0.67777777;
  143.     }
  144.     
  145.     /**
  146.      * Convert points to pixels
  147.      *
  148.      * @param     int $pValue    Value in points
  149.      * @return     int            Value in pixels
  150.      */
  151.     public static function pointsToPixels($pValue 0{
  152.         if ($pValue != 0{
  153.             return (int) ceil($pValue 1.333333333);
  154.         else {
  155.             return 0;
  156.         }
  157.     }
  158.  
  159.     /**
  160.      * Convert degrees to angle
  161.      *
  162.      * @param     int $pValue    Degrees
  163.      * @return     int            Angle
  164.      */
  165.     public static function degreesToAngle($pValue 0{
  166.         return (int)round($pValue 60000);
  167.     }
  168.     
  169.     /**
  170.      * Convert angle to degrees
  171.      *
  172.      * @param     int $pValue    Angle
  173.      * @return     int            Degrees
  174.      */
  175.     public static function angleToDegrees($pValue 0{
  176.         if ($pValue != 0{
  177.             return round($pValue 60000);
  178.         else {
  179.             return 0;
  180.         }
  181.     }
  182. }

Documentation generated on Mon, 11 Jan 2010 08:07:58 +0100 by phpDocumentor 1.4.1