Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

(no description)

File Size: 758 lines (27 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Font  - X-Ref

setAutoSizeMethod($method)   X-Ref
Set autoSize method.

return: bool Success or failure
param: string $method see self::AUTOSIZE_METHOD_*

getAutoSizeMethod()   X-Ref
Get autoSize method.

return: string

setTrueTypeFontPath($folderPath)   X-Ref
Set the path to the folder containing .ttf files. There should be a trailing slash.
Typical locations on variout some platforms:
<ul>
<li>C:/Windows/Fonts/</li>
<li>/usr/share/fonts/truetype/</li>
<li>~/.fonts/</li>
</ul>.

param: string $folderPath

getTrueTypeFontPath()   X-Ref
Get the path to the folder containing .ttf files.

return: string

calculateColumnWidth(FontStyle $font, $cellText = '', $rotation = 0, ?FontStyle $defaultFont = null)   X-Ref
Calculate an (approximate) OpenXML column width, based on font size and text contained.

return: int Column width
param: FontStyle $font Font object
param: RichText|string $cellText Text to calculate width
param: int $rotation Rotation angle
param: null|FontStyle $defaultFont Font object

getTextWidthPixelsExact(string $text, FontStyle $font, int $rotation = 0)   X-Ref
Get GD text width in pixels for a string of text in a certain font at a certain rotation angle.


getTextWidthPixelsApprox($columnText, FontStyle $font, $rotation = 0)   X-Ref
Get approximate width in pixels for a string of text in a certain font at a certain rotation angle.

return: int Text width in pixels (no padding added)
param: string $columnText
param: int $rotation

fontSizeToPixels($fontSizeInPoints)   X-Ref
Calculate an (approximate) pixel size, based on a font points size.

return: int Font size (in pixels)
param: int $fontSizeInPoints Font size (in points)

inchSizeToPixels($sizeInInch)   X-Ref
Calculate an (approximate) pixel size, based on inch size.

return: int Size (in pixels)
param: int $sizeInInch Font size (in inch)

centimeterSizeToPixels($sizeInCm)   X-Ref
Calculate an (approximate) pixel size, based on centimeter size.

return: float Size (in pixels)
param: int $sizeInCm Font size (in centimeters)

getTrueTypeFontFileFromFont(FontStyle $font)   X-Ref
Returns the font path given the font.

return: string Path to TrueType font file

getCharsetFromFontName($fontName)   X-Ref
Returns the associated charset for the font name.

return: int Character set code
param: string $fontName Font name

getDefaultColumnWidthByFont(FontStyle $font, $returnAsPixels = false)   X-Ref
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).

return: mixed Column width
param: FontStyle $font The workbooks default font
param: bool $returnAsPixels true = return column width in pixels, false = return in OOXML units

getDefaultRowHeightByFont(FontStyle $font)   X-Ref
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.

return: float Row height in points
param: FontStyle $font The workbooks default font