Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250620) (7d9030acd6e)
PhpOffice\PhpSpreadsheet\Shared\Font Class Reference

Static Public Member Functions

static calculateColumnWidth (FontStyle $font, $cellText='', int $rotation=0, ?FontStyle $defaultFont=null, bool $filterAdjustment=false, int $indentAdjustment=0)
 Calculate an (approximate) OpenXML column width, based on font size and text contained.
 
static centimeterSizeToPixels (int|float $sizeInCm)
 Calculate an (approximate) pixel size, based on centimeter size.
 
static fontSizeToPixels (float|int $fontSizeInPoints)
 Calculate an (approximate) pixel size, based on a font points size.
 
static getAutoSizeMethod ()
 Get autoSize method.
 
static getCharsetFromFontName (string $fontName)
 Returns the associated charset for the font name.
 
static getDefaultColumnWidthByFont (FontStyle $font, bool $returnAsPixels=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 getDefaultRowHeightByFont (FontStyle $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.
 
static getPaddingAmountExact ()
 Get pad amount for exact in pixels; or null if using best guess.
 
static getTextWidthPixelsApprox (string $columnText, FontStyle $font, int $rotation=0)
 Get approximate width in pixels for a string of text in a certain font at a certain rotation angle.
 
static getTextWidthPixelsExact (string $text, FontStyle $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 getTrueTypeFontFileFromFont (FontStyle $font, bool $checkPath=true)
 Returns the font path given the font.
 
static getTrueTypeFontPath ()
 Get the path to the folder containing .ttf files.
 
static inchSizeToPixels (int|float $sizeInInch)
 Calculate an (approximate) pixel size, based on inch size.
 
static static setAutoSizeMethod (string $method)
 Set autoSize method.
 
static setPaddingAmountExact (null|float|int $paddingAmountExact)
 Set pad amount for exact in pixels; use best guess if null.
 
static setTrueTypeFontPath (string $folderPath)
 Set the path to the folder containing .ttf files.
 

Public Attributes

const ARIAL = 'arial.ttf'
 Font filenames.
 
const ARIAL_BOLD = 'arialbd.ttf'
 
const ARIAL_BOLD_ITALIC = 'arialbi.ttf'
 
const ARIAL_ITALIC = 'ariali.ttf'
 
const AUTOSIZE_METHOD_APPROX = 'approx'
 
const AUTOSIZE_METHOD_EXACT = 'exact'
 
const CALIBRI = 'calibri.ttf'
 
const CALIBRI_BOLD = 'calibrib.ttf'
 
const CALIBRI_BOLD_ITALIC = 'calibriz.ttf'
 
const CALIBRI_ITALIC = 'calibrii.ttf'
 
const CHARSET_ANSI_ARABIC = 0xB2
 
const CHARSET_ANSI_BALTIC = 0xBA
 
const CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86
 
const CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88
 
const CHARSET_ANSI_CYRILLIC = 0xCC
 
const CHARSET_ANSI_GREEK = 0xA1
 
const CHARSET_ANSI_HEBREW = 0xB1
 
const CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80
 
const CHARSET_ANSI_KOREAN_HANGUL = 0x81
 
const CHARSET_ANSI_KOREAN_JOHAB = 0x82
 
file home runner work phpdoc phpdoc moodle lib phpspreadsheet phpspreadsheet src PhpSpreadsheet Shared Font php const CHARSET_ANSI_LATIN = 0x00
 Character set codes used by BIFF5-8 in Font records.
 
const CHARSET_ANSI_LATIN_II = 0xEE
 
const CHARSET_ANSI_THAI = 0xDD
 
const CHARSET_ANSI_TURKISH = 0xA2
 
const CHARSET_ANSI_VIETNAMESE = 0xA3
 
const CHARSET_APPLE_ROMAN = 0x4D
 
const CHARSET_FROM_FONT_NAME
 
const CHARSET_OEM_LATIN_I = 0xFF
 
const CHARSET_SYMBOL = 0x02
 
const CHARSET_SYSTEM_DEFAULT = 0x01
 
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_BOLD_ITALIC = 'courbi.ttf'
 
const COURIER_NEW_ITALIC = 'couri.ttf'
 
const FONT_FILE_NAMES
 
const GEORGIA = 'georgia.ttf'
 
const GEORGIA_BOLD = 'georgiab.ttf'
 
const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf'
 
const GEORGIA_ITALIC = 'georgiai.ttf'
 
const IMPACT = 'impact.ttf'
 
const LIBERATION_SANS = 'LiberationSans-Regular.ttf'
 
const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf'
 
const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf'
 
const LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.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_BOLD_ITALIC = 'palabi.ttf'
 
const PALATINO_LINOTYPE_ITALIC = 'palai.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_BOLD_ITALIC = 'timesbi.ttf'
 
const TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf'
 
const TREBUCHET_MS = 'trebuc.ttf'
 
const TREBUCHET_MS_BOLD = 'trebucbd.ttf'
 
const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf'
 
const TREBUCHET_MS_ITALIC = 'trebucit.ttf'
 
const VERDANA = 'verdana.ttf'
 
const VERDANA_BOLD = 'verdanab.ttf'
 
const VERDANA_BOLD_ITALIC = 'verdanaz.ttf'
 
const VERDANA_ITALIC = 'verdanai.ttf'
 

Member Function Documentation

◆ calculateColumnWidth()

static PhpOffice\PhpSpreadsheet\Shared\Font::calculateColumnWidth ( FontStyle $font,
$cellText = '',
int $rotation = 0,
?FontStyle $defaultFont = null,
bool $filterAdjustment = false,
int $indentAdjustment = 0 )
static

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

Parameters
FontStyle$fontFont object
null | RichText | string$cellTextText to calculate width
int$rotationRotation angle
null | FontStyle$defaultFontFont object
bool$filterAdjustmentAdd space for Autofilter or Table dropdown

◆ centimeterSizeToPixels()

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

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

Parameters
float | int$sizeInCmFont size (in centimeters)
Return values
floatSize (in pixels)

◆ fontSizeToPixels()

static PhpOffice\PhpSpreadsheet\Shared\Font::fontSizeToPixels ( float|int $fontSizeInPoints)
static

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

Parameters
float | int$fontSizeInPointsFont size (in points)
Return values
intFont size (in pixels)

◆ getCharsetFromFontName()

static PhpOffice\PhpSpreadsheet\Shared\Font::getCharsetFromFontName ( string $fontName)
static

Returns the associated charset for the font name.

Parameters
string$fontNameFont name
Return values
intCharacter set code

◆ getDefaultColumnWidthByFont()

static PhpOffice\PhpSpreadsheet\Shared\Font::getDefaultColumnWidthByFont ( FontStyle $font,
bool $returnAsPixels = 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
FontStyle$fontThe workbooks default font
bool$returnAsPixelstrue = return column width in pixels, false = return in OOXML units
Return values
($returnAsPixelsis true ? int : float) Column width

◆ getDefaultRowHeightByFont()

static PhpOffice\PhpSpreadsheet\Shared\Font::getDefaultRowHeightByFont ( FontStyle $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
FontStyle$fontThe workbooks default font
Return values
floatRow height in points

◆ getTextWidthPixelsApprox()

static PhpOffice\PhpSpreadsheet\Shared\Font::getTextWidthPixelsApprox ( string $columnText,
FontStyle $font,
int $rotation = 0 )
static

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

Return values
intText width in pixels (no padding added)

◆ getTrueTypeFontFileFromFont()

static PhpOffice\PhpSpreadsheet\Shared\Font::getTrueTypeFontFileFromFont ( FontStyle $font,
bool $checkPath = true )
static

Returns the font path given the font.

Return values
stringPath to TrueType font file

◆ inchSizeToPixels()

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

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

Parameters
float | int$sizeInInchFont size (in inch)
Return values
float|intSize (in pixels)

◆ setAutoSizeMethod()

static static PhpOffice\PhpSpreadsheet\Shared\Font::setAutoSizeMethod ( string $method)
static

Set autoSize method.

Parameters
string$methodsee self::AUTOSIZE_METHOD_*
Return values
boolSuccess or failure

◆ setTrueTypeFontPath()

static PhpOffice\PhpSpreadsheet\Shared\Font::setTrueTypeFontPath ( string $folderPath)
static

Set the path to the folder containing .ttf files.

There should be a trailing slash. Path will be recursively searched for font file. Typical locations on various platforms:

  • C:/Windows/Fonts/
  • /usr/share/fonts/truetype/
  • ~/.fonts/

.

Member Data Documentation

◆ CHARSET_FROM_FONT_NAME

const PhpOffice\PhpSpreadsheet\Shared\Font::CHARSET_FROM_FONT_NAME
Initial value:
= [
'EucrosiaUPC' => self::CHARSET_ANSI_THAI,
'Wingdings' => self::CHARSET_SYMBOL,
'Wingdings 2' => self::CHARSET_SYMBOL,
'Wingdings 3' => self::CHARSET_SYMBOL,
]

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