paper.js/src/item/PlacedSymbol.js
2011-03-07 00:50:44 +00:00

62 lines
1.5 KiB
JavaScript

/*
* 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://scriptographer.org/
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* All rights reserved. See LICENSE file for details.
*/
var PlacedSymbol = this.PlacedSymbol = Item.extend({
beans: true,
initialize: function() {
this.base();
if (arguments[0] instanceof Symbol) {
this.symbol = arguments[0];
} else {
this.symbol = new Symbol(arguments[0]);
}
if (arguments.length > 1) {
var arg = arguments[1];
if (arg instanceof Matrix) {
this.matrix = arguments[2];
} else {
var offset = Point.read(arguments, 1);
this.matrix = new Matrix().translate(offset);
}
} else {
this.matrix = new Matrix();
}
},
_transform: function(matrix, flags) {
// In order to set the right context transformation when drawing the
// raster, simply preconcatenate the internal matrix with the provided
// one.
this.matrix.preConcatenate(matrix);
},
getBounds: function() {
return this.symbol._definition.getStrokeBounds(this.matrix);
},
getStrokeBounds: function() {
return this.getBounds();
},
draw: function(ctx, param) {
// TODO: we need to preserve strokewidth
ctx.save();
this.matrix.applyToContext(ctx);
Item.draw(this.symbol.getDefinition(), ctx, param);
ctx.restore();
}
// TODO:
// embed()
});