Repository

RichText

Constructor Summary

Public Constructor
public

RichText class uses standard HTML Text to format text drawn with a certain style in a Canvas.

Member Summary

Public Members
public
public
public
public
public

events: *

public

font: *

public
public
public
public

height: *

public
public
public
public
public
public
public
public
public

text: *

public
public
public
public
public

width: *

Private Members
private
private
private
private
private
private

_font: *

private
private

_lines: *[]

Method Summary

Public Methods
public

getCanvas(): Canvas

Get the canvas

public

Get canvas height

public

Returns the width and height of the drawn text in pixels.

public

Get canvas width

public

parseDOMTree(baseNode: DOMNodeObject): Array

Stater method to process the html tree.

public

processDOMTree(baseNode: DOMNodeObject, destArray: Array): *

Recursive process of an html tree from it's main node. This method return a linear list (in the original text strings order) of StyledTextElement in order to cumulate all the tags a piece of string is attach to and the attributes of its immediate parent tag.

public

Render the input HTML text parsed in an array of StyledTextElement in the current canvas

public

setText(text: String)

Private Methods
private
private

Setup bloc called after default font loading

Public Constructors

public constructor(params: Object) source

RichText class uses standard HTML Text to format text drawn with a certain style in a Canvas. Supported HTML style tags are <b> <strong> <i> <em> <br> <p> <font> with attributes color and size. TODO : support of face attribute in <font>. Default font are predefined.

Params:

NameTypeAttributeDescription
paramsObject

Parameters object, given by the constructor.

params.widthNumber
  • optional
  • default: 512

width of the inner canvas

params.heightNumber
  • optional
  • default: 512

height of the inner canvas

params.lineHeightNumber
  • optional
  • default: 1

line height for the text

params.marginsNumber
  • optional
  • default: 10

white space (margin) in pixel on all left, top, right and bottom of the canvas. Text will be drawn within these boundaries with automatic newline management.

params.marginLeftNumber
  • optional
  • default: undefined

white space (margin) in pixel on left side.

params.marginTopNumber
  • optional
  • default: undefined

white space (margin) in pixel on top side.

params.marginRightNumber
  • optional
  • default: undefined

white space (margin) in pixel on right side.

params.marginBottomNumber
  • optional
  • default: undefined

white space (margin) in pixel on bottom side.

params.textSizeNumber
  • optional
  • default: 20

size, in pixels, of the text

params.textColorColor
  • optional
  • default: black

color the text default color

params.textAlignColor
  • optional
  • default: "left"

text alignment in the canvas (margins included), can be one of "left", "center", "right".

params.backgroundColorColor
  • optional
  • default: white

color the background color

params.drawBoundingBoxBoolean
  • optional
  • default: false

tell to draw the bounding boxes of every text blocs or not

params.boundingBoxStrokeWidthNumber
  • optional
  • default: 1

the lineWidth to use for bounding boxes drawing

params.fontFont

Mobilizing Font for the regular font file

params.fontItalicFont

Mobilizing Font for the italic font file

params.fontBoldFont

Mobilizing Font for the bold font file

params.fontBoldItalicFont

Mobilizing Font for the bold-italic font file

Public Members

public autoRender: * source

public backgroundColor: * source

public boundingBoxStrokeWidth: * source

public drawBoundingBox: * source

public events: * source

public font: * source

public fontBold: * source

public fontBoldItalic: * source

public fontItalic: * source

public height: * source

public lineHeight: * source

public marginBottom: * source

public marginLeft: * source

public marginRight: * source

public marginTop: * source

public margins: * source

public maxLines: * source

public styledText: * source

public text: * source

public textAlign: * source

public textColor: * source

public textDimensions: {} source

public textSize: * source

public width: * source

Private Members

private _DOMText: * source

private _boldFont: * source

private _boldItalicFont: * source

private _canvas: * source

private _canvasContext: * source

private _font: * source

private _italicFont: * source

private _lines: *[] source

Public Methods

public getCanvas(): Canvas source

Get the canvas

Return:

Canvas

canvas

public getHeight(): Number source

Get canvas height

Return:

Number

canvas height

public getTextDimensions(): Object source

Returns the width and height of the drawn text in pixels. Computation uses margins and the actual size of the text.

Return:

Object

{width, heigth}

public getWidth(): Number source

Get canvas width

Return:

Number

canvas width

public parseDOMTree(baseNode: DOMNodeObject): Array source

Stater method to process the html tree. Manage internally the array used afterward to contain all StyledTextElement.

Params:

NameTypeAttributeDescription
baseNodeDOMNodeObject

Return:

Array

the resulting StyledTextElement array

public processDOMTree(baseNode: DOMNodeObject, destArray: Array): * source

Recursive process of an html tree from it's main node. This method return a linear list (in the original text strings order) of StyledTextElement in order to cumulate all the tags a piece of string is attach to and the attributes of its immediate parent tag.

Params:

NameTypeAttributeDescription
baseNodeDOMNodeObject
destArrayArray

the array of destination

Return:

*

public render() source

Render the input HTML text parsed in an array of StyledTextElement in the current canvas

public setText(text: String) source

Params:

NameTypeAttributeDescription
textString

Private Methods

private computeTextDimensions() source

private setup() source

Setup bloc called after default font loading