Merge remote branch 'origin/master'

This commit is contained in:
Jonathan Puckey 2011-07-04 15:10:26 +02:00
commit 724fdcd727
122 changed files with 4141 additions and 1713 deletions

View file

@ -117,7 +117,7 @@ If you are fixing a ticket, a convenient way to name the branch is to use the UR
Before we can accept any contributions to Paper.js, you need to sign this [CLA](http://en.wikipedia.org/wiki/Contributor_License_Agreement):
[http://paperjs.org/cla.html](http://paperjs.org/cla.html)
[Contributor License Agreement](https://spreadsheets.google.com/a/paperjs.org/spreadsheet/embeddedform?formkey=dENxd0JBVDY2REo3THVuRmh4YjdWRlE6MQ)
> The purpose of this agreement is to clearly define the terms under which intellectual property has been contributed to Paper.js and thereby allow us to defend the project should there be a legal dispute regarding the software at some future time.

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
#
# All rights reserved. See LICENSE file for details.
# Distributed under the MIT license. See LICENSE file for details.
#
# All rights reserved.
# Usage:
# build.sh MODE

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
#
# All rights reserved. See LICENSE file for details.
# Distributed under the MIT license. See LICENSE file for details.
#
# All rights reserved.
echo "Building paper.js"
./build.sh

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
#
# All rights reserved. See LICENSE file for details.
# Distributed under the MIT license. See LICENSE file for details.
#
# All rights reserved.
# Generate documentation
#

@ -1 +1 @@
Subproject commit 122c76276bddfbd9e0fc1c41b8fa33019fbc4f05
Subproject commit 87368e6dcbcd01b5fae9c1fbc5af558603d0af79

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
#
# All rights reserved. See LICENSE file for details.
# Distributed under the MIT license. See LICENSE file for details.
#
# All rights reserved.
# Generate a paper.js file that uses load.js to directly load the library
# through the seperate source files in the src directory. Very useful during

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
#
# All rights reserved. See LICENSE file for details.
# Distributed under the MIT license. See LICENSE file for details.
#
# All rights reserved.
# Generate a paper.js file that uses load.js to directly load the library
# through the seperate source files in the src directory. Very useful during

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
#
# All rights reserved. See LICENSE file for details.
# Distributed under the MIT license. See LICENSE file for details.
#
# All rights reserved.
# preprocess.sh
#

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
#
# All rights reserved. See LICENSE file for details.
# Distributed under the MIT license. See LICENSE file for details.
#
# All rights reserved.
if [ -f paperjs.zip ]
then

View file

@ -5010,7 +5010,7 @@ var TextItem = this.TextItem = Item.extend({
setContent: function(content) {
this._changed(Change.CONTENT);
this._content = content;
this._content = '' + content;
},
getCharacterStyle: function() {

81
dist/paper.js vendored

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Animated Star</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Extruded</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Future Splash</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Lines</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Radial Rainbows</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -1,8 +1,8 @@
<!-- <!DOCTYPE html> -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Raster</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Rounded Rectangles</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Smoothing</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Space</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Tadpoles</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Arcs</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Bouncing Balls</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Chain</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Circle</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Compound Path</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Curve Time Parameterization</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -1,8 +1,8 @@
<!-- <!DOCTYPE html> -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Division Raster</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Fitting</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Letter</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Path Structure</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">
@ -15,7 +15,7 @@
for (var i = 0; i < 3; i++) {
var text = new PointText();
text.content = '' + i;
text.content = i;
text.justification = 'center';
text.fontSize = 9;
segmentTexts.push(text);

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Phyllotaxis Raster</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -1,8 +1,8 @@
<!-- <!DOCTYPE html> -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Rotation Raster</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Rounded Rectangle</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Stroke Bounds</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">
@ -17,13 +17,12 @@
path.arcTo([250, 20], false);
path.rotate(-5);
path.strokeWidth = 30;
paths.push(path);
path.miterLimit = 3;
paths.push(path);
return path;
}
var path = makePath();
path.fullySelected = true;
path.strokeColor = 'black';
path.strokeCap = 'butt';
path.strokeJoin = 'round';
@ -70,14 +69,19 @@
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
path.fullySelected = true;
path.scale(1.5, new Point(300, 0));
var rect = new Path.Rectangle(path.strokeBounds);
rect.strokeWidth = 0.25;
rect.strokeColor = 'black'
rect.strokeColor = 'black';
rect.fillColor = null;
var rect = new Path.Rectangle(path.bounds);
rect.strokeWidth = 0.25;
rect.strokeColor = 'red'
rect.strokeColor = 'red';
rect.fillColor = null;
var rect = new Path.Rectangle(path.controlBounds);
rect.strokeWidth = 0.25;
rect.strokeColor = 'green';
rect.fillColor = null;
}

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Bezier Tool</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Circles</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Clouds</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Dripping Brush</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Fancy Brush</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Grid</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Meta Balls</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Multi Lines</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Simplify</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Square Rounded</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Stars</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Vektor</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Wave</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

View file

@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<title>Worm Farm</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas">

2
lib/parse-js-min.js vendored

File diff suppressed because one or more lines are too long

1969
lib/parse-js-unicode.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,16 @@
/**
* A JavaScript tokenizer / parser / generator.
*
* Distributed under the BSD license.
* A JavaScript tokenizer / parser / generator, originally written in Lisp.
* Copyright (c) Marijn Haverbeke <marijnh@gmail.com>
* http://marijn.haverbeke.nl/parse-js/
*
* Ported by to JavaScript by Mihai Bazon
* Copyright (c) 2010, Mihai Bazon <mihai.bazon@gmail.com>
* http://mihai.bazon.net/blog/
*
* Modifications and adaption to browser (c) 2011, Juerg Lehni
* Modifications and adaptions to browser (c) 2011, Juerg Lehni
* http://lehni.org/
*
* Based on parse-js, (c) Marijn Haverbeke
* http://marijn.haverbeke.nl/parse-js/
* Distributed under the BSD license.
*/
var parse_js = new function() {
@ -140,7 +140,6 @@ var OPERATORS = array_to_hash([
">>=",
"<<=",
">>>=",
"%=",
"|=",
"^=",
"&=",
@ -158,22 +157,29 @@ var REGEXP_MODIFIERS = array_to_hash(characters("gmsiy"));
/* -----[ Tokenizer ]----- */
function is_alphanumeric_char(ch) {
function is_letter(ch) {
ch = ch.charCodeAt(0);
return (ch >= 48 && ch <= 57) ||
(ch >= 65 && ch <= 90) ||
return (ch >= 65 && ch <= 90) ||
(ch >= 97 && ch <= 122);
};
function is_identifier_char(ch) {
return is_alphanumeric_char(ch) || ch == "$" || ch == "_";
};
function is_digit(ch) {
ch = ch.charCodeAt(0);
return ch >= 48 && ch <= 57;
};
function is_alphanumeric_char(ch) {
return is_digit(ch) || is_letter(ch);
};
function is_identifier_start(ch) {
return ch == "$" || ch == "_" || is_letter(ch);
};
function is_identifier_char(ch) {
return is_identifier_start(ch) || is_digit(ch);
};
function parse_js_number(num) {
if (RE_HEX_NUMBER.test(num)) {
return parseInt(num.substr(2), 16);
@ -308,7 +314,7 @@ function tokenizer($TEXT) {
if (ch == "+") return after_e;
after_e = false;
if (ch == ".") {
if (!has_dot)
if (!has_dot && !has_x)
return has_dot = true;
return false;
}
@ -486,7 +492,7 @@ function tokenizer($TEXT) {
if (ch == ".") return handle_dot();
if (ch == "/") return handle_slash();
if (HOP(OPERATOR_CHARS, ch)) return read_operator();
if (is_identifier_char(ch)) return read_word();
if (ch == "\\" || is_identifier_start(ch)) return read_word();
parse_error("Unexpected character '" + ch + "'");
};
@ -565,7 +571,7 @@ function NodeWithToken(str, start, end) {
NodeWithToken.prototype.toString = function() { return this.name; };
function parse($TEXT, strict_mode, embed_tokens) {
function parse($TEXT, exigent_mode, embed_tokens) {
var S = {
input : typeof $TEXT == "string" ? tokenizer($TEXT, true) : $TEXT,
@ -628,7 +634,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
function expect(punc) { return expect_token("punc", punc); };
function can_insert_semicolon() {
return !strict_mode && (
return !exigent_mode && (
S.token.nlb || is("eof") || is("punc", "}")
);
};
@ -653,14 +659,17 @@ function parse($TEXT, strict_mode, embed_tokens) {
return str instanceof NodeWithToken ? str : new NodeWithToken(str, start, end);
};
var statement = embed_tokens ? function() {
var start = S.token;
var ast = $statement.apply(this, arguments);
ast[0] = add_tokens(ast[0], start, prev());
return ast;
} : $statement;
function maybe_embed_tokens(parser) {
if (embed_tokens) return function() {
var start = S.token;
var ast = parser.apply(this, arguments);
ast[0] = add_tokens(ast[0], start, prev());
return ast;
};
else return parser;
};
function $statement() {
var statement = maybe_embed_tokens(function() {
if (is("operator", "/")) {
S.peeked = null;
S.token = S.input(true); // force regexp
@ -754,12 +763,12 @@ function parse($TEXT, strict_mode, embed_tokens) {
unexpected();
}
}
};
});
function labeled_statement(label) {
S.labels.push(label);
var start = S.token, stat = statement();
if (strict_mode && !HOP(STATEMENTS_WITH_LABELS, stat[0]))
if (exigent_mode && !HOP(STATEMENTS_WITH_LABELS, stat[0]))
unexpected(start);
S.labels.pop();
return as("label", label, stat);
@ -770,7 +779,10 @@ function parse($TEXT, strict_mode, embed_tokens) {
};
function break_cont(type) {
var name = is("name") ? S.token.value : null;
var name;
if (!can_insert_semicolon()) {
name = is("name") ? S.token.value : null;
}
if (name != null) {
next();
if (!member(name, S.labels))
@ -784,36 +796,35 @@ function parse($TEXT, strict_mode, embed_tokens) {
function for_() {
expect("(");
var has_var = is("keyword", "var");
if (has_var)
next();
if (is("name") && is_token(peek(), "operator", "in")) {
// for (i in foo)
var name = S.token.value;
next(); next();
var obj = expression();
expect(")");
return as("for-in", has_var, name, obj, in_loop(statement));
} else {
// classic for
var init = is("punc", ";") ? null : has_var ? var_() : expression();
expect(";");
var test = is("punc", ";") ? null : expression();
expect(";");
var step = is("punc", ")") ? null : expression();
expect(")");
return as("for", init, test, step, in_loop(statement));
var init = null;
if (!is("punc", ";")) {
init = is("keyword", "var")
? (next(), var_(true))
: expression(true, true);
if (is("operator", "in"))
return for_in(init);
}
return regular_for(init);
};
var function_ = embed_tokens ? function() {
var start = prev();
var ast = $function_.apply(this, arguments);
ast[0] = add_tokens(ast[0], start, prev());
return ast;
} : $function_;
function regular_for(init) {
expect(";");
var test = is("punc", ";") ? null : expression();
expect(";");
var step = is("punc", ")") ? null : expression();
expect(")");
return as("for", init, test, step, in_loop(statement));
};
function $function_(in_statement) {
function for_in(init) {
var lhs = init[0] == "var" ? as("name", init[1][0]) : init;
next();
var obj = expression();
expect(")");
return as("for-in", init, lhs, obj, in_loop(statement));
};
var function_ = maybe_embed_tokens(function(in_statement) {
var name = is("name") ? prog1(S.token.value, next) : null;
if (in_statement && !name)
unexpected();
@ -841,7 +852,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
S.in_loop = loop;
return a;
})());
};
});
function if_() {
var cond = parenthesised(), body = statement(), belse;
@ -910,7 +921,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
return as("try", body, bcatch, bfinally);
};
function vardefs() {
function vardefs(no_in) {
var a = [];
for (;;) {
if (!is("name"))
@ -919,7 +930,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
next();
if (is("operator", "=")) {
next();
a.push([ name, expression(false) ]);
a.push([ name, expression(false, no_in) ]);
} else {
a.push([ name ]);
}
@ -930,8 +941,8 @@ function parse($TEXT, strict_mode, embed_tokens) {
return a;
};
function var_() {
return as("var", vardefs());
function var_(no_in) {
return as("var", vardefs(no_in));
};
function const_() {
@ -949,7 +960,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
return subscripts(as("new", newexp, args), true);
};
function expr_atom(allow_calls) {
var expr_atom = maybe_embed_tokens(function(allow_calls) {
if (is("operator", "new")) {
next();
return new_();
@ -984,7 +995,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
return subscripts(prog1(atom, next), allow_calls);
}
unexpected();
};
});
function expr_list(closing, allow_trailing_comma, allow_empty) {
var first = true, a = [];
@ -1002,14 +1013,14 @@ function parse($TEXT, strict_mode, embed_tokens) {
};
function array_() {
return as("array", expr_list("]", !strict_mode, true));
return as("array", expr_list("]", !exigent_mode, true));
};
function object_() {
var first = true, a = [];
while (!is("punc", "}")) {
if (first) first = false; else expect(",");
if (!strict_mode && is("punc", "}"))
if (!exigent_mode && is("punc", "}"))
// allow trailing comma
break;
var type = S.token.type;
@ -1072,64 +1083,68 @@ function parse($TEXT, strict_mode, embed_tokens) {
return as(tag, op, expr);
};
function expr_op(left, min_prec) {
function expr_op(left, min_prec, no_in) {
var op = is("operator") ? S.token.value : null;
if (op && op == "in" && no_in) op = null;
var prec = op != null ? PRECEDENCE[op] : null;
if (prec != null && prec > min_prec) {
next();
var right = expr_op(expr_atom(true), prec);
return expr_op(as("binary", op, left, right), min_prec);
var right = expr_op(expr_atom(true), prec, no_in);
return expr_op(as("binary", op, left, right), min_prec, no_in);
}
return left;
};
function expr_ops() {
return expr_op(expr_atom(true), 0);
function expr_ops(no_in) {
return expr_op(expr_atom(true), 0, no_in);
};
function maybe_conditional() {
var expr = expr_ops();
function maybe_conditional(no_in) {
var expr = expr_ops(no_in);
if (is("operator", "?")) {
next();
var yes = expression(false);
expect(":");
return as("conditional", expr, yes, expression(false));
return as("conditional", expr, yes, expression(false, no_in));
}
return expr;
};
function is_assignable(expr) {
if (!exigent_mode) return true;
switch (expr[0]) {
case "dot":
case "sub":
case "new":
case "call":
return true;
case "name":
return expr[1] != "this";
}
};
function maybe_assign() {
var left = maybe_conditional(), val = S.token.value;
function maybe_assign(no_in) {
var left = maybe_conditional(no_in), val = S.token.value;
if (is("operator") && HOP(ASSIGNMENT, val)) {
if (is_assignable(left)) {
next();
return as("assign", ASSIGNMENT[val], left, maybe_assign());
return as("assign", ASSIGNMENT[val], left, maybe_assign(no_in));
}
croak("Invalid assignment");
}
return left;
};
function expression(commas) {
var expression = maybe_embed_tokens(function(commas, no_in) {
if (arguments.length == 0)
commas = true;
var expr = maybe_assign();
var expr = maybe_assign(no_in);
if (commas && is("punc", ",")) {
next();
return as("seq", expr, expression());
return as("seq", expr, expression(true, no_in));
}
return expr;
};
});
function in_loop(cont) {
try {
@ -1159,6 +1174,12 @@ function ast_walker() {
return a;
}) ];
};
function _block(statements) {
var out = [ this[0] ];
if (statements != null)
out.push(MAP(statements, walk));
return out;
};
var walkers = {
"string": function(str) {
return [ this[0], str ];
@ -1172,12 +1193,8 @@ function ast_walker() {
"toplevel": function(statements) {
return [ this[0], MAP(statements, walk) ];
},
"block": function(statements) {
var out = [ this[0] ];
if (statements != null)
out.push(MAP(statements, walk));
return out;
},
"block": _block,
"splice": _block,
"var": _vardefs,
"const": _vardefs,
"try": function(t, c, f) {
@ -1230,8 +1247,8 @@ function ast_walker() {
"for": function(init, cond, step, block) {
return [ this[0], walk(init), walk(cond), walk(step), walk(block) ];
},
"for-in": function(has_var, key, hash, block) {
return [ this[0], has_var, key, walk(hash), walk(block) ];
"for-in": function(vvar, key, hash, block) {
return [ this[0], walk(vvar), walk(key), walk(hash), walk(block) ];
},
"while": function(cond, block) {
return [ this[0], walk(cond), walk(block) ];
@ -1340,6 +1357,7 @@ function empty(b) {
var DOT_CALL_NO_PARENS = array_to_hash([
"name",
"array",
"object",
"string",
"dot",
"sub",
@ -1362,29 +1380,34 @@ function make_string(str) {
}
return s;
});
if (dq > sq) {
return "'" + str.replace(/\x27/g, "\\'") + "'";
} else {
return '"' + str.replace(/\x22/g, '\\"') + '"';
}
if (dq > sq) return "'" + str.replace(/\x27/g, "\\'") + "'";
else return '"' + str.replace(/\x22/g, '\\"') + '"';
};
function gen_code(ast, beautify) {
if (beautify) beautify = defaults(beautify, {
var SPLICE_NEEDS_BRACKETS = array_to_hash([ "if", "while", "do", "for", "for-in", "with" ]);
function gen_code(ast, options) {
options = defaults(options, {
indent_start : 0,
indent_level : 4,
quote_keys : false,
space_colon : false
space_colon : false,
beautify : false
});
var beautify = !!options.beautify;
var indentation = 0,
newline = beautify ? "\n" : "",
space = beautify ? " " : "";
function make_name(name) {
return name.toString();
};
function indent(line) {
if (line == null)
line = "";
if (beautify)
line = new Array(beautify.indent_start + indentation * beautify.indent_level).join(" ") + line;
line = repeat_string(" ", options.indent_start + indentation * options.indent_level) + line;
return line;
};
@ -1438,7 +1461,7 @@ function gen_code(ast, beautify) {
};
function needs_parens(expr) {
if (expr[0] == "function") {
if (expr[0] == "function" || expr[0] == "object") {
// dot/call on a literal function requires the
// function literal itself to be parenthesized
// only if it's the first "thing" in a
@ -1450,9 +1473,8 @@ function gen_code(ast, beautify) {
var a = slice($stack), self = a.pop(), p = a.pop();
while (p) {
if (p[0] == "stat") return true;
if ((p[0] == "seq" && p[1] === self) ||
(p[0] == "call" && p[1] === self) ||
(p[0] == "binary" && p[2] === self)) {
if (((p[0] == "seq" || p[0] == "call" || p[0] == "dot" || p[0] == "sub" || p[0] == "conditional") && p[1] === self) ||
((p[0] == "binary" || p[0] == "assign" || p[0] == "unary-postfix") && p[2] === self)) {
self = p;
p = a.pop();
} else {
@ -1486,6 +1508,19 @@ function gen_code(ast, beautify) {
return make_block_statements(statements)
.join(newline + newline);
},
"splice": function(statements) {
var parent = $stack[$stack.length - 2][0];
if (HOP(SPLICE_NEEDS_BRACKETS, parent)) {
// we need block brackets in this case
return make_block.apply(this, arguments);
} else {
return MAP(make_block_statements(statements, true),
function(line, i) {
// the first line is already indented
return i > 0 ? indent(line) : line;
}).join(newline);
}
},
"block": make_block,
"var": function(defs) {
return "var " + add_commas(MAP(defs, make_1vardef)) + ";";
@ -1547,9 +1582,10 @@ function gen_code(ast, beautify) {
},
"dot": function(expr) {
var out = make(expr), i = 1;
if (expr[0] == "num")
out += ".";
else if (needs_parens(expr))
if (expr[0] == "num") {
if (!/\./.test(expr[1]))
out += ".";
} else if (needs_parens(expr))
out = "(" + out + ")";
while (i < arguments.length)
out += "." + make_name(arguments[i++]);
@ -1582,12 +1618,11 @@ function gen_code(ast, beautify) {
out.push("(" + args + ")", make(block));
return add_spaces(out);
},
"for-in": function(has_var, key, hash, block) {
var out = add_spaces([ "for", "(" ]);
if (has_var)
out += "var ";
out += add_spaces([ make_name(key) + " in " + make(hash) + ")", make(block) ]);
return out;
"for-in": function(vvar, key, hash, block) {
return add_spaces([ "for", "(" +
(vvar ? make(vvar).replace(/;+$/, "") : make(key)),
"in",
make(hash) + ")", make(block) ]);
},
"while": function(condition, block) {
return add_spaces([ "while", "(" + make(condition) + ")", make(block) ]);
@ -1645,7 +1680,7 @@ function gen_code(ast, beautify) {
return indent(make_function(p[0], p[1][2], p[1][3], p[2]));
}
var key = p[0], val = make(p[1]);
if (beautify && beautify.quote_keys) {
if (options.quote_keys) {
key = make_string(key);
} else if ((typeof key == "number" || !beautify && +key + "" == key)
&& parseFloat(key) >= 0) {
@ -1653,7 +1688,7 @@ function gen_code(ast, beautify) {
} else if (!is_identifier(key)) {
key = make_string(key);
}
return indent(add_spaces(beautify && beautify.space_colon
return indent(add_spaces(beautify && options.space_colon
? [ key, ":", val ]
: [ key + ":", val ]));
}).join("," + newline);
@ -1726,11 +1761,7 @@ function gen_code(ast, beautify) {
return add_spaces([ out, make_block(body) ]);
};
function make_name(name) {
return name.toString();
};
function make_block_statements(statements) {
function make_block_statements(statements, noindent) {
for (var a = [], last = statements.length - 1, i = 0; i <= last; ++i) {
var stat = statements[i];
var code = make(stat);
@ -1748,7 +1779,7 @@ function gen_code(ast, beautify) {
a.push(code);
}
}
return MAP(a, indent);
return noindent ? a : MAP(a, indent);
};
function make_switch_block(body) {
@ -1779,7 +1810,7 @@ function gen_code(ast, beautify) {
function make_1vardef(def) {
var name = def[0], val = def[1];
if (val != null)
name = add_spaces([ name, "=", make(val) ]);
name = add_spaces([ make_name(name), "=", parenthesize(val, "seq") ]);
return name;
};
@ -1836,6 +1867,10 @@ function member(name, array) {
return false;
};
function repeat_string(str, i) {
return i < 1 ? "" : new Array(i + 1).join(str);
};
function defaults(args, defs) {
var ret = {};
if (args === true)

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -119,28 +119,28 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
*
* @name Matrix#scale
* @function
* @param {Number} sx The x-axis scaling factor.
* @param {Number} sy The y-axis scaling factor.
* @param {Number} hor The horizontal scaling factor.
* @param {Number} ver The vertical scaling factor.
* @param {Point} [center] The center for the scaling
* transformation.
* @return {Matrix} This affine transform.
*/
scale: function(sx, sy /* | scale */, center) {
if (arguments.length < 2 || typeof sy === 'object') {
// sx is the single scale parameter, representing both sx and sy
// Read center first from argument 1, then set sy = sx (thus
scale: function(hor, ver /* | scale */, center) {
if (arguments.length < 2 || typeof ver === 'object') {
// hor is the single scale parameter, representing both hor and ver
// Read center first from argument 1, then set ver = hor (thus
// modifing the content of argument 1!)
center = Point.read(arguments, 1);
sy = sx;
ver = hor;
} else {
center = Point.read(arguments, 2);
}
if (center)
this.translate(center);
this._m00 *= sx;
this._m10 *= sx;
this._m01 *= sy;
this._m11 *= sy;
this._m00 *= hor;
this._m10 *= hor;
this._m01 *= ver;
this._m11 *= ver;
if (center)
this.translate(center.negate());
return this;
@ -211,16 +211,16 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
*
* @name Matrix#shear
* @function
* @param {Number} shx The x shear factor.
* @param {Number} shy The y shear factor.
* @param {Number} hor The horizontal shear factor.
* @param {Number} ver The vertical shear factor.
* @param {Point} [center] The center for the shear transformation.
* @return {Matrix} This affine transform.
*/
shear: function(shx, shy, center) {
shear: function(hor, ver, center) {
// See #scale() for explanation of this:
if (arguments.length < 2 || typeof shy === 'object') {
if (arguments.length < 2 || typeof ver === 'object') {
center = Point.read(arguments, 1);
sy = sx;
ver = hor;
} else {
center = Point.read(arguments, 2);
}
@ -228,10 +228,10 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
this.translate(center);
var m00 = this._m00;
var m10 = this._m10;
this._m00 += shy * this._m01;
this._m10 += shy * this._m11;
this._m01 += shx * m00;
this._m11 += shx * m10;
this._m00 += ver * this._m01;
this._m10 += ver * this._m11;
this._m01 += hor * m00;
this._m11 += hor * m10;
if (center)
this.translate(center.negate());
return this;
@ -416,9 +416,9 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
},
getScaling: function() {
var sx = Math.sqrt(this._m00 * this._m00 + this._m10 * this._m10),
sy = Math.sqrt(this._m01 * this._m01 + this._m11 * this._m11);
return new Point(this._m00 < 0 ? -sx : sx, this._m01 < 0 ? -sy : sy);
var hor = Math.sqrt(this._m00 * this._m00 + this._m10 * this._m10),
ver = Math.sqrt(this._m01 * this._m01 + this._m11 * this._m11);
return new Point(this._m00 < 0 ? -hor : hor, this._m01 < 0 ? -ver : ver);
},
/**
@ -490,12 +490,12 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/**
* Sets this transform to a scaling transformation.
*
* @param {Number} sx The x-axis scaling factor.
* @param {Number} sy The y-axis scaling factor.
* @param {Number} hor The horizontal scaling factor.
* @param {Number} ver The vertical scaling factor.
* @return {Matrix} This affine transform.
*/
setToScale: function(sx, sy) {
return this.set(sx, 0, 0, sy, 0, 0);
setToScale: function(hor, ver) {
return this.set(hor, 0, 0, ver, 0, 0);
},
/**
@ -513,12 +513,12 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/**
* Sets this transform to a shearing transformation.
*
* @param {Number} shx The x-axis shear factor.
* @param {Number} shy The y-axis shear factor.
* @param {Number} hor The horizontal shear factor.
* @param {Number} ver The vertical shear factor.
* @return {Matrix} This affine transform.
*/
setToShear: function(shx, shy) {
return this.set(1, shy, shx, 1, 0, 0);
setToShear: function(hor, ver) {
return this.set(1, ver, hor, 1, 0, 0);
},
/**
@ -564,12 +564,12 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/**
* Creates a transform representing a scaling transformation.
*
* @param {Number} sx The x-axis scaling factor.
* @param {Number} sy The y-axis scaling factor.
* @param {Number} hor The horizontal scaling factor.
* @param {Number} ver The vertical scaling factor.
* @return {Matrix} A transform representing a scaling
* transformation.
*/
getScaleInstance: function(sx, sy) {
getScaleInstance: function(hor, ver) {
var mx = new Matrix();
return mx.setToScale.apply(mx, arguments);
},
@ -590,11 +590,11 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/**
* Creates a transform representing a shearing transformation.
*
* @param {Number} shx The x-axis shear factor.
* @param {Number} shy The y-axis shear factor.
* @param {Number} hor The horizontal shear factor.
* @param {Number} ver The vertical shear factor.
* @return {Matrix} A transform representing a shearing transformation.
*/
getShearInstance: function(shx, shy, center) {
getShearInstance: function(hor, ver, center) {
var mx = new Matrix();
return mx.setToShear.apply(mx, arguments);
},

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -1077,6 +1077,16 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
return this._getBounds('getStrokeBounds');
},
/**
* The bounding rectangle of the item including handles.
*
* @type Rectangle
* @bean
*/
getHandleBounds: function() {
return this._getBounds('getHandleBounds');
},
/**
* Loops through all children, gets their bounds and finds the bounds around
* all of them.
@ -1113,11 +1123,6 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
rect.x, rect.y, rect.width, rect.height);
},
/**
* The bounding rectangle of the item including stroke width and controls.
*/
// TODO: getControlBounds
/**
* {@grouptitle Stroke Style}
*
@ -1322,8 +1327,8 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
*
* @name Item#scale
* @function
* @param {Number} sx the horizontal scale factor
* @param {Number} sy the vertical scale factor
* @param {Number} hor the horizontal scale factor
* @param {Number} ver the vertical scale factor
* @param {Point} [center={@link Item#position}]
*
* @example {@paperscript}
@ -1337,13 +1342,13 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
* // Scale the path horizontally by 300%
* circle.scale(3, 1);
*/
scale: function(sx, sy /* | scale */, center) {
scale: function(hor, ver /* | scale */, center) {
// See Matrix#scale for explanation of this:
if (arguments.length < 2 || typeof sy === 'object') {
center = sy;
sy = sx;
if (arguments.length < 2 || typeof ver === 'object') {
center = ver;
ver = hor;
}
return this.transform(new Matrix().scale(sx, sy,
return this.transform(new Matrix().scale(hor, ver,
center || this.getPosition()));
},
@ -1420,19 +1425,19 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
*
* @name Item#shear
* @function
* @param {Number} shearX
* @param {Number} shearY
* @param {Number} hor the horizontal shear factor.
* @param {Number} ver the vertical shear factor.
* @param {Point} [center={@link Item#position}]
* @see Matrix#shear
*/
shear: function(shearX, shearY, center) {
shear: function(hor, ver, center) {
// PORT: Add support for center back to Scriptographer too!
// See Matrix#scale for explanation of this:
if (arguments.length < 2 || typeof sy === 'object') {
center = shearY;
shearY = shearX;
if (arguments.length < 2 || typeof ver === 'object') {
center = ver;
ver = hor;
}
return this.transform(new Matrix().shear(shearX, shearY,
return this.transform(new Matrix().shear(hor, ver,
center || this.getPosition()));
},

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

54
src/item/PlacedItem.js Normal file
View file

@ -0,0 +1,54 @@
/*
* 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/
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name PlacedItem
*
* @class The PlacedItem class is the base for any items that have a matrix
* associated with them, describing their placement in the project, such as
* {@link Raster} and {@link PlacedSymbol}.
*
* @extends Item
*/
var PlacedItem = this.PlacedItem = Item.extend(/** @lends PlacedItem# */{
_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);
},
/**
* The item's transformation matrix, defining position and dimensions in the
* document.
*
* @type Matrix
* @bean
*/
getMatrix: function() {
return this._matrix;
},
setMatrix: function(matrix) {
this._matrix = matrix.clone();
this._changed(Change.GEOMETRY);
},
getStrokeBounds: function() {
return this.getBounds();
}
});

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -20,9 +20,9 @@
* @class A PlacedSymbol represents an instance of a symbol which has been
* placed in a Paper.js project.
*
* @extends Item
* @extends PlacedItem
*/
var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol# */{
/**
* Creates a new PlacedSymbol Item.
*
@ -64,7 +64,7 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
initialize: function(symbol, matrixOrOffset) {
this.base();
this.symbol = symbol instanceof Symbol ? symbol : new Symbol(symbol);
this.matrix = matrixOrOffset !== undefined
this._matrix = matrixOrOffset !== undefined
? matrixOrOffset instanceof Matrix
? matrixOrOffset
: new Matrix().translate(Point.read(arguments, 1))
@ -79,34 +79,23 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{
*/
clone: function() {
return this._clone(new PlacedSymbol(this.symbol, this.matrix.clone()));
},
_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);
return this._clone(new PlacedSymbol(this.symbol, this._matrix.clone()));
},
getBounds: function() {
if (!this._bounds)
this._bounds = this._createBounds(
this.symbol._definition.getStrokeBounds(this.matrix))
this.symbol._definition.getStrokeBounds(this._matrix))
return this._bounds;
},
getStrokeBounds: function() {
return this.getBounds();
},
draw: function(ctx, param) {
if (param.selection) {
Item.drawSelectedBounds(this.symbol._definition.getStrokeBounds(),
ctx, this.matrix);
ctx, this._matrix);
} else {
ctx.save();
this.matrix.applyToContext(ctx);
this._matrix.applyToContext(ctx);
Item.draw(this.symbol.getDefinition(), ctx, param);
ctx.restore();
}

View file

@ -6,20 +6,22 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name Raster
*
* @class The Raster item represents an image in a Paper.js project.
* @extends Item
*
* @extends PlacedItem
*/
var Raster = this.Raster = Item.extend(/** @lends Raster# */{
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
// TODO: Implement url / type, width, height.
// TODO: Have PlacedSymbol & Raster inherit from a shared class?
// DOCS: Document Raster constructor.
@ -40,7 +42,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
//#endif // BROWSER
this.setImage(object);
}
this.matrix = new Matrix();
this._matrix = new Matrix();
},
clone: function() {
@ -52,7 +54,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
image.getContext('2d').drawImage(this._canvas, 0, 0);
}
var copy = new Raster(image);
copy.matrix = this.matrix.clone();
copy._matrix = this._matrix.clone();
return this._clone(copy);
},
@ -103,7 +105,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
* @bean
*/
getPpi: function() {
var matrix = this.matrix,
var matrix = this._matrix,
orig = new Point(0, 0).transform(matrix),
u = new Point(1, 0).transform(matrix).subtract(orig),
v = new Point(0, 1).transform(matrix).subtract(orig);
@ -249,7 +251,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
if (path)
path.draw(ctx, { clip: true });
// Now draw the image clipped into it.
this.matrix.applyToContext(ctx);
this._matrix.applyToContext(ctx);
ctx.drawImage(this._canvas || this._image,
-this._size.width / 2, -this._size.height / 2);
ctx.restore();
@ -341,6 +343,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
return this.getContext().createImageData(size.width, size.height);
},
// TODO: Rename to #get/setImageData, as it will conflict with Item#getData
// DOCS: document Raster#getData
/**
* @param {Rectangle} rect
@ -365,31 +368,20 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{
this.getContext(true).putImageData(data, point.x, point.y);
},
_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() {
if (!this._bounds)
this._bounds = this._createBounds(this.matrix._transformBounds(
this._bounds = this._createBounds(this._matrix._transformBounds(
new Rectangle(this._size).setCenter(0, 0)));
return this._bounds;
},
getStrokeBounds: function() {
return this.getBounds();
},
draw: function(ctx, param) {
if (param.selection) {
var bounds = new Rectangle(this._size).setCenter(0, 0);
Item.drawSelectedBounds(bounds, ctx, this.matrix);
Item.drawSelectedBounds(bounds, ctx, this._matrix);
} else {
ctx.save();
this.matrix.applyToContext(ctx);
this._matrix.applyToContext(ctx);
ctx.drawImage(this._canvas || this._image,
-this._size.width / 2, -this._size.height / 2);
ctx.restore();

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -42,6 +42,7 @@ var sources = [
'src/item/Item.js',
'src/item/Group.js',
'src/item/Layer.js',
'src/item/PlacedItem.js',
'src/item/Raster.js',
'src/item/PlacedSymbol.js',

View file

@ -1,5 +1,5 @@
/***
*
*
* Paper.js
*
* A JavaScript Vector Graphics Library, based on Scriptographer.org and
@ -7,11 +7,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
***
@ -19,20 +19,28 @@
* Bootstrap.js JavaScript Framework.
* http://bootstrapjs.org/
*
* Distributed under the MIT license.
*
* Copyright (c) 2006 - 2011 Juerg Lehni
* http://lehni.org/
*
* Distributed under the MIT license.
*
***
*
* Parse-JS, A JavaScript tokenizer / parser / generator.
* Parse-js
*
* Distributed under the BSD license.
* A JavaScript tokenizer / parser / generator, originally written in Lisp.
* Copyright (c) Marijn Haverbeke <marijnh@gmail.com>
* http://marijn.haverbeke.nl/parse-js/
*
* Ported by to JavaScript by Mihai Bazon
* Copyright (c) 2010, Mihai Bazon <mihai.bazon@gmail.com>
* http://mihai.bazon.net/blog/
*
* Modifications and adaptions to browser (c) 2011, Juerg Lehni
* http://lehni.org/
*
* Distributed under the BSD license.
*
***/
/**
@ -64,6 +72,7 @@ var paper = new function() {
//#include "item/Item.js"
//#include "item/Group.js"
//#include "item/Layer.js"
//#include "item/PlacedItem.js"
//#include "item/Raster.js"
//#include "item/PlacedSymbol.js"

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -1159,6 +1159,14 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
var loc = this.getLocationAt(offset, isParameter);
return loc && loc.getNormal();
}
// TODO: intersects(item)
// TODO: contains(item)
// TODO: contains(point)
// TODO: intersect(item)
// TODO: unite(item)
// TODO: exclude(item)
// TODO: getIntersections(path)
}, new function() { // Scope for drawing
// Note that in the code below we're often accessing _x and _y on point
@ -1826,11 +1834,10 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
}
function addJoin(segment, join) {
var handleIn = segment.getHandleInIfSet(),
handleOut = segment.getHandleOutIfSet();
// When both handles are set in a segment, the join setting is
// ignored and round is always used.
if (join === 'round' || handleIn && handleOut) {
if (join === 'round' || !segment._handleIn.isZero()
&& !segment._handleOut.isZero()) {
bounds = bounds.unite(joinBounds.setCenter(matrix
? matrix.transform(segment._point) : segment._point));
} else if (join == 'bevel') {
@ -1895,17 +1902,38 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
/**
* The bounding rectangle of the item including handles.
*
* @type Rectangle
* @bean
*/
getControlBounds: function() {
// TODO: Implement!
getHandleBounds: function() {
var x1 = Infinity,
x2 = -Infinity,
y1 = x1,
y2 = x2;
function add(point, handle) {
var x = point._x,
y = point._y;
if (handle) {
x += handle._x;
y += handle._y;
}
if (x < x1) x1 = x;
if (x > x2) x2 = x;
if (y < y1) y1 = y;
if (y > y2) y2 = y;
}
for (var i = 0, l = this._segments.length; i < l; i++) {
var segment = this._segments[i],
point = segment._point;
add(point);
add(point, segment._handleIn);
add(point, segment._handleOut);
}
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
}
// TODO: intersects(item)
// TODO: contains(item)
// TODO: contains(point)
// TODO: intersect(item)
// TODO: unite(item)
// TODO: exclude(item)
// TODO: getIntersections(path)
};
});

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,17 +6,21 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name PathItem
* @class
*
* @class The PathItem class is the base for any items that describe paths
* and offer standardised methods for drawing and path manipulation, such as
* {@link Path} and {@link CompoundPath}.
*
* @extends Item
*/
var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -143,11 +143,6 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
// this.corner = !this._handleIn.isColinear(this._handleOut);
},
getHandleInIfSet: function() {
return this._handleIn._x == 0 && this._handleIn._y == 0
? null : this._handleIn;
},
/**
* The handle point relative to the anchor point of the segment that
* describes the out tangent of the segment.
@ -167,11 +162,6 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
// this.corner = !this._handleIn.isColinear(this._handleOut);
},
getHandleOutIfSet: function() {
return this._handleOut._x == 0 && this._handleOut._y == 0
? null : this._handleOut;
},
_isSelected: function(point) {
var state = this._selectionState;
return point == this._point ? !!(state & SelectionState.POINT)
@ -342,12 +332,16 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
// points for largely improved performance, as no calls to
// Point.read() and Point constructors are necessary.
var point = this._point,
// If a matrix is defined, only transform handles if they are set.
// This saves some computation time. If no matrix is set, always
// If change is true, only transform handles if they are set, as
// _transformCoordinates is called only to change the segment, no
// to receive the coords.
// This saves some computation time. If change is false, always
// use the real handles, as we just want to receive a filled
// coords array for getBounds().
handleIn = matrix && this.getHandleInIfSet() || this._handleIn,
handleOut = matrix && this.getHandleOutIfSet() || this._handleOut,
handleIn = !change || !this._handleIn.isZero()
? this._handleIn : null,
handleOut = !change || !this._handleOut.isZero()
? this._handleOut : null,
x = point._x,
y = point._y,
i = 2;
@ -363,34 +357,36 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
coords[i++] = handleOut._x + x;
coords[i++] = handleOut._y + y;
}
if (matrix) {
matrix._transformCoordinates(coords, 0, coords, 0, i / 2);
x = coords[0];
y = coords[1];
if (change) {
// If change is true, we need to set the new values back
point._x = x;
point._y = y;
i = 2;
if (handleIn) {
handleIn._x = coords[i++] - x;
handleIn._y = coords[i++] - y;
}
if (handleOut) {
handleOut._x = coords[i++] - x;
handleOut._y = coords[i++] - y;
}
} else {
// We want to receive the results in coords, so make sure
// handleIn and out are defined too, even if they're 0
if (!handleIn) {
coords[i++] = x;
coords[i++] = y;
}
if (!handleOut) {
coords[i++] = x;
coords[i++] = y;
}
// If no matrix was previded, this was just called to get the coords and
// we are done now.
if (!matrix)
return;
matrix._transformCoordinates(coords, 0, coords, 0, i / 2);
x = coords[0];
y = coords[1];
if (change) {
// If change is true, we need to set the new values back
point._x = x;
point._y = y;
i = 2;
if (handleIn) {
handleIn._x = coords[i++] - x;
handleIn._y = coords[i++] - y;
}
if (handleOut) {
handleOut._x = coords[i++] - x;
handleOut._y = coords[i++] - y;
}
} else {
// We want to receive the results in coords, so make sure
// handleIn and out are defined too, even if they're 0
if (!handleIn) {
coords[i++] = x;
coords[i++] = y;
}
if (!handleOut) {
coords[i++] = x;
coords[i++] = y;
}
}
}

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -80,7 +80,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
setContent: function(content) {
this._changed(Change.CONTENT);
this._content = content;
this._content = '' + content;
},
/**

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/

View file

@ -6,11 +6,11 @@
* 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/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
@ -54,15 +54,9 @@ var View = this.View = Base.extend(/** @lends View# */{
if (!DomElement.isInvisible(canvas))
offset = DomElement.getOffset(canvas, false, true);
// Set the size now, which internally calls onResize
// and redraws the view
that.setViewSize(DomElement.getViewportSize(canvas)
.subtract(offset));
// If there's a _onFrameCallback, call it staight away,
// but without requesting another animation frame.
if (that._onFrameCallback) {
that._onFrameCallback(0, true);
} else {
that.draw(true);
}
}
});
} else {
@ -135,6 +129,8 @@ var View = this.View = Base.extend(/** @lends View# */{
setViewSize: function(size) {
size = Size.read(arguments);
var delta = size.subtract(this._viewSize);
if (delta.isZero())
return;
this._canvas.width = size.width;
this._canvas.height = size.height;
// Call onResize handler on any size change
@ -148,6 +144,15 @@ var View = this.View = Base.extend(/** @lends View# */{
this._viewSize.set(size.width, size.height, true);
// Force recalculation
this._bounds = null;
this._redrawNeeded = true;
if (this._onFrameCallback) {
// If there's a _onFrameCallback, call it staight away,
// but without requesting another animation frame.
this._onFrameCallback(0, true);
} else {
// Otherwise simply redraw the view now
this.draw(true);
}
},
/**

Some files were not shown because too many files have changed in this diff Show more