import RichText from '@mobilizing/library/js/Mobilizing/text/RichText.js'
RichText
Constructor Summary
Public Constructor | ||
public | constructor(params: Object) RichText class uses standard HTML Text to format text drawn with a certain style in a Canvas. |
Member Summary
Public Members | ||
public | autoRender: * | |
public | ||
public | ||
public | ||
public | events: * | |
public | font: * | |
public | fontBold: * | |
public | ||
public | fontItalic: * | |
public | height: * | |
public | lineHeight: * | |
public | marginBottom: * | |
public | marginLeft: * | |
public | marginRight: * | |
public | marginTop: * | |
public | margins: * | |
public | maxLines: * | |
public | styledText: * | |
public | text: * | |
public | textAlign: * | |
public | textColor: * | |
public | textDimensions: {} | |
public | textSize: * | |
public | width: * |
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() Render the input HTML text parsed in an array of StyledTextElement in the current canvas | |
public |
Private Methods | ||
private | ||
private | setup() 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:
Name | Type | Attribute | Description |
params | Object | Parameters object, given by the constructor. | |
params.width | Number |
| width of the inner canvas |
params.height | Number |
| height of the inner canvas |
params.lineHeight | Number |
| line height for the text |
params.margins | Number |
| 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.marginLeft | Number |
| white space (margin) in pixel on left side. |
params.marginTop | Number |
| white space (margin) in pixel on top side. |
params.marginRight | Number |
| white space (margin) in pixel on right side. |
params.marginBottom | Number |
| white space (margin) in pixel on bottom side. |
params.textSize | Number |
| size, in pixels, of the text |
params.textColor | Color |
| color the text default color |
params.textAlign | Color |
| text alignment in the canvas (margins included), can be one of "left", "center", "right". |
params.backgroundColor | Color |
| color the background color |
params.drawBoundingBox | Boolean |
| tell to draw the bounding boxes of every text blocs or not |
params.boundingBoxStrokeWidth | Number |
| the lineWidth to use for bounding boxes drawing |
params.font | Font | Mobilizing Font for the regular font file | |
params.fontItalic | Font | Mobilizing Font for the italic font file | |
params.fontBold | Font | Mobilizing Font for the bold font file | |
params.fontBoldItalic | Font | 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 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 parseDOMTree(baseNode: DOMNodeObject): Array source
Stater method to process the html tree. Manage internally the array used afterward to contain all StyledTextElement.
Params:
Name | Type | Attribute | Description |
baseNode | DOMNodeObject |
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:
Name | Type | Attribute | Description |
baseNode | DOMNodeObject | ||
destArray | Array | the array of destination |
Return:
* |
public render() source
Render the input HTML text parsed in an array of StyledTextElement in the current canvas
Private Methods
private computeTextDimensions() source
private setup() source
Setup bloc called after default font loading