Class zebkit.Font <zebkit>

This class represents a font and provides basic font metrics like height, ascent. Using the class developers can compute string width.

// plain font
var f = new zebkit.Font("Arial", 14);

// bold font
var f = new zebkit.Font("Arial", "bold", 14);

// defining font with CSS font name
var f = new zebkit.Font("100px Futura, Helvetica, sans-serif");
Constructor:
zebkit.Font (name, [style], [size])

Parameters:
  • name <String>

    a name of the font. If size and style parameters has not been passed the name is considered as CSS font name that includes size and style

  • [style] <String>

    a style of the font: "bold", "italic", etc

  • [size] <Integer>

    a size of the font



public <Integer> charsWidth (s, off, len)

Calculate the specified substring width


Parameters:
  • s <String>

    a string

  • off <Integer>

    fist character index

  • len <Integer>

    length of substring


Returns: <Integer>

a substring size in pixels

public <zebkit.Font> resize (size)

Resize font and return new instance of font class with new size.


Parameters:
  • size <Integer | String>

    can be specified in pixels as integer value or as a percentage from the given font:


Returns: <zebkit.Font>

a font


Example:
var font = new zebkit.Font(10); // font 10 pixels
font = font.resize("200%"); // two times higher font
public <zebkit.Font> restyle (style)

Restyle font and return new instance of the font class


Parameters:
Returns: <zebkit.Font>

a font

public <Integer> stringWidth (s)

Compute the given string width in pixels basing on the font metrics.


Parameters:
Returns: <Integer>

a string width

public <String> toString ( )

Returns CSS font representation


Returns: <String>

a CSS representation of the given Font


public <Integer> ascent

Ascent of the font

public <String> family

Font family.

public <Integer> height

Height of the font

public <String> style

Font style (for instance "bold").