original_string: public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0)
      {
          $fontName = $font->getName();
          $fontSize = $font->getSize();
  
          // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.
          switch ($fontName) {
              case 'Calibri':
                  // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.
                  $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
                  break;
  
              case 'Arial':
                  // value 7 was found via interpolation by inspecting real Excel files with Arial 10 font.
  //                $columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText));
                  // value 8 was set because of experience in different exports at Arial 10 font.
                  $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
                  break;
  
              case 'Verdana':
                  // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.
                  $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
                  break;
  
              default:
                  // just assume Calibri
                  $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
                  break;
          }
  
          // Calculate approximate rotated column width
          if ($rotation !== 0) {
              if ($rotation == -165) {
                  // stacked text
                  $columnWidth = 4; // approximation
              } else {
                  // rotated text
                  $columnWidth = $columnWidth * cos(deg2rad($rotation))
                                  + $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation
              }
          }
  
          // pixel width is an integer
          return (int) $columnWidth;
      }
code: public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0)
      {
          $fontName = $font->getName();
          $fontSize = $font->getSize();
  
          // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.
          switch ($fontName) {
              case 'Calibri':
                  // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.
                  $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
                  break;
  
              case 'Arial':
                  // value 7 was found via interpolation by inspecting real Excel files with Arial 10 font.
  //                $columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText));
                  // value 8 was set because of experience in different exports at Arial 10 font.
                  $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
                  break;
  
              case 'Verdana':
                  // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.
                  $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
                  break;
  
              default:
                  // just assume Calibri
                  $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
                  $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
                  break;
          }
  
          // Calculate approximate rotated column width
          if ($rotation !== 0) {
              if ($rotation == -165) {
                  // stacked text
                  $columnWidth = 4; // approximation
              } else {
                  // rotated text
                  $columnWidth = $columnWidth * cos(deg2rad($rotation))
                                  + $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation
              }
          }
  
          // pixel width is an integer
          return (int) $columnWidth;
      }
code_tokens: public static function getTextWidthPixelsApprox ( $ columnText , PHPExcel_Style_Font $ font = null , $ rotation = 0 ) { $ fontName = $ font -> getName ( ) ; $ fontSize = $ font -> getSize ( ) ; // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size. switch ( $ fontName ) { case 'Calibri' : // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font. $ columnWidth = ( int ) ( 8.26 * PHPExcel_Shared_String :: CountCharacters ( $ columnText ) ) ; $ columnWidth = $ columnWidth * $ fontSize / 11 ; // extrapolate from font size break ; case 'Arial' : // value 7 was found via interpolation by inspecting real Excel files with Arial 10 font. //                $columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText)); // value 8 was set because of experience in different exports at Arial 10 font. $ columnWidth = ( int ) ( 8 * PHPExcel_Shared_String :: CountCharacters ( $ columnText ) ) ; $ columnWidth = $ columnWidth * $ fontSize / 10 ; // extrapolate from font size break ; case 'Verdana' : // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font. $ columnWidth = ( int ) ( 8 * PHPExcel_Shared_String :: CountCharacters ( $ columnText ) ) ; $ columnWidth = $ columnWidth * $ fontSize / 10 ; // extrapolate from font size break ; default : // just assume Calibri $ columnWidth = ( int ) ( 8.26 * PHPExcel_Shared_String :: CountCharacters ( $ columnText ) ) ; $ columnWidth = $ columnWidth * $ fontSize / 11 ; // extrapolate from font size break ; } // Calculate approximate rotated column width if ( $ rotation !== 0 ) { if ( $ rotation == - 165 ) { // stacked text $ columnWidth = 4 ; // approximation } else { // rotated text $ columnWidth = $ columnWidth * cos ( deg2rad ( $ rotation ) ) + $ fontSize * abs ( sin ( deg2rad ( $ rotation ) ) ) / 5 ; // approximation } } // pixel width is an integer return ( int ) $ columnWidth ; }
docstring: Get approximate width in pixels for a string of text in a certain font at a certain rotation angle
  
  @param string $columnText
  @param PHPExcel_Style_Font $font
  @param int $rotation
  @return int Text width in pixels (no padding added)
docstring_tokens: Get approximate width in pixels for a string of text in a certain font at a certain rotation angle