class Font (View source)

Constants

AUTOSIZE_METHOD_APPROX

AUTOSIZE_METHOD_EXACT

CHARSET_ANSI_LATIN

Character set codes used by BIFF5-8 in Font records

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

Font filenames

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

Properties

static array $defaultColumnWidths 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.

Methods

static bool
setAutoSizeMethod(string $pValue)

Set autoSize method.

static string
getAutoSizeMethod()

Get autoSize method.

static 
setTrueTypeFontPath(string $pValue)

Set the path to the folder containing .ttf files. There should be a trailing slash.

static string
getTrueTypeFontPath()

Get the path to the folder containing .ttf files.

static int
calculateColumnWidth(Font $font, RichText|string $cellText = '', int $rotation = 0, Font $defaultFont = null)

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

static int
getTextWidthPixelsExact(string $text, 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.

static int
getTextWidthPixelsApprox(string $columnText, Font $font, int $rotation = 0)

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

static int
fontSizeToPixels(int $fontSizeInPoints)

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

static int
inchSizeToPixels(int $sizeInInch)

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

static float
centimeterSizeToPixels(int $sizeInCm)

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

static string
getTrueTypeFontFileFromFont(Font $font)

Returns the font path given the font.

static int
getCharsetFromFontName(string $name)

Returns the associated charset for the font name.

static mixed
getDefaultColumnWidthByFont(Font $font, bool $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).

static float
getDefaultRowHeightByFont(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.

Details

static bool setAutoSizeMethod(string $pValue)

Set autoSize method.

Parameters

string $pValue see self::AUTOSIZE_METHOD_*

Return Value

bool Success or failure

static string getAutoSizeMethod()

Get autoSize method.

Return Value

string

static setTrueTypeFontPath(string $pValue)

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

static string getTrueTypeFontPath()

Get the path to the folder containing .ttf files.

Return Value

string

static int calculateColumnWidth(Font $font, RichText|string $cellText = '', int $rotation = 0, Font $defaultFont = null)

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

Parameters

Font $font Font object
RichText|string $cellText Text to calculate width
int $rotation Rotation angle
Font $defaultFont Font object

Return Value

int Column width

static int getTextWidthPixelsExact(string $text, 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.

Parameters

string $text
Font $font
int $rotation

Return Value

int

Exceptions

Exception

static int getTextWidthPixelsApprox(string $columnText, Font $font, int $rotation = 0)

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

Parameters

string $columnText
Font $font
int $rotation

Return Value

int Text width in pixels (no padding added)

static int fontSizeToPixels(int $fontSizeInPoints)

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

Parameters

int $fontSizeInPoints Font size (in points)

Return Value

int Font size (in pixels)

static int inchSizeToPixels(int $sizeInInch)

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

Parameters

int $sizeInInch Font size (in inch)

Return Value

int Size (in pixels)

static float centimeterSizeToPixels(int $sizeInCm)

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

Parameters

int $sizeInCm Font size (in centimeters)

Return Value

float Size (in pixels)

static string getTrueTypeFontFileFromFont(Font $font)

Returns the font path given the font.

Parameters

Font $font

Return Value

string Path to TrueType font file

static int getCharsetFromFontName(string $name)

Returns the associated charset for the font name.

Parameters

string $name Font name

Return Value

int Character set code

static mixed getDefaultColumnWidthByFont(Font $font, bool $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).

Parameters

Font $font The workbooks default font
bool $pPixels true = return column width in pixels, false = return in OOXML units

Return Value

mixed Column width

static float getDefaultRowHeightByFont(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.

Parameters

Font $font The workbooks default font

Return Value

float Row height in points