From d28bac0734465cd3dd6c8d21a605139791385345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 18 Mar 2014 12:38:29 +0100 Subject: [PATCH] Support Firefox 3.6 still, with surprising little effort. Why, I don't really know :) --- build/build.sh | 2 +- src/canvas/BlendMode.js | 22 +++++++++++++--------- src/legacy.js | 23 +++++++++++++++++++++++ src/options.js | 1 + src/paper.js | 4 ++++ 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/legacy.js diff --git a/build/build.sh b/build/build.sh index 3af89d7d..cea8b297 100755 --- a/build/build.sh +++ b/build/build.sh @@ -32,7 +32,7 @@ fi ./preprocess.sh $MODE ../src/paper.js "-i '../src/constants.js'" ../dist/paper-full.js ./preprocess.sh $MODE ../src/paper.js "-o '{ \"paperScript\": false, \"palette\": false }' -i '../src/constants.js'" ../dist/paper-core.js -./preprocess.sh $MODE ../src/paper.js "-o '{ \"environment\": \"node\" }' -i '../src/constants.js'" ../dist/paper-node.js +./preprocess.sh $MODE ../src/paper.js "-o '{ \"environment\": \"node\", \"legacy\": false }' -i '../src/constants.js'" ../dist/paper-node.js # Remove the existing file and copy paper-full.js to paper.js now if [ -f ../dist/paper.js ] diff --git a/src/canvas/BlendMode.js b/src/canvas/BlendMode.js index c3ccc3dd..b436078a 100644 --- a/src/canvas/BlendMode.js +++ b/src/canvas/BlendMode.js @@ -232,20 +232,24 @@ var BlendMode = new function() { Base.each(modes, function(func, mode) { // Blend #330000 (51) and #aa0000 (170): // Multiplying should lead to #220000 (34) - ctx.save(); // For darken we need to reverse color parameters in order to test mode. var darken = mode === 'darken', ok = false; - ctx.fillStyle = darken ? '#300' : '#a00'; - ctx.fillRect(0, 0, 1, 1); - ctx.globalCompositeOperation = mode; - if (ctx.globalCompositeOperation === mode) { - ctx.fillStyle = darken ? '#a00' : '#300'; + ctx.save(); + // FF 3.6 throws exception when setting globalCompositeOperation to + // unsupported values. + try { + ctx.fillStyle = darken ? '#300' : '#a00'; ctx.fillRect(0, 0, 1, 1); - ok = ctx.getImageData(0, 0, 1, 1).data[0] !== (darken ? 170 : 51); - } - nativeModes[mode] = ok; + ctx.globalCompositeOperation = mode; + if (ctx.globalCompositeOperation === mode) { + ctx.fillStyle = darken ? '#a00' : '#300'; + ctx.fillRect(0, 0, 1, 1); + ok = ctx.getImageData(0, 0, 1, 1).data[0] !== darken ? 170 : 51; + } + } catch (e) {} ctx.restore(); + nativeModes[mode] = ok; }); CanvasProvider.release(ctx); diff --git a/src/legacy.js b/src/legacy.js new file mode 100644 index 00000000..64837105 --- /dev/null +++ b/src/legacy.js @@ -0,0 +1,23 @@ +/* + * Paper.js - The Swiss Army Knife of Vector Graphics Scripting. + * http://paperjs.org/ + * + * Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey + * http://scratchdisk.com/ & http://jonathanpuckey.com/ + * + * Distributed under the MIT license. See LICENSE file for details. + * + * All rights reserved. + */ + +// Support for legacy browsers (mainly FF 3.6). Remove 2nd half of 2014? + +if (!Array.isArray) { + Array.isArray = function(obj) { + return Object.prototype.toString.call(obj) === '[object Array]'; + }; +} + +if (!document.head) { + document.head = document.getElementsByTagName('head')[0]; +} diff --git a/src/options.js b/src/options.js index cf842536..52008b67 100644 --- a/src/options.js +++ b/src/options.js @@ -18,6 +18,7 @@ var __options = { parser: 'acorn', version: 'dev', environment: 'browser', + legacy: true, stats: true, svg: true, fatlineClipping: true, diff --git a/src/paper.js b/src/paper.js index 53d21163..50709922 100644 --- a/src/paper.js +++ b/src/paper.js @@ -40,6 +40,10 @@ var paper = new function(undefined) { /*#*/ include('../bower_components/stats.js/build/stats.min.js'); /*#*/ } // __options.stats +/*#*/ if (__options.legacy) { + /*#*/ include('legacy.js'); +/*#*/ } // __options.legacy + /*#*/ if (__options.version == 'dev') { /*#*/ include('constants.js'); /*#*/ } // __options.version == 'dev'