Introduce Style as a base class for all Style classes, and move the definition of create() there.

This commit is contained in:
Jürg Lehni 2011-06-20 13:56:49 +01:00
parent b9ebd12d22
commit f064886c67
6 changed files with 35 additions and 28 deletions

View file

@ -14,7 +14,7 @@
* All rights reserved.
*/
var PathStyle = this.PathStyle = Base.extend(new function() {
var PathStyle = this.PathStyle = Style.extend(new function() {
/** @lends PathStyle# */
// windingRule / resolution / fillOverprint / strokeOverprint are currently
@ -77,14 +77,6 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
? value.clone() : value;
}
}
},
statics: {
create: function(item) {
var style = new PathStyle(PathStyle.dont);
style._item = item;
return style;
}
}
};

29
src/item/Style.js Normal file
View file

@ -0,0 +1,29 @@
/*
* Paper.js
*
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
* based on Scriptographer.org and designed to be largely API compatible.
* http://paperjs.org/
* http://scriptographer.org/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* All rights reserved.
*/
/**
* Internal base-class for all style objects, e.g. PathStyle, CharacterStyle,
* PargraphStyle.
*/
var Style = Item.extend({
statics: {
create: function(item) {
var style = new this(this.dont);
style._item = item;
return style;
}
}
});

View file

@ -44,6 +44,7 @@ var sources = [
'src/item/Layer.js',
'src/item/Raster.js',
'src/item/PlacedSymbol.js',
'src/item/Style.js',
'src/item/PathStyle.js',
'src/path/Segment.js',

View file

@ -64,6 +64,7 @@ var paper = new function() {
//#include "item/Layer.js"
//#include "item/Raster.js"
//#include "item/PlacedSymbol.js"
//#include "item/Style.js"
//#include "item/PathStyle.js"
//#include "path/Segment.js"

View file

@ -48,7 +48,7 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({
font: 'sans-serif'
});
this.base(style);
},
}
/**
* The font of the character style.
@ -65,12 +65,4 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({
* @default 10
* @type Number
*/
statics: {
create: function(item) {
var style = new CharacterStyle(CharacterStyle.dont);
style._item = item;
return style;
}
}
});

View file

@ -14,7 +14,7 @@
* All rights reserved.
*/
var ParagraphStyle = this.ParagraphStyle = Base.extend({
var ParagraphStyle = this.ParagraphStyle = Style.extend({
/** @lends ParagraphStyle# */
/**
@ -46,7 +46,7 @@ var ParagraphStyle = this.ParagraphStyle = Base.extend({
Base.initialize(this, style, {
justification: 'left'
});
},
}
/**
* The justification of the paragraph.
@ -55,12 +55,4 @@ var ParagraphStyle = this.ParagraphStyle = Base.extend({
* @default 'left'
* @type String('left', 'right', 'center')
*/
statics: {
create: function(item) {
var style = new ParagraphStyle(ParagraphStyle.dont);
style._item = item;
return style;
}
}
});