Constructor
new Font(familyopt, sizeopt, boldopt, italicopt, variantopt)
Font constructor
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
family | string | <optional> | 'Arial' | |
size | number | <optional> | 17 | |
bold | number | <optional> | 0 | |
italic | number | <optional> | 0 | |
variant | string | <optional> | '' |
Members
bold :number
The font bold value
- number
family :string
The font-family
property
- string
italic :number
The font italic value
- number
size :number
The font size
Warning: Do not change size
directly. Use setSize()
instead.
- number
variant :string
The font variant value
- string
(static) ALREADY_CALCULATED_FONTS
Array of font objects with already calculated heights
(static) 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
(static) GOOGLEFONTS
Google Fonts currently used in substitutions
(static) SUBSTITUTIONS
Google Fonts equivalent for special fonts used in some JClic projects.
More substitutions can be added to the list for specific projects indicating afontSubstitutions
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"}}'/>
Methods
_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
- Type:
- module:AWT.
Font
cssFont() → {string}
Gets the codification of this font in a single string, suitable to be used in a font
CSS attribute.
- A string with all the CSS font properties concatenated
- Type:
- string
equals(font) → {boolean}
Checks if two Font objects are equivalent
Name | Type | Description |
---|---|---|
font | module:AWT. | The Font object to compare against this one |
true
if both objects are equivalent,false
otherwise
- Type:
- boolean
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.
- The resulting object, with minimal attrributes
- Type:
- object
getHeight() → {number}
Calculates the font metrics and returns its height
- The font height
- Type:
- number
getMetrics() → {Object}
Calculates the font metrics
- The font metrics
- Type:
- Object
setAttributes(data) → {module:AWT.Font}
Reads the properties of this Font from a data object
Name | Type | Description |
---|---|---|
data | object | The data object to be parsed |
- Type:
- module:AWT.
Font
setProperties($xml) → {module:AWT.Font}
Reads the properties of this Font from an XML element
Name | Type | Description |
---|---|---|
$xml | external:jQuery | The xml element to be parsed |
- Type:
- module:AWT.
Font
setSize(size) → {module:AWT.Font}
Allows to change the size
member, recalculating the vertical metrics.
Name | Type | Description |
---|---|---|
size | number | The new size to set |
- Type:
- module:AWT.
Font
toCss(css) → {object}
Translates the Font properties into CSS statements
Name | Type | Description |
---|---|---|
css | object | The object where to add CSS properties. When null or undefined, a new |
- A set of CSS property-values pairs, ready to be used by JQuery
.css(properties).
- Type:
- object
zoom(amount) → {module:AWT.Font}
Increases or decreases the current font size by the specified amount
Name | Type | Description |
---|---|---|
amount | number | The amount to increase or decrease current size |
- Type:
- module:AWT.
Font
(static) checkTree($tree, optionsopt)
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.
Name | Type | Attributes | Description |
---|---|---|---|
$tree | external:jQuery | The xml element to be processed | |
options | object | <optional> | Optional param that can contain a |
(static) loadGoogleFont(name)
Try to load a specific font from [http://www.google.com/fonts]
Name | Type | Description |
---|---|---|
name | string | The font family name |
(static) loadGoogleFonts(fonts)
Try to load a set of Google fonts
Name | Type | Description |
---|---|---|
fonts | Array.<string> | An array of font names |