A Javascript HTML5 canvas bitmap font renderer, with color-changing abilities. Additional examples coming soon.
Example font definition
var fontMetrics = {
'img': 'images/font3.png', // Can be either pre-loaded DOMElement or img src
'space': 5, // Width of spaces
'tab': 15, // Width of tabs
// Character definition
'character': [top-left x, top-left y, width, height, line height (optional)],
// Example with numbers
'0': [0,1,8,11],
'1': [10,1,5,11],
'2': [20,1,8,11],
'3': [30,1,8,11],
'4': [40,1,8,11],
'5': [50,1,8,11],
'6': [60,1,8,11],
'7': [70,1,8,11],
'8': [80,1,8,11],
'9': [90,1,8,11]
};
Kind: global class
Access: public
- FontBrite
- new FontBrite(ctx)
- instance
- .getFont(name) ⇒
object
- .defineFont(metrics, name) ⇒
string
- .getStringHeight(font, string) ⇒
number
- .getStringWidth(font, string) ⇒
number
- .renderLine(font, string, x, y) ⇒
number
- .renderBlock(font, string, [x], [y], [w], [h], [lh]) ⇒
number
- .colorizeFont([name], font, h, [s], [l]) ⇒
string
- .getFont(name) ⇒
- static
- .hslToRgb(h, s, l) ⇒
Object
- .rgbToHsl(r, g, b) ⇒
Object
- .hslToRgb(h, s, l) ⇒
FontBrite - The awesome color-changing bitmap font rendererer
Param | Type | Description |
---|---|---|
ctx | object |
A canvas context that will be used for output |
Retrieves font metrics for a defined font
Kind: instance method of FontBrite
Returns: object
- The font metrics object
Access: public
Param | Type | Description |
---|---|---|
name | string |
The name of the font to load |
Defines (stores) font metrics with a name
Kind: instance method of FontBrite
Returns: string
- The name of the defined font
Access: public
Param | Type | Description |
---|---|---|
metrics | object |
The metrics object, with dimensions of each character, and source image |
name | string |
The name of the font to define |
Gets the height of the string for the given font (single lines only)
Kind: instance method of FontBrite
Returns: number
- The height
Access: public
Param | Type | Description |
---|---|---|
font | string |
The name of a defined font to use |
string | string |
The string to get the height of |
Gets the width of the string for the given font (single lines only)
Kind: instance method of FontBrite
Returns: number
- The width
Access: public
Param | Type | Description |
---|---|---|
font | string |
The name of a defined font to use |
string | string |
The string to get the width of |
Renders a single line of text in the given font
Kind: instance method of FontBrite
Returns: number
- The bottom y-coordinate of the rendered line
Access: public
Param | Type | Description |
---|---|---|
font | string |
The name of a defined font to use |
string | string |
The string to render |
x | number |
The x-coordinate of the top-left of the output |
y | number |
The y-coordinate of the top-left of the output |
Renders a block (paragraph) of text in the given font
Kind: instance method of FontBrite
Returns: number
- The bottom y-coordinate of the rendered line (may be different from y + h, due to font/line height)
Access: public
Param | Type | Default | Description |
---|---|---|---|
font | string |
The name of a defined font to use | |
string | string |
The string to render | |
[x] | number |
0 |
The x-coordinate of the top-left of the block |
[y] | number |
0 |
The y-coordinate of the top-left of the block |
[w] | number |
Remaining space in canvas |
The desired width of the block. Long lines will be wrapped on whitespace |
[h] | number |
Remaining space in canvas |
The desired height of the block. Long blocks will be truncated |
[lh] | number |
Height of each rendered line |
The desired line height of each line in the block |
Colorizes a font, replacing hot pink in any shade (r === b), with a desired color
Kind: instance method of FontBrite
Returns: string
- The name of the defined font
Access: public
Param | Type | Default | Description |
---|---|---|---|
[name] | string |
"font__h_s_l" |
The stored name of the resulting font |
font | string |
The name of a defined font to use | |
h | number |
The hue to colorzie the font to | |
[s] | number |
100 |
The saturation to use when colorizing the font |
[l] | number |
Source pixel luminosity |
The luminosity to use when colorizing the font |
Converts an HSL color to RGB
Kind: static method of FontBrite
Returns: Object
- The output containing the RGB values for that color
Access: public
Param | Type | Description |
---|---|---|
h | number |
The input hue (0-360) |
s | number |
The input saturation (0-100) |
l | number |
The input luminosity (0-100) |
Converts an RGB color to HSL
Kind: static method of FontBrite
Returns: Object
- The output containing the HSL values for that color
Access: public
Param | Type | Description |
---|---|---|
r | number |
The input red component |
g | number |
The input green component |
b | number |
The input blue component |
Kind: global namespace
- FontBrite :
object
- new FontBrite(ctx)
- instance
- .getFont(name) ⇒
object
- .defineFont(metrics, name) ⇒
string
- .getStringHeight(font, string) ⇒
number
- .getStringWidth(font, string) ⇒
number
- .renderLine(font, string, x, y) ⇒
number
- .renderBlock(font, string, [x], [y], [w], [h], [lh]) ⇒
number
- .colorizeFont([name], font, h, [s], [l]) ⇒
string
- .getFont(name) ⇒
- static
- .hslToRgb(h, s, l) ⇒
Object
- .rgbToHsl(r, g, b) ⇒
Object
- .hslToRgb(h, s, l) ⇒
FontBrite - The awesome color-changing bitmap font rendererer
Param | Type | Description |
---|---|---|
ctx | object |
A canvas context that will be used for output |
Retrieves font metrics for a defined font
Kind: instance method of FontBrite
Returns: object
- The font metrics object
Access: public
Param | Type | Description |
---|---|---|
name | string |
The name of the font to load |
Defines (stores) font metrics with a name
Kind: instance method of FontBrite
Returns: string
- The name of the defined font
Access: public
Param | Type | Description |
---|---|---|
metrics | object |
The metrics object, with dimensions of each character, and source image |
name | string |
The name of the font to define |
Gets the height of the string for the given font (single lines only)
Kind: instance method of FontBrite
Returns: number
- The height
Access: public
Param | Type | Description |
---|---|---|
font | string |
The name of a defined font to use |
string | string |
The string to get the height of |
Gets the width of the string for the given font (single lines only)
Kind: instance method of FontBrite
Returns: number
- The width
Access: public
Param | Type | Description |
---|---|---|
font | string |
The name of a defined font to use |
string | string |
The string to get the width of |
Renders a single line of text in the given font
Kind: instance method of FontBrite
Returns: number
- The bottom y-coordinate of the rendered line
Access: public
Param | Type | Description |
---|---|---|
font | string |
The name of a defined font to use |
string | string |
The string to render |
x | number |
The x-coordinate of the top-left of the output |
y | number |
The y-coordinate of the top-left of the output |
Renders a block (paragraph) of text in the given font
Kind: instance method of FontBrite
Returns: number
- The bottom y-coordinate of the rendered line (may be different from y + h, due to font/line height)
Access: public
Param | Type | Default | Description |
---|---|---|---|
font | string |
The name of a defined font to use | |
string | string |
The string to render | |
[x] | number |
0 |
The x-coordinate of the top-left of the block |
[y] | number |
0 |
The y-coordinate of the top-left of the block |
[w] | number |
Remaining space in canvas |
The desired width of the block. Long lines will be wrapped on whitespace |
[h] | number |
Remaining space in canvas |
The desired height of the block. Long blocks will be truncated |
[lh] | number |
Height of each rendered line |
The desired line height of each line in the block |
Colorizes a font, replacing hot pink in any shade (r === b), with a desired color
Kind: instance method of FontBrite
Returns: string
- The name of the defined font
Access: public
Param | Type | Default | Description |
---|---|---|---|
[name] | string |
"font__h_s_l" |
The stored name of the resulting font |
font | string |
The name of a defined font to use | |
h | number |
The hue to colorzie the font to | |
[s] | number |
100 |
The saturation to use when colorizing the font |
[l] | number |
Source pixel luminosity |
The luminosity to use when colorizing the font |
Converts an HSL color to RGB
Kind: static method of FontBrite
Returns: Object
- The output containing the RGB values for that color
Access: public
Param | Type | Description |
---|---|---|
h | number |
The input hue (0-360) |
s | number |
The input saturation (0-100) |
l | number |
The input luminosity (0-100) |
Converts an RGB color to HSL
Kind: static method of FontBrite
Returns: Object
- The output containing the HSL values for that color
Access: public
Param | Type | Description |
---|---|---|
r | number |
The input red component |
g | number |
The input green component |
b | number |
The input blue component |