API Documentation

for 0.0.1
Show:

RichText Class

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

, with attributes color and size. TODO : support of face attribute in . Default font are predefined.

Constructor

RichText

(
  • params
)

Parameters:

  • params Object

    Parameters Object

    • htmlText HTMLNode

      the html text to draw in the canvas

    • [width=512] Number optional

      width of the inner canvas

    • [height=512] Number optional

      height of the inner canvas

    • [lineHeight=1] Number optional

      line height for the text

    • [margins=10] Number optional

      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.

    • [marginLeft=10] Number optional

      white space (margin) in pixel on left side.

    • [marginTop=10] Number optional

      white space (margin) in pixel on top side.

    • [marginRight=10] Number optional

      white space (margin) in pixel on right side.

    • [marginBottom=10] Number optional

      white space (margin) in pixel on bottom side.

    • [textSize=20] Number optional

      size, in pixels, of the text

    • [textColor=black] Color optional

      color the text default color

    • [textAlign="left"] Color optional

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

    • [backgroundColor=white] Color optional

      color the background color

    • [drawBoundingBox=false] Boolean optional

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

    • [boundingBoxStrokeWidth=1] Number optional

      the lineWidth to use for bounding boxes drawing

    • fontURL URL

      url for the regular font file

    • fontItalicURL URL

      url for the italic font file

    • fontBoldURL URL

      url for the bold font file

    • fontBoldItalicURL URL

      url for the bold-italic font file

Methods

getCanvas

() Canvas

Get the canvas

Returns:

Canvas:

canvas

getContext

() Context

Inherited from Base but overwritten in src/js/Mobilizing/Base.js:37

Get the Mobilizing context

Returns:

Context: The Mobilizing context

getHeight

() Number

Get canvas height

Returns:

Number:

canvas height

getID

() Int
Get the Object unique ID

Returns:

Int: The Object ID

getWidth

() Number

Get canvas width

Returns:

Number:

canvas width

parseDOMTree

(
  • baseNode
)
Array

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

Parameters:

  • baseNode DOMNodeObject

Returns:

Array:

the resulting StyledTextElement array

processDOMTree

(
  • baseNode
  • destArray
)

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.

Parameters:

  • baseNode DOMNodeObject
  • destArray Array

    the array of destination

render

()

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

setContext

(
  • context
)
Set the Mobilizing context

Parameters:

  • context Context
    The Mobilizing Context

setName

(
  • name
)
Set the Object name

Parameters:

  • name String
    The Object name

setup

() private

Setup bloc called after default font loading

Properties

_context

Context private
A reference to the Mobilizing context

Events

drawn

Triggered when the canvas has been redrawn, useful to synchronise Texture update and canvas refresh