1 /**
  2  * The Render Engine
  3  * AbstractTextRenderer
  4  *
  5  * @fileoverview Abstract class that provides basic interface for all
  6  *               text render objects used by the text renderer.
  7  *
  8  * @author: Brett Fattori (brettf@renderengine.com)
  9  *
 10  * @author: $Author: bfattori $
 11  * @version: $Revision: 1555 $
 12  *
 13  * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com)
 14  *
 15  * Permission is hereby granted, free of charge, to any person obtaining a copy
 16  * of this software and associated documentation files (the "Software"), to deal
 17  * in the Software without restriction, including without limitation the rights
 18  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 19  * copies of the Software, and to permit persons to whom the Software is
 20  * furnished to do so, subject to the following conditions:
 21  *
 22  * The above copyright notice and this permission notice shall be included in
 23  * all copies or substantial portions of the Software.
 24  *
 25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 28  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 30  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 31  * THE SOFTWARE.
 32  *
 33  */
 34 
 35 // The class this file defines and its required classes
 36 R.Engine.define({
 37     "class":"R.text.AbstractTextRenderer",
 38     "requires":[
 39         "R.components.Base"
 40     ]
 41 });
 42 
 43 /**
 44  * @class Abstract class that provides the basic interface for all
 45  *        text render objects used by the {@link R.text.TextRenderer}.
 46  *
 47  * @constructor
 48  * @param componentName {String} The name of the renderer
 49  * @param priority {Number} The priority of the rendering order. Default: <tt>0.1</tt>
 50  * @extends R.components.Base
 51  */
 52 R.text.AbstractTextRenderer = function () {
 53     return R.components.Base.extend(/** @scope R.text.AbstractTextRenderer.prototype */{
 54 
 55         text:null,
 56         color:"#000000",
 57         alignment:null,
 58         weight:null,
 59         size:1,
 60         font:null,
 61         style:null,
 62         lineSpacing:7,
 63 
 64         /** @private */
 65         constructor:function (componentName, priority) {
 66             this.base(componentName || "TextRenderObject", R.components.Base.TYPE_RENDERING, priority || 0.1);
 67 
 68             this.text = "";
 69             this.size = 1;
 70             this.weight = 1;
 71             this.font = null;
 72             this.style = null;
 73             this.alignment = R.text.AbstractTextRenderer.ALIGN_LEFT;
 74             this.lineSpacing = 7;
 75         },
 76 
 77         /**
 78          * Releases the object back into the object pool.  See {@link R.engine.PooledObject#release}
 79          * for more information.
 80          */
 81         release:function () {
 82             this.base();
 83             this.text = null;
 84             this.color = "#000000";
 85             this.size = 1;
 86             this.weight = null;
 87             this.font = null;
 88             this.style = null;
 89             this.alignment = null;
 90             this.lineSpacing = 7;
 91         },
 92 
 93         /**
 94          * Return <tt>true</tt> if the text renderer is native to the context.
 95          * @return {Boolean}
 96          */
 97         isNative:function () {
 98             return false;
 99         },
100 
101         /**
102          * Get the text being rendered
103          * @return {String} The text this renderer will draw
104          */
105         getText:function () {
106             return this.text;
107         },
108 
109         /**
110          * Set the text to be rendered
111          *
112          * @param text {String} The text to render
113          */
114         setText:function (text) {
115             this.text = text;
116         },
117 
118         /**
119          * Set the font of the text to be renderer
120          * @param font {String} The font name
121          */
122         setTextFont:function (font) {
123             this.font = font;
124         },
125 
126         /**
127          * Get the font of the text to be rendered
128          * @return {String} The font name
129          */
130         getTextFont:function () {
131             return this.font;
132         },
133 
134         /**
135          * Set the weight of the text to render.  Higher weights
136          * are bolder text.
137          *
138          * @param weight {Number} The weight of the text.
139          */
140         setTextWeight:function (weight) {
141             this.weight = weight;
142         },
143 
144         /**
145          * Get the weight of the text to render.
146          * @return {Number} The weight of the text
147          */
148         getTextWeight:function () {
149             return this.weight;
150         },
151 
152         /**
153          * Set the style of the text, usually italics or normal, for the text renderer.
154          * @param style {Object} The style of the text
155          */
156         setTextStyle:function (style) {
157             this.style = style;
158         },
159 
160         /**
161          * Get the style of the text for the renderer.
162          * @return {Object} The style of the text
163          */
164         getTextStyle:function () {
165             return this.style;
166         },
167 
168         /**
169          * Set the alignment of the text.
170          *
171          * @param alignment {Object} The alignment for the text renderer
172          */
173         setTextAlignment:function (alignment) {
174             this.alignment = alignment;
175         },
176 
177         /**
178          * Get the alignment of the text.
179          * @return {Object} The alignment of the text renderer
180          */
181         getTextAlignment:function () {
182             return this.alignment;
183         },
184 
185         /**
186          * Set the scaling of the text
187          * @param size {Number}
188          */
189         setSize:function (size) {
190             this.size = size;
191         },
192 
193         /**
194          * Get the scaling of the text
195          * @return {Number}
196          */
197         getSize:function () {
198             return this.size;
199         },
200 
201         /**
202          * Set the color of the text to render.
203          *
204          * @param color {String} The color of the text to render
205          */
206         setColor:function (color) {
207             this.color = color;
208         },
209 
210         /**
211          * Get the color of the text to render.
212          * @return {String} The text color
213          */
214         getColor:function () {
215             return this.color;
216         },
217 
218         /**
219          * Set the line spacing between lines of text in a multi-line text string.
220          * Multi-line text is separated by the carriage return (0xA).
221          *
222          * @param lineSpacing {Number} Line spacing (default: 7)
223          */
224         setLineSpacing:function (lineSpacing) {
225             this.lineSpacing = lineSpacing;
226         },
227 
228         /**
229          * Get the space between lines in multi-line text.
230          * @return {Number}
231          */
232         getLineSpacing:function () {
233             return this.lineSpacing;
234         }
235 
236     }, /** @scope R.text.AbstractTextRenderer.prototype */{
237 
238         /**
239          * Get the class name of this object
240          * @return {String} The string "R.text.AbstractTextRenderer"
241          */
242         getClassName:function () {
243             return "R.text.AbstractTextRenderer";
244         },
245 
246         /**
247          * Align text with the left edge of the string at the point specified.
248          * @type Number
249          */
250         ALIGN_LEFT:0,
251 
252         /**
253          * Align text with the right edge of the string at the point specified
254          * @type Number
255          */
256         ALIGN_RIGHT:1,
257 
258         /**
259          * Align text with the center of the string at the point specified
260          * @type Number
261          */
262         ALIGN_CENTER:2
263 
264     });
265 
266 };