mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Add getter/setter for TextItem#content and use Change.CONTENT to notify of changes.
This commit is contained in:
parent
ad04db85aa
commit
af0e5a07b7
3 changed files with 18 additions and 6 deletions
|
@ -28,6 +28,8 @@ var ChangeFlag = {
|
|||
STYLE: 16,
|
||||
// Item attributes: visible, blendMode, locked, name, opacity, clipMask ...
|
||||
ATTRIBUTE: 32,
|
||||
// Text content
|
||||
CONTENT: 64,
|
||||
// Clipping in one of the child items
|
||||
CLIPPING: 64
|
||||
};
|
||||
|
@ -38,5 +40,6 @@ var Change = {
|
|||
GEOMETRY: ChangeFlag.GEOMETRY | ChangeFlag.APPEARANCE,
|
||||
STROKE: ChangeFlag.STROKE | ChangeFlag.APPEARANCE,
|
||||
STYLE: ChangeFlag.STYLE | ChangeFlag.APPEARANCE,
|
||||
ATTRIBUTE: ChangeFlag.ATTRIBUTE | ChangeFlag.APPEARANCE
|
||||
ATTRIBUTE: ChangeFlag.ATTRIBUTE | ChangeFlag.APPEARANCE,
|
||||
CONTENT: ChangeFlag.CONTENT | ChangeFlag.APPEARANCE
|
||||
};
|
||||
|
|
|
@ -83,7 +83,7 @@ var PointText = this.PointText = TextItem.extend({
|
|||
},
|
||||
|
||||
draw: function(ctx) {
|
||||
if (this.content == null)
|
||||
if (!this._content)
|
||||
return;
|
||||
ctx.save();
|
||||
ctx.font = this._characterStyle.fontSize + 'pt ' +
|
||||
|
@ -97,11 +97,11 @@ var PointText = this.PointText = TextItem.extend({
|
|||
ctx.globalAlpha = this._opacity;
|
||||
if (fillColor) {
|
||||
ctx.fillStyle = fillColor.getCanvasStyle(ctx);
|
||||
ctx.fillText(this.content, 0, 0);
|
||||
ctx.fillText(this._content, 0, 0);
|
||||
}
|
||||
if (strokeColor) {
|
||||
ctx.strokeStyle = strokeColor.getCanvasStyle(ctx);
|
||||
ctx.strokeText(this.content, 0, 0);
|
||||
ctx.strokeText(this._content, 0, 0);
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ var TextItem = this.TextItem = Item.extend({
|
|||
*/
|
||||
initialize: function() {
|
||||
this.base();
|
||||
this.content = '';
|
||||
this._content = '';
|
||||
this._characterStyle = CharacterStyle.create(this);
|
||||
this.setCharacterStyle(this._project.getCurrentStyle());
|
||||
this._paragraphStyle = ParagraphStyle.create(this);
|
||||
|
@ -70,12 +70,21 @@ var TextItem = this.TextItem = Item.extend({
|
|||
*/
|
||||
|
||||
_clone: function(copy) {
|
||||
copy.content = this.content;
|
||||
copy._content = this._content;
|
||||
copy.setCharacterStyle(this._characterStyle);
|
||||
copy.setParagraphStyle(this._paragraphStyle);
|
||||
return this.base(copy);
|
||||
},
|
||||
|
||||
getContent: function() {
|
||||
return this._content;
|
||||
},
|
||||
|
||||
setContent: function(content) {
|
||||
this._changed(Change.CONTENT);
|
||||
this._content = content;
|
||||
},
|
||||
|
||||
/**
|
||||
* {@grouptitle Style Properties}
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue