Font
Source: AWT.js:38
Font contains properties and provides methods to manage fonts
Constructor
new Font(
family?: string,
size?: number,
bold?: number,
italic?: number,
variant?: string,
): FontFont constructor
Parameters
family(string, optional, default: "'Arial'")size(number, optional, default: 17)bold(number, optional, default: 0)italic(number, optional, default: 0)variant(string, optional, default: "''")
Instance Methods
setProperties($xml: external:jQuery): module:AWT.Font
Reads the properties of this Font from an XML element
Parameters
$xml(external:jQuery) — The xml element to be parsed
Returns
getAttributes(): object
Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.
Returns
object
setAttributes(data: object): module:AWT.Font
Reads the properties of this Font from a data object
Parameters
data(object) — The data object to be parsed
Returns
setSize(size: number): module:AWT.Font
Allows to change the size member, recalculating the vertical metrics.
Parameters
size(number) — The new size to set
Returns
zoom(amount: number): module:AWT.Font
Increases or decreases the current font size by the specified amount
Parameters
amount(number) — The amount to increase or decrease current size
Returns
getMetrics(): Object
Calculates the font metrics
Returns
Object
getHeight(): number
Calculates the font metrics and returns its height
Returns
number
toCss(css: object): object
Translates the Font properties into CSS statements
Parameters
css(object) — The object where to add CSS properties. When null or undefined, a new
object will be created and returned.
Returns
object
cssFont(): string
Gets the codification of this font in a single string, suitable to be used in a font
CSS attribute.
Returns
string
_calcHeight(): module:AWT.Font
The TextMetrics object used
by CanvasRenderingContext2D
does not provide a heigth value for rendered text.
This stackoverflow question
has an excellent response by Daniel Earwicker explaining how to measure the
vertical dimension of rendered text using a span element.
The code has been slighty adapted to deal with Font objects.
Warning: Do not call this method direcly. Use getHeight() or getMetrics() instead
Returns
equals(font: module:AWT.Font): boolean
Checks if two Font objects are equivalent
Parameters
font(module:AWT.Font) — The Font object to compare against this one
Returns
boolean
Static Methods
checkTree($tree: external:jQuery, options?: object)
Finds the XML elements with typeface specifications, checks its value against the font
substitution list, replacing the family attribute and loading the alternative font when needed.
Parameters
$tree(external:jQuery) — The xml element to be processedoptions(object, optional) — Optional param that can contain afontSubstitutionsattribute with
a substition table to be added to SUBSTITUTIONS
loadGoogleFont(name: string)
Try to load a specific font from [http://www.google.com/fonts]
Parameters
name(string) — The font family name
loadGoogleFonts(fonts: Array.<string>)
Try to load a set of Google fonts
Parameters
fonts(Array.<string>) — An array of font names
Instance Fields
family: string
The font-family property
size: number
The font size
Warning: Do not change size directly. Use setSize() instead.
bold: number
The font bold value
italic: number
The font italic value
variant: string
The font variant value
Static Fields
ALREADY_CALCULATED_FONTS
Array of font objects with already calculated heights
ALREADY_LOADED_FONTS
Array of font names already loaded from Google Fonts, or generic names provided by browsers by default
See: https://developer.mozilla.org/en-US/docs/Web/CSS/font-family
SUBSTITUTIONS
Google Fonts equivalent for special fonts used in some JClic projects.
More substitutions can be added to the list for specific projects indicating a
fontSubstitutions object in the data-options attribute of the HTML div element
containing the player.
For example:
<div class ="JClic" data-project="demo.jclic" data-options='{"fontSubstitutions":{"arial":"Arimo"}}'/>
GOOGLEFONTS
Google Fonts currently used in substitutions