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;
214 return self::$autoSizeMethod;
230 self::$trueTypeFontPath = $pValue;
240 return self::$trueTypeFontPath;
255 $cellText = $cellText->getPlainText();
259 if (strpos($cellText,
"\n") !==
false) {
260 $lineTexts = explode(
"\n", $cellText);
261 $lineWidths =
array();
262 foreach ($lineTexts as $lineText) {
263 $lineWidths[] = self::calculateColumnWidth($font, $lineText, $rotation = 0, $defaultFont);
265 return max($lineWidths);
269 $approximate = self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX;
271 $columnWidthAdjust = ceil(self::getTextWidthPixelsExact(
'n', $font, 0) * 1.07);
275 $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation) + $columnWidthAdjust;
282 $columnWidthAdjust = self::getTextWidthPixelsApprox(
'n', $font, 0);
285 $columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation) + $columnWidthAdjust;
292 return round($columnWidth, 6);
305 if (!function_exists(
'imagettfbbox')) {
311 $fontFile = self::getTrueTypeFontFileFromFont($font);
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();
437 $bold ? ($italic ? self::ARIAL_BOLD_ITALIC : self::ARIAL_BOLD)
438 : ($italic ? self::ARIAL_ITALIC : self::ARIAL)
444 $bold ? ($italic ? self::CALIBRI_BOLD_ITALIC : self::CALIBRI_BOLD)
445 : ($italic ? self::CALIBRI_ITALIC : self::CALIBRI)
451 $bold ? ($italic ? self::COURIER_NEW_BOLD_ITALIC : self::COURIER_NEW_BOLD)
452 : ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW)
456 case 'Comic Sans MS':
458 $bold ? self::COMIC_SANS_MS_BOLD : self::COMIC_SANS_MS
464 $bold ? ($italic ? self::GEORGIA_BOLD_ITALIC : self::GEORGIA_BOLD)
465 : ($italic ? self::GEORGIA_ITALIC : self::GEORGIA)
470 $fontFile = self::IMPACT;
473 case 'Liberation Sans':
475 $bold ? ($italic ? self::LIBERATION_SANS_BOLD_ITALIC : self::LIBERATION_SANS_BOLD)
476 : ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS)
480 case 'Lucida Console':
481 $fontFile = self::LUCIDA_CONSOLE;
484 case 'Lucida Sans Unicode':
485 $fontFile = self::LUCIDA_SANS_UNICODE;
488 case 'Microsoft Sans Serif':
489 $fontFile = self::MICROSOFT_SANS_SERIF;
492 case 'Palatino Linotype':
494 $bold ? ($italic ? self::PALATINO_LINOTYPE_BOLD_ITALIC : self::PALATINO_LINOTYPE_BOLD)
495 : ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE)
500 $fontFile = self::SYMBOL;
505 $bold ? self::TAHOMA_BOLD : self::TAHOMA
509 case 'Times New Roman':
511 $bold ? ($italic ? self::TIMES_NEW_ROMAN_BOLD_ITALIC : self::TIMES_NEW_ROMAN_BOLD)
512 : ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN)
518 $bold ? ($italic ? self::TREBUCHET_MS_BOLD_ITALIC : self::TREBUCHET_MS_BOLD)
519 : ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS)
525 $bold ? ($italic ? self::VERDANA_BOLD_ITALIC : self::VERDANA_BOLD)
526 : ($italic ? self::VERDANA_ITALIC : self::VERDANA)
535 $fontFile = self::$trueTypeFontPath . $fontFile;
538 if (!file_exists($fontFile)) {
555 case 'EucrosiaUPC':
return self::CHARSET_ANSI_THAI;
556 case 'Wingdings':
return self::CHARSET_SYMBOL;
557 case 'Wingdings 2':
return self::CHARSET_SYMBOL;
558 case 'Wingdings 3':
return self::CHARSET_SYMBOL;
559 default:
return self::CHARSET_ANSI_LATIN;
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;
const CHARSET_ANSI_VIETNAMESE
static centimeterSizeToPixels($sizeInCm=1)
Calculate an (approximate) pixel size, based on centimeter size.
const AUTOSIZE_METHOD_APPROX
static getDefaultRowHeightByFont(PHPExcel_Style_Font $font)
Get the effective row height for rows without a row dimension or rows with height -1 For example...
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.
const CHARSET_OEM_LATIN_I
const CHARSET_ANSI_LATIN
Character set codes used by BIFF5-8 in Font records.
const CHARSET_APPLE_ROMAN
const CHARSET_ANSI_CYRILLIC
const PALATINO_LINOTYPE_BOLD_ITALIC
const TIMES_NEW_ROMAN_BOLD_ITALIC
const CHARSET_ANSI_HEBREW
static getCharsetFromFontName($name)
Returns the associated charset for the font name.
const GEORGIA_BOLD_ITALIC
const MICROSOFT_SANS_SERIF
const CHARSET_ANSI_KOREAN_JOHAB
const VERDANA_BOLD_ITALIC
const LUCIDA_SANS_UNICODE
static inchSizeToPixels($sizeInInch=1)
Calculate an (approximate) pixel size, based on inch size.
const COURIER_NEW_BOLD_ITALIC
const CHARSET_ANSI_CHINESE_TRADITIONAL
const AUTOSIZE_METHOD_EXACT
const LIBERATION_SANS_BOLD_ITALIC
static $defaultColumnWidths
const TIMES_NEW_ROMAN_ITALIC
const CHARSET_ANSI_CHINESE_SIMIPLIFIED
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...
static getTrueTypeFontFileFromFont($font)
Returns the font path given the font.
const PALATINO_LINOTYPE_BOLD
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 CHARSET_ANSI_LATIN_II
static getTrueTypeFontPath()
Get the path to the folder containing .ttf files.
static fontSizeToPixels($fontSizeInPoints=11)
Calculate an (approximate) pixel size, based on a font points size.
Create styles array
The data for the language used.
const CHARSET_ANSI_ARABIC
const ARIAL
Font filenames.
static getAutoSizeMethod()
Get autoSize method.
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 LIBERATION_SANS_BOLD
static pixelsToCellDimension($pValue=0, PHPExcel_Style_Font $pDefaultFont)
Convert pixels to column width.
const TREBUCHET_MS_BOLD_ITALIC
const CHARSET_ANSI_BALTIC
const CHARSET_ANSI_KOREAN_HANGUL
const LIBERATION_SANS_ITALIC
const CHARSET_ANSI_TURKISH
const CHARSET_ANSI_JAPANESE_SHIFTJIS
const CHARSET_SYSTEM_DEFAULT
const TREBUCHET_MS_ITALIC
static setTrueTypeFontPath($pValue='')
Set the path to the folder containing .ttf files.
static CountCharacters($value, $enc='UTF-8')
Get character count.
static setAutoSizeMethod($pValue=self::AUTOSIZE_METHOD_APPROX)
Set autoSize method.
const PALATINO_LINOTYPE_ITALIC
const TIMES_NEW_ROMAN_BOLD
const CALIBRI_BOLD_ITALIC