ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Shared\Font Class Reference
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Shared\Font:

Static Public Member Functions

static static setAutoSizeMethod ($pValue)
 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 (\PhpOffice\PhpSpreadsheet\Style\Font $font, $cellText='', $rotation=0, ?\PhpOffice\PhpSpreadsheet\Style\Font $defaultFont=null)
 Calculate an (approximate) OpenXML column width, based on font size and text contained. More...
 
static getTextWidthPixelsExact (string $text, \PhpOffice\PhpSpreadsheet\Style\Font $font, int $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, \PhpOffice\PhpSpreadsheet\Style\Font $font, $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)
 Calculate an (approximate) pixel size, based on a font points size. More...
 
static inchSizeToPixels ($sizeInInch)
 Calculate an (approximate) pixel size, based on inch size. More...
 
static centimeterSizeToPixels ($sizeInCm)
 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 (\PhpOffice\PhpSpreadsheet\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 (\PhpOffice\PhpSpreadsheet\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 9 of file Font.php.

Member Function Documentation

◆ calculateColumnWidth()

static PhpOffice\PhpSpreadsheet\Shared\Font::calculateColumnWidth ( \PhpOffice\PhpSpreadsheet\Style\Font  $font,
  $cellText = '',
  $rotation = 0,
?\PhpOffice\PhpSpreadsheet\Style\Font  $defaultFont = null 
)
static

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

Parameters
\PhpOffice\PhpSpreadsheet\Style\Font$fontFont object
RichText | string$cellTextText to calculate width
int$rotationRotation angle
null | \PhpOffice\PhpSpreadsheet\Style\Font$defaultFontFont object
Returns
int Column width

Definition at line 227 of file Font.php.

References PhpOffice\PhpSpreadsheet\Shared\Drawing\pixelsToCellDimension().

Referenced by PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\calculateColumnWidths().

228  {
229  // If it is rich text, use plain text
230  if ($cellText instanceof RichText) {
231  $cellText = $cellText->getPlainText();
232  }
233 
234  // Special case if there are one or more newline characters ("\n")
235  if (strpos($cellText ?? '', "\n") !== false) {
236  $lineTexts = explode("\n", $cellText);
237  $lineWidths = [];
238  foreach ($lineTexts as $lineText) {
239  $lineWidths[] = self::calculateColumnWidth($font, $lineText, $rotation = 0, $defaultFont);
240  }
241 
242  return max($lineWidths); // width of longest line in cell
243  }
244 
245  // Try to get the exact text width in pixels
246  $approximate = self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX;
247  $columnWidth = 0;
248  if (!$approximate) {
249  $columnWidthAdjust = ceil(self::getTextWidthPixelsExact('n', $font, 0) * 1.07);
250 
251  try {
252  // Width of text in pixels excl. padding
253  // and addition because Excel adds some padding, just use approx width of 'n' glyph
254  $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation) + $columnWidthAdjust;
255  } catch (PhpSpreadsheetException $e) {
256  $approximate = true;
257  }
258  }
259 
260  if ($approximate) {
261  $columnWidthAdjust = self::getTextWidthPixelsApprox('n', $font, 0);
262  // Width of text in pixels excl. padding, approximation
263  // and addition because Excel adds some padding, just use approx width of 'n' glyph
264  $columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation) + $columnWidthAdjust;
265  }
266 
267  // Convert from pixel width to column width
268  $columnWidth = Drawing::pixelsToCellDimension($columnWidth, $defaultFont);
269 
270  // Return
271  return (int) round($columnWidth, 6);
272  }
static pixelsToCellDimension($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
Convert pixels to column width.
Definition: Drawing.php:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ centimeterSizeToPixels()

static PhpOffice\PhpSpreadsheet\Shared\Font::centimeterSizeToPixels (   $sizeInCm)
static

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

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

Definition at line 386 of file Font.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xlsx\toCSSArray().

387  {
388  return $sizeInCm * 37.795275591;
389  }
+ Here is the caller graph for this function:

◆ fontSizeToPixels()

static PhpOffice\PhpSpreadsheet\Shared\Font::fontSizeToPixels (   $fontSizeInPoints)
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 362 of file Font.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\Xls\sizeRow(), and PhpOffice\PhpSpreadsheet\Reader\Xlsx\toCSSArray().

363  {
364  return (int) ((4 / 3) * $fontSizeInPoints);
365  }
+ Here is the caller graph for this function:

◆ getAutoSizeMethod()

static PhpOffice\PhpSpreadsheet\Shared\Font::getAutoSizeMethod ( )
static

Get autoSize method.

Returns
string

Definition at line 186 of file Font.php.

187  {
188  return self::$autoSizeMethod;
189  }

◆ getCharsetFromFontName()

static PhpOffice\PhpSpreadsheet\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 528 of file Font.php.

References $name.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\Font\writeFont().

529  {
530  switch ($name) {
531  // Add more cases. Check FONT records in real Excel files.
532  case 'EucrosiaUPC':
533  return self::CHARSET_ANSI_THAI;
534  case 'Wingdings':
535  return self::CHARSET_SYMBOL;
536  case 'Wingdings 2':
537  return self::CHARSET_SYMBOL;
538  case 'Wingdings 3':
539  return self::CHARSET_SYMBOL;
540  default:
541  return self::CHARSET_ANSI_LATIN;
542  }
543  }
+ Here is the caller graph for this function:

◆ getDefaultColumnWidthByFont()

static PhpOffice\PhpSpreadsheet\Shared\Font::getDefaultColumnWidthByFont ( \PhpOffice\PhpSpreadsheet\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
\PhpOffice\PhpSpreadsheet\Style\Font$fontThe workbooks default font
bool$pPixelstrue = return column width in pixels, false = return in OOXML units
Returns
mixed Column width

Definition at line 554 of file Font.php.

Referenced by PhpOffice\PhpSpreadsheet\Writer\Xls\Worksheet\__construct(), and PhpOffice\PhpSpreadsheet\Shared\Xls\sizeCol().

555  {
556  if (isset(self::$defaultColumnWidths[$font->getName()][$font->getSize()])) {
557  // Exact width can be determined
558  $columnWidth = $pPixels ?
559  self::$defaultColumnWidths[$font->getName()][$font->getSize()]['px']
560  : self::$defaultColumnWidths[$font->getName()][$font->getSize()]['width'];
561  } else {
562  // We don't have data for this particular font and size, use approximation by
563  // extrapolating from Calibri 11
564  $columnWidth = $pPixels ?
565  self::$defaultColumnWidths['Calibri'][11]['px']
566  : self::$defaultColumnWidths['Calibri'][11]['width'];
567  $columnWidth = $columnWidth * $font->getSize() / 11;
568 
569  // Round pixels to closest integer
570  if ($pPixels) {
571  $columnWidth = (int) round($columnWidth);
572  }
573  }
574 
575  return $columnWidth;
576  }
+ Here is the caller graph for this function:

◆ getDefaultRowHeightByFont()

static PhpOffice\PhpSpreadsheet\Shared\Font::getDefaultRowHeightByFont ( \PhpOffice\PhpSpreadsheet\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
\PhpOffice\PhpSpreadsheet\Style\Font$fontThe workbooks default font
Returns
float Row height in points

Definition at line 586 of file Font.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\Xls\sizeRow().

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

◆ getTextWidthPixelsApprox()

static PhpOffice\PhpSpreadsheet\Shared\Font::getTextWidthPixelsApprox (   $columnText,
\PhpOffice\PhpSpreadsheet\Style\Font  $font,
  $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
int$rotation
Returns
int Text width in pixels (no padding added)

Definition at line 306 of file Font.php.

References PhpOffice\PhpSpreadsheet\Shared\StringHelper\countCharacters(), and PhpOffice\PhpSpreadsheet\Style\Alignment\TEXTROTATION_STACK_PHPSPREADSHEET.

307  {
308  $fontName = $font->getName();
309  $fontSize = $font->getSize();
310 
311  // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.
312  switch ($fontName) {
313  case 'Calibri':
314  // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.
315  $columnWidth = (int) (8.26 * StringHelper::countCharacters($columnText));
316  $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
317 
318  break;
319  case 'Arial':
320  // value 8 was set because of experience in different exports at Arial 10 font.
321  $columnWidth = (int) (8 * StringHelper::countCharacters($columnText));
322  $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
323 
324  break;
325  case 'Verdana':
326  // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.
327  $columnWidth = (int) (8 * StringHelper::countCharacters($columnText));
328  $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
329 
330  break;
331  default:
332  // just assume Calibri
333  $columnWidth = (int) (8.26 * StringHelper::countCharacters($columnText));
334  $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
335 
336  break;
337  }
338 
339  // Calculate approximate rotated column width
340  if ($rotation !== 0) {
342  // stacked text
343  $columnWidth = 4; // approximation
344  } else {
345  // rotated text
346  $columnWidth = $columnWidth * cos(deg2rad($rotation))
347  + $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation
348  }
349  }
350 
351  // pixel width is an integer
352  return (int) $columnWidth;
353  }
static countCharacters($value, $enc='UTF-8')
Get character count.
+ Here is the call graph for this function:

◆ getTextWidthPixelsExact()

static PhpOffice\PhpSpreadsheet\Shared\Font::getTextWidthPixelsExact ( string  $text,
\PhpOffice\PhpSpreadsheet\Style\Font  $font,
int  $rotation = 0 
)
static

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

Definition at line 277 of file Font.php.

References $text.

277  : int
278  {
279  if (!function_exists('imagettfbbox')) {
280  throw new PhpSpreadsheetException('GD library needs to be enabled');
281  }
282 
283  // font size should really be supplied in pixels in GD2,
284  // but since GD2 seems to assume 72dpi, pixels and points are the same
285  $fontFile = self::getTrueTypeFontFileFromFont($font);
286  $textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text);
287 
288  // Get corners positions
289  $lowerLeftCornerX = $textBox[0];
290  $lowerRightCornerX = $textBox[2];
291  $upperRightCornerX = $textBox[4];
292  $upperLeftCornerX = $textBox[6];
293 
294  // Consider the rotation when calculating the width
295  return max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX);
296  }
$text
Definition: errorreport.php:18

◆ getTrueTypeFontFileFromFont()

static PhpOffice\PhpSpreadsheet\Shared\Font::getTrueTypeFontFileFromFont (   $font)
static

Returns the font path given the font.

Parameters
\PhpOffice\PhpSpreadsheet\Style\Font$font
Returns
string Path to TrueType font file

Definition at line 398 of file Font.php.

References $name.

399  {
400  if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) {
401  throw new PhpSpreadsheetException('Valid directory to TrueType Font files not specified');
402  }
403 
404  $name = $font->getName();
405  $bold = $font->getBold();
406  $italic = $font->getItalic();
407 
408  // Check if we can map font to true type font file
409  switch ($name) {
410  case 'Arial':
411  $fontFile = (
412  $bold ? ($italic ? self::ARIAL_BOLD_ITALIC : self::ARIAL_BOLD)
413  : ($italic ? self::ARIAL_ITALIC : self::ARIAL)
414  );
415 
416  break;
417  case 'Calibri':
418  $fontFile = (
419  $bold ? ($italic ? self::CALIBRI_BOLD_ITALIC : self::CALIBRI_BOLD)
420  : ($italic ? self::CALIBRI_ITALIC : self::CALIBRI)
421  );
422 
423  break;
424  case 'Courier New':
425  $fontFile = (
426  $bold ? ($italic ? self::COURIER_NEW_BOLD_ITALIC : self::COURIER_NEW_BOLD)
427  : ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW)
428  );
429 
430  break;
431  case 'Comic Sans MS':
432  $fontFile = (
433  $bold ? self::COMIC_SANS_MS_BOLD : self::COMIC_SANS_MS
434  );
435 
436  break;
437  case 'Georgia':
438  $fontFile = (
439  $bold ? ($italic ? self::GEORGIA_BOLD_ITALIC : self::GEORGIA_BOLD)
440  : ($italic ? self::GEORGIA_ITALIC : self::GEORGIA)
441  );
442 
443  break;
444  case 'Impact':
445  $fontFile = self::IMPACT;
446 
447  break;
448  case 'Liberation Sans':
449  $fontFile = (
450  $bold ? ($italic ? self::LIBERATION_SANS_BOLD_ITALIC : self::LIBERATION_SANS_BOLD)
451  : ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS)
452  );
453 
454  break;
455  case 'Lucida Console':
456  $fontFile = self::LUCIDA_CONSOLE;
457 
458  break;
459  case 'Lucida Sans Unicode':
460  $fontFile = self::LUCIDA_SANS_UNICODE;
461 
462  break;
463  case 'Microsoft Sans Serif':
464  $fontFile = self::MICROSOFT_SANS_SERIF;
465 
466  break;
467  case 'Palatino Linotype':
468  $fontFile = (
469  $bold ? ($italic ? self::PALATINO_LINOTYPE_BOLD_ITALIC : self::PALATINO_LINOTYPE_BOLD)
470  : ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE)
471  );
472 
473  break;
474  case 'Symbol':
475  $fontFile = self::SYMBOL;
476 
477  break;
478  case 'Tahoma':
479  $fontFile = (
480  $bold ? self::TAHOMA_BOLD : self::TAHOMA
481  );
482 
483  break;
484  case 'Times New Roman':
485  $fontFile = (
486  $bold ? ($italic ? self::TIMES_NEW_ROMAN_BOLD_ITALIC : self::TIMES_NEW_ROMAN_BOLD)
487  : ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN)
488  );
489 
490  break;
491  case 'Trebuchet MS':
492  $fontFile = (
493  $bold ? ($italic ? self::TREBUCHET_MS_BOLD_ITALIC : self::TREBUCHET_MS_BOLD)
494  : ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS)
495  );
496 
497  break;
498  case 'Verdana':
499  $fontFile = (
500  $bold ? ($italic ? self::VERDANA_BOLD_ITALIC : self::VERDANA_BOLD)
501  : ($italic ? self::VERDANA_ITALIC : self::VERDANA)
502  );
503 
504  break;
505  default:
506  throw new PhpSpreadsheetException('Unknown font name "' . $name . '". Cannot map to TrueType font file');
507 
508  break;
509  }
510 
511  $fontFile = self::$trueTypeFontPath . $fontFile;
512 
513  // Check if file actually exists
514  if (!file_exists($fontFile)) {
515  throw new PhpSpreadsheetException('TrueType Font file not found');
516  }
517 
518  return $fontFile;
519  }

◆ getTrueTypeFontPath()

static PhpOffice\PhpSpreadsheet\Shared\Font::getTrueTypeFontPath ( )
static

Get the path to the folder containing .ttf files.

Returns
string

Definition at line 212 of file Font.php.

213  {
214  return self::$trueTypeFontPath;
215  }

◆ inchSizeToPixels()

static PhpOffice\PhpSpreadsheet\Shared\Font::inchSizeToPixels (   $sizeInInch)
static

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

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

Definition at line 374 of file Font.php.

Referenced by PhpOffice\PhpSpreadsheet\Reader\Xlsx\toCSSArray().

375  {
376  return $sizeInInch * 96;
377  }
+ Here is the caller graph for this function:

◆ setAutoSizeMethod()

static static PhpOffice\PhpSpreadsheet\Shared\Font::setAutoSizeMethod (   $pValue)
static

Set autoSize method.

Parameters
string$pValuesee self::AUTOSIZE_METHOD_*
Returns
bool Success or failure

Definition at line 171 of file Font.php.

172  {
173  if (!in_array($pValue, self::$autoSizeMethods)) {
174  return false;
175  }
176  self::$autoSizeMethod = $pValue;
177 
178  return true;
179  }

◆ setTrueTypeFontPath()

static PhpOffice\PhpSpreadsheet\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 202 of file Font.php.

202  : void
203  {
204  self::$trueTypeFontPath = $pValue;
205  }

Field Documentation

◆ $autoSizeMethod

PhpOffice\PhpSpreadsheet\Shared\Font::$autoSizeMethod = self::AUTOSIZE_METHOD_APPROX
staticprivate

Definition at line 108 of file Font.php.

◆ $autoSizeMethods

PhpOffice\PhpSpreadsheet\Shared\Font::$autoSizeMethods
staticprivate
Initial value:
= [
self::AUTOSIZE_METHOD_APPROX,
self::AUTOSIZE_METHOD_EXACT,
]

Definition at line 15 of file Font.php.

◆ $defaultColumnWidths

PhpOffice\PhpSpreadsheet\Shared\Font::$defaultColumnWidths
static
Initial value:
= [
'Arial' => [
1 => ['px' => 24

Definition at line 124 of file Font.php.

Referenced by PhpOffice\PhpSpreadsheet\Shared\Drawing\cellDimensionToPixels(), and PhpOffice\PhpSpreadsheet\Shared\Drawing\pixelsToCellDimension().

◆ $trueTypeFontPath

PhpOffice\PhpSpreadsheet\Shared\Font::$trueTypeFontPath = null
staticprivate

Definition at line 115 of file Font.php.

◆ ARIAL

const PhpOffice\PhpSpreadsheet\Shared\Font::ARIAL = 'arial.ttf'

Font filenames.

Definition at line 43 of file Font.php.

◆ ARIAL_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::ARIAL_BOLD = 'arialbd.ttf'

Definition at line 44 of file Font.php.

◆ ARIAL_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::ARIAL_BOLD_ITALIC = 'arialbi.ttf'

Definition at line 46 of file Font.php.

◆ ARIAL_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::ARIAL_ITALIC = 'ariali.ttf'

Definition at line 45 of file Font.php.

◆ AUTOSIZE_METHOD_APPROX

const PhpOffice\PhpSpreadsheet\Shared\Font::AUTOSIZE_METHOD_APPROX = 'approx'

Definition at line 12 of file Font.php.

◆ AUTOSIZE_METHOD_EXACT

const PhpOffice\PhpSpreadsheet\Shared\Font::AUTOSIZE_METHOD_EXACT = 'exact'

Definition at line 13 of file Font.php.

◆ CALIBRI

const PhpOffice\PhpSpreadsheet\Shared\Font::CALIBRI = 'CALIBRI.TTF'

Definition at line 48 of file Font.php.

◆ CALIBRI_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::CALIBRI_BOLD = 'CALIBRIB.TTF'

Definition at line 49 of file Font.php.

◆ CALIBRI_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF'

Definition at line 51 of file Font.php.

◆ CALIBRI_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::CALIBRI_ITALIC = 'CALIBRII.TTF'

Definition at line 50 of file Font.php.

◆ CHARSET_ANSI_ARABIC

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_ARABIC = 0xB2

Definition at line 34 of file Font.php.

◆ CHARSET_ANSI_BALTIC

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_BALTIC = 0xBA

Definition at line 35 of file Font.php.

◆ CHARSET_ANSI_CHINESE_SIMIPLIFIED

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86

Definition at line 28 of file Font.php.

◆ CHARSET_ANSI_CHINESE_TRADITIONAL

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88

Definition at line 29 of file Font.php.

◆ CHARSET_ANSI_CYRILLIC

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_CYRILLIC = 0xCC

Definition at line 36 of file Font.php.

◆ CHARSET_ANSI_GREEK

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_GREEK = 0xA1

Definition at line 30 of file Font.php.

◆ CHARSET_ANSI_HEBREW

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_HEBREW = 0xB1

Definition at line 33 of file Font.php.

◆ CHARSET_ANSI_JAPANESE_SHIFTJIS

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80

Definition at line 25 of file Font.php.

◆ CHARSET_ANSI_KOREAN_HANGUL

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_KOREAN_HANGUL = 0x81

Definition at line 26 of file Font.php.

◆ CHARSET_ANSI_KOREAN_JOHAB

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_KOREAN_JOHAB = 0x82

Definition at line 27 of file Font.php.

◆ CHARSET_ANSI_LATIN

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_LATIN = 0x00

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

Definition at line 21 of file Font.php.

◆ CHARSET_ANSI_LATIN_II

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_LATIN_II = 0xEE

Definition at line 38 of file Font.php.

◆ CHARSET_ANSI_THAI

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_THAI = 0xDD

Definition at line 37 of file Font.php.

◆ CHARSET_ANSI_TURKISH

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_TURKISH = 0xA2

Definition at line 31 of file Font.php.

◆ CHARSET_ANSI_VIETNAMESE

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_ANSI_VIETNAMESE = 0xA3

Definition at line 32 of file Font.php.

◆ CHARSET_APPLE_ROMAN

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_APPLE_ROMAN = 0x4D

Definition at line 24 of file Font.php.

◆ CHARSET_OEM_LATIN_I

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_OEM_LATIN_I = 0xFF

Definition at line 39 of file Font.php.

◆ CHARSET_SYMBOL

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_SYMBOL = 0x02

Definition at line 23 of file Font.php.

◆ CHARSET_SYSTEM_DEFAULT

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_SYSTEM_DEFAULT = 0x01

Definition at line 22 of file Font.php.

◆ COMIC_SANS_MS

const PhpOffice\PhpSpreadsheet\Shared\Font::COMIC_SANS_MS = 'comic.ttf'

Definition at line 53 of file Font.php.

◆ COMIC_SANS_MS_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::COMIC_SANS_MS_BOLD = 'comicbd.ttf'

Definition at line 54 of file Font.php.

◆ COURIER_NEW

const PhpOffice\PhpSpreadsheet\Shared\Font::COURIER_NEW = 'cour.ttf'

Definition at line 56 of file Font.php.

◆ COURIER_NEW_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::COURIER_NEW_BOLD = 'courbd.ttf'

Definition at line 57 of file Font.php.

◆ COURIER_NEW_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::COURIER_NEW_BOLD_ITALIC = 'courbi.ttf'

Definition at line 59 of file Font.php.

◆ COURIER_NEW_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::COURIER_NEW_ITALIC = 'couri.ttf'

Definition at line 58 of file Font.php.

◆ GEORGIA

const PhpOffice\PhpSpreadsheet\Shared\Font::GEORGIA = 'georgia.ttf'

Definition at line 61 of file Font.php.

◆ GEORGIA_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::GEORGIA_BOLD = 'georgiab.ttf'

Definition at line 62 of file Font.php.

◆ GEORGIA_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::GEORGIA_BOLD_ITALIC = 'georgiaz.ttf'

Definition at line 64 of file Font.php.

◆ GEORGIA_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::GEORGIA_ITALIC = 'georgiai.ttf'

Definition at line 63 of file Font.php.

◆ IMPACT

const PhpOffice\PhpSpreadsheet\Shared\Font::IMPACT = 'impact.ttf'

Definition at line 66 of file Font.php.

◆ LIBERATION_SANS

const PhpOffice\PhpSpreadsheet\Shared\Font::LIBERATION_SANS = 'LiberationSans-Regular.ttf'

Definition at line 68 of file Font.php.

◆ LIBERATION_SANS_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf'

Definition at line 69 of file Font.php.

◆ LIBERATION_SANS_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf'

Definition at line 71 of file Font.php.

◆ LIBERATION_SANS_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf'

Definition at line 70 of file Font.php.

◆ LUCIDA_CONSOLE

const PhpOffice\PhpSpreadsheet\Shared\Font::LUCIDA_CONSOLE = 'lucon.ttf'

Definition at line 73 of file Font.php.

◆ LUCIDA_SANS_UNICODE

const PhpOffice\PhpSpreadsheet\Shared\Font::LUCIDA_SANS_UNICODE = 'l_10646.ttf'

Definition at line 74 of file Font.php.

◆ MICROSOFT_SANS_SERIF

const PhpOffice\PhpSpreadsheet\Shared\Font::MICROSOFT_SANS_SERIF = 'micross.ttf'

Definition at line 76 of file Font.php.

◆ PALATINO_LINOTYPE

const PhpOffice\PhpSpreadsheet\Shared\Font::PALATINO_LINOTYPE = 'pala.ttf'

Definition at line 78 of file Font.php.

◆ PALATINO_LINOTYPE_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::PALATINO_LINOTYPE_BOLD = 'palab.ttf'

Definition at line 79 of file Font.php.

◆ PALATINO_LINOTYPE_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf'

Definition at line 81 of file Font.php.

◆ PALATINO_LINOTYPE_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::PALATINO_LINOTYPE_ITALIC = 'palai.ttf'

Definition at line 80 of file Font.php.

◆ SYMBOL

const PhpOffice\PhpSpreadsheet\Shared\Font::SYMBOL = 'symbol.ttf'

Definition at line 83 of file Font.php.

◆ TAHOMA

const PhpOffice\PhpSpreadsheet\Shared\Font::TAHOMA = 'tahoma.ttf'

Definition at line 85 of file Font.php.

◆ TAHOMA_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::TAHOMA_BOLD = 'tahomabd.ttf'

Definition at line 86 of file Font.php.

◆ TIMES_NEW_ROMAN

const PhpOffice\PhpSpreadsheet\Shared\Font::TIMES_NEW_ROMAN = 'times.ttf'

Definition at line 88 of file Font.php.

◆ TIMES_NEW_ROMAN_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf'

Definition at line 89 of file Font.php.

◆ TIMES_NEW_ROMAN_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf'

Definition at line 91 of file Font.php.

◆ TIMES_NEW_ROMAN_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf'

Definition at line 90 of file Font.php.

◆ TREBUCHET_MS

const PhpOffice\PhpSpreadsheet\Shared\Font::TREBUCHET_MS = 'trebuc.ttf'

Definition at line 93 of file Font.php.

◆ TREBUCHET_MS_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::TREBUCHET_MS_BOLD = 'trebucbd.ttf'

Definition at line 94 of file Font.php.

◆ TREBUCHET_MS_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf'

Definition at line 96 of file Font.php.

◆ TREBUCHET_MS_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::TREBUCHET_MS_ITALIC = 'trebucit.ttf'

Definition at line 95 of file Font.php.

◆ VERDANA

const PhpOffice\PhpSpreadsheet\Shared\Font::VERDANA = 'verdana.ttf'

Definition at line 98 of file Font.php.

◆ VERDANA_BOLD

const PhpOffice\PhpSpreadsheet\Shared\Font::VERDANA_BOLD = 'verdanab.ttf'

Definition at line 99 of file Font.php.

◆ VERDANA_BOLD_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::VERDANA_BOLD_ITALIC = 'verdanaz.ttf'

Definition at line 101 of file Font.php.

◆ VERDANA_ITALIC

const PhpOffice\PhpSpreadsheet\Shared\Font::VERDANA_ITALIC = 'verdanai.ttf'

Definition at line 100 of file Font.php.


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