Skip to content

Commit 808e043

Browse files
committed
1 parent 213cc61 commit 808e043

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

src/easeljs/display/Text.js

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,31 @@ this.createjs = this.createjs||{};
6969
**/
7070
function Text(text, font, color) {
7171
this.DisplayObject_constructor();
72-
73-
72+
73+
7474
// public properties:
7575
/**
7676
* The text to display.
7777
* @property text
7878
* @type String
7979
**/
8080
this.text = text;
81-
81+
8282
/**
8383
* The font style to use. Any valid value for the CSS font attribute is acceptable (ex. "bold 36px Arial").
8484
* @property font
8585
* @type String
8686
**/
8787
this.font = font;
88-
88+
8989
/**
9090
* The color to draw the text in. Any valid value for the CSS color attribute is acceptable (ex. "#F00"). Default is "#000".
9191
* It will also accept valid canvas fillStyle values.
9292
* @property color
9393
* @type String
9494
**/
9595
this.color = color;
96-
96+
9797
/**
9898
* The horizontal text alignment. Any of "start", "end", "left", "right", and "center". For detailed
9999
* information view the
@@ -103,7 +103,7 @@ this.createjs = this.createjs||{};
103103
* @type String
104104
**/
105105
this.textAlign = "left";
106-
106+
107107
/**
108108
* The vertical alignment point on the font. Any of "top", "hanging", "middle", "alphabetic", "ideographic", or
109109
* "bottom". For detailed information view the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-styles">
@@ -112,7 +112,7 @@ this.createjs = this.createjs||{};
112112
* @type String
113113
*/
114114
this.textBaseline = "top";
115-
115+
116116
/**
117117
* The maximum width to draw the text. If maxWidth is specified (not null), the text will be condensed or
118118
* shrunk to make it fit in this width. For detailed information view the
@@ -122,36 +122,50 @@ this.createjs = this.createjs||{};
122122
* @type Number
123123
*/
124124
this.maxWidth = null;
125-
125+
126126
/**
127127
* If greater than 0, the text will be drawn as a stroke (outline) of the specified width.
128128
* @property outline
129129
* @type Number
130130
**/
131131
this.outline = 0;
132-
132+
133133
/**
134134
* Indicates the line height (vertical distance between baselines) for multi-line text. If null or 0,
135135
* the value of getMeasuredLineHeight is used.
136136
* @property lineHeight
137137
* @type Number
138138
**/
139139
this.lineHeight = 0;
140-
140+
141141
/**
142142
* Indicates the maximum width for a line of text before it is wrapped to multiple lines. If null,
143143
* the text will not be wrapped.
144144
* @property lineWidth
145145
* @type Number
146146
**/
147147
this.lineWidth = null;
148+
149+
/**
150+
* The type of corner created, when two lines meet. Any of "bevel", "round", and "miter". Default is "miter".
151+
* @property lineJoin
152+
* @type String
153+
**/
154+
this.lineJoin = "miter";
155+
156+
/**
157+
* The miter length is the distance between the inner corner and the outer corner where two lines meet. Default is 10.
158+
* @property miterLimit
159+
* @type Number
160+
**/
161+
this.miterLimit = 10;
148162
}
149163
var p = createjs.extend(Text, createjs.DisplayObject);
150164

151165
// TODO: deprecated
152166
// p.initialize = function() {}; // searchable for devs wondering where it is. REMOVED. See docs for details.
153167

154-
168+
155169
// static properties:
156170
/**
157171
* @property _workingContext
@@ -160,8 +174,8 @@ this.createjs = this.createjs||{};
160174
**/
161175
var canvas = (createjs.createCanvas?createjs.createCanvas():document.createElement("canvas"));
162176
if (canvas.getContext) { Text._workingContext = canvas.getContext("2d"); canvas.width = canvas.height = 1; }
163-
164-
177+
178+
165179
// constants:
166180
/**
167181
* Lookup table for the ratio to offset bounds x calculations based on the textAlign property.
@@ -171,7 +185,7 @@ this.createjs = this.createjs||{};
171185
* @static
172186
**/
173187
Text.H_OFFSETS = {start: 0, left: 0, center: -0.5, end: -1, right: -1};
174-
188+
175189
/**
176190
* Lookup table for the ratio to offset bounds y calculations based on the textBaseline property.
177191
* @property H_OFFSETS
@@ -209,9 +223,14 @@ this.createjs = this.createjs||{};
209223
if (this.DisplayObject_draw(ctx, ignoreCache)) { return true; }
210224

211225
var col = this.color || "#000";
212-
if (this.outline) { ctx.strokeStyle = col; ctx.lineWidth = this.outline*1; }
226+
if (this.outline) {
227+
ctx.strokeStyle = col;
228+
ctx.lineWidth = this.outline*1;
229+
ctx.miterLimit = this.miterLimit;
230+
ctx.lineJoin = this.lineJoin;
231+
}
213232
else { ctx.fillStyle = col; }
214-
233+
215234
this._drawText(this._prepContext(ctx));
216235
return true;
217236
};
@@ -259,7 +278,7 @@ this.createjs = this.createjs||{};
259278
var y = lineHeight * Text.V_OFFSETS[this.textBaseline||"top"];
260279
return this._rectangle.setValues(x, y, w, o.height);
261280
};
262-
281+
263282
/**
264283
* Returns an object with width, height, and lines properties. The width and height are the visual width and height
265284
* of the drawn text. The lines property contains an array of strings, one for
@@ -344,19 +363,19 @@ this.createjs = this.createjs||{};
344363
this._prepContext(ctx);
345364
}
346365
var lineHeight = this.lineHeight||this.getMeasuredLineHeight();
347-
366+
348367
var maxW = 0, count = 0;
349368
var hardLines = String(this.text).split(/(?:\r\n|\r|\n)/);
350369
for (var i=0, l=hardLines.length; i<l; i++) {
351370
var str = hardLines[i];
352371
var w = null;
353-
372+
354373
if (this.lineWidth != null && (w = ctx.measureText(str).width) > this.lineWidth) {
355374
// text wrapping:
356375
var words = str.split(/(\s)/);
357376
str = words[0];
358377
w = ctx.measureText(str).width;
359-
378+
360379
for (var j=1, jl=words.length; j<jl; j+=2) {
361380
// Line needs to wrap:
362381
var wordW = ctx.measureText(words[j] + words[j+1]).width;
@@ -373,14 +392,14 @@ this.createjs = this.createjs||{};
373392
}
374393
}
375394
}
376-
395+
377396
if (paint) { this._drawTextLine(ctx, str, count*lineHeight); }
378397
if (lines) { lines.push(str); }
379398
if (o && w == null) { w = ctx.measureText(str).width; }
380399
if (w > maxW) { maxW = w; }
381400
count++;
382401
}
383-
402+
384403
if (o) {
385404
o.width = maxW;
386405
o.height = count*lineHeight;
@@ -401,8 +420,8 @@ this.createjs = this.createjs||{};
401420
if (this.outline) { ctx.strokeText(text, 0, y, this.maxWidth||0xFFFF); }
402421
else { ctx.fillText(text, 0, y, this.maxWidth||0xFFFF); }
403422
};
404-
405-
423+
424+
406425
/**
407426
* @method _getMeasuredWidth
408427
* @param {String} text

0 commit comments

Comments
 (0)