Skip to content

Commit

Permalink
support textPositionRect
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Jun 11, 2017
1 parent 4de8ebc commit 366c3d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/graphic/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ define(function (require) {

// Draw rect text
if (style.text != null) {
// var rect = this.getBoundingRect();
this.drawRectText(ctx, this.getBoundingRect());
}
},
Expand Down
6 changes: 6 additions & 0 deletions src/graphic/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ define(function (require) {
*/
textPosition: 'inside',

/**
* If not specified, use the boundingRect of a `displayable`.
* @type {Object}
*/
textPositionRect: null,

/**
* [x, y]
* @type {Array.<number>}
Expand Down
3 changes: 2 additions & 1 deletion src/graphic/mixin/RectText.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ define(function (require) {
var font = style.textFont || style.font;
var baseline = style.textBaseline;
var verticalAlign = style.textVerticalAlign;
rect = style.textPositionRect || rect;

textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);

Expand Down Expand Up @@ -137,7 +138,7 @@ define(function (require) {
}

for (var i = 0; i < textLines.length; i++) {
// Fill after stroke so the outline will not cover the main part.
// Fill after stroke so the outline will not cover the main part.
textStroke && ctx.strokeText(textLines[i], x, y);
textFill && ctx.fillText(textLines[i], x, y);
y += textRect.lineHeight;
Expand Down

0 comments on commit 366c3d1

Please sign in to comment.