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): 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. > 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 # Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # 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: # Usage:
# build.sh MODE # build.sh MODE

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # 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" echo "Building paper.js"
./build.sh ./build.sh

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # 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 # Generate documentation
# #

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

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # 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 # 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 # 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 # Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # 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 # 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 # 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 # Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # 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 # preprocess.sh
# #

View file

@ -9,7 +9,9 @@
# Copyright (c) 2011, Juerg Lehni & Jonathan Puckey # Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/ # 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 ] if [ -f paperjs.zip ]
then then

View file

@ -5010,7 +5010,7 @@ var TextItem = this.TextItem = Item.extend({
setContent: function(content) { setContent: function(content) {
this._changed(Change.CONTENT); this._changed(Change.CONTENT);
this._content = content; this._content = '' + content;
}, },
getCharacterStyle: function() { 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> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <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"> <link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper.js"></script> <script type="text/javascript" src="../../dist/paper.js"></script>
<script type="text/paperscript" canvas="canvas"> <script type="text/paperscript" canvas="canvas">

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

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

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

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

View file

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

View file

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

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */
@ -42,6 +42,7 @@ var sources = [
'src/item/Item.js', 'src/item/Item.js',
'src/item/Group.js', 'src/item/Group.js',
'src/item/Layer.js', 'src/item/Layer.js',
'src/item/PlacedItem.js',
'src/item/Raster.js', 'src/item/Raster.js',
'src/item/PlacedSymbol.js', 'src/item/PlacedSymbol.js',

View file

@ -7,11 +7,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
* *
*** ***
@ -19,20 +19,28 @@
* Bootstrap.js JavaScript Framework. * Bootstrap.js JavaScript Framework.
* http://bootstrapjs.org/ * http://bootstrapjs.org/
* *
* Distributed under the MIT license.
*
* Copyright (c) 2006 - 2011 Juerg Lehni * Copyright (c) 2006 - 2011 Juerg Lehni
* http://lehni.org/ * 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> * Copyright (c) 2010, Mihai Bazon <mihai.bazon@gmail.com>
* http://mihai.bazon.net/blog/ * 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/Item.js"
//#include "item/Group.js" //#include "item/Group.js"
//#include "item/Layer.js" //#include "item/Layer.js"
//#include "item/PlacedItem.js"
//#include "item/Raster.js" //#include "item/Raster.js"
//#include "item/PlacedSymbol.js" //#include "item/PlacedSymbol.js"

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */
@ -1159,6 +1159,14 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
var loc = this.getLocationAt(offset, isParameter); var loc = this.getLocationAt(offset, isParameter);
return loc && loc.getNormal(); 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 }, new function() { // Scope for drawing
// Note that in the code below we're often accessing _x and _y on point // 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) { function addJoin(segment, join) {
var handleIn = segment.getHandleInIfSet(),
handleOut = segment.getHandleOutIfSet();
// When both handles are set in a segment, the join setting is // When both handles are set in a segment, the join setting is
// ignored and round is always used. // 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 bounds = bounds.unite(joinBounds.setCenter(matrix
? matrix.transform(segment._point) : segment._point)); ? matrix.transform(segment._point) : segment._point));
} else if (join == 'bevel') { } else if (join == 'bevel') {
@ -1895,17 +1902,38 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
/** /**
* The bounding rectangle of the item including handles. * The bounding rectangle of the item including handles.
*
* @type Rectangle
* @bean
*/ */
getControlBounds: function() { getHandleBounds: function() {
// TODO: Implement! 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://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,17 +6,21 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */
/** /**
* @name PathItem * @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 * @extends Item
*/ */
var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{ var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */
@ -143,11 +143,6 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
// this.corner = !this._handleIn.isColinear(this._handleOut); // 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 * The handle point relative to the anchor point of the segment that
* describes the out tangent of the segment. * 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); // this.corner = !this._handleIn.isColinear(this._handleOut);
}, },
getHandleOutIfSet: function() {
return this._handleOut._x == 0 && this._handleOut._y == 0
? null : this._handleOut;
},
_isSelected: function(point) { _isSelected: function(point) {
var state = this._selectionState; var state = this._selectionState;
return point == this._point ? !!(state & SelectionState.POINT) 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 // points for largely improved performance, as no calls to
// Point.read() and Point constructors are necessary. // Point.read() and Point constructors are necessary.
var point = this._point, var point = this._point,
// If a matrix is defined, only transform handles if they are set. // If change is true, only transform handles if they are set, as
// This saves some computation time. If no matrix is set, always // _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 // use the real handles, as we just want to receive a filled
// coords array for getBounds(). // coords array for getBounds().
handleIn = matrix && this.getHandleInIfSet() || this._handleIn, handleIn = !change || !this._handleIn.isZero()
handleOut = matrix && this.getHandleOutIfSet() || this._handleOut, ? this._handleIn : null,
handleOut = !change || !this._handleOut.isZero()
? this._handleOut : null,
x = point._x, x = point._x,
y = point._y, y = point._y,
i = 2; i = 2;
@ -363,7 +357,10 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
coords[i++] = handleOut._x + x; coords[i++] = handleOut._x + x;
coords[i++] = handleOut._y + y; coords[i++] = handleOut._y + y;
} }
if (matrix) { // 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); matrix._transformCoordinates(coords, 0, coords, 0, i / 2);
x = coords[0]; x = coords[0];
y = coords[1]; y = coords[1];
@ -393,5 +390,4 @@ var Segment = this.Segment = Base.extend(/** @lends Segment# */{
} }
} }
} }
}
}); });

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */
@ -80,7 +80,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
setContent: function(content) { setContent: function(content) {
this._changed(Change.CONTENT); this._changed(Change.CONTENT);
this._content = content; this._content = '' + content;
}, },
/** /**

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */

View file

@ -6,11 +6,11 @@
* http://paperjs.org/ * http://paperjs.org/
* http://scriptographer.org/ * http://scriptographer.org/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/ * http://lehni.org/ & http://jonathanpuckey.com/
* *
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved. * All rights reserved.
*/ */
@ -54,15 +54,9 @@ var View = this.View = Base.extend(/** @lends View# */{
if (!DomElement.isInvisible(canvas)) if (!DomElement.isInvisible(canvas))
offset = DomElement.getOffset(canvas, false, true); offset = DomElement.getOffset(canvas, false, true);
// Set the size now, which internally calls onResize // Set the size now, which internally calls onResize
// and redraws the view
that.setViewSize(DomElement.getViewportSize(canvas) that.setViewSize(DomElement.getViewportSize(canvas)
.subtract(offset)); .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 { } else {
@ -135,6 +129,8 @@ var View = this.View = Base.extend(/** @lends View# */{
setViewSize: function(size) { setViewSize: function(size) {
size = Size.read(arguments); size = Size.read(arguments);
var delta = size.subtract(this._viewSize); var delta = size.subtract(this._viewSize);
if (delta.isZero())
return;
this._canvas.width = size.width; this._canvas.width = size.width;
this._canvas.height = size.height; this._canvas.height = size.height;
// Call onResize handler on any size change // 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); this._viewSize.set(size.width, size.height, true);
// Force recalculation // Force recalculation
this._bounds = null; 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