Documentation

FontMetrics
in package

The font metrics class

This class provides information about fonts and text. It can resolve font names into actual installed font files, as well as determine the size of text in a particular font and size.

Tags
static

Table of Contents

CACHE_FILE  = "dompdf_font_family_cache.php"
Name of the font cache file
$canvas  : Canvas
Underlying {@link Canvas} object to perform text size calculations
$fontLookup  : array<string|int, mixed>
Array of font family names to font files
$pdf  : Canvas
$options  : Options
__construct()  : mixed
Class initialization
get_family()  : null|string
get_font()  : string
get_font_families()  : array<string|int, mixed>
get_font_height()  : float
get_text_width()  : float
get_type()  : string
getCacheFile()  : string
getCanvas()  : Canvas
getFamily()  : null|string
getFont()  : string
Resolves a font family & subtype into an actual font file Subtype can be one of 'normal', 'bold', 'italic' or 'bold_italic'. If the particular font family has no suitable font file, the default font ({@link Options::defaultFont}) is used. The font file returned is the absolute pathname to the font file on the system.
getFontFamilies()  : array<string|int, mixed>
Returns the current font lookup table
getFontHeight()  : float
Calculates font height
getOptions()  : Options
getType()  : string
load_font_families()  : mixed
loadFontFamilies()  : mixed
Loads the stored font family cache
register_font()  : bool
registerFont()  : bool
save_font_families()  : mixed
saveFontFamilies()  : mixed
Saves the stored font family cache
set_font_family()  : mixed
setCanvas()  : $this
setFontFamily()  : mixed
setOptions()  : $this

Constants

CACHE_FILE

Name of the font cache file

public mixed CACHE_FILE = "dompdf_font_family_cache.php"

This file must be writable by the webserver process only to update it with save_font_families() after adding the .afm file references of a new font family with FontMetrics::saveFontFamilies(). This is typically done only from command line with load_font.php on converting ttf fonts to ufm with php-font-lib.

Properties

$canvas

Underlying {@link Canvas} object to perform text size calculations

protected Canvas $canvas

$fontLookup

Array of font family names to font files

protected array<string|int, mixed> $fontLookup = []

Usually cached by the script

Methods

get_family()

public get_family( $family) : null|string
Parameters
$family :
Tags
deprecated
Return values
null|string

get_font()

public get_font( $family_raw[, string $subtype_raw = "normal" ]) : string
Parameters
$family_raw :
$subtype_raw : string = "normal"
Tags
deprecated
Return values
string

get_font_families()

public get_font_families() : array<string|int, mixed>
Tags
deprecated
Return values
array<string|int, mixed>

get_font_height()

public get_font_height( $font,  $size) : float
Parameters
$font :
$size :
Tags
deprecated
Return values
float

get_text_width()

public get_text_width( $text,  $font,  $size[, float $word_spacing = 0.0 ][, float $char_spacing = 0.0 ]) : float
Parameters
$text :
$font :
$size :
$word_spacing : float = 0.0
$char_spacing : float = 0.0
Tags
deprecated
Return values
float

get_type()

public get_type( $type) : string
Parameters
$type :
Tags
deprecated
Return values
string

getCacheFile()

public getCacheFile() : string
Return values
string

getFamily()

public getFamily(string $family) : null|string
Parameters
$family : string
Return values
null|string

getFont()

Resolves a font family & subtype into an actual font file Subtype can be one of 'normal', 'bold', 'italic' or 'bold_italic'. If the particular font family has no suitable font file, the default font ({@link Options::defaultFont}) is used. The font file returned is the absolute pathname to the font file on the system.

public getFont(string $familyRaw[, string $subtypeRaw = "normal" ]) : string
Parameters
$familyRaw : string
$subtypeRaw : string = "normal"
Return values
string

getFontFamilies()

Returns the current font lookup table

public getFontFamilies() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFontHeight()

Calculates font height

public getFontHeight(string $font, float $size) : float
Parameters
$font : string
$size : float
Return values
float

getType()

public getType(string $type) : string
Parameters
$type : string
Return values
string

load_font_families()

public load_font_families() : mixed
Tags
deprecated
Return values
mixed

register_font()

public register_font(array<string|int, mixed> $style, string $remote_file[, resource $context = null ]) : bool
Parameters
$style : array<string|int, mixed>
$remote_file : string
$context : resource = null
Tags
deprecated
Return values
bool

registerFont()

public registerFont(array<string|int, mixed> $style, string $remoteFile[, resource $context = null ]) : bool
Parameters
$style : array<string|int, mixed>
$remoteFile : string
$context : resource = null
Return values
bool

save_font_families()

public save_font_families() : mixed
Tags
deprecated
Return values
mixed

saveFontFamilies()

Saves the stored font family cache

public saveFontFamilies() : mixed

The name and location of the cache file are determined by . This file should be writable by the webserver process.

Tags
see
FontMetrics::loadFontFamilies()
Return values
mixed

set_font_family()

public set_font_family(string $fontname, mixed $entry) : mixed
Parameters
$fontname : string
$entry : mixed
Tags
deprecated
Return values
mixed

setFontFamily()

public setFontFamily(string $fontname, mixed $entry) : mixed
Parameters
$fontname : string
$entry : mixed
Return values
mixed

Search results