ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
PHPExcel_Shared_Font Class Reference
+ Collaboration diagram for PHPExcel_Shared_Font:

Static Public Member Functions

static setAutoSizeMethod ($pValue=self::AUTOSIZE_METHOD_APPROX)
 Set autoSize method. More...
 
static getAutoSizeMethod ()
 Get autoSize method. More...
 
static setTrueTypeFontPath ($pValue='')
 Set the path to the folder containing .ttf files. More...
 
static getTrueTypeFontPath ()
 Get the path to the folder containing .ttf files. More...
 
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. More...
 
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. More...
 
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. More...
 
static fontSizeToPixels ($fontSizeInPoints=11)
 Calculate an (approximate) pixel size, based on a font points size. More...
 
static inchSizeToPixels ($sizeInInch=1)
 Calculate an (approximate) pixel size, based on inch size. More...
 
static centimeterSizeToPixels ($sizeInCm=1)
 Calculate an (approximate) pixel size, based on centimeter size. More...
 
static getTrueTypeFontFileFromFont ($font)
 Returns the font path given the font. More...
 
static getCharsetFromFontName ($name)
 Returns the associated charset for the font name. More...
 
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 example, for Calibri 11 this is 9.140625 (64 px) More...
 
static getDefaultRowHeightByFont (PHPExcel_Style_Font $font)
 Get the effective row height for rows without a row dimension or rows with height -1 For example, for Calibri 11 this is 15 points. More...
 

Data Fields

const AUTOSIZE_METHOD_APPROX = 'approx'
 
const AUTOSIZE_METHOD_EXACT = 'exact'
 
const CHARSET_ANSI_LATIN = 0x00
 Character set codes used by BIFF5-8 in Font records. More...
 
const CHARSET_SYSTEM_DEFAULT = 0x01
 
const CHARSET_SYMBOL = 0x02
 
const CHARSET_APPLE_ROMAN = 0x4D
 
const CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80
 
const CHARSET_ANSI_KOREAN_HANGUL = 0x81
 
const CHARSET_ANSI_KOREAN_JOHAB = 0x82
 
const CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86
 
const CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88
 
const CHARSET_ANSI_GREEK = 0xA1
 
const CHARSET_ANSI_TURKISH = 0xA2
 
const CHARSET_ANSI_VIETNAMESE = 0xA3
 
const CHARSET_ANSI_HEBREW = 0xB1
 
const CHARSET_ANSI_ARABIC = 0xB2
 
const CHARSET_ANSI_BALTIC = 0xBA
 
const CHARSET_ANSI_CYRILLIC = 0xCC
 
const CHARSET_ANSI_THAI = 0xDD
 
const CHARSET_ANSI_LATIN_II = 0xEE
 
const CHARSET_OEM_LATIN_I = 0xFF
 
const ARIAL = 'arial.ttf'
 Font filenames. More...
 
const ARIAL_BOLD = 'arialbd.ttf'
 
const ARIAL_ITALIC = 'ariali.ttf'
 
const ARIAL_BOLD_ITALIC = 'arialbi.ttf'
 
const CALIBRI = 'CALIBRI.TTF'
 
const CALIBRI_BOLD = 'CALIBRIB.TTF'
 
const CALIBRI_ITALIC = 'CALIBRII.TTF'
 
const CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF'
 
const COMIC_SANS_MS = 'comic.ttf'
 
const COMIC_SANS_MS_BOLD = 'comicbd.ttf'
 
const COURIER_NEW = 'cour.ttf'
 
const COURIER_NEW_BOLD = 'courbd.ttf'
 
const COURIER_NEW_ITALIC = 'couri.ttf'
 
const COURIER_NEW_BOLD_ITALIC = 'courbi.ttf'
 
const GEORGIA = 'georgia.ttf'
 
const GEORGIA_BOLD = 'georgiab.ttf'
 
const GEORGIA_ITALIC = 'georgiai.ttf'
 
const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf'
 
const IMPACT = 'impact.ttf'
 
const LIBERATION_SANS = 'LiberationSans-Regular.ttf'
 
const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf'
 
const LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf'
 
const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf'
 
const LUCIDA_CONSOLE = 'lucon.ttf'
 
const LUCIDA_SANS_UNICODE = 'l_10646.ttf'
 
const MICROSOFT_SANS_SERIF = 'micross.ttf'
 
const PALATINO_LINOTYPE = 'pala.ttf'
 
const PALATINO_LINOTYPE_BOLD = 'palab.ttf'
 
const PALATINO_LINOTYPE_ITALIC = 'palai.ttf'
 
const PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf'
 
const SYMBOL = 'symbol.ttf'
 
const TAHOMA = 'tahoma.ttf'
 
const TAHOMA_BOLD = 'tahomabd.ttf'
 
const TIMES_NEW_ROMAN = 'times.ttf'
 
const TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf'
 
const TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf'
 
const TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf'
 
const TREBUCHET_MS = 'trebuc.ttf'
 
const TREBUCHET_MS_BOLD = 'trebucbd.ttf'
 
const TREBUCHET_MS_ITALIC = 'trebucit.ttf'
 
const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf'
 
const VERDANA = 'verdana.ttf'
 
const VERDANA_BOLD = 'verdanab.ttf'
 
const VERDANA_ITALIC = 'verdanai.ttf'
 
const VERDANA_BOLD_ITALIC = 'verdanaz.ttf'
 

Static Public Attributes

static $defaultColumnWidths
 

Static Private Attributes

static $_autoSizeMethods
 
static $autoSizeMethod = self::AUTOSIZE_METHOD_APPROX
 
static $trueTypeFontPath = null
 

Detailed Description

Definition at line 36 of file Font.php.

Member Function Documentation

◆ calculateColumnWidth()

static PHPExcel_Shared_Font::calculateColumnWidth ( PHPExcel_Style_Font  $font,
  $cellText = '',
  $rotation = 0,
PHPExcel_Style_Font  $defaultFont = null 
)
static

Calculate an (approximate) OpenXML column width, based on font size and text contained.

Parameters
PHPExcel_Style_Font$fontFont object
PHPExcel_RichText | string$cellTextText to calculate width
integer$rotationRotation angle
PHPExcel_Style_Font | NULL$defaultFontFont object
Returns
integer Column width

Definition at line 252 of file Font.php.

252 {
253 // If it is rich text, use plain text
254 if ($cellText instanceof PHPExcel_RichText) {
255 $cellText = $cellText->getPlainText();
256 }
257
258 // Special case if there are one or more newline characters ("\n")
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);
264 }
265 return max($lineWidths); // width of longest line in cell
266 }
267
268 // Try to get the exact text width in pixels
269 $approximate = self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX;
270 if (!$approximate) {
271 $columnWidthAdjust = ceil(self::getTextWidthPixelsExact('n', $font, 0) * 1.07);
272 try {
273 // Width of text in pixels excl. padding
274 // and addition because Excel adds some padding, just use approx width of 'n' glyph
275 $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation) + $columnWidthAdjust;
276 } catch (PHPExcel_Exception $e) {
277 $approximate = true;
278 }
279 }
280
281 if ($approximate) {
282 $columnWidthAdjust = self::getTextWidthPixelsApprox('n', $font, 0);
283 // Width of text in pixels excl. padding, approximation
284 // and addition because Excel adds some padding, just use approx width of 'n' glyph
285 $columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation) + $columnWidthAdjust;
286 }
287
288 // Convert from pixel width to column width
289 $columnWidth = PHPExcel_Shared_Drawing::pixelsToCellDimension($columnWidth, $defaultFont);
290
291 // Return
292 return round($columnWidth, 6);
293 }
static pixelsToCellDimension($pValue=0, PHPExcel_Style_Font $pDefaultFont)
Convert pixels to column width.
Definition: Drawing.php:71
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.
Definition: Font.php:304
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.
Definition: Font.php:252
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.
Definition: Font.php:338
const AUTOSIZE_METHOD_APPROX
Definition: Font.php:39

References AUTOSIZE_METHOD_APPROX, calculateColumnWidth(), getTextWidthPixelsApprox(), getTextWidthPixelsExact(), and PHPExcel_Shared_Drawing\pixelsToCellDimension().

Referenced by calculateColumnWidth(), and PHPExcel_Worksheet\calculateColumnWidths().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ centimeterSizeToPixels()

static PHPExcel_Shared_Font::centimeterSizeToPixels (   $sizeInCm = 1)
static

Calculate an (approximate) pixel size, based on centimeter size.

Parameters
int$sizeInCmFont size (in centimeters)
Returns
int Size (in pixels)

Definition at line 414 of file Font.php.

414 {
415 return ($sizeInCm * 37.795275591);
416 }

Referenced by PHPExcel_Reader_Excel2007\toCSSArray().

+ Here is the caller graph for this function:

◆ fontSizeToPixels()

static PHPExcel_Shared_Font::fontSizeToPixels (   $fontSizeInPoints = 11)
static

Calculate an (approximate) pixel size, based on a font points size.

Parameters
int$fontSizeInPointsFont size (in points)
Returns
int Font size (in pixels)

Definition at line 394 of file Font.php.

394 {
395 return (int) ((4 / 3) * $fontSizeInPoints);
396 }

Referenced by PHPExcel_Shared_Excel5\sizeRow(), and PHPExcel_Reader_Excel2007\toCSSArray().

+ Here is the caller graph for this function:

◆ getAutoSizeMethod()

static PHPExcel_Shared_Font::getAutoSizeMethod ( )
static

Get autoSize method.

Returns
string

Definition at line 212 of file Font.php.

213 {
215 }
static $autoSizeMethod
Definition: Font.php:135

References $autoSizeMethod.

◆ getCharsetFromFontName()

static PHPExcel_Shared_Font::getCharsetFromFontName (   $name)
static

Returns the associated charset for the font name.

Parameters
string$nameFont name
Returns
int Character set code

Definition at line 551 of file Font.php.

552 {
553 switch ($name) {
554 // Add more cases. Check FONT records in real Excel files.
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;
560 }
561 }
const CHARSET_SYMBOL
Definition: Font.php:50
const CHARSET_ANSI_THAI
Definition: Font.php:64
const CHARSET_ANSI_LATIN
Character set codes used by BIFF5-8 in Font records.
Definition: Font.php:48

References CHARSET_ANSI_LATIN, CHARSET_ANSI_THAI, and CHARSET_SYMBOL.

Referenced by PHPExcel_Writer_Excel5_Font\writeFont().

+ Here is the caller graph for this function:

◆ getDefaultColumnWidthByFont()

static PHPExcel_Shared_Font::getDefaultColumnWidthByFont ( PHPExcel_Style_Font  $font,
  $pPixels = false 
)
static

Get the effective column width for columns without a column dimension or column with width -1 For example, for Calibri 11 this is 9.140625 (64 px)

Parameters
PHPExcel_Style_Font$fontThe workbooks default font
boolean$pPixelstrue = return column width in pixels, false = return in OOXML units
Returns
mixed Column width

Definition at line 571 of file Font.php.

572 {
573 if (isset(self::$defaultColumnWidths[$font->getName()][$font->getSize()])) {
574 // Exact width can be determined
575 $columnWidth = $pPixels ?
576 self::$defaultColumnWidths[$font->getName()][$font->getSize()]['px']
577 : self::$defaultColumnWidths[$font->getName()][$font->getSize()]['width'];
578
579 } else {
580 // We don't have data for this particular font and size, use approximation by
581 // extrapolating from Calibri 11
582 $columnWidth = $pPixels ?
583 self::$defaultColumnWidths['Calibri'][11]['px']
584 : self::$defaultColumnWidths['Calibri'][11]['width'];
585 $columnWidth = $columnWidth * $font->getSize() / 11;
586
587 // Round pixels to closest integer
588 if ($pPixels) {
589 $columnWidth = (int) round($columnWidth);
590 }
591 }
592
593 return $columnWidth;
594 }
getSize()
Get Size.
Definition: Font.php:262
getName()
Get Name.
Definition: Font.php:231

References PHPExcel_Style_Font\getName(), and PHPExcel_Style_Font\getSize().

Referenced by PHPExcel_Writer_Excel5_Worksheet\close(), and PHPExcel_Shared_Excel5\sizeCol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultRowHeightByFont()

static PHPExcel_Shared_Font::getDefaultRowHeightByFont ( PHPExcel_Style_Font  $font)
static

Get the effective row height for rows without a row dimension or rows with height -1 For example, for Calibri 11 this is 15 points.

Parameters
PHPExcel_Style_Font$fontThe workbooks default font
Returns
float Row height in points

Definition at line 603 of file Font.php.

604 {
605 switch ($font->getName()) {
606 case 'Arial':
607 switch ($font->getSize()) {
608 case 10:
609 // inspection of Arial 10 workbook says 12.75pt ~17px
610 $rowHeight = 12.75;
611 break;
612
613 case 9:
614 // inspection of Arial 9 workbook says 12.00pt ~16px
615 $rowHeight = 12;
616 break;
617
618 case 8:
619 // inspection of Arial 8 workbook says 11.25pt ~15px
620 $rowHeight = 11.25;
621 break;
622
623 case 7:
624 // inspection of Arial 7 workbook says 9.00pt ~12px
625 $rowHeight = 9;
626 break;
627
628 case 6:
629 case 5:
630 // inspection of Arial 5,6 workbook says 8.25pt ~11px
631 $rowHeight = 8.25;
632 break;
633
634 case 4:
635 // inspection of Arial 4 workbook says 6.75pt ~9px
636 $rowHeight = 6.75;
637 break;
638
639 case 3:
640 // inspection of Arial 3 workbook says 6.00pt ~8px
641 $rowHeight = 6;
642 break;
643
644 case 2:
645 case 1:
646 // inspection of Arial 1,2 workbook says 5.25pt ~7px
647 $rowHeight = 5.25;
648 break;
649
650 default:
651 // use Arial 10 workbook as an approximation, extrapolation
652 $rowHeight = 12.75 * $font->getSize() / 10;
653 break;
654 }
655 break;
656
657 case 'Calibri':
658 switch ($font->getSize()) {
659 case 11:
660 // inspection of Calibri 11 workbook says 15.00pt ~20px
661 $rowHeight = 15;
662 break;
663
664 case 10:
665 // inspection of Calibri 10 workbook says 12.75pt ~17px
666 $rowHeight = 12.75;
667 break;
668
669 case 9:
670 // inspection of Calibri 9 workbook says 12.00pt ~16px
671 $rowHeight = 12;
672 break;
673
674 case 8:
675 // inspection of Calibri 8 workbook says 11.25pt ~15px
676 $rowHeight = 11.25;
677 break;
678
679 case 7:
680 // inspection of Calibri 7 workbook says 9.00pt ~12px
681 $rowHeight = 9;
682 break;
683
684 case 6:
685 case 5:
686 // inspection of Calibri 5,6 workbook says 8.25pt ~11px
687 $rowHeight = 8.25;
688 break;
689
690 case 4:
691 // inspection of Calibri 4 workbook says 6.75pt ~9px
692 $rowHeight = 6.75;
693 break;
694
695 case 3:
696 // inspection of Calibri 3 workbook says 6.00pt ~8px
697 $rowHeight = 6.00;
698 break;
699
700 case 2:
701 case 1:
702 // inspection of Calibri 1,2 workbook says 5.25pt ~7px
703 $rowHeight = 5.25;
704 break;
705
706 default:
707 // use Calibri 11 workbook as an approximation, extrapolation
708 $rowHeight = 15 * $font->getSize() / 11;
709 break;
710 }
711 break;
712
713 case 'Verdana':
714 switch ($font->getSize()) {
715 case 10:
716 // inspection of Verdana 10 workbook says 12.75pt ~17px
717 $rowHeight = 12.75;
718 break;
719
720 case 9:
721 // inspection of Verdana 9 workbook says 11.25pt ~15px
722 $rowHeight = 11.25;
723 break;
724
725 case 8:
726 // inspection of Verdana 8 workbook says 10.50pt ~14px
727 $rowHeight = 10.50;
728 break;
729
730 case 7:
731 // inspection of Verdana 7 workbook says 9.00pt ~12px
732 $rowHeight = 9.00;
733 break;
734
735 case 6:
736 case 5:
737 // inspection of Verdana 5,6 workbook says 8.25pt ~11px
738 $rowHeight = 8.25;
739 break;
740
741 case 4:
742 // inspection of Verdana 4 workbook says 6.75pt ~9px
743 $rowHeight = 6.75;
744 break;
745
746 case 3:
747 // inspection of Verdana 3 workbook says 6.00pt ~8px
748 $rowHeight = 6;
749 break;
750
751 case 2:
752 case 1:
753 // inspection of Verdana 1,2 workbook says 5.25pt ~7px
754 $rowHeight = 5.25;
755 break;
756
757 default:
758 // use Verdana 10 workbook as an approximation, extrapolation
759 $rowHeight = 12.75 * $font->getSize() / 10;
760 break;
761 }
762 break;
763
764 default:
765 // just use Calibri as an approximation
766 $rowHeight = 15 * $font->getSize() / 11;
767 break;
768 }
769
770 return $rowHeight;
771 }

References PHPExcel_Style_Font\getName(), and PHPExcel_Style_Font\getSize().

Referenced by PHPExcel_Writer_HTML\buildCSS(), and PHPExcel_Shared_Excel5\sizeRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTextWidthPixelsApprox()

static PHPExcel_Shared_Font::getTextWidthPixelsApprox (   $columnText,
PHPExcel_Style_Font  $font = null,
  $rotation = 0 
)
static

Get approximate width in pixels for a string of text in a certain font at a certain rotation angle.

Parameters
string$columnText
PHPExcel_Style_Font$font
int$rotation
Returns
int Text width in pixels (no padding added)

Definition at line 338 of file Font.php.

339 {
340 $fontName = $font->getName();
341 $fontSize = $font->getSize();
342
343 // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.
344 switch ($fontName) {
345 case 'Calibri':
346 // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.
347 $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
348 $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
349 break;
350
351 case 'Arial':
352 // value 7 was found via interpolation by inspecting real Excel files with Arial 10 font.
353// $columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText));
354 // value 8 was set because of experience in different exports at Arial 10 font.
355 $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
356 $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
357 break;
358
359 case 'Verdana':
360 // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.
361 $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
362 $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
363 break;
364
365 default:
366 // just assume Calibri
367 $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
368 $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
369 break;
370 }
371
372 // Calculate approximate rotated column width
373 if ($rotation !== 0) {
374 if ($rotation == -165) {
375 // stacked text
376 $columnWidth = 4; // approximation
377 } else {
378 // rotated text
379 $columnWidth = $columnWidth * cos(deg2rad($rotation))
380 + $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation
381 }
382 }
383
384 // pixel width is an integer
385 return (int) $columnWidth;
386 }
static CountCharacters($value, $enc='UTF-8')
Get character count.
Definition: String.php:550

References PHPExcel_Shared_String\CountCharacters().

Referenced by calculateColumnWidth().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTextWidthPixelsExact()

static PHPExcel_Shared_Font::getTextWidthPixelsExact (   $text,
PHPExcel_Style_Font  $font,
  $rotation = 0 
)
static

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

Parameters
string$text
PHPExcel_Style_Font
int$rotation
Returns
int
Exceptions
PHPExcel_Exception

Definition at line 304 of file Font.php.

304 {
305 if (!function_exists('imagettfbbox')) {
306 throw new PHPExcel_Exception('GD library needs to be enabled');
307 }
308
309 // font size should really be supplied in pixels in GD2,
310 // but since GD2 seems to assume 72dpi, pixels and points are the same
311 $fontFile = self::getTrueTypeFontFileFromFont($font);
312 $textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text);
313
314 // Get corners positions
315 $lowerLeftCornerX = $textBox[0];
316// $lowerLeftCornerY = $textBox[1];
317 $lowerRightCornerX = $textBox[2];
318// $lowerRightCornerY = $textBox[3];
319 $upperRightCornerX = $textBox[4];
320// $upperRightCornerY = $textBox[5];
321 $upperLeftCornerX = $textBox[6];
322// $upperLeftCornerY = $textBox[7];
323
324 // Consider the rotation when calculating the width
325 $textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX);
326
327 return $textWidth;
328 }
static getTrueTypeFontFileFromFont($font)
Returns the font path given the font.
Definition: Font.php:424
$text

References $text, PHPExcel_Style_Font\getSize(), and getTrueTypeFontFileFromFont().

Referenced by calculateColumnWidth().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTrueTypeFontFileFromFont()

static PHPExcel_Shared_Font::getTrueTypeFontFileFromFont (   $font)
static

Returns the font path given the font.

Parameters
PHPExcel_Style_Font
Returns
string Path to TrueType font file

Definition at line 424 of file Font.php.

424 {
425 if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) {
426 throw new PHPExcel_Exception('Valid directory to TrueType Font files not specified');
427 }
428
429 $name = $font->getName();
430 $bold = $font->getBold();
431 $italic = $font->getItalic();
432
433 // Check if we can map font to true type font file
434 switch ($name) {
435 case 'Arial':
436 $fontFile = (
437 $bold ? ($italic ? self::ARIAL_BOLD_ITALIC : self::ARIAL_BOLD)
438 : ($italic ? self::ARIAL_ITALIC : self::ARIAL)
439 );
440 break;
441
442 case 'Calibri':
443 $fontFile = (
445 : ($italic ? self::CALIBRI_ITALIC : self::CALIBRI)
446 );
447 break;
448
449 case 'Courier New':
450 $fontFile = (
452 : ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW)
453 );
454 break;
455
456 case 'Comic Sans MS':
457 $fontFile = (
459 );
460 break;
461
462 case 'Georgia':
463 $fontFile = (
465 : ($italic ? self::GEORGIA_ITALIC : self::GEORGIA)
466 );
467 break;
468
469 case 'Impact':
470 $fontFile = self::IMPACT;
471 break;
472
473 case 'Liberation Sans':
474 $fontFile = (
476 : ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS)
477 );
478 break;
479
480 case 'Lucida Console':
481 $fontFile = self::LUCIDA_CONSOLE;
482 break;
483
484 case 'Lucida Sans Unicode':
485 $fontFile = self::LUCIDA_SANS_UNICODE;
486 break;
487
488 case 'Microsoft Sans Serif':
489 $fontFile = self::MICROSOFT_SANS_SERIF;
490 break;
491
492 case 'Palatino Linotype':
493 $fontFile = (
495 : ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE)
496 );
497 break;
498
499 case 'Symbol':
500 $fontFile = self::SYMBOL;
501 break;
502
503 case 'Tahoma':
504 $fontFile = (
506 );
507 break;
508
509 case 'Times New Roman':
510 $fontFile = (
512 : ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN)
513 );
514 break;
515
516 case 'Trebuchet MS':
517 $fontFile = (
519 : ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS)
520 );
521 break;
522
523 case 'Verdana':
524 $fontFile = (
526 : ($italic ? self::VERDANA_ITALIC : self::VERDANA)
527 );
528 break;
529
530 default:
531 throw new PHPExcel_Exception('Unknown font name "'. $name .'". Cannot map to TrueType font file');
532 break;
533 }
534
535 $fontFile = self::$trueTypeFontPath . $fontFile;
536
537 // Check if file actually exists
538 if (!file_exists($fontFile)) {
539 throw New PHPExcel_Exception('TrueType Font file not found');
540 }
541
542 return $fontFile;
543 }
const COMIC_SANS_MS
Definition: Font.php:80
const GEORGIA_BOLD_ITALIC
Definition: Font.php:91
const ARIAL_BOLD_ITALIC
Definition: Font.php:73
const PALATINO_LINOTYPE_BOLD_ITALIC
Definition: Font.php:108
const MICROSOFT_SANS_SERIF
Definition: Font.php:103
const CALIBRI_BOLD
Definition: Font.php:76
const COMIC_SANS_MS_BOLD
Definition: Font.php:81
const LIBERATION_SANS_BOLD_ITALIC
Definition: Font.php:98
const COURIER_NEW_BOLD
Definition: Font.php:84
const LUCIDA_SANS_UNICODE
Definition: Font.php:101
const LIBERATION_SANS_BOLD
Definition: Font.php:96
const COURIER_NEW_BOLD_ITALIC
Definition: Font.php:86
const VERDANA_BOLD
Definition: Font.php:126
const PALATINO_LINOTYPE_BOLD
Definition: Font.php:106
const ARIAL_BOLD
Definition: Font.php:71
const LUCIDA_CONSOLE
Definition: Font.php:100
const VERDANA_BOLD_ITALIC
Definition: Font.php:128
const TREBUCHET_MS_BOLD_ITALIC
Definition: Font.php:123
const GEORGIA_BOLD
Definition: Font.php:89
const CALIBRI_BOLD_ITALIC
Definition: Font.php:78
const TREBUCHET_MS_BOLD
Definition: Font.php:121
const TIMES_NEW_ROMAN_BOLD
Definition: Font.php:116
const TIMES_NEW_ROMAN_BOLD_ITALIC
Definition: Font.php:118

References ARIAL_BOLD, ARIAL_BOLD_ITALIC, CALIBRI_BOLD, CALIBRI_BOLD_ITALIC, COMIC_SANS_MS, COMIC_SANS_MS_BOLD, COURIER_NEW_BOLD, COURIER_NEW_BOLD_ITALIC, GEORGIA_BOLD, GEORGIA_BOLD_ITALIC, IMPACT, LIBERATION_SANS_BOLD, LIBERATION_SANS_BOLD_ITALIC, LUCIDA_CONSOLE, LUCIDA_SANS_UNICODE, MICROSOFT_SANS_SERIF, PALATINO_LINOTYPE_BOLD, PALATINO_LINOTYPE_BOLD_ITALIC, SYMBOL, TAHOMA, TAHOMA_BOLD, TIMES_NEW_ROMAN_BOLD, TIMES_NEW_ROMAN_BOLD_ITALIC, TREBUCHET_MS_BOLD, TREBUCHET_MS_BOLD_ITALIC, VERDANA_BOLD, and VERDANA_BOLD_ITALIC.

Referenced by getTextWidthPixelsExact().

+ Here is the caller graph for this function:

◆ getTrueTypeFontPath()

static PHPExcel_Shared_Font::getTrueTypeFontPath ( )
static

Get the path to the folder containing .ttf files.

Returns
string

Definition at line 238 of file Font.php.

239 {
241 }
static $trueTypeFontPath
Definition: Font.php:142

References $trueTypeFontPath.

◆ inchSizeToPixels()

static PHPExcel_Shared_Font::inchSizeToPixels (   $sizeInInch = 1)
static

Calculate an (approximate) pixel size, based on inch size.

Parameters
int$sizeInInchFont size (in inch)
Returns
int Size (in pixels)

Definition at line 404 of file Font.php.

404 {
405 return ($sizeInInch * 96);
406 }

Referenced by PHPExcel_Reader_Excel2007\toCSSArray().

+ Here is the caller graph for this function:

◆ setAutoSizeMethod()

static PHPExcel_Shared_Font::setAutoSizeMethod (   $pValue = self::AUTOSIZE_METHOD_APPROX)
static

Set autoSize method.

Parameters
string$pValue
Returns
boolean Success or failure

Definition at line 197 of file Font.php.

198 {
199 if (!in_array($pValue,self::$_autoSizeMethods)) {
200 return FALSE;
201 }
202 self::$autoSizeMethod = $pValue;
203
204 return TRUE;
205 }

◆ setTrueTypeFontPath()

static PHPExcel_Shared_Font::setTrueTypeFontPath (   $pValue = '')
static

Set the path to the folder containing .ttf files.

There should be a trailing slash. Typical locations on variout some platforms:

  • C:/Windows/Fonts/
  • /usr/share/fonts/truetype/
  • ~/.fonts/
Parameters
string$pValue

Definition at line 228 of file Font.php.

229 {
230 self::$trueTypeFontPath = $pValue;
231 }

Field Documentation

◆ $_autoSizeMethods

PHPExcel_Shared_Font::$_autoSizeMethods
staticprivate
Initial value:
= array(
self::AUTOSIZE_METHOD_APPROX,
self::AUTOSIZE_METHOD_EXACT,
)

Definition at line 42 of file Font.php.

◆ $autoSizeMethod

PHPExcel_Shared_Font::$autoSizeMethod = self::AUTOSIZE_METHOD_APPROX
staticprivate

Definition at line 135 of file Font.php.

Referenced by getAutoSizeMethod().

◆ $defaultColumnWidths

PHPExcel_Shared_Font::$defaultColumnWidths
static

◆ $trueTypeFontPath

PHPExcel_Shared_Font::$trueTypeFontPath = null
staticprivate

Definition at line 142 of file Font.php.

Referenced by getTrueTypeFontPath().

◆ ARIAL

const PHPExcel_Shared_Font::ARIAL = 'arial.ttf'

Font filenames.

Definition at line 70 of file Font.php.

◆ ARIAL_BOLD

const PHPExcel_Shared_Font::ARIAL_BOLD = 'arialbd.ttf'

Definition at line 71 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ ARIAL_BOLD_ITALIC

const PHPExcel_Shared_Font::ARIAL_BOLD_ITALIC = 'arialbi.ttf'

Definition at line 73 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ ARIAL_ITALIC

const PHPExcel_Shared_Font::ARIAL_ITALIC = 'ariali.ttf'

Definition at line 72 of file Font.php.

◆ AUTOSIZE_METHOD_APPROX

const PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX = 'approx'

◆ AUTOSIZE_METHOD_EXACT

const PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT = 'exact'

Definition at line 40 of file Font.php.

Referenced by FontTest\testSetAutoSizeMethod().

◆ CALIBRI

const PHPExcel_Shared_Font::CALIBRI = 'CALIBRI.TTF'

Definition at line 75 of file Font.php.

◆ CALIBRI_BOLD

const PHPExcel_Shared_Font::CALIBRI_BOLD = 'CALIBRIB.TTF'

Definition at line 76 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ CALIBRI_BOLD_ITALIC

const PHPExcel_Shared_Font::CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF'

Definition at line 78 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ CALIBRI_ITALIC

const PHPExcel_Shared_Font::CALIBRI_ITALIC = 'CALIBRII.TTF'

Definition at line 77 of file Font.php.

◆ CHARSET_ANSI_ARABIC

const PHPExcel_Shared_Font::CHARSET_ANSI_ARABIC = 0xB2

Definition at line 61 of file Font.php.

◆ CHARSET_ANSI_BALTIC

const PHPExcel_Shared_Font::CHARSET_ANSI_BALTIC = 0xBA

Definition at line 62 of file Font.php.

◆ CHARSET_ANSI_CHINESE_SIMIPLIFIED

const PHPExcel_Shared_Font::CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86

Definition at line 55 of file Font.php.

◆ CHARSET_ANSI_CHINESE_TRADITIONAL

const PHPExcel_Shared_Font::CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88

Definition at line 56 of file Font.php.

◆ CHARSET_ANSI_CYRILLIC

const PHPExcel_Shared_Font::CHARSET_ANSI_CYRILLIC = 0xCC

Definition at line 63 of file Font.php.

◆ CHARSET_ANSI_GREEK

const PHPExcel_Shared_Font::CHARSET_ANSI_GREEK = 0xA1

Definition at line 57 of file Font.php.

◆ CHARSET_ANSI_HEBREW

const PHPExcel_Shared_Font::CHARSET_ANSI_HEBREW = 0xB1

Definition at line 60 of file Font.php.

◆ CHARSET_ANSI_JAPANESE_SHIFTJIS

const PHPExcel_Shared_Font::CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80

Definition at line 52 of file Font.php.

◆ CHARSET_ANSI_KOREAN_HANGUL

const PHPExcel_Shared_Font::CHARSET_ANSI_KOREAN_HANGUL = 0x81

Definition at line 53 of file Font.php.

◆ CHARSET_ANSI_KOREAN_JOHAB

const PHPExcel_Shared_Font::CHARSET_ANSI_KOREAN_JOHAB = 0x82

Definition at line 54 of file Font.php.

◆ CHARSET_ANSI_LATIN

const PHPExcel_Shared_Font::CHARSET_ANSI_LATIN = 0x00

Character set codes used by BIFF5-8 in Font records.

Definition at line 48 of file Font.php.

Referenced by getCharsetFromFontName().

◆ CHARSET_ANSI_LATIN_II

const PHPExcel_Shared_Font::CHARSET_ANSI_LATIN_II = 0xEE

Definition at line 65 of file Font.php.

◆ CHARSET_ANSI_THAI

const PHPExcel_Shared_Font::CHARSET_ANSI_THAI = 0xDD

Definition at line 64 of file Font.php.

Referenced by getCharsetFromFontName().

◆ CHARSET_ANSI_TURKISH

const PHPExcel_Shared_Font::CHARSET_ANSI_TURKISH = 0xA2

Definition at line 58 of file Font.php.

◆ CHARSET_ANSI_VIETNAMESE

const PHPExcel_Shared_Font::CHARSET_ANSI_VIETNAMESE = 0xA3

Definition at line 59 of file Font.php.

◆ CHARSET_APPLE_ROMAN

const PHPExcel_Shared_Font::CHARSET_APPLE_ROMAN = 0x4D

Definition at line 51 of file Font.php.

◆ CHARSET_OEM_LATIN_I

const PHPExcel_Shared_Font::CHARSET_OEM_LATIN_I = 0xFF

Definition at line 66 of file Font.php.

◆ CHARSET_SYMBOL

const PHPExcel_Shared_Font::CHARSET_SYMBOL = 0x02

Definition at line 50 of file Font.php.

Referenced by getCharsetFromFontName().

◆ CHARSET_SYSTEM_DEFAULT

const PHPExcel_Shared_Font::CHARSET_SYSTEM_DEFAULT = 0x01

Definition at line 49 of file Font.php.

◆ COMIC_SANS_MS

const PHPExcel_Shared_Font::COMIC_SANS_MS = 'comic.ttf'

Definition at line 80 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ COMIC_SANS_MS_BOLD

const PHPExcel_Shared_Font::COMIC_SANS_MS_BOLD = 'comicbd.ttf'

Definition at line 81 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ COURIER_NEW

const PHPExcel_Shared_Font::COURIER_NEW = 'cour.ttf'

Definition at line 83 of file Font.php.

◆ COURIER_NEW_BOLD

const PHPExcel_Shared_Font::COURIER_NEW_BOLD = 'courbd.ttf'

Definition at line 84 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ COURIER_NEW_BOLD_ITALIC

const PHPExcel_Shared_Font::COURIER_NEW_BOLD_ITALIC = 'courbi.ttf'

Definition at line 86 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ COURIER_NEW_ITALIC

const PHPExcel_Shared_Font::COURIER_NEW_ITALIC = 'couri.ttf'

Definition at line 85 of file Font.php.

◆ GEORGIA

const PHPExcel_Shared_Font::GEORGIA = 'georgia.ttf'

Definition at line 88 of file Font.php.

◆ GEORGIA_BOLD

const PHPExcel_Shared_Font::GEORGIA_BOLD = 'georgiab.ttf'

Definition at line 89 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ GEORGIA_BOLD_ITALIC

const PHPExcel_Shared_Font::GEORGIA_BOLD_ITALIC = 'georgiaz.ttf'

Definition at line 91 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ GEORGIA_ITALIC

const PHPExcel_Shared_Font::GEORGIA_ITALIC = 'georgiai.ttf'

Definition at line 90 of file Font.php.

◆ IMPACT

const PHPExcel_Shared_Font::IMPACT = 'impact.ttf'

Definition at line 93 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ LIBERATION_SANS

const PHPExcel_Shared_Font::LIBERATION_SANS = 'LiberationSans-Regular.ttf'

Definition at line 95 of file Font.php.

◆ LIBERATION_SANS_BOLD

const PHPExcel_Shared_Font::LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf'

Definition at line 96 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ LIBERATION_SANS_BOLD_ITALIC

const PHPExcel_Shared_Font::LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf'

Definition at line 98 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ LIBERATION_SANS_ITALIC

const PHPExcel_Shared_Font::LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf'

Definition at line 97 of file Font.php.

◆ LUCIDA_CONSOLE

const PHPExcel_Shared_Font::LUCIDA_CONSOLE = 'lucon.ttf'

Definition at line 100 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ LUCIDA_SANS_UNICODE

const PHPExcel_Shared_Font::LUCIDA_SANS_UNICODE = 'l_10646.ttf'

Definition at line 101 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ MICROSOFT_SANS_SERIF

const PHPExcel_Shared_Font::MICROSOFT_SANS_SERIF = 'micross.ttf'

Definition at line 103 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ PALATINO_LINOTYPE

const PHPExcel_Shared_Font::PALATINO_LINOTYPE = 'pala.ttf'

Definition at line 105 of file Font.php.

◆ PALATINO_LINOTYPE_BOLD

const PHPExcel_Shared_Font::PALATINO_LINOTYPE_BOLD = 'palab.ttf'

Definition at line 106 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ PALATINO_LINOTYPE_BOLD_ITALIC

const PHPExcel_Shared_Font::PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf'

Definition at line 108 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ PALATINO_LINOTYPE_ITALIC

const PHPExcel_Shared_Font::PALATINO_LINOTYPE_ITALIC = 'palai.ttf'

Definition at line 107 of file Font.php.

◆ SYMBOL

const PHPExcel_Shared_Font::SYMBOL = 'symbol.ttf'

Definition at line 110 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ TAHOMA

const PHPExcel_Shared_Font::TAHOMA = 'tahoma.ttf'

Definition at line 112 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ TAHOMA_BOLD

const PHPExcel_Shared_Font::TAHOMA_BOLD = 'tahomabd.ttf'

Definition at line 113 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ TIMES_NEW_ROMAN

const PHPExcel_Shared_Font::TIMES_NEW_ROMAN = 'times.ttf'

Definition at line 115 of file Font.php.

◆ TIMES_NEW_ROMAN_BOLD

const PHPExcel_Shared_Font::TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf'

Definition at line 116 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ TIMES_NEW_ROMAN_BOLD_ITALIC

const PHPExcel_Shared_Font::TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf'

Definition at line 118 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ TIMES_NEW_ROMAN_ITALIC

const PHPExcel_Shared_Font::TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf'

Definition at line 117 of file Font.php.

◆ TREBUCHET_MS

const PHPExcel_Shared_Font::TREBUCHET_MS = 'trebuc.ttf'

Definition at line 120 of file Font.php.

◆ TREBUCHET_MS_BOLD

const PHPExcel_Shared_Font::TREBUCHET_MS_BOLD = 'trebucbd.ttf'

Definition at line 121 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ TREBUCHET_MS_BOLD_ITALIC

const PHPExcel_Shared_Font::TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf'

Definition at line 123 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ TREBUCHET_MS_ITALIC

const PHPExcel_Shared_Font::TREBUCHET_MS_ITALIC = 'trebucit.ttf'

Definition at line 122 of file Font.php.

◆ VERDANA

const PHPExcel_Shared_Font::VERDANA = 'verdana.ttf'

Definition at line 125 of file Font.php.

◆ VERDANA_BOLD

const PHPExcel_Shared_Font::VERDANA_BOLD = 'verdanab.ttf'

Definition at line 126 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ VERDANA_BOLD_ITALIC

const PHPExcel_Shared_Font::VERDANA_BOLD_ITALIC = 'verdanaz.ttf'

Definition at line 128 of file Font.php.

Referenced by getTrueTypeFontFileFromFont().

◆ VERDANA_ITALIC

const PHPExcel_Shared_Font::VERDANA_ITALIC = 'verdanai.ttf'

Definition at line 127 of file Font.php.


The documentation for this class was generated from the following file: