Derive Item#type from Item#_class and use that instead in code that depends on Item types.

This commit is contained in:
Jürg Lehni 2013-04-06 18:07:30 +02:00
parent f43b322d2a
commit 18ed9010a6
5 changed files with 23 additions and 20 deletions

View file

@ -30,6 +30,9 @@ var Item = this.Item = Base.extend(Callback, {
if (src._serializeFields)
src._serializeFields = Base.merge(
this.prototype._serializeFields, src._serializeFields);
// Derive the _type string from _class
if (src._class)
src._type = Base.hyphenate(src._class);
return this.base.apply(this, arguments);
}
}
@ -247,14 +250,14 @@ var Item = this.Item = Base.extend(Callback, {
},
/**
* The class-name of the item as a string.
* The type of the item as a string.
*
* @type String('Group', 'Layer', 'Path', 'CompoundPath', 'Raster',
* 'PlacedSymbol', 'PointText')
* @type String('group', 'layer', 'path', 'compound-path', 'raster',
* 'placed-symbol', 'point-text')
* @bean
*/
getClassName: function() {
return this._class;
getType: function() {
return this._type;
},
/**
@ -2797,7 +2800,7 @@ var Item = this.Item = Base.extend(Callback, {
// Exclude Raster items since they never draw a stroke and handle
// opacity by themselves (they also don't call _setStyles)
if (item._blendMode !== 'normal' || item._opacity < 1
&& item._class !== 'Raster' && (item._class !== 'Path'
&& item._type !== 'raster' && (item._type !== 'path'
|| item.getFillColor() && item.getStrokeColor())) {
var bounds = item.getStrokeBounds();
if (!bounds.width || !bounds.height)

View file

@ -60,7 +60,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath#
insertChild: function(index, item, _cloning) {
// Only allow the insertion of paths
if (item._class !== 'Path')
if (item._type !== 'path')
return null;
item = this.base(index, item);
// All children except for the bottom one (first one in list) are set

View file

@ -1,4 +1,4 @@
/*
g/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
@ -102,7 +102,7 @@ var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{
}
// First clear the previous content
if (this._class === 'Path')
if (this._type === 'path')
this.removeSegments();
else
this.removeChildren();

View file

@ -389,13 +389,13 @@ new function() {
}
var exporters = {
Group: exportGroup,
Layer: exportGroup,
Raster: exportRaster,
PointText: exportText,
PlacedSymbol: exportPlacedSymbol,
Path: exportPath,
CompoundPath: exportCompoundPath
group: exportGroup,
layer: exportGroup,
raster: exportRaster,
path: exportPath,
'point-text': exportText,
'placed-symbol': exportPlacedSymbol,
'compound-path': exportCompoundPath
};
function applyStyle(item, node) {
@ -449,7 +449,7 @@ new function() {
}
function setDefinition(item, node) {
var type = item._class.toLowerCase(),
var type = item._type,
id = definitions.ids[type] = (definitions.ids[type] || 0) + 1;
node.id = type + '-' + id;
definitions.svgs[item._id] = node;
@ -476,8 +476,8 @@ new function() {
}
function exportSvg(item) {
var exporter = exporters[item._class],
node = exporter && exporter(item, item._class);
var exporter = exporters[item._type],
node = exporter && exporter(item, item._type);
return node && applyStyle(item, node);
}

View file

@ -473,7 +473,7 @@ new function() {
importer = importers[type],
item = importer && importer(node, type);
// See importGroup() for an explanation of this filtering:
if (item && item._class !== 'Group')
if (item && item._type !== 'group')
item = applyAttributes(item, node);
// Clear definitions at the end of import?
if (clearDefs)