mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-14 00:39:57 -04:00
Make TextItem#style a reference to #characterStyle.
Internally, CharacterStyle extends PathStyle and is now stored in TextItem#_style.
This commit is contained in:
parent
19429d9b6d
commit
ea0eaf04ea
3 changed files with 23 additions and 13 deletions
src
|
@ -108,7 +108,9 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// hierarchy. Used by Layer, where it's added to project.layers instead
|
||||
if (!this._project)
|
||||
paper.project.activeLayer.addChild(this);
|
||||
this._style = PathStyle.create(this);
|
||||
// TextItem defines its own _style, based on CharacterStyle
|
||||
if (!this._style)
|
||||
this._style = PathStyle.create(this);
|
||||
this.setStyle(this._project.getCurrentStyle());
|
||||
this._matrix = new Matrix();
|
||||
},
|
||||
|
|
|
@ -30,12 +30,10 @@
|
|||
* fillColor: 'black',
|
||||
* };
|
||||
*/
|
||||
// TODO: Note that CharacterStyle extends PathStyle and thus injects the same
|
||||
// Note that CharacterStyle extends PathStyle and thus injects the same
|
||||
// accessors into its _owner TextItem, overriding those previously defined by
|
||||
// PathStyle for Item. This means that when we set ttextItem.fillColor,
|
||||
// textItem.characterStyle.fillColor gets defined, not textItem.style.fillColor.
|
||||
// In fact, textItem.style does not have any impact on textItem appearance...
|
||||
// Ideally it should become a pointer to textItem.characterStyle!
|
||||
// PathStyle for Item. It is also returned from TextItem#getStyle instead of
|
||||
// PathStyle. TextItem#characterStyle is now simply a pointer to #style.
|
||||
var CharacterStyle = this.CharacterStyle = PathStyle.extend(/** @lends CharacterStyle# */{
|
||||
_defaults: Base.merge(PathStyle.prototype._defaults, {
|
||||
// Override default fillColor of CharacterStyle
|
||||
|
@ -45,7 +43,7 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend(/** @lends Character
|
|||
font: 'sans-serif'
|
||||
}),
|
||||
_owner: TextItem,
|
||||
_style: 'characterStyle'
|
||||
_style: 'style',
|
||||
|
||||
/**
|
||||
* CharacterStyle objects don't need to be created directly. Just pass an
|
||||
|
|
|
@ -31,13 +31,16 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
_boundsType: 'bounds',
|
||||
|
||||
initialize: function() {
|
||||
// Note that internally #characterStyle is the same as #style, but
|
||||
// defined as an instance of CharacterStyle. We need to define it before
|
||||
// calling this.base(), to override the default PathStyle instance.
|
||||
this._style = CharacterStyle.create(this);
|
||||
this._paragraphStyle = ParagraphStyle.create(this);
|
||||
this.base();
|
||||
// Call with no parameter to initalize defaults now.
|
||||
this.setParagraphStyle();
|
||||
this._content = '';
|
||||
this._lines = [];
|
||||
this._characterStyle = CharacterStyle.create(this);
|
||||
this.setCharacterStyle(this._project.getCurrentStyle());
|
||||
this._paragraphStyle = ParagraphStyle.create(this);
|
||||
this.setParagraphStyle();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -74,7 +77,6 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
|
||||
_clone: function(copy) {
|
||||
copy.setContent(this._content);
|
||||
copy.setCharacterStyle(this._characterStyle);
|
||||
copy.setParagraphStyle(this._paragraphStyle);
|
||||
return this.base(copy);
|
||||
},
|
||||
|
@ -94,11 +96,19 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
*
|
||||
* The character style of the text item.
|
||||
*
|
||||
* @name TextItem#getCharacterStyle
|
||||
* @type CharacterStyle
|
||||
* @bean
|
||||
*/
|
||||
|
||||
// As explained in CharacterStyle, this is internally the same as #style.
|
||||
getCharacterStyle: function() {
|
||||
return this.getStyle();
|
||||
},
|
||||
|
||||
setCharacterStyle: function(style) {
|
||||
this.setStyle(style);
|
||||
},
|
||||
|
||||
/**
|
||||
* The paragraph style of the text item.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue