\PhpOffice\PhpSpreadsheet\SharedFont

Summary

Methods
Properties
Constants
setAutoSizeMethod()
getAutoSizeMethod()
setTrueTypeFontPath()
getTrueTypeFontPath()
calculateColumnWidth()
getTextWidthPixelsExact()
getTextWidthPixelsApprox()
fontSizeToPixels()
inchSizeToPixels()
centimeterSizeToPixels()
getTrueTypeFontFileFromFont()
getCharsetFromFontName()
getDefaultColumnWidthByFont()
getDefaultRowHeightByFont()
$defaultColumnWidths
AUTOSIZE_METHOD_APPROX
AUTOSIZE_METHOD_EXACT
CHARSET_ANSI_LATIN
CHARSET_SYSTEM_DEFAULT
CHARSET_SYMBOL
CHARSET_APPLE_ROMAN
CHARSET_ANSI_JAPANESE_SHIFTJIS
CHARSET_ANSI_KOREAN_HANGUL
CHARSET_ANSI_KOREAN_JOHAB
CHARSET_ANSI_CHINESE_SIMIPLIFIED
CHARSET_ANSI_CHINESE_TRADITIONAL
CHARSET_ANSI_GREEK
CHARSET_ANSI_TURKISH
CHARSET_ANSI_VIETNAMESE
CHARSET_ANSI_HEBREW
CHARSET_ANSI_ARABIC
CHARSET_ANSI_BALTIC
CHARSET_ANSI_CYRILLIC
CHARSET_ANSI_THAI
CHARSET_ANSI_LATIN_II
CHARSET_OEM_LATIN_I
ARIAL
ARIAL_BOLD
ARIAL_ITALIC
ARIAL_BOLD_ITALIC
CALIBRI
CALIBRI_BOLD
CALIBRI_ITALIC
CALIBRI_BOLD_ITALIC
COMIC_SANS_MS
COMIC_SANS_MS_BOLD
COURIER_NEW
COURIER_NEW_BOLD
COURIER_NEW_ITALIC
COURIER_NEW_BOLD_ITALIC
GEORGIA
GEORGIA_BOLD
GEORGIA_ITALIC
GEORGIA_BOLD_ITALIC
IMPACT
LIBERATION_SANS
LIBERATION_SANS_BOLD
LIBERATION_SANS_ITALIC
LIBERATION_SANS_BOLD_ITALIC
LUCIDA_CONSOLE
LUCIDA_SANS_UNICODE
MICROSOFT_SANS_SERIF
PALATINO_LINOTYPE
PALATINO_LINOTYPE_BOLD
PALATINO_LINOTYPE_ITALIC
PALATINO_LINOTYPE_BOLD_ITALIC
SYMBOL
TAHOMA
TAHOMA_BOLD
TIMES_NEW_ROMAN
TIMES_NEW_ROMAN_BOLD
TIMES_NEW_ROMAN_ITALIC
TIMES_NEW_ROMAN_BOLD_ITALIC
TREBUCHET_MS
TREBUCHET_MS_BOLD
TREBUCHET_MS_ITALIC
TREBUCHET_MS_BOLD_ITALIC
VERDANA
VERDANA_BOLD
VERDANA_ITALIC
VERDANA_BOLD_ITALIC
No protected methods found
No protected properties found
N/A
No private methods found
$autoSizeMethods
$autoSizeMethod
$trueTypeFontPath
N/A

Constants

AUTOSIZE_METHOD_APPROX

AUTOSIZE_METHOD_APPROX = 'approx'

AUTOSIZE_METHOD_EXACT

AUTOSIZE_METHOD_EXACT = 'exact'

CHARSET_ANSI_LATIN

CHARSET_ANSI_LATIN = 0x0

Character set codes used by BIFF5-8 in Font records

CHARSET_SYSTEM_DEFAULT

CHARSET_SYSTEM_DEFAULT = 0x1

CHARSET_SYMBOL

CHARSET_SYMBOL = 0x2

CHARSET_APPLE_ROMAN

CHARSET_APPLE_ROMAN = 0x4d

CHARSET_ANSI_JAPANESE_SHIFTJIS

CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80

CHARSET_ANSI_KOREAN_HANGUL

CHARSET_ANSI_KOREAN_HANGUL = 0x81

CHARSET_ANSI_KOREAN_JOHAB

CHARSET_ANSI_KOREAN_JOHAB = 0x82

CHARSET_ANSI_CHINESE_SIMIPLIFIED

CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86

CHARSET_ANSI_CHINESE_TRADITIONAL

CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88

CHARSET_ANSI_GREEK

CHARSET_ANSI_GREEK = 0xa1

CHARSET_ANSI_TURKISH

CHARSET_ANSI_TURKISH = 0xa2

CHARSET_ANSI_VIETNAMESE

CHARSET_ANSI_VIETNAMESE = 0xa3

CHARSET_ANSI_HEBREW

CHARSET_ANSI_HEBREW = 0xb1

CHARSET_ANSI_ARABIC

CHARSET_ANSI_ARABIC = 0xb2

CHARSET_ANSI_BALTIC

CHARSET_ANSI_BALTIC = 0xba

CHARSET_ANSI_CYRILLIC

CHARSET_ANSI_CYRILLIC = 0xcc

CHARSET_ANSI_THAI

CHARSET_ANSI_THAI = 0xdd

CHARSET_ANSI_LATIN_II

CHARSET_ANSI_LATIN_II = 0xee

CHARSET_OEM_LATIN_I

CHARSET_OEM_LATIN_I = 0xff

ARIAL

ARIAL = 'arial.ttf'

Font filenames

ARIAL_BOLD

ARIAL_BOLD = 'arialbd.ttf'

ARIAL_ITALIC

ARIAL_ITALIC = 'ariali.ttf'

ARIAL_BOLD_ITALIC

ARIAL_BOLD_ITALIC = 'arialbi.ttf'

CALIBRI

CALIBRI = 'CALIBRI.TTF'

CALIBRI_BOLD

CALIBRI_BOLD = 'CALIBRIB.TTF'

CALIBRI_ITALIC

CALIBRI_ITALIC = 'CALIBRII.TTF'

CALIBRI_BOLD_ITALIC

CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF'

COMIC_SANS_MS

COMIC_SANS_MS = 'comic.ttf'

COMIC_SANS_MS_BOLD

COMIC_SANS_MS_BOLD = 'comicbd.ttf'

COURIER_NEW

COURIER_NEW = 'cour.ttf'

COURIER_NEW_BOLD

COURIER_NEW_BOLD = 'courbd.ttf'

COURIER_NEW_ITALIC

COURIER_NEW_ITALIC = 'couri.ttf'

COURIER_NEW_BOLD_ITALIC

COURIER_NEW_BOLD_ITALIC = 'courbi.ttf'

GEORGIA

GEORGIA = 'georgia.ttf'

GEORGIA_BOLD

GEORGIA_BOLD = 'georgiab.ttf'

GEORGIA_ITALIC

GEORGIA_ITALIC = 'georgiai.ttf'

GEORGIA_BOLD_ITALIC

GEORGIA_BOLD_ITALIC = 'georgiaz.ttf'

IMPACT

IMPACT = 'impact.ttf'

LIBERATION_SANS

LIBERATION_SANS = 'LiberationSans-Regular.ttf'

LIBERATION_SANS_BOLD

LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf'

LIBERATION_SANS_ITALIC

LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf'

LIBERATION_SANS_BOLD_ITALIC

LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf'

LUCIDA_CONSOLE

LUCIDA_CONSOLE = 'lucon.ttf'

LUCIDA_SANS_UNICODE

LUCIDA_SANS_UNICODE = 'l_10646.ttf'

MICROSOFT_SANS_SERIF

MICROSOFT_SANS_SERIF = 'micross.ttf'

PALATINO_LINOTYPE

PALATINO_LINOTYPE = 'pala.ttf'

PALATINO_LINOTYPE_BOLD

PALATINO_LINOTYPE_BOLD = 'palab.ttf'

PALATINO_LINOTYPE_ITALIC

PALATINO_LINOTYPE_ITALIC = 'palai.ttf'

PALATINO_LINOTYPE_BOLD_ITALIC

PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf'

SYMBOL

SYMBOL = 'symbol.ttf'

TAHOMA

TAHOMA = 'tahoma.ttf'

TAHOMA_BOLD

TAHOMA_BOLD = 'tahomabd.ttf'

TIMES_NEW_ROMAN

TIMES_NEW_ROMAN = 'times.ttf'

TIMES_NEW_ROMAN_BOLD

TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf'

TIMES_NEW_ROMAN_ITALIC

TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf'

TIMES_NEW_ROMAN_BOLD_ITALIC

TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf'

TREBUCHET_MS

TREBUCHET_MS = 'trebuc.ttf'

TREBUCHET_MS_BOLD

TREBUCHET_MS_BOLD = 'trebucbd.ttf'

TREBUCHET_MS_ITALIC

TREBUCHET_MS_ITALIC = 'trebucit.ttf'

TREBUCHET_MS_BOLD_ITALIC

TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf'

VERDANA

VERDANA = 'verdana.ttf'

VERDANA_BOLD

VERDANA_BOLD = 'verdanab.ttf'

VERDANA_ITALIC

VERDANA_ITALIC = 'verdanai.ttf'

VERDANA_BOLD_ITALIC

VERDANA_BOLD_ITALIC = 'verdanaz.ttf'

Properties

$defaultColumnWidths

$defaultColumnWidths : array

How wide is a default column for a given default font and size? Empirical data found by inspecting real Excel files and reading off the pixel width in Microsoft Office Excel 2007.

Type

array

$autoSizeMethods

$autoSizeMethods

$autoSizeMethod

$autoSizeMethod : string

AutoSize method.

Type

string

$trueTypeFontPath

$trueTypeFontPath : string

Path to folder containing TrueType font .ttf files.

Type

string

Methods

setAutoSizeMethod()

setAutoSizeMethod(string  $pValue) : bool

Set autoSize method.

Parameters

string $pValue

see self::AUTOSIZE_METHOD_*

Returns

bool —

Success or failure

getAutoSizeMethod()

getAutoSizeMethod() : string

Get autoSize method.

Returns

string —

setTrueTypeFontPath()

setTrueTypeFontPath(string  $pValue) : void

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

getTrueTypeFontPath()

getTrueTypeFontPath() : string

Get the path to the folder containing .ttf files.

Returns

string —

calculateColumnWidth()

calculateColumnWidth(\PhpOffice\PhpSpreadsheet\Style\Font  $font, \PhpOffice\PhpSpreadsheet\RichText\RichText|string  $cellText = '', int  $rotation, null|\PhpOffice\PhpSpreadsheet\Style\Font  $defaultFont = null) : int

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

Parameters

\PhpOffice\PhpSpreadsheet\Style\Font $font

Font object

\PhpOffice\PhpSpreadsheet\RichText\RichText|string $cellText

Text to calculate width

int $rotation

Rotation angle

null|\PhpOffice\PhpSpreadsheet\Style\Font $defaultFont

Font object

Returns

int —

Column width

getTextWidthPixelsExact()

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

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

Parameters

string $text
\PhpOffice\PhpSpreadsheet\Style\Font $font
int $rotation

Returns

int —

getTextWidthPixelsApprox()

getTextWidthPixelsApprox(string  $columnText, \PhpOffice\PhpSpreadsheet\Style\Font  $font, int  $rotation) : int

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

Parameters

string $columnText
\PhpOffice\PhpSpreadsheet\Style\Font $font
int $rotation

Returns

int —

Text width in pixels (no padding added)

fontSizeToPixels()

fontSizeToPixels(int  $fontSizeInPoints) : int

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

Parameters

int $fontSizeInPoints

Font size (in points)

Returns

int —

Font size (in pixels)

inchSizeToPixels()

inchSizeToPixels(int  $sizeInInch) : int

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

Parameters

int $sizeInInch

Font size (in inch)

Returns

int —

Size (in pixels)

centimeterSizeToPixels()

centimeterSizeToPixels(int  $sizeInCm) : float

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

Parameters

int $sizeInCm

Font size (in centimeters)

Returns

float —

Size (in pixels)

getTrueTypeFontFileFromFont()

getTrueTypeFontFileFromFont(\PhpOffice\PhpSpreadsheet\Style\Font  $font) : string

Returns the font path given the font.

Parameters

\PhpOffice\PhpSpreadsheet\Style\Font $font

Returns

string —

Path to TrueType font file

getCharsetFromFontName()

getCharsetFromFontName(string  $name) : int

Returns the associated charset for the font name.

Parameters

string $name

Font name

Returns

int —

Character set code

getDefaultColumnWidthByFont()

getDefaultColumnWidthByFont(\PhpOffice\PhpSpreadsheet\Style\Font  $font, bool  $pPixels = false) : mixed

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 $font

The workbooks default font

bool $pPixels

true = return column width in pixels, false = return in OOXML units

Returns

mixed —

Column width

getDefaultRowHeightByFont()

getDefaultRowHeightByFont(\PhpOffice\PhpSpreadsheet\Style\Font  $font) : float

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 $font

The workbooks default font

Returns

float —

Row height in points