You are here

public static function PHPExcel_Shared_Font::getTextWidthPixelsExact in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Font.php \PHPExcel_Shared_Font::getTextWidthPixelsExact()

* Get GD text width in pixels for a string of text in a certain font at a certain rotation angle * *

Parameters

string $text: * @param PHPExcel_Style_Font * @param int $rotation * @return int * @throws PHPExcel_Exception

1 call to PHPExcel_Shared_Font::getTextWidthPixelsExact()
PHPExcel_Shared_Font::calculateColumnWidth in vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Font.php
* Calculate an (approximate) OpenXML column width, based on font size and text contained * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/Font.php, line 304

Class

PHPExcel_Shared_Font
PHPExcel_Shared_Font

Code

public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) {
  if (!function_exists('imagettfbbox')) {
    throw new PHPExcel_Exception('GD library needs to be enabled');
  }

  // font size should really be supplied in pixels in GD2,
  // but since GD2 seems to assume 72dpi, pixels and points are the same
  $fontFile = self::getTrueTypeFontFileFromFont($font);
  $textBox = imagettfbbox($font
    ->getSize(), $rotation, $fontFile, $text);

  // Get corners positions
  $lowerLeftCornerX = $textBox[0];

  //		$lowerLeftCornerY  = $textBox[1];
  $lowerRightCornerX = $textBox[2];

  //		$lowerRightCornerY = $textBox[3];
  $upperRightCornerX = $textBox[4];

  //		$upperRightCornerY = $textBox[5];
  $upperLeftCornerX = $textBox[6];

  //		$upperLeftCornerY  = $textBox[7];
  // Consider the rotation when calculating the width
  $textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX);
  return $textWidth;
}