Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

(no description)

File Size: 637 lines (23 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.

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

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,bool $filterAdjustment = false,int $indentAdjustment = 0)   X-Ref
Calculate an (approximate) OpenXML column width, based on font size and text contained.

param: FontStyle $font Font object
param: null|RichText|string $cellText Text to calculate width
param: int $rotation Rotation angle
param: null|FontStyle $defaultFont Font object
param: bool $filterAdjustment Add space for Autofilter or Table dropdown

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.

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

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

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

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

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

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

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

getTrueTypeFontFileFromFont(FontStyle $font, bool $checkPath = true)   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.

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

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).

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

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.

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