43 self::AUTOSIZE_METHOD_APPROX,
44 self::AUTOSIZE_METHOD_EXACT,
153 1 => array(
'px' => 24,
'width' => 12.00000000),
154 2 => array(
'px' => 24,
'width' => 12.00000000),
155 3 => array(
'px' => 32,
'width' => 10.66406250),
156 4 => array(
'px' => 32,
'width' => 10.66406250),
157 5 => array(
'px' => 40,
'width' => 10.00000000),
158 6 => array(
'px' => 48,
'width' => 9.59765625),
159 7 => array(
'px' => 48,
'width' => 9.59765625),
160 8 => array(
'px' => 56,
'width' => 9.33203125),
161 9 => array(
'px' => 64,
'width' => 9.14062500),
162 10 => array(
'px' => 64,
'width' => 9.14062500),
165 1 => array(
'px' => 24,
'width' => 12.00000000),
166 2 => array(
'px' => 24,
'width' => 12.00000000),
167 3 => array(
'px' => 32,
'width' => 10.66406250),
168 4 => array(
'px' => 32,
'width' => 10.66406250),
169 5 => array(
'px' => 40,
'width' => 10.00000000),
170 6 => array(
'px' => 48,
'width' => 9.59765625),
171 7 => array(
'px' => 48,
'width' => 9.59765625),
172 8 => array(
'px' => 56,
'width' => 9.33203125),
173 9 => array(
'px' => 56,
'width' => 9.33203125),
174 10 => array(
'px' => 64,
'width' => 9.14062500),
175 11 => array(
'px' => 64,
'width' => 9.14062500),
178 1 => array(
'px' => 24,
'width' => 12.00000000),
179 2 => array(
'px' => 24,
'width' => 12.00000000),
180 3 => array(
'px' => 32,
'width' => 10.66406250),
181 4 => array(
'px' => 32,
'width' => 10.66406250),
182 5 => array(
'px' => 40,
'width' => 10.00000000),
183 6 => array(
'px' => 48,
'width' => 9.59765625),
184 7 => array(
'px' => 48,
'width' => 9.59765625),
185 8 => array(
'px' => 64,
'width' => 9.14062500),
186 9 => array(
'px' => 72,
'width' => 9.00000000),
187 10 => array(
'px' => 72,
'width' => 9.00000000),
199 if (!in_array($pValue,self::$_autoSizeMethods)) {
202 self::$autoSizeMethod = $pValue;
230 self::$trueTypeFontPath = $pValue;
255 $cellText = $cellText->getPlainText();
259 if (strpos($cellText,
"\n") !==
false) {
260 $lineTexts = explode(
"\n", $cellText);
261 $lineWidths = array();
262 foreach ($lineTexts as $lineText) {
265 return max($lineWidths);
271 $columnWidthAdjust = ceil(self::getTextWidthPixelsExact(
'n', $font, 0) * 1.07);
292 return round($columnWidth, 6);
305 if (!function_exists(
'imagettfbbox')) {
312 $textBox = imagettfbbox($font->
getSize(), $rotation, $fontFile,
$text);
315 $lowerLeftCornerX = $textBox[0];
317 $lowerRightCornerX = $textBox[2];
319 $upperRightCornerX = $textBox[4];
321 $upperLeftCornerX = $textBox[6];
325 $textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX);
340 $fontName = $font->getName();
341 $fontSize = $font->getSize();
348 $columnWidth = $columnWidth * $fontSize / 11;
356 $columnWidth = $columnWidth * $fontSize / 10;
362 $columnWidth = $columnWidth * $fontSize / 10;
368 $columnWidth = $columnWidth * $fontSize / 11;
373 if ($rotation !== 0) {
374 if ($rotation == -165) {
379 $columnWidth = $columnWidth * cos(deg2rad($rotation))
380 + $fontSize * abs(sin(deg2rad($rotation))) / 5;
385 return (
int) $columnWidth;
395 return (
int) ((4 / 3) * $fontSizeInPoints);
405 return ($sizeInInch * 96);
415 return ($sizeInCm * 37.795275591);
425 if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) {
429 $name = $font->getName();
430 $bold = $font->getBold();
431 $italic = $font->getItalic();
438 : ($italic ? self::ARIAL_ITALIC : self::ARIAL)
445 : ($italic ? self::CALIBRI_ITALIC : self::CALIBRI)
452 : ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW)
456 case 'Comic Sans MS':
465 : ($italic ? self::GEORGIA_ITALIC : self::GEORGIA)
473 case 'Liberation Sans':
476 : ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS)
480 case 'Lucida Console':
484 case 'Lucida Sans Unicode':
488 case 'Microsoft Sans Serif':
492 case 'Palatino Linotype':
495 : ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE)
509 case 'Times New Roman':
512 : ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN)
519 : ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS)
526 : ($italic ? self::VERDANA_ITALIC : self::VERDANA)
535 $fontFile = self::$trueTypeFontPath . $fontFile;
538 if (!file_exists($fontFile)) {
573 if (isset(self::$defaultColumnWidths[$font->
getName()][$font->
getSize()])) {
575 $columnWidth = $pPixels ?
576 self::$defaultColumnWidths[$font->
getName()][$font->
getSize()][
'px']
577 : self::$defaultColumnWidths[$font->
getName()][$font->
getSize()][
'width'];
582 $columnWidth = $pPixels ?
583 self::$defaultColumnWidths[
'Calibri'][11][
'px']
584 : self::$defaultColumnWidths[
'Calibri'][11][
'width'];
585 $columnWidth = $columnWidth * $font->
getSize() / 11;
589 $columnWidth = (int) round($columnWidth);
652 $rowHeight = 12.75 * $font->
getSize() / 10;
708 $rowHeight = 15 * $font->
getSize() / 11;
759 $rowHeight = 12.75 * $font->
getSize() / 10;
766 $rowHeight = 15 * $font->
getSize() / 11;
An exception for terminatinating execution or to throw for unit testing.
static pixelsToCellDimension($pValue=0, PHPExcel_Style_Font $pDefaultFont)
Convert pixels to column width.
static setTrueTypeFontPath($pValue='')
Set the path to the folder containing .ttf files.
const CHARSET_ANSI_KOREAN_HANGUL
static fontSizeToPixels($fontSizeInPoints=11)
Calculate an (approximate) pixel size, based on a font points size.
const GEORGIA_BOLD_ITALIC
const CHARSET_ANSI_ARABIC
static getAutoSizeMethod()
Get autoSize method.
static getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation=0)
Get GD text width in pixels for a string of text in a certain font at a certain rotation angle.
const PALATINO_LINOTYPE_BOLD_ITALIC
const CHARSET_ANSI_JAPANESE_SHIFTJIS
const AUTOSIZE_METHOD_EXACT
const MICROSOFT_SANS_SERIF
const CHARSET_ANSI_KOREAN_JOHAB
const TIMES_NEW_ROMAN_ITALIC
static calculateColumnWidth(PHPExcel_Style_Font $font, $cellText='', $rotation=0, PHPExcel_Style_Font $defaultFont=null)
Calculate an (approximate) OpenXML column width, based on font size and text contained.
static getTrueTypeFontPath()
Get the path to the folder containing .ttf files.
const CHARSET_ANSI_CHINESE_TRADITIONAL
const LIBERATION_SANS_BOLD_ITALIC
const LUCIDA_SANS_UNICODE
const TREBUCHET_MS_ITALIC
const LIBERATION_SANS_BOLD
const COURIER_NEW_BOLD_ITALIC
static getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font=null, $rotation=0)
Get approximate width in pixels for a string of text in a certain font at a certain rotation angle.
const ARIAL
Font filenames.
static centimeterSizeToPixels($sizeInCm=1)
Calculate an (approximate) pixel size, based on centimeter size.
static getDefaultColumnWidthByFont(PHPExcel_Style_Font $font, $pPixels=false)
Get the effective column width for columns without a column dimension or column with width -1 For exa...
const AUTOSIZE_METHOD_APPROX
const CHARSET_ANSI_CHINESE_SIMIPLIFIED
const PALATINO_LINOTYPE_BOLD
static getCharsetFromFontName($name)
Returns the associated charset for the font name.
const CHARSET_ANSI_HEBREW
static getTrueTypeFontFileFromFont($font)
Returns the font path given the font.
const LIBERATION_SANS_ITALIC
const VERDANA_BOLD_ITALIC
const PALATINO_LINOTYPE_ITALIC
const TREBUCHET_MS_BOLD_ITALIC
static inchSizeToPixels($sizeInInch=1)
Calculate an (approximate) pixel size, based on inch size.
const CHARSET_SYSTEM_DEFAULT
static setAutoSizeMethod($pValue=self::AUTOSIZE_METHOD_APPROX)
Set autoSize method.
static getDefaultRowHeightByFont(PHPExcel_Style_Font $font)
Get the effective row height for rows without a row dimension or rows with height -1 For example,...
const CHARSET_ANSI_LATIN
Character set codes used by BIFF5-8 in Font records.
const CHARSET_ANSI_CYRILLIC
const CHARSET_OEM_LATIN_I
const CALIBRI_BOLD_ITALIC
const TIMES_NEW_ROMAN_BOLD
const CHARSET_APPLE_ROMAN
const CHARSET_ANSI_TURKISH
const CHARSET_ANSI_VIETNAMESE
const CHARSET_ANSI_BALTIC
const TIMES_NEW_ROMAN_BOLD_ITALIC
static $defaultColumnWidths
const CHARSET_ANSI_LATIN_II
static CountCharacters($value, $enc='UTF-8')
Get character count.