Add getter/setter for TextItem#content and use Change.CONTENT to notify of changes.

This commit is contained in:
Jürg Lehni 2011-06-19 23:28:41 +01:00
parent ad04db85aa
commit af0e5a07b7
3 changed files with 18 additions and 6 deletions

View file

@ -28,6 +28,8 @@ var ChangeFlag = {
STYLE: 16, STYLE: 16,
// Item attributes: visible, blendMode, locked, name, opacity, clipMask ... // Item attributes: visible, blendMode, locked, name, opacity, clipMask ...
ATTRIBUTE: 32, ATTRIBUTE: 32,
// Text content
CONTENT: 64,
// Clipping in one of the child items // Clipping in one of the child items
CLIPPING: 64 CLIPPING: 64
}; };
@ -38,5 +40,6 @@ var Change = {
GEOMETRY: ChangeFlag.GEOMETRY | ChangeFlag.APPEARANCE, GEOMETRY: ChangeFlag.GEOMETRY | ChangeFlag.APPEARANCE,
STROKE: ChangeFlag.STROKE | ChangeFlag.APPEARANCE, STROKE: ChangeFlag.STROKE | ChangeFlag.APPEARANCE,
STYLE: ChangeFlag.STYLE | ChangeFlag.APPEARANCE, STYLE: ChangeFlag.STYLE | ChangeFlag.APPEARANCE,
ATTRIBUTE: ChangeFlag.ATTRIBUTE | ChangeFlag.APPEARANCE ATTRIBUTE: ChangeFlag.ATTRIBUTE | ChangeFlag.APPEARANCE,
CONTENT: ChangeFlag.CONTENT | ChangeFlag.APPEARANCE
}; };

View file

@ -83,7 +83,7 @@ var PointText = this.PointText = TextItem.extend({
}, },
draw: function(ctx) { draw: function(ctx) {
if (this.content == null) if (!this._content)
return; return;
ctx.save(); ctx.save();
ctx.font = this._characterStyle.fontSize + 'pt ' + ctx.font = this._characterStyle.fontSize + 'pt ' +
@ -97,11 +97,11 @@ var PointText = this.PointText = TextItem.extend({
ctx.globalAlpha = this._opacity; ctx.globalAlpha = this._opacity;
if (fillColor) { if (fillColor) {
ctx.fillStyle = fillColor.getCanvasStyle(ctx); ctx.fillStyle = fillColor.getCanvasStyle(ctx);
ctx.fillText(this.content, 0, 0); ctx.fillText(this._content, 0, 0);
} }
if (strokeColor) { if (strokeColor) {
ctx.strokeStyle = strokeColor.getCanvasStyle(ctx); ctx.strokeStyle = strokeColor.getCanvasStyle(ctx);
ctx.strokeText(this.content, 0, 0); ctx.strokeText(this._content, 0, 0);
} }
ctx.restore(); ctx.restore();
} }

View file

@ -30,7 +30,7 @@ var TextItem = this.TextItem = Item.extend({
*/ */
initialize: function() { initialize: function() {
this.base(); this.base();
this.content = ''; this._content = '';
this._characterStyle = CharacterStyle.create(this); this._characterStyle = CharacterStyle.create(this);
this.setCharacterStyle(this._project.getCurrentStyle()); this.setCharacterStyle(this._project.getCurrentStyle());
this._paragraphStyle = ParagraphStyle.create(this); this._paragraphStyle = ParagraphStyle.create(this);
@ -70,12 +70,21 @@ var TextItem = this.TextItem = Item.extend({
*/ */
_clone: function(copy) { _clone: function(copy) {
copy.content = this.content; copy._content = this._content;
copy.setCharacterStyle(this._characterStyle); copy.setCharacterStyle(this._characterStyle);
copy.setParagraphStyle(this._paragraphStyle); copy.setParagraphStyle(this._paragraphStyle);
return this.base(copy); return this.base(copy);
}, },
getContent: function() {
return this._content;
},
setContent: function(content) {
this._changed(Change.CONTENT);
this._content = content;
},
/** /**
* {@grouptitle Style Properties} * {@grouptitle Style Properties}
* *