API Docs for:
Show:

gs.Font Class

A class to describe fonts. Fonts can be loaded from installed fonts or from imported fonts. (Graphics/Fonts)

Constructor

gs.Font

(
  • name
  • size
)

Parameters:

  • name String
    • The font name.
  • size String
    • The font size in pixels.

Methods

compare

(
  • font
)
Boolean

Compares the font to the specified font. Only name and size are compared.

Parameters:

  • font gs.Font
    • The font to compare to.

Returns:

Boolean:

If true both fonts are equal. Otherwise false

createDefault

() gs.Font static

Creates a new default font.

Returns:

gs.Font:

A new created default font.

loadCustomFonts

(
  • A
)

Loads custom fonts and makes them ready to use.

Parameters:

  • A Function

    callback called if the loading-process has been done. It has the following signature:

    
    // error - Indicates if an error occurred during the loading-process
    function(error) {}
    

measureChar

(
  • c
)
gs.Size

Measures the size of a single character. The result isn't pixel-perfect.

Parameters:

  • c String
    • A single character.

Returns:

gs.Size:

The size of the character.

measureText

(
  • text
)
gs.Size

Measures a specified text. The result isn't pixel-perfect.

Parameters:

  • text String
    • The text to measure.

Returns:

gs.Size:

The size of the text.

measureTextPlain

(
  • text
)
gs.Size

Measures a specified text as plain text. Formatting like outlines, style, etc. is ignored. The result isn't pixel-perfect.

Parameters:

  • text String
    • The text to measure.

Returns:

gs.Size:

The size of the text.

set

(
  • font
)

Assigns all properties from the specified font.

Parameters:

  • font gs.Font
    • The font to get all properties from.

toDataBundle

() Object

Converts the font into a data bundle.

Returns:

Object:

The data bundle.

toDataBundle

(
  • data
)

Restores the font from a data bundle.

Parameters:

  • data Object
    • The data bundle.

toString

() String

Returns a CSS string representation of the font like "italic bold 12px Arial".

Returns:

String:

A CSS representation of the font.

Properties

@shadowOffsetX

Number

The vertical shadow offset.

@shadowOffsetX

Number

The horizontal shadow offset.

bold

Boolean

Indicates if the font-style is bold.

border

Boolean

Indicates if the font has an outline/border.

borderColor

gs.Color

The outline color.

borderSize

Number

The outline size.

color

gs.Color

The font's color.

italic

Boolean

Indicates if the font-style is italic.

loaded

Boolean

Indicates if the font is loaded.

metrics

gs.FontMetrics

Font metrics contains additional info about the font.

name

String

The font name.

shadow

Boolean

Indicates if the font has a shadow.

shadowColor

gs.Color

The shadow color.

size

Number

The font size in pixels.

smallCaps

Boolean

Indicates if the font-style is small-caps.

strikeThrough

Boolean

Indicates if the font-style is strike-through.

underline

Boolean

Indicates if the font-style is underline.