mobile-graphic-easel-src-easeljs-display-Text.js / js
Display one or more lines of dynamic text (not user editable) in the display list. Line wrapping support (using the lineWidth) is very basic, wrapping on spaces and tabs only. Note that as an alternative to Text, you can position HTML text above or below the canvas relative to items in the display list using the {{#crossLink "DisplayObject/localToGlobal"}}{{/crossLink}} method, or using {{#crossLink "DOMElement"}}{{/crossLink}}. <b>Please note that Text does not support HTML text, and can only display one font style at a time.</b> To use multiple font styles, you will need to create multiple text instances, and position them manually. <h4>Example</h4> var text = new createjs.Text("Hello World", "20px Arial", "#ff7700"); text.x = 100; text.textBaseline = "alphabetic"; CreateJS Text supports web fonts (the same rules as Canvas). The font must be loaded and supported by the browser before it can be displayed. @class Text @extends DisplayObject @constructor
parameter: {String} [text] The text to display.
parameter: {String} [font] The font style to use. Any valid value for the CSS font attribute is acceptable (ex. "bold 36px Arial").
parameter: {String} [color] The color to draw the text in. Any valid value for the CSS color attribute is acceptable (ex. "#F00", "red", or "#FF0000").
@property _workingContext @type CanvasRenderingContext2D @private
The text to display. @property text @type String
The font style to use. Any valid value for the CSS font attribute is acceptable (ex. "bold 36px Arial"). @property font @type String
The color to draw the text in. Any valid value for the CSS color attribute is acceptable (ex. "#F00"). Default is "#000". @property color @type String
The horizontal text alignment. Any of "start", "end", "left", "right", and "center". For detailed information view the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-styles"> whatwg spec</a>. Default is "left". @property textAlign @type String
The vertical alignment point on the font. Any of "top", "hanging", "middle", "alphabetic", "ideographic", or "bottom". For detailed information view the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-styles"> whatwg spec</a>. Default is "top". @property textBaseline @type String
The maximum width to draw the text. If maxWidth is specified (not null), the text will be condensed or shrunk to make it fit in this width. For detailed information view the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-styles"> whatwg spec</a>. @property maxWidth @type Number
If true, the text will be drawn as a stroke (outline). If false, the text will be drawn as a fill. @property outline @type Boolean
Indicates the line height (vertical distance between baselines) for multi-line text. If null or 0, the value of getMeasuredLineHeight is used. @property lineHeight @type Number
Indicates the maximum width for a line of text before it is wrapped to multiple lines. If null, the text will not be wrapped. @property lineWidth @type Number
@property DisplayObject_initialize @private @type Function
Initialization method. @method initialize @protected
Returns true or false indicating whether the display object would be visible if drawn to a canvas. This does not account for whether it would be visible within the boundaries of the stage. NOTE: This method is mainly for internal use, though it may be useful for advanced uses. @method isVisible
returns: {Boolean} Whether the display object would be visible if drawn to a canvas
@property DisplayObject_draw @private @type Function
Draws the Text into the specified context ignoring it's visible, alpha, shadow, and transform. Returns true if the draw was handled (useful for overriding functionality). NOTE: This method is mainly for internal use, though it may be useful for advanced uses. @method draw
parameter: {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
parameter: {Boolean} ignoreCache Indicates whether the draw operation should ignore any current cache. For example, used for drawing the cache (to prevent it from simply drawing an existing cache back into itself).
Returns the measured, untransformed width of the text without wrapping. @method getMeasuredWidth
returns: {Number} The measured, untransformed width of the text.
Returns an approximate line height of the text, ignoring the lineHeight property. This is based on the measured width of a "M" character multiplied by 1.2, which approximates em for most fonts. @method getMeasuredLineHeight
returns: {Number} an approximate line height of the text, ignoring the lineHeight property. This is based on the measured width of a "M" character multiplied by 1.2, which approximates em for most fonts.
Returns the approximate height of multiline text by multiplying the number of lines against either the lineHeight (if specified) or getMeasuredLineHeight(). Note that this operation requires the text flowing logic to run, which has an associated CPU cost. @method getMeasuredHeight
returns: {Number} The approximate height of the drawn multiline text.
Returns a clone of the Text instance. @method clone
returns: {Text} a clone of the Text instance.
Returns a string representation of this object. @method toString
returns: {String} a string representation of the instance.
@property DisplayObject_cloneProps @private @type Function
@method cloneProps
parameter: {Text} o @protected
@method _getWorkingContext @protected
Draws multiline text. @method _getWorkingContext @protected
returns: {Number} The number of lines drawn.
@method _drawTextLine
parameter: {CanvasRenderingContext2D} ctx
parameter: {Text} text
parameter: {Number} y @protected
(C) Æliens 04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.