| author | ymh <ymh.work@gmail.com> |
| Sun, 14 Jul 2024 22:00:08 +0200 | |
| changeset 666 | 9d6550026232 |
| parent 598 | eb4f4eceada0 |
| permissions | -rw-r--r-- |
| 442 | 1 |
/*! |
| 598 | 2 |
* Paper.js v0.9.25 - The Swiss Army Knife of Vector Graphics Scripting. |
| 442 | 3 |
* http://paperjs.org/ |
4 |
* |
|
5 |
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey |
|
6 |
* http://scratchdisk.com/ & http://jonathanpuckey.com/ |
|
7 |
* |
|
8 |
* Distributed under the MIT license. See LICENSE file for details. |
|
9 |
* |
|
10 |
* All rights reserved. |
|
11 |
* |
|
| 598 | 12 |
* Date: Sun Oct 25 11:23:38 2015 +0100 |
| 442 | 13 |
* |
14 |
*** |
|
15 |
* |
|
16 |
* Straps.js - Class inheritance library with support for bean-style accessors |
|
17 |
* |
|
18 |
* Copyright (c) 2006 - 2013 Juerg Lehni |
|
19 |
* http://scratchdisk.com/ |
|
20 |
* |
|
21 |
* Distributed under the MIT license. |
|
22 |
* |
|
23 |
*** |
|
24 |
* |
|
25 |
* Acorn.js |
|
26 |
* http://marijnhaverbeke.nl/acorn/ |
|
27 |
* |
|
28 |
* Acorn is a tiny, fast JavaScript parser written in JavaScript, |
|
29 |
* created by Marijn Haverbeke and released under an MIT license. |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
33 |
var paper = new function(undefined) {
|
|
34 |
||
35 |
var Base = new function() {
|
|
36 |
var hidden = /^(statics|enumerable|beans|preserve)$/, |
|
37 |
||
38 |
forEach = [].forEach || function(iter, bind) {
|
|
39 |
for (var i = 0, l = this.length; i < l; i++) |
|
40 |
iter.call(bind, this[i], i, this); |
|
41 |
}, |
|
42 |
||
43 |
forIn = function(iter, bind) {
|
|
44 |
for (var i in this) |
|
45 |
if (this.hasOwnProperty(i)) |
|
46 |
iter.call(bind, this[i], i, this); |
|
47 |
}, |
|
48 |
||
49 |
create = Object.create || function(proto) {
|
|
50 |
return { __proto__: proto };
|
|
51 |
}, |
|
52 |
||
53 |
describe = Object.getOwnPropertyDescriptor || function(obj, name) {
|
|
54 |
var get = obj.__lookupGetter__ && obj.__lookupGetter__(name); |
|
55 |
return get |
|
56 |
? { get: get, set: obj.__lookupSetter__(name),
|
|
57 |
enumerable: true, configurable: true } |
|
58 |
: obj.hasOwnProperty(name) |
|
59 |
? { value: obj[name], enumerable: true,
|
|
60 |
configurable: true, writable: true } |
|
61 |
: null; |
|
62 |
}, |
|
63 |
||
64 |
_define = Object.defineProperty || function(obj, name, desc) {
|
|
65 |
if ((desc.get || desc.set) && obj.__defineGetter__) {
|
|
66 |
if (desc.get) |
|
67 |
obj.__defineGetter__(name, desc.get); |
|
68 |
if (desc.set) |
|
69 |
obj.__defineSetter__(name, desc.set); |
|
70 |
} else {
|
|
71 |
obj[name] = desc.value; |
|
72 |
} |
|
73 |
return obj; |
|
74 |
}, |
|
75 |
||
76 |
define = function(obj, name, desc) {
|
|
77 |
delete obj[name]; |
|
78 |
return _define(obj, name, desc); |
|
79 |
}; |
|
80 |
||
81 |
function inject(dest, src, enumerable, beans, preserve) {
|
|
82 |
var beansNames = {};
|
|
83 |
||
84 |
function field(name, val) {
|
|
85 |
val = val || (val = describe(src, name)) |
|
86 |
&& (val.get ? val : val.value); |
|
87 |
if (typeof val === 'string' && val[0] === '#') |
|
88 |
val = dest[val.substring(1)] || val; |
|
89 |
var isFunc = typeof val === 'function', |
|
90 |
res = val, |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
91 |
prev = preserve || isFunc && !val.base |
| 442 | 92 |
? (val && val.get ? name in dest : dest[name]) |
93 |
: null, |
|
94 |
bean; |
|
95 |
if (!preserve || !prev) {
|
|
96 |
if (isFunc && prev) |
|
97 |
val.base = prev; |
|
98 |
if (isFunc && beans !== false |
|
99 |
&& (bean = name.match(/^([gs]et|is)(([A-Z])(.*))$/))) |
|
100 |
beansNames[bean[3].toLowerCase() + bean[4]] = bean[2]; |
|
101 |
if (!res || isFunc || !res.get || typeof res.get !== 'function' |
|
102 |
|| !Base.isPlainObject(res)) |
|
103 |
res = { value: res, writable: true };
|
|
104 |
if ((describe(dest, name) |
|
105 |
|| { configurable: true }).configurable) {
|
|
106 |
res.configurable = true; |
|
107 |
res.enumerable = enumerable; |
|
108 |
} |
|
109 |
define(dest, name, res); |
|
110 |
} |
|
111 |
} |
|
112 |
if (src) {
|
|
113 |
for (var name in src) {
|
|
114 |
if (src.hasOwnProperty(name) && !hidden.test(name)) |
|
115 |
field(name); |
|
116 |
} |
|
117 |
for (var name in beansNames) {
|
|
118 |
var part = beansNames[name], |
|
119 |
set = dest['set' + part], |
|
120 |
get = dest['get' + part] || set && dest['is' + part]; |
|
121 |
if (get && (beans === true || get.length === 0)) |
|
122 |
field(name, { get: get, set: set });
|
|
123 |
} |
|
124 |
} |
|
125 |
return dest; |
|
126 |
} |
|
127 |
||
128 |
function each(obj, iter, bind) {
|
|
129 |
if (obj) |
|
130 |
('length' in obj && !obj.getLength
|
|
131 |
&& typeof obj.length === 'number' |
|
132 |
? forEach |
|
133 |
: forIn).call(obj, iter, bind = bind || obj); |
|
134 |
return bind; |
|
135 |
} |
|
136 |
||
137 |
function set(obj, props, exclude) {
|
|
138 |
for (var key in props) |
|
139 |
if (props.hasOwnProperty(key) && !(exclude && exclude[key])) |
|
140 |
obj[key] = props[key]; |
|
141 |
return obj; |
|
142 |
} |
|
143 |
||
144 |
return inject(function Base() {
|
|
145 |
for (var i = 0, l = arguments.length; i < l; i++) |
|
146 |
set(this, arguments[i]); |
|
147 |
}, {
|
|
148 |
inject: function(src) {
|
|
149 |
if (src) {
|
|
150 |
var statics = src.statics === true ? src : src.statics, |
|
151 |
beans = src.beans, |
|
152 |
preserve = src.preserve; |
|
153 |
if (statics !== src) |
|
154 |
inject(this.prototype, src, src.enumerable, beans, preserve); |
|
155 |
inject(this, statics, true, beans, preserve); |
|
156 |
} |
|
157 |
for (var i = 1, l = arguments.length; i < l; i++) |
|
158 |
this.inject(arguments[i]); |
|
159 |
return this; |
|
160 |
}, |
|
161 |
||
162 |
extend: function() {
|
|
163 |
var base = this, |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
164 |
ctor, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
165 |
proto; |
| 442 | 166 |
for (var i = 0, l = arguments.length; i < l; i++) |
167 |
if (ctor = arguments[i].initialize) |
|
168 |
break; |
|
169 |
ctor = ctor || function() {
|
|
170 |
base.apply(this, arguments); |
|
171 |
}; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
172 |
proto = ctor.prototype = create(this.prototype); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
173 |
define(proto, 'constructor', |
| 442 | 174 |
{ value: ctor, writable: true, configurable: true });
|
175 |
inject(ctor, this, true); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
176 |
if (arguments.length) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
177 |
this.inject.apply(ctor, arguments); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
178 |
ctor.base = base; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
179 |
return ctor; |
| 442 | 180 |
} |
181 |
}, true).inject({
|
|
182 |
inject: function() {
|
|
183 |
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
184 |
var src = arguments[i]; |
|
185 |
if (src) |
|
186 |
inject(this, src, src.enumerable, src.beans, src.preserve); |
|
187 |
} |
|
188 |
return this; |
|
189 |
}, |
|
190 |
||
191 |
extend: function() {
|
|
192 |
var res = create(this); |
|
193 |
return res.inject.apply(res, arguments); |
|
194 |
}, |
|
195 |
||
196 |
each: function(iter, bind) {
|
|
197 |
return each(this, iter, bind); |
|
198 |
}, |
|
199 |
||
200 |
set: function(props) {
|
|
201 |
return set(this, props); |
|
202 |
}, |
|
203 |
||
204 |
clone: function() {
|
|
205 |
return new this.constructor(this); |
|
206 |
}, |
|
207 |
||
208 |
statics: {
|
|
209 |
each: each, |
|
210 |
create: create, |
|
211 |
define: define, |
|
212 |
describe: describe, |
|
213 |
set: set, |
|
214 |
||
215 |
clone: function(obj) {
|
|
216 |
return set(new obj.constructor(), obj); |
|
217 |
}, |
|
218 |
||
219 |
isPlainObject: function(obj) {
|
|
220 |
var ctor = obj != null && obj.constructor; |
|
221 |
return ctor && (ctor === Object || ctor === Base |
|
222 |
|| ctor.name === 'Object'); |
|
223 |
}, |
|
224 |
||
225 |
pick: function(a, b) {
|
|
226 |
return a !== undefined ? a : b; |
|
227 |
} |
|
228 |
} |
|
229 |
}); |
|
230 |
}; |
|
231 |
||
232 |
if (typeof module !== 'undefined') |
|
233 |
module.exports = Base; |
|
234 |
||
235 |
Base.inject({
|
|
236 |
toString: function() {
|
|
237 |
return this._id != null |
|
238 |
? (this._class || 'Object') + (this._name |
|
239 |
? " '" + this._name + "'" |
|
240 |
: ' @' + this._id) |
|
241 |
: '{ ' + Base.each(this, function(value, key) {
|
|
242 |
if (!/^_/.test(key)) {
|
|
243 |
var type = typeof value; |
|
244 |
this.push(key + ': ' + (type === 'number' |
|
245 |
? Formatter.instance.number(value) |
|
246 |
: type === 'string' ? "'" + value + "'" : value)); |
|
247 |
} |
|
248 |
}, []).join(', ') + ' }';
|
|
249 |
}, |
|
250 |
||
251 |
getClassName: function() {
|
|
252 |
return this._class || ''; |
|
253 |
}, |
|
254 |
||
255 |
exportJSON: function(options) {
|
|
256 |
return Base.exportJSON(this, options); |
|
257 |
}, |
|
258 |
||
259 |
toJSON: function() {
|
|
260 |
return Base.serialize(this); |
|
261 |
}, |
|
262 |
||
263 |
_set: function(props, exclude, dontCheck) {
|
|
264 |
if (props && (dontCheck || Base.isPlainObject(props))) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
265 |
var keys = Object.keys(props._filtering || props); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
266 |
for (var i = 0, l = keys.length; i < l; i++) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
267 |
var key = keys[i]; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
268 |
if (!(exclude && exclude[key])) {
|
| 442 | 269 |
var value = props[key]; |
270 |
if (value !== undefined) |
|
271 |
this[key] = value; |
|
272 |
} |
|
273 |
} |
|
274 |
return true; |
|
275 |
} |
|
276 |
}, |
|
277 |
||
278 |
statics: {
|
|
279 |
||
280 |
exports: {
|
|
281 |
enumerable: true |
|
282 |
}, |
|
283 |
||
284 |
extend: function extend() {
|
|
285 |
var res = extend.base.apply(this, arguments), |
|
286 |
name = res.prototype._class; |
|
287 |
if (name && !Base.exports[name]) |
|
288 |
Base.exports[name] = res; |
|
289 |
return res; |
|
290 |
}, |
|
291 |
||
292 |
equals: function(obj1, obj2) {
|
|
293 |
if (obj1 === obj2) |
|
294 |
return true; |
|
295 |
if (obj1 && obj1.equals) |
|
296 |
return obj1.equals(obj2); |
|
297 |
if (obj2 && obj2.equals) |
|
298 |
return obj2.equals(obj1); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
299 |
if (obj1 && obj2 |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
300 |
&& typeof obj1 === 'object' && typeof obj2 === 'object') {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
301 |
if (Array.isArray(obj1) && Array.isArray(obj2)) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
302 |
var length = obj1.length; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
303 |
if (length !== obj2.length) |
| 442 | 304 |
return false; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
305 |
while (length--) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
306 |
if (!Base.equals(obj1[length], obj2[length])) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
307 |
return false; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
308 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
309 |
} else {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
310 |
var keys = Object.keys(obj1), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
311 |
length = keys.length; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
312 |
if (length !== Object.keys(obj2).length) |
| 442 | 313 |
return false; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
314 |
while (length--) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
315 |
var key = keys[length]; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
316 |
if (!(obj2.hasOwnProperty(key) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
317 |
&& Base.equals(obj1[key], obj2[key]))) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
318 |
return false; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
319 |
} |
| 442 | 320 |
} |
321 |
return true; |
|
322 |
} |
|
323 |
return false; |
|
324 |
}, |
|
325 |
||
326 |
read: function(list, start, options, length) {
|
|
327 |
if (this === Base) {
|
|
328 |
var value = this.peek(list, start); |
|
329 |
list.__index++; |
|
330 |
return value; |
|
331 |
} |
|
332 |
var proto = this.prototype, |
|
333 |
readIndex = proto._readIndex, |
|
334 |
index = start || readIndex && list.__index || 0; |
|
335 |
if (!length) |
|
336 |
length = list.length - index; |
|
337 |
var obj = list[index]; |
|
338 |
if (obj instanceof this |
|
339 |
|| options && options.readNull && obj == null && length <= 1) {
|
|
340 |
if (readIndex) |
|
341 |
list.__index = index + 1; |
|
342 |
return obj && options && options.clone ? obj.clone() : obj; |
|
343 |
} |
|
344 |
obj = Base.create(this.prototype); |
|
345 |
if (readIndex) |
|
346 |
obj.__read = true; |
|
347 |
obj = obj.initialize.apply(obj, index > 0 || length < list.length |
|
348 |
? Array.prototype.slice.call(list, index, index + length) |
|
349 |
: list) || obj; |
|
350 |
if (readIndex) {
|
|
351 |
list.__index = index + obj.__read; |
|
352 |
obj.__read = undefined; |
|
353 |
} |
|
354 |
return obj; |
|
355 |
}, |
|
356 |
||
357 |
peek: function(list, start) {
|
|
358 |
return list[list.__index = start || list.__index || 0]; |
|
359 |
}, |
|
360 |
||
361 |
remain: function(list) {
|
|
362 |
return list.length - (list.__index || 0); |
|
363 |
}, |
|
364 |
||
365 |
readAll: function(list, start, options) {
|
|
366 |
var res = [], |
|
367 |
entry; |
|
368 |
for (var i = start || 0, l = list.length; i < l; i++) {
|
|
369 |
res.push(Array.isArray(entry = list[i]) |
|
370 |
? this.read(entry, 0, options) |
|
371 |
: this.read(list, i, options, 1)); |
|
372 |
} |
|
373 |
return res; |
|
374 |
}, |
|
375 |
||
376 |
readNamed: function(list, name, start, options, length) {
|
|
377 |
var value = this.getNamed(list, name), |
|
378 |
hasObject = value !== undefined; |
|
379 |
if (hasObject) {
|
|
380 |
var filtered = list._filtered; |
|
381 |
if (!filtered) {
|
|
382 |
filtered = list._filtered = Base.create(list[0]); |
|
383 |
filtered._filtering = list[0]; |
|
384 |
} |
|
385 |
filtered[name] = undefined; |
|
386 |
} |
|
387 |
return this.read(hasObject ? [value] : list, start, options, length); |
|
388 |
}, |
|
389 |
||
390 |
getNamed: function(list, name) {
|
|
391 |
var arg = list[0]; |
|
392 |
if (list._hasObject === undefined) |
|
393 |
list._hasObject = list.length === 1 && Base.isPlainObject(arg); |
|
394 |
if (list._hasObject) |
|
395 |
return name ? arg[name] : list._filtered || arg; |
|
396 |
}, |
|
397 |
||
398 |
hasNamed: function(list, name) {
|
|
399 |
return !!this.getNamed(list, name); |
|
400 |
}, |
|
401 |
||
402 |
isPlainValue: function(obj, asString) {
|
|
403 |
return this.isPlainObject(obj) || Array.isArray(obj) |
|
404 |
|| asString && typeof obj === 'string'; |
|
405 |
}, |
|
406 |
||
407 |
serialize: function(obj, options, compact, dictionary) {
|
|
408 |
options = options || {};
|
|
409 |
||
410 |
var root = !dictionary, |
|
411 |
res; |
|
412 |
if (root) {
|
|
413 |
options.formatter = new Formatter(options.precision); |
|
414 |
dictionary = {
|
|
415 |
length: 0, |
|
416 |
definitions: {},
|
|
417 |
references: {},
|
|
418 |
add: function(item, create) {
|
|
419 |
var id = '#' + item._id, |
|
420 |
ref = this.references[id]; |
|
421 |
if (!ref) {
|
|
422 |
this.length++; |
|
423 |
var res = create.call(item), |
|
424 |
name = item._class; |
|
425 |
if (name && res[0] !== name) |
|
426 |
res.unshift(name); |
|
427 |
this.definitions[id] = res; |
|
428 |
ref = this.references[id] = [id]; |
|
429 |
} |
|
430 |
return ref; |
|
431 |
} |
|
432 |
}; |
|
433 |
} |
|
434 |
if (obj && obj._serialize) {
|
|
435 |
res = obj._serialize(options, dictionary); |
|
436 |
var name = obj._class; |
|
437 |
if (name && !compact && !res._compact && res[0] !== name) |
|
438 |
res.unshift(name); |
|
439 |
} else if (Array.isArray(obj)) {
|
|
440 |
res = []; |
|
441 |
for (var i = 0, l = obj.length; i < l; i++) |
|
442 |
res[i] = Base.serialize(obj[i], options, compact, |
|
443 |
dictionary); |
|
444 |
if (compact) |
|
445 |
res._compact = true; |
|
446 |
} else if (Base.isPlainObject(obj)) {
|
|
447 |
res = {};
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
448 |
var keys = Object.keys(obj); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
449 |
for (var i = 0, l = keys.length; i < l; i++) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
450 |
var key = keys[i]; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
451 |
res[key] = Base.serialize(obj[key], options, compact, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
452 |
dictionary); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
453 |
} |
| 442 | 454 |
} else if (typeof obj === 'number') {
|
455 |
res = options.formatter.number(obj, options.precision); |
|
456 |
} else {
|
|
457 |
res = obj; |
|
458 |
} |
|
459 |
return root && dictionary.length > 0 |
|
460 |
? [['dictionary', dictionary.definitions], res] |
|
461 |
: res; |
|
462 |
}, |
|
463 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
464 |
deserialize: function(json, create, _data, _isDictionary) {
|
| 442 | 465 |
var res = json, |
466 |
isRoot = !_data; |
|
467 |
_data = _data || {};
|
|
468 |
if (Array.isArray(json)) {
|
|
469 |
var type = json[0], |
|
470 |
isDictionary = type === 'dictionary'; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
471 |
if (json.length == 1 && /^#/.test(type)) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
472 |
return _data.dictionary[type]; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
473 |
type = Base.exports[type]; |
| 442 | 474 |
res = []; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
475 |
if (_isDictionary) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
476 |
_data.dictionary = res; |
| 442 | 477 |
for (var i = type ? 1 : 0, l = json.length; i < l; i++) |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
478 |
res.push(Base.deserialize(json[i], create, _data, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
479 |
isDictionary)); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
480 |
if (type) {
|
| 442 | 481 |
var args = res; |
482 |
if (create) {
|
|
483 |
res = create(type, args); |
|
484 |
} else {
|
|
485 |
res = Base.create(type.prototype); |
|
486 |
type.apply(res, args); |
|
487 |
} |
|
488 |
} |
|
489 |
} else if (Base.isPlainObject(json)) {
|
|
490 |
res = {};
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
491 |
if (_isDictionary) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
492 |
_data.dictionary = res; |
| 442 | 493 |
for (var key in json) |
494 |
res[key] = Base.deserialize(json[key], create, _data); |
|
495 |
} |
|
496 |
return isRoot && json && json.length && json[0][0] === 'dictionary' |
|
497 |
? res[1] |
|
498 |
: res; |
|
499 |
}, |
|
500 |
||
501 |
exportJSON: function(obj, options) {
|
|
502 |
var json = Base.serialize(obj, options); |
|
503 |
return options && options.asString === false |
|
504 |
? json |
|
505 |
: JSON.stringify(json); |
|
506 |
}, |
|
507 |
||
508 |
importJSON: function(json, target) {
|
|
509 |
return Base.deserialize( |
|
510 |
typeof json === 'string' ? JSON.parse(json) : json, |
|
511 |
function(type, args) {
|
|
512 |
var obj = target && target.constructor === type |
|
513 |
? target |
|
514 |
: Base.create(type.prototype), |
|
515 |
isTarget = obj === target; |
|
516 |
if (args.length === 1 && obj instanceof Item |
|
517 |
&& (isTarget || !(obj instanceof Layer))) {
|
|
518 |
var arg = args[0]; |
|
519 |
if (Base.isPlainObject(arg)) |
|
520 |
arg.insert = false; |
|
521 |
} |
|
522 |
type.apply(obj, args); |
|
523 |
if (isTarget) |
|
524 |
target = null; |
|
525 |
return obj; |
|
526 |
}); |
|
527 |
}, |
|
528 |
||
529 |
splice: function(list, items, index, remove) {
|
|
530 |
var amount = items && items.length, |
|
531 |
append = index === undefined; |
|
532 |
index = append ? list.length : index; |
|
533 |
if (index > list.length) |
|
534 |
index = list.length; |
|
535 |
for (var i = 0; i < amount; i++) |
|
536 |
items[i]._index = index + i; |
|
537 |
if (append) {
|
|
538 |
list.push.apply(list, items); |
|
539 |
return []; |
|
540 |
} else {
|
|
541 |
var args = [index, remove]; |
|
542 |
if (items) |
|
543 |
args.push.apply(args, items); |
|
544 |
var removed = list.splice.apply(list, args); |
|
545 |
for (var i = 0, l = removed.length; i < l; i++) |
|
546 |
removed[i]._index = undefined; |
|
547 |
for (var i = index + amount, l = list.length; i < l; i++) |
|
548 |
list[i]._index = i; |
|
549 |
return removed; |
|
550 |
} |
|
551 |
}, |
|
552 |
||
553 |
capitalize: function(str) {
|
|
554 |
return str.replace(/\b[a-z]/g, function(match) {
|
|
555 |
return match.toUpperCase(); |
|
556 |
}); |
|
557 |
}, |
|
558 |
||
559 |
camelize: function(str) {
|
|
560 |
return str.replace(/-(.)/g, function(all, chr) {
|
|
561 |
return chr.toUpperCase(); |
|
562 |
}); |
|
563 |
}, |
|
564 |
||
565 |
hyphenate: function(str) {
|
|
566 |
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
|
567 |
} |
|
568 |
} |
|
569 |
}); |
|
570 |
||
571 |
var Emitter = {
|
|
572 |
on: function(type, func) {
|
|
573 |
if (typeof type !== 'string') {
|
|
574 |
Base.each(type, function(value, key) {
|
|
575 |
this.on(key, value); |
|
576 |
}, this); |
|
577 |
} else {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
578 |
var types = this._eventTypes, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
579 |
entry = types && types[type], |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
580 |
handlers = this._callbacks = this._callbacks || {};
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
581 |
handlers = handlers[type] = handlers[type] || []; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
582 |
if (handlers.indexOf(func) === -1) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
583 |
handlers.push(func); |
| 598 | 584 |
if (entry && entry.install && handlers.length === 1) |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
585 |
entry.install.call(this, type); |
| 442 | 586 |
} |
587 |
} |
|
588 |
return this; |
|
589 |
}, |
|
590 |
||
591 |
off: function(type, func) {
|
|
592 |
if (typeof type !== 'string') {
|
|
593 |
Base.each(type, function(value, key) {
|
|
594 |
this.off(key, value); |
|
595 |
}, this); |
|
596 |
return; |
|
597 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
598 |
var types = this._eventTypes, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
599 |
entry = types && types[type], |
| 442 | 600 |
handlers = this._callbacks && this._callbacks[type], |
601 |
index; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
602 |
if (handlers) {
|
| 442 | 603 |
if (!func || (index = handlers.indexOf(func)) !== -1 |
604 |
&& handlers.length === 1) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
605 |
if (entry && entry.uninstall) |
| 442 | 606 |
entry.uninstall.call(this, type); |
607 |
delete this._callbacks[type]; |
|
608 |
} else if (index !== -1) {
|
|
609 |
handlers.splice(index, 1); |
|
610 |
} |
|
611 |
} |
|
612 |
return this; |
|
613 |
}, |
|
614 |
||
615 |
once: function(type, func) {
|
|
616 |
return this.on(type, function() {
|
|
617 |
func.apply(this, arguments); |
|
618 |
this.off(type, func); |
|
619 |
}); |
|
620 |
}, |
|
621 |
||
622 |
emit: function(type, event) {
|
|
623 |
var handlers = this._callbacks && this._callbacks[type]; |
|
624 |
if (!handlers) |
|
625 |
return false; |
|
626 |
var args = [].slice.call(arguments, 1); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
627 |
handlers = handlers.slice(); |
| 442 | 628 |
for (var i = 0, l = handlers.length; i < l; i++) {
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
629 |
if (handlers[i].apply(this, args) === false) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
630 |
if (event && event.stop) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
631 |
event.stop(); |
| 442 | 632 |
break; |
633 |
} |
|
634 |
} |
|
635 |
return true; |
|
636 |
}, |
|
637 |
||
638 |
responds: function(type) {
|
|
639 |
return !!(this._callbacks && this._callbacks[type]); |
|
640 |
}, |
|
641 |
||
642 |
attach: '#on', |
|
643 |
detach: '#off', |
|
644 |
fire: '#emit', |
|
645 |
||
646 |
_installEvents: function(install) {
|
|
647 |
var handlers = this._callbacks, |
|
648 |
key = install ? 'install' : 'uninstall'; |
|
649 |
for (var type in handlers) {
|
|
650 |
if (handlers[type].length > 0) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
651 |
var types = this._eventTypes, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
652 |
entry = types && types[type], |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
653 |
func = entry && entry[key]; |
| 442 | 654 |
if (func) |
655 |
func.call(this, type); |
|
656 |
} |
|
657 |
} |
|
658 |
}, |
|
659 |
||
660 |
statics: {
|
|
661 |
inject: function inject(src) {
|
|
662 |
var events = src._events; |
|
663 |
if (events) {
|
|
664 |
var types = {};
|
|
665 |
Base.each(events, function(entry, key) {
|
|
666 |
var isString = typeof entry === 'string', |
|
667 |
name = isString ? entry : key, |
|
668 |
part = Base.capitalize(name), |
|
669 |
type = name.substring(2).toLowerCase(); |
|
670 |
types[type] = isString ? {} : entry;
|
|
671 |
name = '_' + name; |
|
672 |
src['get' + part] = function() {
|
|
673 |
return this[name]; |
|
674 |
}; |
|
675 |
src['set' + part] = function(func) {
|
|
676 |
var prev = this[name]; |
|
677 |
if (prev) |
|
678 |
this.off(type, prev); |
|
679 |
if (func) |
|
680 |
this.on(type, func); |
|
681 |
this[name] = func; |
|
682 |
}; |
|
683 |
}); |
|
684 |
src._eventTypes = types; |
|
685 |
} |
|
686 |
return inject.base.apply(this, arguments); |
|
687 |
} |
|
688 |
} |
|
689 |
}; |
|
690 |
||
691 |
var PaperScope = Base.extend({
|
|
692 |
_class: 'PaperScope', |
|
693 |
||
694 |
initialize: function PaperScope() {
|
|
695 |
paper = this; |
|
696 |
this.settings = new Base({
|
|
697 |
applyMatrix: true, |
|
698 |
handleSize: 4, |
|
699 |
hitTolerance: 0 |
|
700 |
}); |
|
701 |
this.project = null; |
|
702 |
this.projects = []; |
|
703 |
this.tools = []; |
|
704 |
this.palettes = []; |
|
705 |
this._id = PaperScope._id++; |
|
706 |
PaperScope._scopes[this._id] = this; |
|
707 |
var proto = PaperScope.prototype; |
|
708 |
if (!this.support) {
|
|
709 |
var ctx = CanvasProvider.getContext(1, 1); |
|
710 |
proto.support = {
|
|
711 |
nativeDash: 'setLineDash' in ctx || 'mozDash' in ctx, |
|
712 |
nativeBlendModes: BlendMode.nativeModes |
|
713 |
}; |
|
714 |
CanvasProvider.release(ctx); |
|
715 |
} |
|
716 |
||
717 |
if (!this.browser) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
718 |
var agent = navigator.userAgent.toLowerCase(), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
719 |
platform = (/(win)/.exec(agent) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
720 |
|| /(mac)/.exec(agent) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
721 |
|| /(linux)/.exec(agent) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
722 |
|| [])[0], |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
723 |
browser = proto.browser = { platform: platform };
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
724 |
if (platform) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
725 |
browser[platform] = true; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
726 |
agent.replace( |
| 442 | 727 |
/(opera|chrome|safari|webkit|firefox|msie|trident|atom)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:([.\d]+))?/g, |
728 |
function(all, n, v1, v2, rv) {
|
|
729 |
if (!browser.chrome) {
|
|
730 |
var v = n === 'opera' ? v2 : v1; |
|
731 |
if (n === 'trident') {
|
|
732 |
v = rv; |
|
733 |
n = 'msie'; |
|
734 |
} |
|
735 |
browser.version = v; |
|
736 |
browser.versionNumber = parseFloat(v); |
|
737 |
browser.name = n; |
|
738 |
browser[n] = true; |
|
739 |
} |
|
740 |
} |
|
741 |
); |
|
742 |
if (browser.chrome) |
|
743 |
delete browser.webkit; |
|
744 |
if (browser.atom) |
|
745 |
delete browser.chrome; |
|
746 |
} |
|
747 |
}, |
|
748 |
||
| 598 | 749 |
version: "0.9.25", |
| 442 | 750 |
|
751 |
getView: function() {
|
|
752 |
return this.project && this.project.getView(); |
|
753 |
}, |
|
754 |
||
755 |
getPaper: function() {
|
|
756 |
return this; |
|
757 |
}, |
|
758 |
||
759 |
execute: function(code, url, options) {
|
|
760 |
paper.PaperScript.execute(code, this, url, options); |
|
761 |
View.updateFocus(); |
|
762 |
}, |
|
763 |
||
764 |
install: function(scope) {
|
|
765 |
var that = this; |
|
766 |
Base.each(['project', 'view', 'tool'], function(key) {
|
|
767 |
Base.define(scope, key, {
|
|
768 |
configurable: true, |
|
769 |
get: function() {
|
|
770 |
return that[key]; |
|
771 |
} |
|
772 |
}); |
|
773 |
}); |
|
774 |
for (var key in this) |
|
775 |
if (!/^_/.test(key) && this[key]) |
|
776 |
scope[key] = this[key]; |
|
777 |
}, |
|
778 |
||
779 |
setup: function(element) {
|
|
780 |
paper = this; |
|
781 |
this.project = new Project(element); |
|
782 |
return this; |
|
783 |
}, |
|
784 |
||
785 |
activate: function() {
|
|
786 |
paper = this; |
|
787 |
}, |
|
788 |
||
789 |
clear: function() {
|
|
790 |
for (var i = this.projects.length - 1; i >= 0; i--) |
|
791 |
this.projects[i].remove(); |
|
792 |
for (var i = this.tools.length - 1; i >= 0; i--) |
|
793 |
this.tools[i].remove(); |
|
794 |
for (var i = this.palettes.length - 1; i >= 0; i--) |
|
795 |
this.palettes[i].remove(); |
|
796 |
}, |
|
797 |
||
798 |
remove: function() {
|
|
799 |
this.clear(); |
|
800 |
delete PaperScope._scopes[this._id]; |
|
801 |
}, |
|
802 |
||
803 |
statics: new function() {
|
|
804 |
function handleAttribute(name) {
|
|
805 |
name += 'Attribute'; |
|
806 |
return function(el, attr) {
|
|
807 |
return el[name](attr) || el[name]('data-paper-' + attr);
|
|
808 |
}; |
|
809 |
} |
|
810 |
||
811 |
return {
|
|
812 |
_scopes: {},
|
|
813 |
_id: 0, |
|
814 |
||
815 |
get: function(id) {
|
|
816 |
return this._scopes[id] || null; |
|
817 |
}, |
|
818 |
||
819 |
getAttribute: handleAttribute('get'),
|
|
820 |
hasAttribute: handleAttribute('has')
|
|
821 |
}; |
|
822 |
} |
|
823 |
}); |
|
824 |
||
825 |
var PaperScopeItem = Base.extend(Emitter, {
|
|
826 |
||
827 |
initialize: function(activate) {
|
|
828 |
this._scope = paper; |
|
829 |
this._index = this._scope[this._list].push(this) - 1; |
|
830 |
if (activate || !this._scope[this._reference]) |
|
831 |
this.activate(); |
|
832 |
}, |
|
833 |
||
834 |
activate: function() {
|
|
835 |
if (!this._scope) |
|
836 |
return false; |
|
837 |
var prev = this._scope[this._reference]; |
|
838 |
if (prev && prev !== this) |
|
839 |
prev.emit('deactivate');
|
|
840 |
this._scope[this._reference] = this; |
|
841 |
this.emit('activate', prev);
|
|
842 |
return true; |
|
843 |
}, |
|
844 |
||
845 |
isActive: function() {
|
|
846 |
return this._scope[this._reference] === this; |
|
847 |
}, |
|
848 |
||
849 |
remove: function() {
|
|
850 |
if (this._index == null) |
|
851 |
return false; |
|
852 |
Base.splice(this._scope[this._list], null, this._index, 1); |
|
853 |
if (this._scope[this._reference] == this) |
|
854 |
this._scope[this._reference] = null; |
|
855 |
this._scope = null; |
|
856 |
return true; |
|
857 |
} |
|
858 |
}); |
|
859 |
||
860 |
var Formatter = Base.extend({
|
|
861 |
initialize: function(precision) {
|
|
862 |
this.precision = precision || 5; |
|
863 |
this.multiplier = Math.pow(10, this.precision); |
|
864 |
}, |
|
865 |
||
866 |
number: function(val) {
|
|
867 |
return Math.round(val * this.multiplier) / this.multiplier; |
|
868 |
}, |
|
869 |
||
870 |
pair: function(val1, val2, separator) {
|
|
871 |
return this.number(val1) + (separator || ',') + this.number(val2); |
|
872 |
}, |
|
873 |
||
874 |
point: function(val, separator) {
|
|
875 |
return this.number(val.x) + (separator || ',') + this.number(val.y); |
|
876 |
}, |
|
877 |
||
878 |
size: function(val, separator) {
|
|
879 |
return this.number(val.width) + (separator || ',') |
|
880 |
+ this.number(val.height); |
|
881 |
}, |
|
882 |
||
883 |
rectangle: function(val, separator) {
|
|
884 |
return this.point(val, separator) + (separator || ',') |
|
885 |
+ this.size(val, separator); |
|
886 |
} |
|
887 |
}); |
|
888 |
||
889 |
Formatter.instance = new Formatter(); |
|
890 |
||
891 |
var Numerical = new function() {
|
|
892 |
||
893 |
var abscissas = [ |
|
894 |
[ 0.5773502691896257645091488], |
|
895 |
[0,0.7745966692414833770358531], |
|
896 |
[ 0.3399810435848562648026658,0.8611363115940525752239465], |
|
897 |
[0,0.5384693101056830910363144,0.9061798459386639927976269], |
|
898 |
[ 0.2386191860831969086305017,0.6612093864662645136613996,0.9324695142031520278123016], |
|
899 |
[0,0.4058451513773971669066064,0.7415311855993944398638648,0.9491079123427585245261897], |
|
900 |
[ 0.1834346424956498049394761,0.5255324099163289858177390,0.7966664774136267395915539,0.9602898564975362316835609], |
|
901 |
[0,0.3242534234038089290385380,0.6133714327005903973087020,0.8360311073266357942994298,0.9681602395076260898355762], |
|
902 |
[ 0.1488743389816312108848260,0.4333953941292471907992659,0.6794095682990244062343274,0.8650633666889845107320967,0.9739065285171717200779640], |
|
903 |
[0,0.2695431559523449723315320,0.5190961292068118159257257,0.7301520055740493240934163,0.8870625997680952990751578,0.9782286581460569928039380], |
|
904 |
[ 0.1252334085114689154724414,0.3678314989981801937526915,0.5873179542866174472967024,0.7699026741943046870368938,0.9041172563704748566784659,0.9815606342467192506905491], |
|
905 |
[0,0.2304583159551347940655281,0.4484927510364468528779129,0.6423493394403402206439846,0.8015780907333099127942065,0.9175983992229779652065478,0.9841830547185881494728294], |
|
906 |
[ 0.1080549487073436620662447,0.3191123689278897604356718,0.5152486363581540919652907,0.6872929048116854701480198,0.8272013150697649931897947,0.9284348836635735173363911,0.9862838086968123388415973], |
|
907 |
[0,0.2011940939974345223006283,0.3941513470775633698972074,0.5709721726085388475372267,0.7244177313601700474161861,0.8482065834104272162006483,0.9372733924007059043077589,0.9879925180204854284895657], |
|
908 |
[ 0.0950125098376374401853193,0.2816035507792589132304605,0.4580167776572273863424194,0.6178762444026437484466718,0.7554044083550030338951012,0.8656312023878317438804679,0.9445750230732325760779884,0.9894009349916499325961542] |
|
909 |
]; |
|
910 |
||
911 |
var weights = [ |
|
912 |
[1], |
|
913 |
[0.8888888888888888888888889,0.5555555555555555555555556], |
|
914 |
[0.6521451548625461426269361,0.3478548451374538573730639], |
|
915 |
[0.5688888888888888888888889,0.4786286704993664680412915,0.2369268850561890875142640], |
|
916 |
[0.4679139345726910473898703,0.3607615730481386075698335,0.1713244923791703450402961], |
|
917 |
[0.4179591836734693877551020,0.3818300505051189449503698,0.2797053914892766679014678,0.1294849661688696932706114], |
|
918 |
[0.3626837833783619829651504,0.3137066458778872873379622,0.2223810344533744705443560,0.1012285362903762591525314], |
|
919 |
[0.3302393550012597631645251,0.3123470770400028400686304,0.2606106964029354623187429,0.1806481606948574040584720,0.0812743883615744119718922], |
|
920 |
[0.2955242247147528701738930,0.2692667193099963550912269,0.2190863625159820439955349,0.1494513491505805931457763,0.0666713443086881375935688], |
|
921 |
[0.2729250867779006307144835,0.2628045445102466621806889,0.2331937645919904799185237,0.1862902109277342514260976,0.1255803694649046246346943,0.0556685671161736664827537], |
|
922 |
[0.2491470458134027850005624,0.2334925365383548087608499,0.2031674267230659217490645,0.1600783285433462263346525,0.1069393259953184309602547,0.0471753363865118271946160], |
|
923 |
[0.2325515532308739101945895,0.2262831802628972384120902,0.2078160475368885023125232,0.1781459807619457382800467,0.1388735102197872384636018,0.0921214998377284479144218,0.0404840047653158795200216], |
|
924 |
[0.2152638534631577901958764,0.2051984637212956039659241,0.1855383974779378137417166,0.1572031671581935345696019,0.1215185706879031846894148,0.0801580871597602098056333,0.0351194603317518630318329], |
|
925 |
[0.2025782419255612728806202,0.1984314853271115764561183,0.1861610000155622110268006,0.1662692058169939335532009,0.1395706779261543144478048,0.1071592204671719350118695,0.0703660474881081247092674,0.0307532419961172683546284], |
|
926 |
[0.1894506104550684962853967,0.1826034150449235888667637,0.1691565193950025381893121,0.1495959888165767320815017,0.1246289712555338720524763,0.0951585116824927848099251,0.0622535239386478928628438,0.0271524594117540948517806] |
|
927 |
]; |
|
928 |
||
929 |
var abs = Math.abs, |
|
930 |
sqrt = Math.sqrt, |
|
931 |
pow = Math.pow, |
|
932 |
EPSILON = 1e-12, |
|
933 |
MACHINE_EPSILON = 1.12e-16; |
|
934 |
||
| 598 | 935 |
function clip(value, min, max) {
|
936 |
return value < min ? min : value > max ? max : value; |
|
937 |
} |
|
938 |
||
| 442 | 939 |
return {
|
| 598 | 940 |
TOLERANCE: 1e-6, |
| 442 | 941 |
EPSILON: EPSILON, |
942 |
MACHINE_EPSILON: MACHINE_EPSILON, |
|
| 598 | 943 |
CURVETIME_EPSILON: 4e-7, |
944 |
GEOMETRIC_EPSILON: 2e-7, |
|
945 |
WINDING_EPSILON: 2e-7, |
|
946 |
TRIGONOMETRIC_EPSILON: 1e-7, |
|
947 |
CLIPPING_EPSILON: 1e-7, |
|
| 442 | 948 |
KAPPA: 4 * (sqrt(2) - 1) / 3, |
949 |
||
950 |
isZero: function(val) {
|
|
| 598 | 951 |
return val >= -EPSILON && val <= EPSILON; |
| 442 | 952 |
}, |
953 |
||
954 |
integrate: function(f, a, b, n) {
|
|
955 |
var x = abscissas[n - 2], |
|
956 |
w = weights[n - 2], |
|
957 |
A = (b - a) * 0.5, |
|
958 |
B = A + a, |
|
959 |
i = 0, |
|
960 |
m = (n + 1) >> 1, |
|
961 |
sum = n & 1 ? w[i++] * f(B) : 0; |
|
962 |
while (i < m) {
|
|
963 |
var Ax = A * x[i]; |
|
964 |
sum += w[i++] * (f(B + Ax) + f(B - Ax)); |
|
965 |
} |
|
966 |
return A * sum; |
|
967 |
}, |
|
968 |
||
969 |
findRoot: function(f, df, x, a, b, n, tolerance) {
|
|
970 |
for (var i = 0; i < n; i++) {
|
|
971 |
var fx = f(x), |
|
972 |
dx = fx / df(x), |
|
973 |
nx = x - dx; |
|
974 |
if (abs(dx) < tolerance) |
|
975 |
return nx; |
|
976 |
if (fx > 0) {
|
|
977 |
b = x; |
|
978 |
x = nx <= a ? (a + b) * 0.5 : nx; |
|
979 |
} else {
|
|
980 |
a = x; |
|
981 |
x = nx >= b ? (a + b) * 0.5 : nx; |
|
982 |
} |
|
983 |
} |
|
984 |
return x; |
|
985 |
}, |
|
986 |
||
987 |
solveQuadratic: function(a, b, c, roots, min, max) {
|
|
988 |
var count = 0, |
|
| 598 | 989 |
eMin = min - EPSILON, |
990 |
eMax = max + EPSILON, |
|
| 442 | 991 |
x1, x2 = Infinity, |
992 |
B = b, |
|
993 |
D; |
|
| 598 | 994 |
b /= -2; |
| 442 | 995 |
D = b * b - a * c; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
996 |
if (D !== 0 && abs(D) < MACHINE_EPSILON) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
997 |
var gmC = pow(abs(a * b * c), 1 / 3); |
| 442 | 998 |
if (gmC < 1e-8) {
|
| 598 | 999 |
var mult = pow(10, |
1000 |
abs(Math.floor(Math.log(gmC) * Math.LOG10E))); |
|
| 442 | 1001 |
if (!isFinite(mult)) |
1002 |
mult = 0; |
|
1003 |
a *= mult; |
|
1004 |
b *= mult; |
|
1005 |
c *= mult; |
|
1006 |
D = b * b - a * c; |
|
1007 |
} |
|
1008 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1009 |
if (abs(a) < EPSILON) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1010 |
if (abs(B) < EPSILON) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1011 |
return abs(c) < EPSILON ? -1 : 0; |
| 442 | 1012 |
x1 = -c / B; |
| 598 | 1013 |
} else if (D >= -MACHINE_EPSILON) {
|
1014 |
var Q = D < 0 ? 0 : sqrt(D), |
|
1015 |
R = b + (b < 0 ? -Q : Q); |
|
1016 |
if (R === 0) {
|
|
1017 |
x1 = c / a; |
|
1018 |
x2 = -x1; |
|
1019 |
} else {
|
|
1020 |
x1 = R / a; |
|
1021 |
x2 = c / R; |
|
1022 |
} |
|
1023 |
} |
|
1024 |
if (isFinite(x1) && (min == null || x1 > eMin && x1 < eMax)) |
|
1025 |
roots[count++] = min == null ? x1 : clip(x1, min, max); |
|
| 442 | 1026 |
if (x2 !== x1 |
| 598 | 1027 |
&& isFinite(x2) && (min == null || x2 > eMin && x2 < eMax)) |
1028 |
roots[count++] = min == null ? x2 : clip(x2, min, max); |
|
| 442 | 1029 |
return count; |
1030 |
}, |
|
1031 |
||
1032 |
solveCubic: function(a, b, c, d, roots, min, max) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1033 |
var count = 0, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1034 |
x, b1, c2; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1035 |
if (abs(a) < EPSILON) {
|
| 442 | 1036 |
a = b; |
1037 |
b1 = c; |
|
1038 |
c2 = d; |
|
1039 |
x = Infinity; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1040 |
} else if (abs(d) < EPSILON) {
|
| 442 | 1041 |
b1 = b; |
1042 |
c2 = c; |
|
1043 |
x = 0; |
|
1044 |
} else {
|
|
1045 |
var ec = 1 + MACHINE_EPSILON, |
|
1046 |
x0, q, qd, t, r, s, tmp; |
|
1047 |
x = -(b / a) / 3; |
|
1048 |
tmp = a * x, |
|
1049 |
b1 = tmp + b, |
|
1050 |
c2 = b1 * x + c, |
|
1051 |
qd = (tmp + b1) * x + c2, |
|
1052 |
q = c2 * x + d; |
|
1053 |
t = q /a; |
|
1054 |
r = pow(abs(t), 1/3); |
|
1055 |
s = t < 0 ? -1 : 1; |
|
1056 |
t = -qd / a; |
|
1057 |
r = t > 0 ? 1.3247179572 * Math.max(r, sqrt(t)) : r; |
|
1058 |
x0 = x - s * r; |
|
1059 |
if (x0 !== x) {
|
|
1060 |
do {
|
|
1061 |
x = x0; |
|
1062 |
tmp = a * x, |
|
1063 |
b1 = tmp + b, |
|
1064 |
c2 = b1 * x + c, |
|
1065 |
qd = (tmp + b1) * x + c2, |
|
1066 |
q = c2 * x + d; |
|
1067 |
x0 = qd === 0 ? x : x - q / qd / ec; |
|
1068 |
if (x0 === x) {
|
|
1069 |
x = x0; |
|
1070 |
break; |
|
1071 |
} |
|
1072 |
} while (s * x0 > s * x); |
|
1073 |
if (abs(a) * x * x > abs(d / x)) {
|
|
1074 |
c2 = -d / x; |
|
1075 |
b1 = (c2 - c) / x; |
|
1076 |
} |
|
1077 |
} |
|
1078 |
} |
|
1079 |
var count = Numerical.solveQuadratic(a, b1, c2, roots, min, max); |
|
1080 |
if (isFinite(x) && (count === 0 || x !== roots[count - 1]) |
|
| 598 | 1081 |
&& (min == null || x > min - EPSILON && x < max + EPSILON)) |
1082 |
roots[count++] = min == null ? x : clip(x, min, max); |
|
| 442 | 1083 |
return count; |
1084 |
} |
|
1085 |
}; |
|
1086 |
}; |
|
1087 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1088 |
var UID = {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1089 |
_id: 1, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1090 |
_pools: {},
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1091 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1092 |
get: function(ctor) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1093 |
if (ctor) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1094 |
var name = ctor._class, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1095 |
pool = this._pools[name]; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1096 |
if (!pool) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1097 |
pool = this._pools[name] = { _id: 1 };
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1098 |
return pool._id++; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1099 |
} else {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1100 |
return this._id++; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1101 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1102 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1103 |
}; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1104 |
|
| 442 | 1105 |
var Point = Base.extend({
|
1106 |
_class: 'Point', |
|
1107 |
_readIndex: true, |
|
1108 |
||
1109 |
initialize: function Point(arg0, arg1) {
|
|
1110 |
var type = typeof arg0; |
|
1111 |
if (type === 'number') {
|
|
1112 |
var hasY = typeof arg1 === 'number'; |
|
1113 |
this.x = arg0; |
|
1114 |
this.y = hasY ? arg1 : arg0; |
|
1115 |
if (this.__read) |
|
1116 |
this.__read = hasY ? 2 : 1; |
|
1117 |
} else if (type === 'undefined' || arg0 === null) {
|
|
1118 |
this.x = this.y = 0; |
|
1119 |
if (this.__read) |
|
1120 |
this.__read = arg0 === null ? 1 : 0; |
|
1121 |
} else {
|
|
1122 |
if (Array.isArray(arg0)) {
|
|
1123 |
this.x = arg0[0]; |
|
1124 |
this.y = arg0.length > 1 ? arg0[1] : arg0[0]; |
|
1125 |
} else if (arg0.x != null) {
|
|
1126 |
this.x = arg0.x; |
|
1127 |
this.y = arg0.y; |
|
1128 |
} else if (arg0.width != null) {
|
|
1129 |
this.x = arg0.width; |
|
1130 |
this.y = arg0.height; |
|
1131 |
} else if (arg0.angle != null) {
|
|
1132 |
this.x = arg0.length; |
|
1133 |
this.y = 0; |
|
1134 |
this.setAngle(arg0.angle); |
|
1135 |
} else {
|
|
1136 |
this.x = this.y = 0; |
|
1137 |
if (this.__read) |
|
1138 |
this.__read = 0; |
|
1139 |
} |
|
1140 |
if (this.__read) |
|
1141 |
this.__read = 1; |
|
1142 |
} |
|
1143 |
}, |
|
1144 |
||
1145 |
set: function(x, y) {
|
|
1146 |
this.x = x; |
|
1147 |
this.y = y; |
|
1148 |
return this; |
|
1149 |
}, |
|
1150 |
||
1151 |
equals: function(point) {
|
|
1152 |
return this === point || point |
|
1153 |
&& (this.x === point.x && this.y === point.y |
|
1154 |
|| Array.isArray(point) |
|
1155 |
&& this.x === point[0] && this.y === point[1]) |
|
1156 |
|| false; |
|
1157 |
}, |
|
1158 |
||
1159 |
clone: function() {
|
|
1160 |
return new Point(this.x, this.y); |
|
1161 |
}, |
|
1162 |
||
1163 |
toString: function() {
|
|
1164 |
var f = Formatter.instance; |
|
1165 |
return '{ x: ' + f.number(this.x) + ', y: ' + f.number(this.y) + ' }';
|
|
1166 |
}, |
|
1167 |
||
1168 |
_serialize: function(options) {
|
|
1169 |
var f = options.formatter; |
|
1170 |
return [f.number(this.x), f.number(this.y)]; |
|
1171 |
}, |
|
1172 |
||
1173 |
getLength: function() {
|
|
1174 |
return Math.sqrt(this.x * this.x + this.y * this.y); |
|
1175 |
}, |
|
1176 |
||
1177 |
setLength: function(length) {
|
|
1178 |
if (this.isZero()) {
|
|
1179 |
var angle = this._angle || 0; |
|
1180 |
this.set( |
|
1181 |
Math.cos(angle) * length, |
|
1182 |
Math.sin(angle) * length |
|
1183 |
); |
|
1184 |
} else {
|
|
1185 |
var scale = length / this.getLength(); |
|
1186 |
if (Numerical.isZero(scale)) |
|
1187 |
this.getAngle(); |
|
1188 |
this.set( |
|
1189 |
this.x * scale, |
|
1190 |
this.y * scale |
|
1191 |
); |
|
1192 |
} |
|
1193 |
}, |
|
1194 |
getAngle: function() {
|
|
1195 |
return this.getAngleInRadians.apply(this, arguments) * 180 / Math.PI; |
|
1196 |
}, |
|
1197 |
||
1198 |
setAngle: function(angle) {
|
|
1199 |
this.setAngleInRadians.call(this, angle * Math.PI / 180); |
|
1200 |
}, |
|
1201 |
||
1202 |
getAngleInDegrees: '#getAngle', |
|
1203 |
setAngleInDegrees: '#setAngle', |
|
1204 |
||
1205 |
getAngleInRadians: function() {
|
|
1206 |
if (!arguments.length) {
|
|
1207 |
return this.isZero() |
|
1208 |
? this._angle || 0 |
|
1209 |
: this._angle = Math.atan2(this.y, this.x); |
|
1210 |
} else {
|
|
1211 |
var point = Point.read(arguments), |
|
1212 |
div = this.getLength() * point.getLength(); |
|
1213 |
if (Numerical.isZero(div)) {
|
|
1214 |
return NaN; |
|
1215 |
} else {
|
|
1216 |
var a = this.dot(point) / div; |
|
1217 |
return Math.acos(a < -1 ? -1 : a > 1 ? 1 : a); |
|
1218 |
} |
|
1219 |
} |
|
1220 |
}, |
|
1221 |
||
1222 |
setAngleInRadians: function(angle) {
|
|
1223 |
this._angle = angle; |
|
1224 |
if (!this.isZero()) {
|
|
1225 |
var length = this.getLength(); |
|
1226 |
this.set( |
|
1227 |
Math.cos(angle) * length, |
|
1228 |
Math.sin(angle) * length |
|
1229 |
); |
|
1230 |
} |
|
1231 |
}, |
|
1232 |
||
1233 |
getQuadrant: function() {
|
|
1234 |
return this.x >= 0 ? this.y >= 0 ? 1 : 4 : this.y >= 0 ? 2 : 3; |
|
1235 |
} |
|
1236 |
}, {
|
|
1237 |
beans: false, |
|
1238 |
||
1239 |
getDirectedAngle: function() {
|
|
1240 |
var point = Point.read(arguments); |
|
1241 |
return Math.atan2(this.cross(point), this.dot(point)) * 180 / Math.PI; |
|
1242 |
}, |
|
1243 |
||
1244 |
getDistance: function() {
|
|
1245 |
var point = Point.read(arguments), |
|
1246 |
x = point.x - this.x, |
|
1247 |
y = point.y - this.y, |
|
1248 |
d = x * x + y * y, |
|
1249 |
squared = Base.read(arguments); |
|
1250 |
return squared ? d : Math.sqrt(d); |
|
1251 |
}, |
|
1252 |
||
1253 |
normalize: function(length) {
|
|
1254 |
if (length === undefined) |
|
1255 |
length = 1; |
|
1256 |
var current = this.getLength(), |
|
1257 |
scale = current !== 0 ? length / current : 0, |
|
1258 |
point = new Point(this.x * scale, this.y * scale); |
|
1259 |
if (scale >= 0) |
|
1260 |
point._angle = this._angle; |
|
1261 |
return point; |
|
1262 |
}, |
|
1263 |
||
1264 |
rotate: function(angle, center) {
|
|
1265 |
if (angle === 0) |
|
1266 |
return this.clone(); |
|
1267 |
angle = angle * Math.PI / 180; |
|
1268 |
var point = center ? this.subtract(center) : this, |
|
| 598 | 1269 |
sin = Math.sin(angle), |
1270 |
cos = Math.cos(angle); |
|
| 442 | 1271 |
point = new Point( |
| 598 | 1272 |
point.x * cos - point.y * sin, |
1273 |
point.x * sin + point.y * cos |
|
| 442 | 1274 |
); |
1275 |
return center ? point.add(center) : point; |
|
1276 |
}, |
|
1277 |
||
1278 |
transform: function(matrix) {
|
|
1279 |
return matrix ? matrix._transformPoint(this) : this; |
|
1280 |
}, |
|
1281 |
||
1282 |
add: function() {
|
|
1283 |
var point = Point.read(arguments); |
|
1284 |
return new Point(this.x + point.x, this.y + point.y); |
|
1285 |
}, |
|
1286 |
||
1287 |
subtract: function() {
|
|
1288 |
var point = Point.read(arguments); |
|
1289 |
return new Point(this.x - point.x, this.y - point.y); |
|
1290 |
}, |
|
1291 |
||
1292 |
multiply: function() {
|
|
1293 |
var point = Point.read(arguments); |
|
1294 |
return new Point(this.x * point.x, this.y * point.y); |
|
1295 |
}, |
|
1296 |
||
1297 |
divide: function() {
|
|
1298 |
var point = Point.read(arguments); |
|
1299 |
return new Point(this.x / point.x, this.y / point.y); |
|
1300 |
}, |
|
1301 |
||
1302 |
modulo: function() {
|
|
1303 |
var point = Point.read(arguments); |
|
1304 |
return new Point(this.x % point.x, this.y % point.y); |
|
1305 |
}, |
|
1306 |
||
1307 |
negate: function() {
|
|
1308 |
return new Point(-this.x, -this.y); |
|
1309 |
}, |
|
1310 |
||
1311 |
isInside: function() {
|
|
1312 |
return Rectangle.read(arguments).contains(this); |
|
1313 |
}, |
|
1314 |
||
| 598 | 1315 |
isClose: function() {
|
1316 |
var point = Point.read(arguments), |
|
1317 |
tolerance = Base.read(arguments); |
|
| 442 | 1318 |
return this.getDistance(point) < tolerance; |
1319 |
}, |
|
1320 |
||
| 598 | 1321 |
isCollinear: function() {
|
1322 |
var point = Point.read(arguments); |
|
1323 |
return Point.isCollinear(this.x, this.y, point.x, point.y); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1324 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1325 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
1326 |
isColinear: '#isCollinear', |
| 442 | 1327 |
|
| 598 | 1328 |
isOrthogonal: function() {
|
1329 |
var point = Point.read(arguments); |
|
1330 |
return Point.isOrthogonal(this.x, this.y, point.x, point.y); |
|
| 442 | 1331 |
}, |
1332 |
||
1333 |
isZero: function() {
|
|
1334 |
return Numerical.isZero(this.x) && Numerical.isZero(this.y); |
|
1335 |
}, |
|
1336 |
||
1337 |
isNaN: function() {
|
|
1338 |
return isNaN(this.x) || isNaN(this.y); |
|
1339 |
}, |
|
1340 |
||
1341 |
dot: function() {
|
|
1342 |
var point = Point.read(arguments); |
|
1343 |
return this.x * point.x + this.y * point.y; |
|
1344 |
}, |
|
1345 |
||
1346 |
cross: function() {
|
|
1347 |
var point = Point.read(arguments); |
|
1348 |
return this.x * point.y - this.y * point.x; |
|
1349 |
}, |
|
1350 |
||
1351 |
project: function() {
|
|
| 598 | 1352 |
var point = Point.read(arguments), |
1353 |
scale = point.isZero() ? 0 : this.dot(point) / point.dot(point); |
|
1354 |
return new Point( |
|
1355 |
point.x * scale, |
|
1356 |
point.y * scale |
|
1357 |
); |
|
| 442 | 1358 |
}, |
1359 |
||
1360 |
statics: {
|
|
1361 |
min: function() {
|
|
1362 |
var point1 = Point.read(arguments), |
|
1363 |
point2 = Point.read(arguments); |
|
1364 |
return new Point( |
|
1365 |
Math.min(point1.x, point2.x), |
|
1366 |
Math.min(point1.y, point2.y) |
|
1367 |
); |
|
1368 |
}, |
|
1369 |
||
1370 |
max: function() {
|
|
1371 |
var point1 = Point.read(arguments), |
|
1372 |
point2 = Point.read(arguments); |
|
1373 |
return new Point( |
|
1374 |
Math.max(point1.x, point2.x), |
|
1375 |
Math.max(point1.y, point2.y) |
|
1376 |
); |
|
1377 |
}, |
|
1378 |
||
1379 |
random: function() {
|
|
1380 |
return new Point(Math.random(), Math.random()); |
|
| 598 | 1381 |
}, |
1382 |
||
1383 |
isCollinear: function(x1, y1, x2, y2) {
|
|
1384 |
return Math.abs(x1 * y2 - y1 * x2) |
|
1385 |
<= Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)) |
|
1386 |
* 1e-7; |
|
1387 |
}, |
|
1388 |
||
1389 |
isOrthogonal: function(x1, y1, x2, y2) {
|
|
1390 |
return Math.abs(x1 * x2 + y1 * y2) |
|
1391 |
<= Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)) |
|
1392 |
* 1e-7; |
|
| 442 | 1393 |
} |
1394 |
} |
|
1395 |
}, Base.each(['round', 'ceil', 'floor', 'abs'], function(name) {
|
|
1396 |
var op = Math[name]; |
|
1397 |
this[name] = function() {
|
|
1398 |
return new Point(op(this.x), op(this.y)); |
|
1399 |
}; |
|
1400 |
}, {}));
|
|
1401 |
||
1402 |
var LinkedPoint = Point.extend({
|
|
1403 |
initialize: function Point(x, y, owner, setter) {
|
|
1404 |
this._x = x; |
|
1405 |
this._y = y; |
|
1406 |
this._owner = owner; |
|
1407 |
this._setter = setter; |
|
1408 |
}, |
|
1409 |
||
1410 |
set: function(x, y, _dontNotify) {
|
|
1411 |
this._x = x; |
|
1412 |
this._y = y; |
|
1413 |
if (!_dontNotify) |
|
1414 |
this._owner[this._setter](this); |
|
1415 |
return this; |
|
1416 |
}, |
|
1417 |
||
1418 |
getX: function() {
|
|
1419 |
return this._x; |
|
1420 |
}, |
|
1421 |
||
1422 |
setX: function(x) {
|
|
1423 |
this._x = x; |
|
1424 |
this._owner[this._setter](this); |
|
1425 |
}, |
|
1426 |
||
1427 |
getY: function() {
|
|
1428 |
return this._y; |
|
1429 |
}, |
|
1430 |
||
1431 |
setY: function(y) {
|
|
1432 |
this._y = y; |
|
1433 |
this._owner[this._setter](this); |
|
1434 |
} |
|
1435 |
}); |
|
1436 |
||
1437 |
var Size = Base.extend({
|
|
1438 |
_class: 'Size', |
|
1439 |
_readIndex: true, |
|
1440 |
||
1441 |
initialize: function Size(arg0, arg1) {
|
|
1442 |
var type = typeof arg0; |
|
1443 |
if (type === 'number') {
|
|
1444 |
var hasHeight = typeof arg1 === 'number'; |
|
1445 |
this.width = arg0; |
|
1446 |
this.height = hasHeight ? arg1 : arg0; |
|
1447 |
if (this.__read) |
|
1448 |
this.__read = hasHeight ? 2 : 1; |
|
1449 |
} else if (type === 'undefined' || arg0 === null) {
|
|
1450 |
this.width = this.height = 0; |
|
1451 |
if (this.__read) |
|
1452 |
this.__read = arg0 === null ? 1 : 0; |
|
1453 |
} else {
|
|
1454 |
if (Array.isArray(arg0)) {
|
|
1455 |
this.width = arg0[0]; |
|
1456 |
this.height = arg0.length > 1 ? arg0[1] : arg0[0]; |
|
1457 |
} else if (arg0.width != null) {
|
|
1458 |
this.width = arg0.width; |
|
1459 |
this.height = arg0.height; |
|
1460 |
} else if (arg0.x != null) {
|
|
1461 |
this.width = arg0.x; |
|
1462 |
this.height = arg0.y; |
|
1463 |
} else {
|
|
1464 |
this.width = this.height = 0; |
|
1465 |
if (this.__read) |
|
1466 |
this.__read = 0; |
|
1467 |
} |
|
1468 |
if (this.__read) |
|
1469 |
this.__read = 1; |
|
1470 |
} |
|
1471 |
}, |
|
1472 |
||
1473 |
set: function(width, height) {
|
|
1474 |
this.width = width; |
|
1475 |
this.height = height; |
|
1476 |
return this; |
|
1477 |
}, |
|
1478 |
||
1479 |
equals: function(size) {
|
|
1480 |
return size === this || size && (this.width === size.width |
|
1481 |
&& this.height === size.height |
|
1482 |
|| Array.isArray(size) && this.width === size[0] |
|
1483 |
&& this.height === size[1]) || false; |
|
1484 |
}, |
|
1485 |
||
1486 |
clone: function() {
|
|
1487 |
return new Size(this.width, this.height); |
|
1488 |
}, |
|
1489 |
||
1490 |
toString: function() {
|
|
1491 |
var f = Formatter.instance; |
|
1492 |
return '{ width: ' + f.number(this.width)
|
|
1493 |
+ ', height: ' + f.number(this.height) + ' }'; |
|
1494 |
}, |
|
1495 |
||
1496 |
_serialize: function(options) {
|
|
1497 |
var f = options.formatter; |
|
1498 |
return [f.number(this.width), |
|
1499 |
f.number(this.height)]; |
|
1500 |
}, |
|
1501 |
||
1502 |
add: function() {
|
|
1503 |
var size = Size.read(arguments); |
|
1504 |
return new Size(this.width + size.width, this.height + size.height); |
|
1505 |
}, |
|
1506 |
||
1507 |
subtract: function() {
|
|
1508 |
var size = Size.read(arguments); |
|
1509 |
return new Size(this.width - size.width, this.height - size.height); |
|
1510 |
}, |
|
1511 |
||
1512 |
multiply: function() {
|
|
1513 |
var size = Size.read(arguments); |
|
1514 |
return new Size(this.width * size.width, this.height * size.height); |
|
1515 |
}, |
|
1516 |
||
1517 |
divide: function() {
|
|
1518 |
var size = Size.read(arguments); |
|
1519 |
return new Size(this.width / size.width, this.height / size.height); |
|
1520 |
}, |
|
1521 |
||
1522 |
modulo: function() {
|
|
1523 |
var size = Size.read(arguments); |
|
1524 |
return new Size(this.width % size.width, this.height % size.height); |
|
1525 |
}, |
|
1526 |
||
1527 |
negate: function() {
|
|
1528 |
return new Size(-this.width, -this.height); |
|
1529 |
}, |
|
1530 |
||
1531 |
isZero: function() {
|
|
1532 |
return Numerical.isZero(this.width) && Numerical.isZero(this.height); |
|
1533 |
}, |
|
1534 |
||
1535 |
isNaN: function() {
|
|
1536 |
return isNaN(this.width) || isNaN(this.height); |
|
1537 |
}, |
|
1538 |
||
1539 |
statics: {
|
|
1540 |
min: function(size1, size2) {
|
|
1541 |
return new Size( |
|
1542 |
Math.min(size1.width, size2.width), |
|
1543 |
Math.min(size1.height, size2.height)); |
|
1544 |
}, |
|
1545 |
||
1546 |
max: function(size1, size2) {
|
|
1547 |
return new Size( |
|
1548 |
Math.max(size1.width, size2.width), |
|
1549 |
Math.max(size1.height, size2.height)); |
|
1550 |
}, |
|
1551 |
||
1552 |
random: function() {
|
|
1553 |
return new Size(Math.random(), Math.random()); |
|
1554 |
} |
|
1555 |
} |
|
1556 |
}, Base.each(['round', 'ceil', 'floor', 'abs'], function(name) {
|
|
1557 |
var op = Math[name]; |
|
1558 |
this[name] = function() {
|
|
1559 |
return new Size(op(this.width), op(this.height)); |
|
1560 |
}; |
|
1561 |
}, {}));
|
|
1562 |
||
1563 |
var LinkedSize = Size.extend({
|
|
1564 |
initialize: function Size(width, height, owner, setter) {
|
|
1565 |
this._width = width; |
|
1566 |
this._height = height; |
|
1567 |
this._owner = owner; |
|
1568 |
this._setter = setter; |
|
1569 |
}, |
|
1570 |
||
1571 |
set: function(width, height, _dontNotify) {
|
|
1572 |
this._width = width; |
|
1573 |
this._height = height; |
|
1574 |
if (!_dontNotify) |
|
1575 |
this._owner[this._setter](this); |
|
1576 |
return this; |
|
1577 |
}, |
|
1578 |
||
1579 |
getWidth: function() {
|
|
1580 |
return this._width; |
|
1581 |
}, |
|
1582 |
||
1583 |
setWidth: function(width) {
|
|
1584 |
this._width = width; |
|
1585 |
this._owner[this._setter](this); |
|
1586 |
}, |
|
1587 |
||
1588 |
getHeight: function() {
|
|
1589 |
return this._height; |
|
1590 |
}, |
|
1591 |
||
1592 |
setHeight: function(height) {
|
|
1593 |
this._height = height; |
|
1594 |
this._owner[this._setter](this); |
|
1595 |
} |
|
1596 |
}); |
|
1597 |
||
1598 |
var Rectangle = Base.extend({
|
|
1599 |
_class: 'Rectangle', |
|
1600 |
_readIndex: true, |
|
1601 |
beans: true, |
|
1602 |
||
1603 |
initialize: function Rectangle(arg0, arg1, arg2, arg3) {
|
|
1604 |
var type = typeof arg0, |
|
1605 |
read = 0; |
|
1606 |
if (type === 'number') {
|
|
1607 |
this.x = arg0; |
|
1608 |
this.y = arg1; |
|
1609 |
this.width = arg2; |
|
1610 |
this.height = arg3; |
|
1611 |
read = 4; |
|
1612 |
} else if (type === 'undefined' || arg0 === null) {
|
|
1613 |
this.x = this.y = this.width = this.height = 0; |
|
1614 |
read = arg0 === null ? 1 : 0; |
|
1615 |
} else if (arguments.length === 1) {
|
|
1616 |
if (Array.isArray(arg0)) {
|
|
1617 |
this.x = arg0[0]; |
|
1618 |
this.y = arg0[1]; |
|
1619 |
this.width = arg0[2]; |
|
1620 |
this.height = arg0[3]; |
|
1621 |
read = 1; |
|
1622 |
} else if (arg0.x !== undefined || arg0.width !== undefined) {
|
|
1623 |
this.x = arg0.x || 0; |
|
1624 |
this.y = arg0.y || 0; |
|
1625 |
this.width = arg0.width || 0; |
|
1626 |
this.height = arg0.height || 0; |
|
1627 |
read = 1; |
|
1628 |
} else if (arg0.from === undefined && arg0.to === undefined) {
|
|
1629 |
this.x = this.y = this.width = this.height = 0; |
|
1630 |
this._set(arg0); |
|
1631 |
read = 1; |
|
1632 |
} |
|
1633 |
} |
|
1634 |
if (!read) {
|
|
1635 |
var point = Point.readNamed(arguments, 'from'), |
|
1636 |
next = Base.peek(arguments); |
|
1637 |
this.x = point.x; |
|
1638 |
this.y = point.y; |
|
1639 |
if (next && next.x !== undefined || Base.hasNamed(arguments, 'to')) {
|
|
1640 |
var to = Point.readNamed(arguments, 'to'); |
|
1641 |
this.width = to.x - point.x; |
|
1642 |
this.height = to.y - point.y; |
|
1643 |
if (this.width < 0) {
|
|
1644 |
this.x = to.x; |
|
1645 |
this.width = -this.width; |
|
1646 |
} |
|
1647 |
if (this.height < 0) {
|
|
1648 |
this.y = to.y; |
|
1649 |
this.height = -this.height; |
|
1650 |
} |
|
1651 |
} else {
|
|
1652 |
var size = Size.read(arguments); |
|
1653 |
this.width = size.width; |
|
1654 |
this.height = size.height; |
|
1655 |
} |
|
1656 |
read = arguments.__index; |
|
1657 |
} |
|
1658 |
if (this.__read) |
|
1659 |
this.__read = read; |
|
1660 |
}, |
|
1661 |
||
1662 |
set: function(x, y, width, height) {
|
|
1663 |
this.x = x; |
|
1664 |
this.y = y; |
|
1665 |
this.width = width; |
|
1666 |
this.height = height; |
|
1667 |
return this; |
|
1668 |
}, |
|
1669 |
||
1670 |
clone: function() {
|
|
1671 |
return new Rectangle(this.x, this.y, this.width, this.height); |
|
1672 |
}, |
|
1673 |
||
1674 |
equals: function(rect) {
|
|
1675 |
var rt = Base.isPlainValue(rect) |
|
1676 |
? Rectangle.read(arguments) |
|
1677 |
: rect; |
|
1678 |
return rt === this |
|
1679 |
|| rt && this.x === rt.x && this.y === rt.y |
|
1680 |
&& this.width === rt.width && this.height === rt.height |
|
1681 |
|| false; |
|
1682 |
}, |
|
1683 |
||
1684 |
toString: function() {
|
|
1685 |
var f = Formatter.instance; |
|
1686 |
return '{ x: ' + f.number(this.x)
|
|
1687 |
+ ', y: ' + f.number(this.y) |
|
1688 |
+ ', width: ' + f.number(this.width) |
|
1689 |
+ ', height: ' + f.number(this.height) |
|
1690 |
+ ' }'; |
|
1691 |
}, |
|
1692 |
||
1693 |
_serialize: function(options) {
|
|
1694 |
var f = options.formatter; |
|
1695 |
return [f.number(this.x), |
|
1696 |
f.number(this.y), |
|
1697 |
f.number(this.width), |
|
1698 |
f.number(this.height)]; |
|
1699 |
}, |
|
1700 |
||
1701 |
getPoint: function(_dontLink) {
|
|
1702 |
var ctor = _dontLink ? Point : LinkedPoint; |
|
1703 |
return new ctor(this.x, this.y, this, 'setPoint'); |
|
1704 |
}, |
|
1705 |
||
1706 |
setPoint: function() {
|
|
1707 |
var point = Point.read(arguments); |
|
1708 |
this.x = point.x; |
|
1709 |
this.y = point.y; |
|
1710 |
}, |
|
1711 |
||
1712 |
getSize: function(_dontLink) {
|
|
1713 |
var ctor = _dontLink ? Size : LinkedSize; |
|
1714 |
return new ctor(this.width, this.height, this, 'setSize'); |
|
1715 |
}, |
|
1716 |
||
1717 |
setSize: function() {
|
|
1718 |
var size = Size.read(arguments); |
|
1719 |
if (this._fixX) |
|
1720 |
this.x += (this.width - size.width) * this._fixX; |
|
1721 |
if (this._fixY) |
|
1722 |
this.y += (this.height - size.height) * this._fixY; |
|
1723 |
this.width = size.width; |
|
1724 |
this.height = size.height; |
|
1725 |
this._fixW = 1; |
|
1726 |
this._fixH = 1; |
|
1727 |
}, |
|
1728 |
||
1729 |
getLeft: function() {
|
|
1730 |
return this.x; |
|
1731 |
}, |
|
1732 |
||
1733 |
setLeft: function(left) {
|
|
1734 |
if (!this._fixW) |
|
1735 |
this.width -= left - this.x; |
|
1736 |
this.x = left; |
|
1737 |
this._fixX = 0; |
|
1738 |
}, |
|
1739 |
||
1740 |
getTop: function() {
|
|
1741 |
return this.y; |
|
1742 |
}, |
|
1743 |
||
1744 |
setTop: function(top) {
|
|
1745 |
if (!this._fixH) |
|
1746 |
this.height -= top - this.y; |
|
1747 |
this.y = top; |
|
1748 |
this._fixY = 0; |
|
1749 |
}, |
|
1750 |
||
1751 |
getRight: function() {
|
|
1752 |
return this.x + this.width; |
|
1753 |
}, |
|
1754 |
||
1755 |
setRight: function(right) {
|
|
1756 |
if (this._fixX !== undefined && this._fixX !== 1) |
|
1757 |
this._fixW = 0; |
|
1758 |
if (this._fixW) |
|
1759 |
this.x = right - this.width; |
|
1760 |
else |
|
1761 |
this.width = right - this.x; |
|
1762 |
this._fixX = 1; |
|
1763 |
}, |
|
1764 |
||
1765 |
getBottom: function() {
|
|
1766 |
return this.y + this.height; |
|
1767 |
}, |
|
1768 |
||
1769 |
setBottom: function(bottom) {
|
|
1770 |
if (this._fixY !== undefined && this._fixY !== 1) |
|
1771 |
this._fixH = 0; |
|
1772 |
if (this._fixH) |
|
1773 |
this.y = bottom - this.height; |
|
1774 |
else |
|
1775 |
this.height = bottom - this.y; |
|
1776 |
this._fixY = 1; |
|
1777 |
}, |
|
1778 |
||
1779 |
getCenterX: function() {
|
|
1780 |
return this.x + this.width * 0.5; |
|
1781 |
}, |
|
1782 |
||
1783 |
setCenterX: function(x) {
|
|
1784 |
this.x = x - this.width * 0.5; |
|
1785 |
this._fixX = 0.5; |
|
1786 |
}, |
|
1787 |
||
1788 |
getCenterY: function() {
|
|
1789 |
return this.y + this.height * 0.5; |
|
1790 |
}, |
|
1791 |
||
1792 |
setCenterY: function(y) {
|
|
1793 |
this.y = y - this.height * 0.5; |
|
1794 |
this._fixY = 0.5; |
|
1795 |
}, |
|
1796 |
||
1797 |
getCenter: function(_dontLink) {
|
|
1798 |
var ctor = _dontLink ? Point : LinkedPoint; |
|
1799 |
return new ctor(this.getCenterX(), this.getCenterY(), this, 'setCenter'); |
|
1800 |
}, |
|
1801 |
||
1802 |
setCenter: function() {
|
|
1803 |
var point = Point.read(arguments); |
|
1804 |
this.setCenterX(point.x); |
|
1805 |
this.setCenterY(point.y); |
|
1806 |
return this; |
|
1807 |
}, |
|
1808 |
||
1809 |
getArea: function() {
|
|
1810 |
return this.width * this.height; |
|
1811 |
}, |
|
1812 |
||
1813 |
isEmpty: function() {
|
|
1814 |
return this.width === 0 || this.height === 0; |
|
1815 |
}, |
|
1816 |
||
1817 |
contains: function(arg) {
|
|
1818 |
return arg && arg.width !== undefined |
|
1819 |
|| (Array.isArray(arg) ? arg : arguments).length == 4 |
|
1820 |
? this._containsRectangle(Rectangle.read(arguments)) |
|
1821 |
: this._containsPoint(Point.read(arguments)); |
|
1822 |
}, |
|
1823 |
||
1824 |
_containsPoint: function(point) {
|
|
1825 |
var x = point.x, |
|
1826 |
y = point.y; |
|
1827 |
return x >= this.x && y >= this.y |
|
1828 |
&& x <= this.x + this.width |
|
1829 |
&& y <= this.y + this.height; |
|
1830 |
}, |
|
1831 |
||
1832 |
_containsRectangle: function(rect) {
|
|
1833 |
var x = rect.x, |
|
1834 |
y = rect.y; |
|
1835 |
return x >= this.x && y >= this.y |
|
1836 |
&& x + rect.width <= this.x + this.width |
|
1837 |
&& y + rect.height <= this.y + this.height; |
|
1838 |
}, |
|
1839 |
||
1840 |
intersects: function() {
|
|
1841 |
var rect = Rectangle.read(arguments); |
|
1842 |
return rect.x + rect.width > this.x |
|
1843 |
&& rect.y + rect.height > this.y |
|
1844 |
&& rect.x < this.x + this.width |
|
1845 |
&& rect.y < this.y + this.height; |
|
1846 |
}, |
|
1847 |
||
1848 |
touches: function() {
|
|
1849 |
var rect = Rectangle.read(arguments); |
|
1850 |
return rect.x + rect.width >= this.x |
|
1851 |
&& rect.y + rect.height >= this.y |
|
1852 |
&& rect.x <= this.x + this.width |
|
1853 |
&& rect.y <= this.y + this.height; |
|
1854 |
}, |
|
1855 |
||
1856 |
intersect: function() {
|
|
1857 |
var rect = Rectangle.read(arguments), |
|
1858 |
x1 = Math.max(this.x, rect.x), |
|
1859 |
y1 = Math.max(this.y, rect.y), |
|
1860 |
x2 = Math.min(this.x + this.width, rect.x + rect.width), |
|
1861 |
y2 = Math.min(this.y + this.height, rect.y + rect.height); |
|
1862 |
return new Rectangle(x1, y1, x2 - x1, y2 - y1); |
|
1863 |
}, |
|
1864 |
||
1865 |
unite: function() {
|
|
1866 |
var rect = Rectangle.read(arguments), |
|
1867 |
x1 = Math.min(this.x, rect.x), |
|
1868 |
y1 = Math.min(this.y, rect.y), |
|
1869 |
x2 = Math.max(this.x + this.width, rect.x + rect.width), |
|
1870 |
y2 = Math.max(this.y + this.height, rect.y + rect.height); |
|
1871 |
return new Rectangle(x1, y1, x2 - x1, y2 - y1); |
|
1872 |
}, |
|
1873 |
||
1874 |
include: function() {
|
|
1875 |
var point = Point.read(arguments); |
|
1876 |
var x1 = Math.min(this.x, point.x), |
|
1877 |
y1 = Math.min(this.y, point.y), |
|
1878 |
x2 = Math.max(this.x + this.width, point.x), |
|
1879 |
y2 = Math.max(this.y + this.height, point.y); |
|
1880 |
return new Rectangle(x1, y1, x2 - x1, y2 - y1); |
|
1881 |
}, |
|
1882 |
||
1883 |
expand: function() {
|
|
1884 |
var amount = Size.read(arguments), |
|
1885 |
hor = amount.width, |
|
1886 |
ver = amount.height; |
|
1887 |
return new Rectangle(this.x - hor / 2, this.y - ver / 2, |
|
1888 |
this.width + hor, this.height + ver); |
|
1889 |
}, |
|
1890 |
||
1891 |
scale: function(hor, ver) {
|
|
1892 |
return this.expand(this.width * hor - this.width, |
|
1893 |
this.height * (ver === undefined ? hor : ver) - this.height); |
|
1894 |
} |
|
1895 |
}, Base.each([ |
|
1896 |
['Top', 'Left'], ['Top', 'Right'], |
|
1897 |
['Bottom', 'Left'], ['Bottom', 'Right'], |
|
1898 |
['Left', 'Center'], ['Top', 'Center'], |
|
1899 |
['Right', 'Center'], ['Bottom', 'Center'] |
|
1900 |
], |
|
1901 |
function(parts, index) {
|
|
1902 |
var part = parts.join('');
|
|
1903 |
var xFirst = /^[RL]/.test(part); |
|
1904 |
if (index >= 4) |
|
1905 |
parts[1] += xFirst ? 'Y' : 'X'; |
|
1906 |
var x = parts[xFirst ? 0 : 1], |
|
1907 |
y = parts[xFirst ? 1 : 0], |
|
1908 |
getX = 'get' + x, |
|
1909 |
getY = 'get' + y, |
|
1910 |
setX = 'set' + x, |
|
1911 |
setY = 'set' + y, |
|
1912 |
get = 'get' + part, |
|
1913 |
set = 'set' + part; |
|
1914 |
this[get] = function(_dontLink) {
|
|
1915 |
var ctor = _dontLink ? Point : LinkedPoint; |
|
1916 |
return new ctor(this[getX](), this[getY](), this, set); |
|
1917 |
}; |
|
1918 |
this[set] = function() {
|
|
1919 |
var point = Point.read(arguments); |
|
1920 |
this[setX](point.x); |
|
1921 |
this[setY](point.y); |
|
1922 |
}; |
|
1923 |
}, {
|
|
1924 |
beans: true |
|
1925 |
} |
|
1926 |
)); |
|
1927 |
||
1928 |
var LinkedRectangle = Rectangle.extend({
|
|
1929 |
initialize: function Rectangle(x, y, width, height, owner, setter) {
|
|
1930 |
this.set(x, y, width, height, true); |
|
1931 |
this._owner = owner; |
|
1932 |
this._setter = setter; |
|
1933 |
}, |
|
1934 |
||
1935 |
set: function(x, y, width, height, _dontNotify) {
|
|
1936 |
this._x = x; |
|
1937 |
this._y = y; |
|
1938 |
this._width = width; |
|
1939 |
this._height = height; |
|
1940 |
if (!_dontNotify) |
|
1941 |
this._owner[this._setter](this); |
|
1942 |
return this; |
|
1943 |
} |
|
| 598 | 1944 |
}, |
1945 |
new function() {
|
|
| 442 | 1946 |
var proto = Rectangle.prototype; |
1947 |
||
1948 |
return Base.each(['x', 'y', 'width', 'height'], function(key) {
|
|
1949 |
var part = Base.capitalize(key); |
|
1950 |
var internal = '_' + key; |
|
1951 |
this['get' + part] = function() {
|
|
1952 |
return this[internal]; |
|
1953 |
}; |
|
1954 |
||
1955 |
this['set' + part] = function(value) {
|
|
1956 |
this[internal] = value; |
|
1957 |
if (!this._dontNotify) |
|
1958 |
this._owner[this._setter](this); |
|
1959 |
}; |
|
1960 |
}, Base.each(['Point', 'Size', 'Center', |
|
1961 |
'Left', 'Top', 'Right', 'Bottom', 'CenterX', 'CenterY', |
|
1962 |
'TopLeft', 'TopRight', 'BottomLeft', 'BottomRight', |
|
1963 |
'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'], |
|
1964 |
function(key) {
|
|
1965 |
var name = 'set' + key; |
|
1966 |
this[name] = function() {
|
|
1967 |
this._dontNotify = true; |
|
1968 |
proto[name].apply(this, arguments); |
|
1969 |
this._dontNotify = false; |
|
1970 |
this._owner[this._setter](this); |
|
1971 |
}; |
|
1972 |
}, {
|
|
1973 |
isSelected: function() {
|
|
1974 |
return this._owner._boundsSelected; |
|
1975 |
}, |
|
1976 |
||
1977 |
setSelected: function(selected) {
|
|
1978 |
var owner = this._owner; |
|
1979 |
if (owner.setSelected) {
|
|
1980 |
owner._boundsSelected = selected; |
|
1981 |
owner.setSelected(selected || owner._selectedSegmentState > 0); |
|
1982 |
} |
|
1983 |
} |
|
1984 |
}) |
|
1985 |
); |
|
1986 |
}); |
|
1987 |
||
1988 |
var Matrix = Base.extend({
|
|
1989 |
_class: 'Matrix', |
|
1990 |
||
1991 |
initialize: function Matrix(arg) {
|
|
1992 |
var count = arguments.length, |
|
1993 |
ok = true; |
|
1994 |
if (count === 6) {
|
|
1995 |
this.set.apply(this, arguments); |
|
1996 |
} else if (count === 1) {
|
|
1997 |
if (arg instanceof Matrix) {
|
|
1998 |
this.set(arg._a, arg._c, arg._b, arg._d, arg._tx, arg._ty); |
|
1999 |
} else if (Array.isArray(arg)) {
|
|
2000 |
this.set.apply(this, arg); |
|
2001 |
} else {
|
|
2002 |
ok = false; |
|
2003 |
} |
|
2004 |
} else if (count === 0) {
|
|
2005 |
this.reset(); |
|
2006 |
} else {
|
|
2007 |
ok = false; |
|
2008 |
} |
|
2009 |
if (!ok) |
|
2010 |
throw new Error('Unsupported matrix parameters');
|
|
2011 |
}, |
|
2012 |
||
2013 |
set: function(a, c, b, d, tx, ty, _dontNotify) {
|
|
2014 |
this._a = a; |
|
2015 |
this._c = c; |
|
2016 |
this._b = b; |
|
2017 |
this._d = d; |
|
2018 |
this._tx = tx; |
|
2019 |
this._ty = ty; |
|
2020 |
if (!_dontNotify) |
|
2021 |
this._changed(); |
|
2022 |
return this; |
|
2023 |
}, |
|
2024 |
||
2025 |
_serialize: function(options) {
|
|
2026 |
return Base.serialize(this.getValues(), options); |
|
2027 |
}, |
|
2028 |
||
2029 |
_changed: function() {
|
|
2030 |
var owner = this._owner; |
|
2031 |
if (owner) {
|
|
2032 |
if (owner._applyMatrix) {
|
|
2033 |
owner.transform(null, true); |
|
2034 |
} else {
|
|
2035 |
owner._changed(9); |
|
2036 |
} |
|
2037 |
} |
|
2038 |
}, |
|
2039 |
||
2040 |
clone: function() {
|
|
2041 |
return new Matrix(this._a, this._c, this._b, this._d, |
|
2042 |
this._tx, this._ty); |
|
2043 |
}, |
|
2044 |
||
2045 |
equals: function(mx) {
|
|
2046 |
return mx === this || mx && this._a === mx._a && this._b === mx._b |
|
2047 |
&& this._c === mx._c && this._d === mx._d |
|
2048 |
&& this._tx === mx._tx && this._ty === mx._ty |
|
2049 |
|| false; |
|
2050 |
}, |
|
2051 |
||
2052 |
toString: function() {
|
|
2053 |
var f = Formatter.instance; |
|
2054 |
return '[[' + [f.number(this._a), f.number(this._b), |
|
2055 |
f.number(this._tx)].join(', ') + '], ['
|
|
2056 |
+ [f.number(this._c), f.number(this._d), |
|
2057 |
f.number(this._ty)].join(', ') + ']]';
|
|
2058 |
}, |
|
2059 |
||
2060 |
reset: function(_dontNotify) {
|
|
2061 |
this._a = this._d = 1; |
|
2062 |
this._c = this._b = this._tx = this._ty = 0; |
|
2063 |
if (!_dontNotify) |
|
2064 |
this._changed(); |
|
2065 |
return this; |
|
2066 |
}, |
|
2067 |
||
2068 |
apply: function(recursively, _setApplyMatrix) {
|
|
2069 |
var owner = this._owner; |
|
2070 |
if (owner) {
|
|
2071 |
owner.transform(null, true, Base.pick(recursively, true), |
|
2072 |
_setApplyMatrix); |
|
2073 |
return this.isIdentity(); |
|
2074 |
} |
|
2075 |
return false; |
|
2076 |
}, |
|
2077 |
||
2078 |
translate: function() {
|
|
2079 |
var point = Point.read(arguments), |
|
2080 |
x = point.x, |
|
2081 |
y = point.y; |
|
2082 |
this._tx += x * this._a + y * this._b; |
|
2083 |
this._ty += x * this._c + y * this._d; |
|
2084 |
this._changed(); |
|
2085 |
return this; |
|
2086 |
}, |
|
2087 |
||
2088 |
scale: function() {
|
|
2089 |
var scale = Point.read(arguments), |
|
2090 |
center = Point.read(arguments, 0, { readNull: true });
|
|
2091 |
if (center) |
|
2092 |
this.translate(center); |
|
2093 |
this._a *= scale.x; |
|
2094 |
this._c *= scale.x; |
|
2095 |
this._b *= scale.y; |
|
2096 |
this._d *= scale.y; |
|
2097 |
if (center) |
|
2098 |
this.translate(center.negate()); |
|
2099 |
this._changed(); |
|
2100 |
return this; |
|
2101 |
}, |
|
2102 |
||
2103 |
rotate: function(angle ) {
|
|
2104 |
angle *= Math.PI / 180; |
|
2105 |
var center = Point.read(arguments, 1), |
|
2106 |
x = center.x, |
|
2107 |
y = center.y, |
|
2108 |
cos = Math.cos(angle), |
|
2109 |
sin = Math.sin(angle), |
|
2110 |
tx = x - x * cos + y * sin, |
|
2111 |
ty = y - x * sin - y * cos, |
|
2112 |
a = this._a, |
|
2113 |
b = this._b, |
|
2114 |
c = this._c, |
|
2115 |
d = this._d; |
|
2116 |
this._a = cos * a + sin * b; |
|
2117 |
this._b = -sin * a + cos * b; |
|
2118 |
this._c = cos * c + sin * d; |
|
2119 |
this._d = -sin * c + cos * d; |
|
2120 |
this._tx += tx * a + ty * b; |
|
2121 |
this._ty += tx * c + ty * d; |
|
2122 |
this._changed(); |
|
2123 |
return this; |
|
2124 |
}, |
|
2125 |
||
2126 |
shear: function() {
|
|
2127 |
var shear = Point.read(arguments), |
|
2128 |
center = Point.read(arguments, 0, { readNull: true });
|
|
2129 |
if (center) |
|
2130 |
this.translate(center); |
|
2131 |
var a = this._a, |
|
2132 |
c = this._c; |
|
2133 |
this._a += shear.y * this._b; |
|
2134 |
this._c += shear.y * this._d; |
|
2135 |
this._b += shear.x * a; |
|
2136 |
this._d += shear.x * c; |
|
2137 |
if (center) |
|
2138 |
this.translate(center.negate()); |
|
2139 |
this._changed(); |
|
2140 |
return this; |
|
2141 |
}, |
|
2142 |
||
2143 |
skew: function() {
|
|
2144 |
var skew = Point.read(arguments), |
|
2145 |
center = Point.read(arguments, 0, { readNull: true }),
|
|
2146 |
toRadians = Math.PI / 180, |
|
2147 |
shear = new Point(Math.tan(skew.x * toRadians), |
|
2148 |
Math.tan(skew.y * toRadians)); |
|
2149 |
return this.shear(shear, center); |
|
2150 |
}, |
|
2151 |
||
2152 |
concatenate: function(mx) {
|
|
2153 |
var a1 = this._a, |
|
2154 |
b1 = this._b, |
|
2155 |
c1 = this._c, |
|
2156 |
d1 = this._d, |
|
2157 |
a2 = mx._a, |
|
2158 |
b2 = mx._b, |
|
2159 |
c2 = mx._c, |
|
2160 |
d2 = mx._d, |
|
2161 |
tx2 = mx._tx, |
|
2162 |
ty2 = mx._ty; |
|
2163 |
this._a = a2 * a1 + c2 * b1; |
|
2164 |
this._b = b2 * a1 + d2 * b1; |
|
2165 |
this._c = a2 * c1 + c2 * d1; |
|
2166 |
this._d = b2 * c1 + d2 * d1; |
|
2167 |
this._tx += tx2 * a1 + ty2 * b1; |
|
2168 |
this._ty += tx2 * c1 + ty2 * d1; |
|
2169 |
this._changed(); |
|
2170 |
return this; |
|
2171 |
}, |
|
2172 |
||
2173 |
preConcatenate: function(mx) {
|
|
2174 |
var a1 = this._a, |
|
2175 |
b1 = this._b, |
|
2176 |
c1 = this._c, |
|
2177 |
d1 = this._d, |
|
2178 |
tx1 = this._tx, |
|
2179 |
ty1 = this._ty, |
|
2180 |
a2 = mx._a, |
|
2181 |
b2 = mx._b, |
|
2182 |
c2 = mx._c, |
|
2183 |
d2 = mx._d, |
|
2184 |
tx2 = mx._tx, |
|
2185 |
ty2 = mx._ty; |
|
2186 |
this._a = a2 * a1 + b2 * c1; |
|
2187 |
this._b = a2 * b1 + b2 * d1; |
|
2188 |
this._c = c2 * a1 + d2 * c1; |
|
2189 |
this._d = c2 * b1 + d2 * d1; |
|
2190 |
this._tx = a2 * tx1 + b2 * ty1 + tx2; |
|
2191 |
this._ty = c2 * tx1 + d2 * ty1 + ty2; |
|
2192 |
this._changed(); |
|
2193 |
return this; |
|
2194 |
}, |
|
2195 |
||
2196 |
chain: function(mx) {
|
|
2197 |
var a1 = this._a, |
|
2198 |
b1 = this._b, |
|
2199 |
c1 = this._c, |
|
2200 |
d1 = this._d, |
|
2201 |
tx1 = this._tx, |
|
2202 |
ty1 = this._ty, |
|
2203 |
a2 = mx._a, |
|
2204 |
b2 = mx._b, |
|
2205 |
c2 = mx._c, |
|
2206 |
d2 = mx._d, |
|
2207 |
tx2 = mx._tx, |
|
2208 |
ty2 = mx._ty; |
|
2209 |
return new Matrix( |
|
2210 |
a2 * a1 + c2 * b1, |
|
2211 |
a2 * c1 + c2 * d1, |
|
2212 |
b2 * a1 + d2 * b1, |
|
2213 |
b2 * c1 + d2 * d1, |
|
2214 |
tx1 + tx2 * a1 + ty2 * b1, |
|
2215 |
ty1 + tx2 * c1 + ty2 * d1); |
|
2216 |
}, |
|
2217 |
||
2218 |
isIdentity: function() {
|
|
2219 |
return this._a === 1 && this._c === 0 && this._b === 0 && this._d === 1 |
|
2220 |
&& this._tx === 0 && this._ty === 0; |
|
2221 |
}, |
|
2222 |
||
2223 |
orNullIfIdentity: function() {
|
|
2224 |
return this.isIdentity() ? null : this; |
|
2225 |
}, |
|
2226 |
||
2227 |
isInvertible: function() {
|
|
2228 |
return !!this._getDeterminant(); |
|
2229 |
}, |
|
2230 |
||
2231 |
isSingular: function() {
|
|
2232 |
return !this._getDeterminant(); |
|
2233 |
}, |
|
2234 |
||
2235 |
transform: function( src, dst, count) {
|
|
2236 |
return arguments.length < 3 |
|
2237 |
? this._transformPoint(Point.read(arguments)) |
|
2238 |
: this._transformCoordinates(src, dst, count); |
|
2239 |
}, |
|
2240 |
||
2241 |
_transformPoint: function(point, dest, _dontNotify) {
|
|
2242 |
var x = point.x, |
|
2243 |
y = point.y; |
|
2244 |
if (!dest) |
|
2245 |
dest = new Point(); |
|
2246 |
return dest.set( |
|
2247 |
x * this._a + y * this._b + this._tx, |
|
2248 |
x * this._c + y * this._d + this._ty, |
|
2249 |
_dontNotify |
|
2250 |
); |
|
2251 |
}, |
|
2252 |
||
2253 |
_transformCoordinates: function(src, dst, count) {
|
|
2254 |
var i = 0, |
|
2255 |
j = 0, |
|
2256 |
max = 2 * count; |
|
2257 |
while (i < max) {
|
|
2258 |
var x = src[i++], |
|
2259 |
y = src[i++]; |
|
2260 |
dst[j++] = x * this._a + y * this._b + this._tx; |
|
2261 |
dst[j++] = x * this._c + y * this._d + this._ty; |
|
2262 |
} |
|
2263 |
return dst; |
|
2264 |
}, |
|
2265 |
||
2266 |
_transformCorners: function(rect) {
|
|
2267 |
var x1 = rect.x, |
|
2268 |
y1 = rect.y, |
|
2269 |
x2 = x1 + rect.width, |
|
2270 |
y2 = y1 + rect.height, |
|
2271 |
coords = [ x1, y1, x2, y1, x2, y2, x1, y2 ]; |
|
2272 |
return this._transformCoordinates(coords, coords, 4); |
|
2273 |
}, |
|
2274 |
||
2275 |
_transformBounds: function(bounds, dest, _dontNotify) {
|
|
2276 |
var coords = this._transformCorners(bounds), |
|
2277 |
min = coords.slice(0, 2), |
|
| 598 | 2278 |
max = min.slice(); |
| 442 | 2279 |
for (var i = 2; i < 8; i++) {
|
2280 |
var val = coords[i], |
|
2281 |
j = i & 1; |
|
2282 |
if (val < min[j]) |
|
2283 |
min[j] = val; |
|
2284 |
else if (val > max[j]) |
|
2285 |
max[j] = val; |
|
2286 |
} |
|
2287 |
if (!dest) |
|
2288 |
dest = new Rectangle(); |
|
2289 |
return dest.set(min[0], min[1], max[0] - min[0], max[1] - min[1], |
|
2290 |
_dontNotify); |
|
2291 |
}, |
|
2292 |
||
2293 |
inverseTransform: function() {
|
|
2294 |
return this._inverseTransform(Point.read(arguments)); |
|
2295 |
}, |
|
2296 |
||
2297 |
_getDeterminant: function() {
|
|
2298 |
var det = this._a * this._d - this._b * this._c; |
|
2299 |
return isFinite(det) && !Numerical.isZero(det) |
|
2300 |
&& isFinite(this._tx) && isFinite(this._ty) |
|
2301 |
? det : null; |
|
2302 |
}, |
|
2303 |
||
2304 |
_inverseTransform: function(point, dest, _dontNotify) {
|
|
2305 |
var det = this._getDeterminant(); |
|
2306 |
if (!det) |
|
2307 |
return null; |
|
2308 |
var x = point.x - this._tx, |
|
2309 |
y = point.y - this._ty; |
|
2310 |
if (!dest) |
|
2311 |
dest = new Point(); |
|
2312 |
return dest.set( |
|
2313 |
(x * this._d - y * this._b) / det, |
|
2314 |
(y * this._a - x * this._c) / det, |
|
2315 |
_dontNotify |
|
2316 |
); |
|
2317 |
}, |
|
2318 |
||
2319 |
decompose: function() {
|
|
2320 |
var a = this._a, b = this._b, c = this._c, d = this._d; |
|
2321 |
if (Numerical.isZero(a * d - b * c)) |
|
2322 |
return null; |
|
2323 |
||
2324 |
var scaleX = Math.sqrt(a * a + b * b); |
|
2325 |
a /= scaleX; |
|
2326 |
b /= scaleX; |
|
2327 |
||
2328 |
var shear = a * c + b * d; |
|
2329 |
c -= a * shear; |
|
2330 |
d -= b * shear; |
|
2331 |
||
2332 |
var scaleY = Math.sqrt(c * c + d * d); |
|
2333 |
c /= scaleY; |
|
2334 |
d /= scaleY; |
|
2335 |
shear /= scaleY; |
|
2336 |
||
2337 |
if (a * d < b * c) {
|
|
2338 |
a = -a; |
|
2339 |
b = -b; |
|
2340 |
shear = -shear; |
|
2341 |
scaleX = -scaleX; |
|
2342 |
} |
|
2343 |
||
2344 |
return {
|
|
2345 |
scaling: new Point(scaleX, scaleY), |
|
2346 |
rotation: -Math.atan2(b, a) * 180 / Math.PI, |
|
2347 |
shearing: shear |
|
2348 |
}; |
|
2349 |
}, |
|
2350 |
||
2351 |
getValues: function() {
|
|
2352 |
return [ this._a, this._c, this._b, this._d, this._tx, this._ty ]; |
|
2353 |
}, |
|
2354 |
||
2355 |
getTranslation: function() {
|
|
2356 |
return new Point(this._tx, this._ty); |
|
2357 |
}, |
|
2358 |
||
2359 |
getScaling: function() {
|
|
2360 |
return (this.decompose() || {}).scaling;
|
|
2361 |
}, |
|
2362 |
||
2363 |
getRotation: function() {
|
|
2364 |
return (this.decompose() || {}).rotation;
|
|
2365 |
}, |
|
2366 |
||
2367 |
inverted: function() {
|
|
2368 |
var det = this._getDeterminant(); |
|
2369 |
return det && new Matrix( |
|
2370 |
this._d / det, |
|
2371 |
-this._c / det, |
|
2372 |
-this._b / det, |
|
2373 |
this._a / det, |
|
2374 |
(this._b * this._ty - this._d * this._tx) / det, |
|
2375 |
(this._c * this._tx - this._a * this._ty) / det); |
|
2376 |
}, |
|
2377 |
||
2378 |
shiftless: function() {
|
|
2379 |
return new Matrix(this._a, this._c, this._b, this._d, 0, 0); |
|
2380 |
}, |
|
2381 |
||
2382 |
applyToContext: function(ctx) {
|
|
2383 |
ctx.transform(this._a, this._c, this._b, this._d, this._tx, this._ty); |
|
2384 |
} |
|
2385 |
}, Base.each(['a', 'c', 'b', 'd', 'tx', 'ty'], function(name) {
|
|
2386 |
var part = Base.capitalize(name), |
|
2387 |
prop = '_' + name; |
|
2388 |
this['get' + part] = function() {
|
|
2389 |
return this[prop]; |
|
2390 |
}; |
|
2391 |
this['set' + part] = function(value) {
|
|
2392 |
this[prop] = value; |
|
2393 |
this._changed(); |
|
2394 |
}; |
|
2395 |
}, {}));
|
|
2396 |
||
2397 |
var Line = Base.extend({
|
|
2398 |
_class: 'Line', |
|
2399 |
||
2400 |
initialize: function Line(arg0, arg1, arg2, arg3, arg4) {
|
|
2401 |
var asVector = false; |
|
2402 |
if (arguments.length >= 4) {
|
|
2403 |
this._px = arg0; |
|
2404 |
this._py = arg1; |
|
2405 |
this._vx = arg2; |
|
2406 |
this._vy = arg3; |
|
2407 |
asVector = arg4; |
|
2408 |
} else {
|
|
2409 |
this._px = arg0.x; |
|
2410 |
this._py = arg0.y; |
|
2411 |
this._vx = arg1.x; |
|
2412 |
this._vy = arg1.y; |
|
2413 |
asVector = arg2; |
|
2414 |
} |
|
2415 |
if (!asVector) {
|
|
2416 |
this._vx -= this._px; |
|
2417 |
this._vy -= this._py; |
|
2418 |
} |
|
2419 |
}, |
|
2420 |
||
2421 |
getPoint: function() {
|
|
2422 |
return new Point(this._px, this._py); |
|
2423 |
}, |
|
2424 |
||
2425 |
getVector: function() {
|
|
2426 |
return new Point(this._vx, this._vy); |
|
2427 |
}, |
|
2428 |
||
2429 |
getLength: function() {
|
|
2430 |
return this.getVector().getLength(); |
|
2431 |
}, |
|
2432 |
||
2433 |
intersect: function(line, isInfinite) {
|
|
2434 |
return Line.intersect( |
|
2435 |
this._px, this._py, this._vx, this._vy, |
|
2436 |
line._px, line._py, line._vx, line._vy, |
|
2437 |
true, isInfinite); |
|
2438 |
}, |
|
2439 |
||
| 598 | 2440 |
getSide: function(point, isInfinite) {
|
| 442 | 2441 |
return Line.getSide( |
2442 |
this._px, this._py, this._vx, this._vy, |
|
| 598 | 2443 |
point.x, point.y, true, isInfinite); |
| 442 | 2444 |
}, |
2445 |
||
2446 |
getDistance: function(point) {
|
|
2447 |
return Math.abs(Line.getSignedDistance( |
|
2448 |
this._px, this._py, this._vx, this._vy, |
|
2449 |
point.x, point.y, true)); |
|
2450 |
}, |
|
2451 |
||
| 598 | 2452 |
isCollinear: function(line) {
|
2453 |
return Point.isCollinear(this._vx, this._vy, line._vx, line._vy); |
|
2454 |
}, |
|
2455 |
||
2456 |
isOrthogonal: function(line) {
|
|
2457 |
return Point.isOrthogonal(this._vx, this._vy, line._vx, line._vy); |
|
2458 |
}, |
|
2459 |
||
| 442 | 2460 |
statics: {
|
| 598 | 2461 |
intersect: function(p1x, p1y, v1x, v1y, p2x, p2y, v2x, v2y, asVector, |
| 442 | 2462 |
isInfinite) {
|
2463 |
if (!asVector) {
|
|
| 598 | 2464 |
v1x -= p1x; |
2465 |
v1y -= p1y; |
|
2466 |
v2x -= p2x; |
|
2467 |
v2y -= p2y; |
|
2468 |
} |
|
2469 |
var cross = v1x * v2y - v1y * v2x; |
|
| 442 | 2470 |
if (!Numerical.isZero(cross)) {
|
| 598 | 2471 |
var dx = p1x - p2x, |
2472 |
dy = p1y - p2y, |
|
2473 |
u1 = (v2x * dy - v2y * dx) / cross, |
|
2474 |
u2 = (v1x * dy - v1y * dx) / cross, |
|
2475 |
epsilon = 1e-12, |
|
2476 |
uMin = -epsilon, |
|
2477 |
uMax = 1 + epsilon; |
|
2478 |
if (isInfinite |
|
2479 |
|| uMin < u1 && u1 < uMax && uMin < u2 && u2 < uMax) {
|
|
2480 |
if (!isInfinite) {
|
|
2481 |
u1 = u1 <= 0 ? 0 : u1 >= 1 ? 1 : u1; |
|
2482 |
} |
|
| 442 | 2483 |
return new Point( |
| 598 | 2484 |
p1x + u1 * v1x, |
2485 |
p1y + u1 * v1y); |
|
2486 |
} |
|
2487 |
} |
|
2488 |
}, |
|
2489 |
||
2490 |
getSide: function(px, py, vx, vy, x, y, asVector, isInfinite) {
|
|
| 442 | 2491 |
if (!asVector) {
|
2492 |
vx -= px; |
|
2493 |
vy -= py; |
|
2494 |
} |
|
2495 |
var v2x = x - px, |
|
2496 |
v2y = y - py, |
|
2497 |
ccw = v2x * vy - v2y * vx; |
|
| 598 | 2498 |
if (ccw === 0 && !isInfinite) {
|
2499 |
ccw = (v2x * vx + v2x * vx) / (vx * vx + vy * vy); |
|
2500 |
if (ccw >= 0 && ccw <= 1) |
|
2501 |
ccw = 0; |
|
| 442 | 2502 |
} |
2503 |
return ccw < 0 ? -1 : ccw > 0 ? 1 : 0; |
|
2504 |
}, |
|
2505 |
||
2506 |
getSignedDistance: function(px, py, vx, vy, x, y, asVector) {
|
|
2507 |
if (!asVector) {
|
|
2508 |
vx -= px; |
|
2509 |
vy -= py; |
|
2510 |
} |
|
| 598 | 2511 |
return vx === 0 ? vy > 0 ? x - px : px - x |
2512 |
: vy === 0 ? vx < 0 ? y - py : py - y |
|
2513 |
: ((x-px) * vy - (y-py) * vx) / Math.sqrt(vx * vx + vy * vy); |
|
| 442 | 2514 |
} |
2515 |
} |
|
2516 |
}); |
|
2517 |
||
2518 |
var Project = PaperScopeItem.extend({
|
|
2519 |
_class: 'Project', |
|
2520 |
_list: 'projects', |
|
2521 |
_reference: 'project', |
|
2522 |
||
2523 |
initialize: function Project(element) {
|
|
2524 |
PaperScopeItem.call(this, true); |
|
2525 |
this.layers = []; |
|
2526 |
this._activeLayer = null; |
|
2527 |
this.symbols = []; |
|
2528 |
this._currentStyle = new Style(null, null, this); |
|
2529 |
this._view = View.create(this, |
|
2530 |
element || CanvasProvider.getCanvas(1, 1)); |
|
2531 |
this._selectedItems = {};
|
|
2532 |
this._selectedItemCount = 0; |
|
2533 |
this._updateVersion = 0; |
|
2534 |
}, |
|
2535 |
||
2536 |
_serialize: function(options, dictionary) {
|
|
2537 |
return Base.serialize(this.layers, options, true, dictionary); |
|
2538 |
}, |
|
2539 |
||
2540 |
clear: function() {
|
|
2541 |
for (var i = this.layers.length - 1; i >= 0; i--) |
|
2542 |
this.layers[i].remove(); |
|
2543 |
this.symbols = []; |
|
2544 |
}, |
|
2545 |
||
2546 |
isEmpty: function() {
|
|
2547 |
return this.layers.length === 0; |
|
2548 |
}, |
|
2549 |
||
2550 |
remove: function remove() {
|
|
2551 |
if (!remove.base.call(this)) |
|
2552 |
return false; |
|
2553 |
if (this._view) |
|
2554 |
this._view.remove(); |
|
2555 |
return true; |
|
2556 |
}, |
|
2557 |
||
2558 |
getView: function() {
|
|
2559 |
return this._view; |
|
2560 |
}, |
|
2561 |
||
2562 |
getCurrentStyle: function() {
|
|
2563 |
return this._currentStyle; |
|
2564 |
}, |
|
2565 |
||
2566 |
setCurrentStyle: function(style) {
|
|
2567 |
this._currentStyle.initialize(style); |
|
2568 |
}, |
|
2569 |
||
2570 |
getIndex: function() {
|
|
2571 |
return this._index; |
|
2572 |
}, |
|
2573 |
||
2574 |
getOptions: function() {
|
|
2575 |
return this._scope.settings; |
|
2576 |
}, |
|
2577 |
||
2578 |
getActiveLayer: function() {
|
|
2579 |
return this._activeLayer || new Layer({ project: this });
|
|
2580 |
}, |
|
2581 |
||
2582 |
getSelectedItems: function() {
|
|
2583 |
var items = []; |
|
2584 |
for (var id in this._selectedItems) {
|
|
2585 |
var item = this._selectedItems[id]; |
|
2586 |
if (item.isInserted()) |
|
2587 |
items.push(item); |
|
2588 |
} |
|
2589 |
return items; |
|
2590 |
}, |
|
2591 |
||
2592 |
insertChild: function(index, item, _preserve) {
|
|
2593 |
if (item instanceof Layer) {
|
|
2594 |
item._remove(false, true); |
|
2595 |
Base.splice(this.layers, [item], index, 0); |
|
2596 |
item._setProject(this, true); |
|
2597 |
if (this._changes) |
|
2598 |
item._changed(5); |
|
2599 |
if (!this._activeLayer) |
|
2600 |
this._activeLayer = item; |
|
2601 |
} else if (item instanceof Item) {
|
|
2602 |
(this._activeLayer |
|
2603 |
|| this.insertChild(index, new Layer(Item.NO_INSERT))) |
|
2604 |
.insertChild(index, item, _preserve); |
|
2605 |
} else {
|
|
2606 |
item = null; |
|
2607 |
} |
|
2608 |
return item; |
|
2609 |
}, |
|
2610 |
||
2611 |
addChild: function(item, _preserve) {
|
|
2612 |
return this.insertChild(undefined, item, _preserve); |
|
2613 |
}, |
|
2614 |
||
2615 |
_updateSelection: function(item) {
|
|
2616 |
var id = item._id, |
|
2617 |
selectedItems = this._selectedItems; |
|
2618 |
if (item._selected) {
|
|
2619 |
if (selectedItems[id] !== item) {
|
|
2620 |
this._selectedItemCount++; |
|
2621 |
selectedItems[id] = item; |
|
2622 |
} |
|
2623 |
} else if (selectedItems[id] === item) {
|
|
2624 |
this._selectedItemCount--; |
|
2625 |
delete selectedItems[id]; |
|
2626 |
} |
|
2627 |
}, |
|
2628 |
||
2629 |
selectAll: function() {
|
|
2630 |
var layers = this.layers; |
|
2631 |
for (var i = 0, l = layers.length; i < l; i++) |
|
2632 |
layers[i].setFullySelected(true); |
|
2633 |
}, |
|
2634 |
||
2635 |
deselectAll: function() {
|
|
2636 |
var selectedItems = this._selectedItems; |
|
2637 |
for (var i in selectedItems) |
|
2638 |
selectedItems[i].setFullySelected(false); |
|
2639 |
}, |
|
2640 |
||
2641 |
hitTest: function() {
|
|
2642 |
var point = Point.read(arguments), |
|
2643 |
options = HitResult.getOptions(Base.read(arguments)); |
|
2644 |
for (var i = this.layers.length - 1; i >= 0; i--) {
|
|
2645 |
var res = this.layers[i]._hitTest(point, options); |
|
2646 |
if (res) return res; |
|
2647 |
} |
|
2648 |
return null; |
|
2649 |
}, |
|
2650 |
||
2651 |
getItems: function(match) {
|
|
2652 |
return Item._getItems(this.layers, match); |
|
2653 |
}, |
|
2654 |
||
2655 |
getItem: function(match) {
|
|
2656 |
return Item._getItems(this.layers, match, null, null, true)[0] || null; |
|
2657 |
}, |
|
2658 |
||
2659 |
importJSON: function(json) {
|
|
2660 |
this.activate(); |
|
2661 |
var layer = this._activeLayer; |
|
2662 |
return Base.importJSON(json, layer && layer.isEmpty() && layer); |
|
2663 |
}, |
|
2664 |
||
2665 |
draw: function(ctx, matrix, pixelRatio) {
|
|
2666 |
this._updateVersion++; |
|
2667 |
ctx.save(); |
|
2668 |
matrix.applyToContext(ctx); |
|
2669 |
var param = new Base({
|
|
2670 |
offset: new Point(0, 0), |
|
2671 |
pixelRatio: pixelRatio, |
|
2672 |
viewMatrix: matrix.isIdentity() ? null : matrix, |
|
2673 |
matrices: [new Matrix()], |
|
2674 |
updateMatrix: true |
|
2675 |
}); |
|
2676 |
for (var i = 0, layers = this.layers, l = layers.length; i < l; i++) |
|
2677 |
layers[i].draw(ctx, param); |
|
2678 |
ctx.restore(); |
|
2679 |
||
2680 |
if (this._selectedItemCount > 0) {
|
|
2681 |
ctx.save(); |
|
2682 |
ctx.strokeWidth = 1; |
|
2683 |
var items = this._selectedItems, |
|
2684 |
size = this._scope.settings.handleSize, |
|
2685 |
version = this._updateVersion; |
|
2686 |
for (var id in items) |
|
2687 |
items[id]._drawSelection(ctx, matrix, size, items, version); |
|
2688 |
ctx.restore(); |
|
2689 |
} |
|
2690 |
} |
|
2691 |
}); |
|
2692 |
||
2693 |
var Symbol = Base.extend({
|
|
2694 |
_class: 'Symbol', |
|
2695 |
||
2696 |
initialize: function Symbol(item, dontCenter) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
2697 |
this._id = UID.get(); |
| 442 | 2698 |
this.project = paper.project; |
2699 |
this.project.symbols.push(this); |
|
2700 |
if (item) |
|
2701 |
this.setDefinition(item, dontCenter); |
|
2702 |
}, |
|
2703 |
||
2704 |
_serialize: function(options, dictionary) {
|
|
2705 |
return dictionary.add(this, function() {
|
|
2706 |
return Base.serialize([this._class, this._definition], |
|
2707 |
options, false, dictionary); |
|
2708 |
}); |
|
2709 |
}, |
|
2710 |
||
2711 |
_changed: function(flags) {
|
|
2712 |
if (flags & 8) {
|
|
2713 |
Item._clearBoundsCache(this); |
|
2714 |
} |
|
2715 |
if (flags & 1) {
|
|
2716 |
this.project._needsUpdate = true; |
|
2717 |
} |
|
2718 |
}, |
|
2719 |
||
2720 |
getDefinition: function() {
|
|
2721 |
return this._definition; |
|
2722 |
}, |
|
2723 |
||
2724 |
setDefinition: function(item, _dontCenter) {
|
|
2725 |
if (item._parentSymbol) |
|
2726 |
item = item.clone(); |
|
2727 |
if (this._definition) |
|
2728 |
this._definition._parentSymbol = null; |
|
2729 |
this._definition = item; |
|
2730 |
item.remove(); |
|
2731 |
item.setSelected(false); |
|
2732 |
if (!_dontCenter) |
|
2733 |
item.setPosition(new Point()); |
|
2734 |
item._parentSymbol = this; |
|
2735 |
this._changed(9); |
|
2736 |
}, |
|
2737 |
||
2738 |
place: function(position) {
|
|
2739 |
return new PlacedSymbol(this, position); |
|
2740 |
}, |
|
2741 |
||
2742 |
clone: function() {
|
|
2743 |
return new Symbol(this._definition.clone(false)); |
|
2744 |
}, |
|
2745 |
||
2746 |
equals: function(symbol) {
|
|
2747 |
return symbol === this |
|
2748 |
|| symbol && this.definition.equals(symbol.definition) |
|
2749 |
|| false; |
|
2750 |
} |
|
2751 |
}); |
|
2752 |
||
2753 |
var Item = Base.extend(Emitter, {
|
|
2754 |
statics: {
|
|
2755 |
extend: function extend(src) {
|
|
2756 |
if (src._serializeFields) |
|
2757 |
src._serializeFields = new Base( |
|
2758 |
this.prototype._serializeFields, src._serializeFields); |
|
2759 |
return extend.base.apply(this, arguments); |
|
2760 |
}, |
|
2761 |
||
2762 |
NO_INSERT: { insert: false }
|
|
2763 |
}, |
|
2764 |
||
2765 |
_class: 'Item', |
|
2766 |
_applyMatrix: true, |
|
2767 |
_canApplyMatrix: true, |
|
2768 |
_boundsSelected: false, |
|
2769 |
_selectChildren: false, |
|
2770 |
_serializeFields: {
|
|
2771 |
name: null, |
|
2772 |
applyMatrix: null, |
|
2773 |
matrix: new Matrix(), |
|
2774 |
pivot: null, |
|
2775 |
locked: false, |
|
2776 |
visible: true, |
|
2777 |
blendMode: 'normal', |
|
2778 |
opacity: 1, |
|
2779 |
guide: false, |
|
2780 |
selected: false, |
|
2781 |
clipMask: false, |
|
2782 |
data: {}
|
|
2783 |
}, |
|
2784 |
||
2785 |
initialize: function Item() {
|
|
2786 |
}, |
|
2787 |
||
2788 |
_initialize: function(props, point) {
|
|
2789 |
var hasProps = props && Base.isPlainObject(props), |
|
2790 |
internal = hasProps && props.internal === true, |
|
2791 |
matrix = this._matrix = new Matrix(), |
|
2792 |
project = hasProps && props.project || paper.project; |
|
2793 |
if (!internal) |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
2794 |
this._id = UID.get(); |
| 442 | 2795 |
this._applyMatrix = this._canApplyMatrix && paper.settings.applyMatrix; |
2796 |
if (point) |
|
2797 |
matrix.translate(point); |
|
2798 |
matrix._owner = this; |
|
2799 |
this._style = new Style(project._currentStyle, this, project); |
|
2800 |
if (!this._project) {
|
|
2801 |
if (internal || hasProps && props.insert === false) {
|
|
2802 |
this._setProject(project); |
|
2803 |
} else if (hasProps && props.parent) {
|
|
2804 |
this.setParent(props.parent); |
|
2805 |
} else {
|
|
2806 |
(project._activeLayer || new Layer()).addChild(this); |
|
2807 |
} |
|
2808 |
} |
|
2809 |
if (hasProps && props !== Item.NO_INSERT) |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
2810 |
this._set(props, { insert: true, project: true, parent: true },
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
2811 |
true); |
| 442 | 2812 |
return hasProps; |
2813 |
}, |
|
2814 |
||
| 598 | 2815 |
_events: Base.each(['onMouseDown', 'onMouseUp', 'onMouseDrag', 'onClick', |
2816 |
'onDoubleClick', 'onMouseMove', 'onMouseEnter', 'onMouseLeave'], |
|
2817 |
function(name) {
|
|
2818 |
this[name] = {
|
|
2819 |
install: function(type) {
|
|
2820 |
this.getView()._installEvent(type); |
|
2821 |
}, |
|
2822 |
||
2823 |
uninstall: function(type) {
|
|
2824 |
this.getView()._uninstallEvent(type); |
|
2825 |
} |
|
2826 |
}; |
|
2827 |
}, {
|
|
2828 |
onFrame: {
|
|
2829 |
install: function() {
|
|
2830 |
this.getView()._animateItem(this, true); |
|
2831 |
}, |
|
2832 |
||
2833 |
uninstall: function() {
|
|
2834 |
this.getView()._animateItem(this, false); |
|
| 442 | 2835 |
} |
2836 |
}, |
|
| 598 | 2837 |
|
2838 |
onLoad: {}
|
|
2839 |
} |
|
2840 |
), |
|
| 442 | 2841 |
|
2842 |
_serialize: function(options, dictionary) {
|
|
2843 |
var props = {},
|
|
2844 |
that = this; |
|
2845 |
||
2846 |
function serialize(fields) {
|
|
2847 |
for (var key in fields) {
|
|
2848 |
var value = that[key]; |
|
2849 |
if (!Base.equals(value, key === 'leading' |
|
2850 |
? fields.fontSize * 1.2 : fields[key])) {
|
|
2851 |
props[key] = Base.serialize(value, options, |
|
2852 |
key !== 'data', dictionary); |
|
2853 |
} |
|
2854 |
} |
|
2855 |
} |
|
2856 |
||
2857 |
serialize(this._serializeFields); |
|
2858 |
if (!(this instanceof Group)) |
|
2859 |
serialize(this._style._defaults); |
|
2860 |
return [ this._class, props ]; |
|
2861 |
}, |
|
2862 |
||
2863 |
_changed: function(flags) {
|
|
2864 |
var symbol = this._parentSymbol, |
|
2865 |
cacheParent = this._parent || symbol, |
|
2866 |
project = this._project; |
|
2867 |
if (flags & 8) {
|
|
2868 |
this._bounds = this._position = this._decomposed = |
|
2869 |
this._globalMatrix = this._currentPath = undefined; |
|
2870 |
} |
|
2871 |
if (cacheParent |
|
2872 |
&& (flags & 40)) {
|
|
2873 |
Item._clearBoundsCache(cacheParent); |
|
2874 |
} |
|
2875 |
if (flags & 2) {
|
|
2876 |
Item._clearBoundsCache(this); |
|
2877 |
} |
|
2878 |
if (project) {
|
|
2879 |
if (flags & 1) {
|
|
2880 |
project._needsUpdate = true; |
|
2881 |
} |
|
2882 |
if (project._changes) {
|
|
2883 |
var entry = project._changesById[this._id]; |
|
2884 |
if (entry) {
|
|
2885 |
entry.flags |= flags; |
|
2886 |
} else {
|
|
2887 |
entry = { item: this, flags: flags };
|
|
2888 |
project._changesById[this._id] = entry; |
|
2889 |
project._changes.push(entry); |
|
2890 |
} |
|
2891 |
} |
|
2892 |
} |
|
2893 |
if (symbol) |
|
2894 |
symbol._changed(flags); |
|
2895 |
}, |
|
2896 |
||
2897 |
set: function(props) {
|
|
2898 |
if (props) |
|
2899 |
this._set(props); |
|
2900 |
return this; |
|
2901 |
}, |
|
2902 |
||
2903 |
getId: function() {
|
|
2904 |
return this._id; |
|
2905 |
}, |
|
2906 |
||
2907 |
getName: function() {
|
|
2908 |
return this._name; |
|
2909 |
}, |
|
2910 |
||
2911 |
setName: function(name, unique) {
|
|
2912 |
||
2913 |
if (this._name) |
|
2914 |
this._removeNamed(); |
|
2915 |
if (name === (+name) + '') |
|
2916 |
throw new Error( |
|
2917 |
'Names consisting only of numbers are not supported.'); |
|
2918 |
var parent = this._parent; |
|
2919 |
if (name && parent) {
|
|
2920 |
var children = parent._children, |
|
2921 |
namedChildren = parent._namedChildren, |
|
2922 |
orig = name, |
|
2923 |
i = 1; |
|
2924 |
while (unique && children[name]) |
|
2925 |
name = orig + ' ' + (i++); |
|
2926 |
(namedChildren[name] = namedChildren[name] || []).push(this); |
|
2927 |
children[name] = this; |
|
2928 |
} |
|
2929 |
this._name = name || undefined; |
|
2930 |
this._changed(128); |
|
2931 |
}, |
|
2932 |
||
2933 |
getStyle: function() {
|
|
2934 |
return this._style; |
|
2935 |
}, |
|
2936 |
||
2937 |
setStyle: function(style) {
|
|
2938 |
this.getStyle().set(style); |
|
2939 |
} |
|
2940 |
}, Base.each(['locked', 'visible', 'blendMode', 'opacity', 'guide'], |
|
2941 |
function(name) {
|
|
2942 |
var part = Base.capitalize(name), |
|
2943 |
name = '_' + name; |
|
2944 |
this['get' + part] = function() {
|
|
2945 |
return this[name]; |
|
2946 |
}; |
|
2947 |
this['set' + part] = function(value) {
|
|
2948 |
if (value != this[name]) {
|
|
2949 |
this[name] = value; |
|
2950 |
this._changed(name === '_locked' |
|
2951 |
? 128 : 129); |
|
2952 |
} |
|
2953 |
}; |
|
2954 |
}, |
|
2955 |
{}), {
|
|
2956 |
beans: true, |
|
2957 |
||
2958 |
_locked: false, |
|
2959 |
||
2960 |
_visible: true, |
|
2961 |
||
2962 |
_blendMode: 'normal', |
|
2963 |
||
2964 |
_opacity: 1, |
|
2965 |
||
2966 |
_guide: false, |
|
2967 |
||
2968 |
isSelected: function() {
|
|
2969 |
if (this._selectChildren) {
|
|
2970 |
var children = this._children; |
|
2971 |
for (var i = 0, l = children.length; i < l; i++) |
|
2972 |
if (children[i].isSelected()) |
|
2973 |
return true; |
|
2974 |
} |
|
2975 |
return this._selected; |
|
2976 |
}, |
|
2977 |
||
2978 |
setSelected: function(selected, noChildren) {
|
|
2979 |
if (!noChildren && this._selectChildren) {
|
|
2980 |
var children = this._children; |
|
2981 |
for (var i = 0, l = children.length; i < l; i++) |
|
2982 |
children[i].setSelected(selected); |
|
2983 |
} |
|
2984 |
if ((selected = !!selected) ^ this._selected) {
|
|
2985 |
this._selected = selected; |
|
2986 |
this._project._updateSelection(this); |
|
2987 |
this._changed(129); |
|
2988 |
} |
|
2989 |
}, |
|
2990 |
||
2991 |
_selected: false, |
|
2992 |
||
2993 |
isFullySelected: function() {
|
|
2994 |
var children = this._children; |
|
2995 |
if (children && this._selected) {
|
|
2996 |
for (var i = 0, l = children.length; i < l; i++) |
|
2997 |
if (!children[i].isFullySelected()) |
|
2998 |
return false; |
|
2999 |
return true; |
|
3000 |
} |
|
3001 |
return this._selected; |
|
3002 |
}, |
|
3003 |
||
3004 |
setFullySelected: function(selected) {
|
|
3005 |
var children = this._children; |
|
3006 |
if (children) {
|
|
3007 |
for (var i = 0, l = children.length; i < l; i++) |
|
3008 |
children[i].setFullySelected(selected); |
|
3009 |
} |
|
3010 |
this.setSelected(selected, true); |
|
3011 |
}, |
|
3012 |
||
3013 |
isClipMask: function() {
|
|
3014 |
return this._clipMask; |
|
3015 |
}, |
|
3016 |
||
3017 |
setClipMask: function(clipMask) {
|
|
3018 |
if (this._clipMask != (clipMask = !!clipMask)) {
|
|
3019 |
this._clipMask = clipMask; |
|
3020 |
if (clipMask) {
|
|
3021 |
this.setFillColor(null); |
|
3022 |
this.setStrokeColor(null); |
|
3023 |
} |
|
3024 |
this._changed(129); |
|
3025 |
if (this._parent) |
|
3026 |
this._parent._changed(1024); |
|
3027 |
} |
|
3028 |
}, |
|
3029 |
||
3030 |
_clipMask: false, |
|
3031 |
||
3032 |
getData: function() {
|
|
3033 |
if (!this._data) |
|
3034 |
this._data = {};
|
|
3035 |
return this._data; |
|
3036 |
}, |
|
3037 |
||
3038 |
setData: function(data) {
|
|
3039 |
this._data = data; |
|
3040 |
}, |
|
3041 |
||
3042 |
getPosition: function(_dontLink) {
|
|
3043 |
var position = this._position, |
|
3044 |
ctor = _dontLink ? Point : LinkedPoint; |
|
3045 |
if (!position) {
|
|
3046 |
var pivot = this._pivot; |
|
3047 |
position = this._position = pivot |
|
3048 |
? this._matrix._transformPoint(pivot) |
|
3049 |
: this.getBounds().getCenter(true); |
|
3050 |
} |
|
3051 |
return new ctor(position.x, position.y, this, 'setPosition'); |
|
3052 |
}, |
|
3053 |
||
3054 |
setPosition: function() {
|
|
3055 |
this.translate(Point.read(arguments).subtract(this.getPosition(true))); |
|
3056 |
}, |
|
3057 |
||
3058 |
getPivot: function(_dontLink) {
|
|
3059 |
var pivot = this._pivot; |
|
3060 |
if (pivot) {
|
|
3061 |
var ctor = _dontLink ? Point : LinkedPoint; |
|
3062 |
pivot = new ctor(pivot.x, pivot.y, this, 'setPivot'); |
|
3063 |
} |
|
3064 |
return pivot; |
|
3065 |
}, |
|
3066 |
||
3067 |
setPivot: function() {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3068 |
this._pivot = Point.read(arguments, 0, { clone: true, readNull: true });
|
| 442 | 3069 |
this._position = undefined; |
3070 |
}, |
|
3071 |
||
3072 |
_pivot: null, |
|
3073 |
}, Base.each(['bounds', 'strokeBounds', 'handleBounds', 'roughBounds', |
|
3074 |
'internalBounds', 'internalRoughBounds'], |
|
3075 |
function(key) {
|
|
3076 |
var getter = 'get' + Base.capitalize(key), |
|
3077 |
match = key.match(/^internal(.*)$/), |
|
3078 |
internalGetter = match ? 'get' + match[1] : null; |
|
3079 |
this[getter] = function(_matrix) {
|
|
3080 |
var boundsGetter = this._boundsGetter, |
|
3081 |
name = !internalGetter && (typeof boundsGetter === 'string' |
|
3082 |
? boundsGetter : boundsGetter && boundsGetter[getter]) |
|
3083 |
|| getter, |
|
3084 |
bounds = this._getCachedBounds(name, _matrix, this, |
|
3085 |
internalGetter); |
|
3086 |
return key === 'bounds' |
|
3087 |
? new LinkedRectangle(bounds.x, bounds.y, bounds.width, |
|
3088 |
bounds.height, this, 'setBounds') |
|
3089 |
: bounds; |
|
3090 |
}; |
|
3091 |
}, |
|
3092 |
{
|
|
3093 |
beans: true, |
|
3094 |
||
3095 |
_getBounds: function(getter, matrix, cacheItem) {
|
|
3096 |
var children = this._children; |
|
3097 |
if (!children || children.length == 0) |
|
3098 |
return new Rectangle(); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3099 |
Item._updateBoundsCache(this, cacheItem); |
| 442 | 3100 |
var x1 = Infinity, |
3101 |
x2 = -x1, |
|
3102 |
y1 = x1, |
|
3103 |
y2 = x2; |
|
3104 |
for (var i = 0, l = children.length; i < l; i++) {
|
|
3105 |
var child = children[i]; |
|
3106 |
if (child._visible && !child.isEmpty()) {
|
|
3107 |
var rect = child._getCachedBounds(getter, |
|
3108 |
matrix && matrix.chain(child._matrix), cacheItem); |
|
3109 |
x1 = Math.min(rect.x, x1); |
|
3110 |
y1 = Math.min(rect.y, y1); |
|
3111 |
x2 = Math.max(rect.x + rect.width, x2); |
|
3112 |
y2 = Math.max(rect.y + rect.height, y2); |
|
3113 |
} |
|
3114 |
} |
|
3115 |
return isFinite(x1) |
|
3116 |
? new Rectangle(x1, y1, x2 - x1, y2 - y1) |
|
3117 |
: new Rectangle(); |
|
3118 |
}, |
|
3119 |
||
3120 |
setBounds: function() {
|
|
3121 |
var rect = Rectangle.read(arguments), |
|
3122 |
bounds = this.getBounds(), |
|
3123 |
matrix = new Matrix(), |
|
3124 |
center = rect.getCenter(); |
|
3125 |
matrix.translate(center); |
|
3126 |
if (rect.width != bounds.width || rect.height != bounds.height) {
|
|
3127 |
matrix.scale( |
|
3128 |
bounds.width != 0 ? rect.width / bounds.width : 1, |
|
3129 |
bounds.height != 0 ? rect.height / bounds.height : 1); |
|
3130 |
} |
|
3131 |
center = bounds.getCenter(); |
|
3132 |
matrix.translate(-center.x, -center.y); |
|
3133 |
this.transform(matrix); |
|
3134 |
}, |
|
3135 |
||
3136 |
_getCachedBounds: function(getter, matrix, cacheItem, internalGetter) {
|
|
3137 |
matrix = matrix && matrix.orNullIfIdentity(); |
|
3138 |
var _matrix = internalGetter ? null : this._matrix.orNullIfIdentity(), |
|
3139 |
cache = (!matrix || matrix.equals(_matrix)) && getter; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3140 |
Item._updateBoundsCache(this._parent || this._parentSymbol, cacheItem); |
| 442 | 3141 |
if (cache && this._bounds && this._bounds[cache]) |
3142 |
return this._bounds[cache].clone(); |
|
3143 |
var bounds = this._getBounds(internalGetter || getter, |
|
3144 |
matrix || _matrix, cacheItem); |
|
3145 |
if (cache) {
|
|
3146 |
if (!this._bounds) |
|
3147 |
this._bounds = {};
|
|
3148 |
var cached = this._bounds[cache] = bounds.clone(); |
|
3149 |
cached._internal = !!internalGetter; |
|
3150 |
} |
|
3151 |
return bounds; |
|
3152 |
}, |
|
3153 |
||
3154 |
statics: {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3155 |
_updateBoundsCache: function(parent, item) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3156 |
if (parent) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3157 |
var id = item._id, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3158 |
ref = parent._boundsCache = parent._boundsCache || {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3159 |
ids: {},
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3160 |
list: [] |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3161 |
}; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3162 |
if (!ref.ids[id]) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3163 |
ref.list.push(item); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3164 |
ref.ids[id] = item; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3165 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3166 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3167 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3168 |
|
| 442 | 3169 |
_clearBoundsCache: function(item) {
|
3170 |
var cache = item._boundsCache; |
|
3171 |
if (cache) {
|
|
3172 |
item._bounds = item._position = item._boundsCache = undefined; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3173 |
for (var i = 0, list = cache.list, l = list.length; i < l; i++){
|
| 442 | 3174 |
var other = list[i]; |
3175 |
if (other !== item) {
|
|
3176 |
other._bounds = other._position = undefined; |
|
3177 |
if (other._boundsCache) |
|
3178 |
Item._clearBoundsCache(other); |
|
3179 |
} |
|
3180 |
} |
|
3181 |
} |
|
3182 |
} |
|
3183 |
} |
|
3184 |
||
3185 |
}), {
|
|
3186 |
beans: true, |
|
3187 |
||
3188 |
_decompose: function() {
|
|
3189 |
return this._decomposed = this._matrix.decompose(); |
|
3190 |
}, |
|
3191 |
||
3192 |
getRotation: function() {
|
|
3193 |
var decomposed = this._decomposed || this._decompose(); |
|
3194 |
return decomposed && decomposed.rotation; |
|
3195 |
}, |
|
3196 |
||
3197 |
setRotation: function(rotation) {
|
|
3198 |
var current = this.getRotation(); |
|
3199 |
if (current != null && rotation != null) {
|
|
3200 |
var decomposed = this._decomposed; |
|
3201 |
this.rotate(rotation - current); |
|
3202 |
decomposed.rotation = rotation; |
|
3203 |
this._decomposed = decomposed; |
|
3204 |
} |
|
3205 |
}, |
|
3206 |
||
3207 |
getScaling: function(_dontLink) {
|
|
3208 |
var decomposed = this._decomposed || this._decompose(), |
|
3209 |
scaling = decomposed && decomposed.scaling, |
|
3210 |
ctor = _dontLink ? Point : LinkedPoint; |
|
3211 |
return scaling && new ctor(scaling.x, scaling.y, this, 'setScaling'); |
|
3212 |
}, |
|
3213 |
||
3214 |
setScaling: function() {
|
|
3215 |
var current = this.getScaling(); |
|
3216 |
if (current) {
|
|
3217 |
var scaling = Point.read(arguments, 0, { clone: true }),
|
|
3218 |
decomposed = this._decomposed; |
|
3219 |
this.scale(scaling.x / current.x, scaling.y / current.y); |
|
3220 |
decomposed.scaling = scaling; |
|
3221 |
this._decomposed = decomposed; |
|
3222 |
} |
|
3223 |
}, |
|
3224 |
||
3225 |
getMatrix: function() {
|
|
3226 |
return this._matrix; |
|
3227 |
}, |
|
3228 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3229 |
setMatrix: function() {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3230 |
var matrix = this._matrix; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3231 |
matrix.initialize.apply(matrix, arguments); |
| 442 | 3232 |
if (this._applyMatrix) {
|
3233 |
this.transform(null, true); |
|
3234 |
} else {
|
|
3235 |
this._changed(9); |
|
3236 |
} |
|
3237 |
}, |
|
3238 |
||
3239 |
getGlobalMatrix: function(_dontClone) {
|
|
3240 |
var matrix = this._globalMatrix, |
|
3241 |
updateVersion = this._project._updateVersion; |
|
3242 |
if (matrix && matrix._updateVersion !== updateVersion) |
|
3243 |
matrix = null; |
|
3244 |
if (!matrix) {
|
|
3245 |
matrix = this._globalMatrix = this._matrix.clone(); |
|
3246 |
var parent = this._parent; |
|
3247 |
if (parent) |
|
3248 |
matrix.preConcatenate(parent.getGlobalMatrix(true)); |
|
3249 |
matrix._updateVersion = updateVersion; |
|
3250 |
} |
|
3251 |
return _dontClone ? matrix : matrix.clone(); |
|
3252 |
}, |
|
3253 |
||
3254 |
getApplyMatrix: function() {
|
|
3255 |
return this._applyMatrix; |
|
3256 |
}, |
|
3257 |
||
3258 |
setApplyMatrix: function(apply) {
|
|
3259 |
if (this._applyMatrix = this._canApplyMatrix && !!apply) |
|
3260 |
this.transform(null, true); |
|
3261 |
}, |
|
3262 |
||
3263 |
getTransformContent: '#getApplyMatrix', |
|
3264 |
setTransformContent: '#setApplyMatrix', |
|
3265 |
}, {
|
|
3266 |
getProject: function() {
|
|
3267 |
return this._project; |
|
3268 |
}, |
|
3269 |
||
3270 |
_setProject: function(project, installEvents) {
|
|
3271 |
if (this._project !== project) {
|
|
3272 |
if (this._project) |
|
3273 |
this._installEvents(false); |
|
3274 |
this._project = project; |
|
3275 |
var children = this._children; |
|
3276 |
for (var i = 0, l = children && children.length; i < l; i++) |
|
3277 |
children[i]._setProject(project); |
|
3278 |
installEvents = true; |
|
3279 |
} |
|
3280 |
if (installEvents) |
|
3281 |
this._installEvents(true); |
|
3282 |
}, |
|
3283 |
||
3284 |
getView: function() {
|
|
3285 |
return this._project.getView(); |
|
3286 |
}, |
|
3287 |
||
3288 |
_installEvents: function _installEvents(install) {
|
|
3289 |
_installEvents.base.call(this, install); |
|
3290 |
var children = this._children; |
|
3291 |
for (var i = 0, l = children && children.length; i < l; i++) |
|
3292 |
children[i]._installEvents(install); |
|
3293 |
}, |
|
3294 |
||
3295 |
getLayer: function() {
|
|
3296 |
var parent = this; |
|
3297 |
while (parent = parent._parent) {
|
|
3298 |
if (parent instanceof Layer) |
|
3299 |
return parent; |
|
3300 |
} |
|
3301 |
return null; |
|
3302 |
}, |
|
3303 |
||
3304 |
getParent: function() {
|
|
3305 |
return this._parent; |
|
3306 |
}, |
|
3307 |
||
3308 |
setParent: function(item) {
|
|
3309 |
return item.addChild(this); |
|
3310 |
}, |
|
3311 |
||
3312 |
getChildren: function() {
|
|
3313 |
return this._children; |
|
3314 |
}, |
|
3315 |
||
3316 |
setChildren: function(items) {
|
|
3317 |
this.removeChildren(); |
|
3318 |
this.addChildren(items); |
|
3319 |
}, |
|
3320 |
||
3321 |
getFirstChild: function() {
|
|
3322 |
return this._children && this._children[0] || null; |
|
3323 |
}, |
|
3324 |
||
3325 |
getLastChild: function() {
|
|
3326 |
return this._children && this._children[this._children.length - 1] |
|
3327 |
|| null; |
|
3328 |
}, |
|
3329 |
||
3330 |
getNextSibling: function() {
|
|
3331 |
return this._parent && this._parent._children[this._index + 1] || null; |
|
3332 |
}, |
|
3333 |
||
3334 |
getPreviousSibling: function() {
|
|
3335 |
return this._parent && this._parent._children[this._index - 1] || null; |
|
3336 |
}, |
|
3337 |
||
3338 |
getIndex: function() {
|
|
3339 |
return this._index; |
|
3340 |
}, |
|
3341 |
||
3342 |
equals: function(item) {
|
|
3343 |
return item === this || item && this._class === item._class |
|
3344 |
&& this._style.equals(item._style) |
|
3345 |
&& this._matrix.equals(item._matrix) |
|
3346 |
&& this._locked === item._locked |
|
3347 |
&& this._visible === item._visible |
|
3348 |
&& this._blendMode === item._blendMode |
|
3349 |
&& this._opacity === item._opacity |
|
3350 |
&& this._clipMask === item._clipMask |
|
3351 |
&& this._guide === item._guide |
|
3352 |
&& this._equals(item) |
|
3353 |
|| false; |
|
3354 |
}, |
|
3355 |
||
3356 |
_equals: function(item) {
|
|
3357 |
return Base.equals(this._children, item._children); |
|
3358 |
}, |
|
3359 |
||
3360 |
clone: function(insert) {
|
|
3361 |
return this._clone(new this.constructor(Item.NO_INSERT), insert); |
|
3362 |
}, |
|
3363 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3364 |
_clone: function(copy, insert, includeMatrix) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3365 |
var keys = ['_locked', '_visible', '_blendMode', '_opacity', |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3366 |
'_clipMask', '_guide'], |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3367 |
children = this._children; |
| 442 | 3368 |
copy.setStyle(this._style); |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3369 |
for (var i = 0, l = children && children.length; i < l; i++) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3370 |
copy.addChild(children[i].clone(false), true); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3371 |
} |
| 442 | 3372 |
for (var i = 0, l = keys.length; i < l; i++) {
|
3373 |
var key = keys[i]; |
|
3374 |
if (this.hasOwnProperty(key)) |
|
3375 |
copy[key] = this[key]; |
|
3376 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3377 |
if (includeMatrix !== false) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3378 |
copy._matrix.initialize(this._matrix); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3379 |
copy.setApplyMatrix(this._applyMatrix); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3380 |
copy.setPivot(this._pivot); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3381 |
copy.setSelected(this._selected); |
| 442 | 3382 |
copy._data = this._data ? Base.clone(this._data) : null; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3383 |
if (insert || insert === undefined) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3384 |
copy.insertAbove(this); |
| 442 | 3385 |
if (this._name) |
3386 |
copy.setName(this._name, true); |
|
3387 |
return copy; |
|
3388 |
}, |
|
3389 |
||
3390 |
copyTo: function(itemOrProject) {
|
|
3391 |
return itemOrProject.addChild(this.clone(false)); |
|
3392 |
}, |
|
3393 |
||
3394 |
rasterize: function(resolution) {
|
|
3395 |
var bounds = this.getStrokeBounds(), |
|
3396 |
scale = (resolution || this.getView().getResolution()) / 72, |
|
3397 |
topLeft = bounds.getTopLeft().floor(), |
|
3398 |
bottomRight = bounds.getBottomRight().ceil(), |
|
3399 |
size = new Size(bottomRight.subtract(topLeft)), |
|
3400 |
canvas = CanvasProvider.getCanvas(size.multiply(scale)), |
|
3401 |
ctx = canvas.getContext('2d'),
|
|
3402 |
matrix = new Matrix().scale(scale).translate(topLeft.negate()); |
|
3403 |
ctx.save(); |
|
3404 |
matrix.applyToContext(ctx); |
|
3405 |
this.draw(ctx, new Base({ matrices: [matrix] }));
|
|
3406 |
ctx.restore(); |
|
3407 |
var raster = new Raster(Item.NO_INSERT); |
|
3408 |
raster.setCanvas(canvas); |
|
3409 |
raster.transform(new Matrix().translate(topLeft.add(size.divide(2))) |
|
3410 |
.scale(1 / scale)); |
|
3411 |
raster.insertAbove(this); |
|
3412 |
return raster; |
|
3413 |
}, |
|
3414 |
||
3415 |
contains: function() {
|
|
3416 |
return !!this._contains( |
|
3417 |
this._matrix._inverseTransform(Point.read(arguments))); |
|
3418 |
}, |
|
3419 |
||
3420 |
_contains: function(point) {
|
|
3421 |
if (this._children) {
|
|
3422 |
for (var i = this._children.length - 1; i >= 0; i--) {
|
|
3423 |
if (this._children[i].contains(point)) |
|
3424 |
return true; |
|
3425 |
} |
|
3426 |
return false; |
|
3427 |
} |
|
3428 |
return point.isInside(this.getInternalBounds()); |
|
3429 |
}, |
|
3430 |
||
3431 |
isInside: function() {
|
|
3432 |
return Rectangle.read(arguments).contains(this.getBounds()); |
|
3433 |
}, |
|
3434 |
||
3435 |
_asPathItem: function() {
|
|
3436 |
return new Path.Rectangle({
|
|
3437 |
rectangle: this.getInternalBounds(), |
|
3438 |
matrix: this._matrix, |
|
3439 |
insert: false, |
|
3440 |
}); |
|
3441 |
}, |
|
3442 |
||
3443 |
intersects: function(item, _matrix) {
|
|
3444 |
if (!(item instanceof Item)) |
|
3445 |
return false; |
|
| 598 | 3446 |
return this._asPathItem().getIntersections(item._asPathItem(), null, |
3447 |
_matrix || item._matrix, true).length > 0; |
|
| 442 | 3448 |
}, |
3449 |
||
3450 |
hitTest: function() {
|
|
3451 |
return this._hitTest( |
|
3452 |
Point.read(arguments), |
|
3453 |
HitResult.getOptions(Base.read(arguments))); |
|
3454 |
}, |
|
3455 |
||
3456 |
_hitTest: function(point, options) {
|
|
3457 |
if (this._locked || !this._visible || this._guide && !options.guides |
|
3458 |
|| this.isEmpty()) |
|
3459 |
return null; |
|
3460 |
||
3461 |
var matrix = this._matrix, |
|
3462 |
parentTotalMatrix = options._totalMatrix, |
|
3463 |
view = this.getView(), |
|
3464 |
totalMatrix = options._totalMatrix = parentTotalMatrix |
|
3465 |
? parentTotalMatrix.chain(matrix) |
|
3466 |
: this.getGlobalMatrix().preConcatenate(view._matrix), |
|
3467 |
tolerancePadding = options._tolerancePadding = new Size( |
|
3468 |
Path._getPenPadding(1, totalMatrix.inverted()) |
|
3469 |
).multiply( |
|
| 598 | 3470 |
Math.max(options.tolerance, 1e-6) |
| 442 | 3471 |
); |
3472 |
point = matrix._inverseTransform(point); |
|
3473 |
||
3474 |
if (!this._children && !this.getInternalRoughBounds() |
|
3475 |
.expand(tolerancePadding.multiply(2))._containsPoint(point)) |
|
3476 |
return null; |
|
3477 |
var checkSelf = !(options.guides && !this._guide |
|
3478 |
|| options.selected && !this._selected |
|
3479 |
|| options.type && options.type !== Base.hyphenate(this._class) |
|
3480 |
|| options.class && !(this instanceof options.class)), |
|
3481 |
that = this, |
|
3482 |
res; |
|
3483 |
||
3484 |
function checkBounds(type, part) {
|
|
3485 |
var pt = bounds['get' + part](); |
|
3486 |
if (point.subtract(pt).divide(tolerancePadding).length <= 1) |
|
3487 |
return new HitResult(type, that, |
|
3488 |
{ name: Base.hyphenate(part), point: pt });
|
|
3489 |
} |
|
3490 |
||
3491 |
if (checkSelf && (options.center || options.bounds) && this._parent) {
|
|
3492 |
var bounds = this.getInternalBounds(); |
|
3493 |
if (options.center) |
|
3494 |
res = checkBounds('center', 'Center');
|
|
3495 |
if (!res && options.bounds) {
|
|
3496 |
var points = [ |
|
3497 |
'TopLeft', 'TopRight', 'BottomLeft', 'BottomRight', |
|
3498 |
'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter' |
|
3499 |
]; |
|
3500 |
for (var i = 0; i < 8 && !res; i++) |
|
3501 |
res = checkBounds('bounds', points[i]);
|
|
3502 |
} |
|
3503 |
} |
|
3504 |
||
3505 |
var children = !res && this._children; |
|
3506 |
if (children) {
|
|
3507 |
var opts = this._getChildHitTestOptions(options); |
|
3508 |
for (var i = children.length - 1; i >= 0 && !res; i--) |
|
3509 |
res = children[i]._hitTest(point, opts); |
|
3510 |
} |
|
3511 |
if (!res && checkSelf) |
|
3512 |
res = this._hitTestSelf(point, options); |
|
3513 |
if (res && res.point) |
|
3514 |
res.point = matrix.transform(res.point); |
|
3515 |
options._totalMatrix = parentTotalMatrix; |
|
3516 |
return res; |
|
3517 |
}, |
|
3518 |
||
3519 |
_getChildHitTestOptions: function(options) {
|
|
3520 |
return options; |
|
3521 |
}, |
|
3522 |
||
3523 |
_hitTestSelf: function(point, options) {
|
|
3524 |
if (options.fill && this.hasFill() && this._contains(point)) |
|
3525 |
return new HitResult('fill', this);
|
|
3526 |
}, |
|
3527 |
||
3528 |
matches: function(name, compare) {
|
|
3529 |
function matchObject(obj1, obj2) {
|
|
3530 |
for (var i in obj1) {
|
|
3531 |
if (obj1.hasOwnProperty(i)) {
|
|
3532 |
var val1 = obj1[i], |
|
3533 |
val2 = obj2[i]; |
|
3534 |
if (Base.isPlainObject(val1) && Base.isPlainObject(val2)) {
|
|
3535 |
if (!matchObject(val1, val2)) |
|
3536 |
return false; |
|
3537 |
} else if (!Base.equals(val1, val2)) {
|
|
3538 |
return false; |
|
3539 |
} |
|
3540 |
} |
|
3541 |
} |
|
3542 |
return true; |
|
3543 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3544 |
var type = typeof name; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3545 |
if (type === 'object') {
|
| 442 | 3546 |
for (var key in name) {
|
3547 |
if (name.hasOwnProperty(key) && !this.matches(key, name[key])) |
|
3548 |
return false; |
|
3549 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3550 |
} else if (type === 'function') {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3551 |
return name(this); |
| 442 | 3552 |
} else {
|
3553 |
var value = /^(empty|editable)$/.test(name) |
|
3554 |
? this['is' + Base.capitalize(name)]() |
|
3555 |
: name === 'type' |
|
3556 |
? Base.hyphenate(this._class) |
|
3557 |
: this[name]; |
|
3558 |
if (/^(constructor|class)$/.test(name)) {
|
|
3559 |
if (!(this instanceof compare)) |
|
3560 |
return false; |
|
3561 |
} else if (compare instanceof RegExp) {
|
|
3562 |
if (!compare.test(value)) |
|
3563 |
return false; |
|
3564 |
} else if (typeof compare === 'function') {
|
|
3565 |
if (!compare(value)) |
|
3566 |
return false; |
|
3567 |
} else if (Base.isPlainObject(compare)) {
|
|
3568 |
if (!matchObject(compare, value)) |
|
3569 |
return false; |
|
3570 |
} else if (!Base.equals(value, compare)) {
|
|
3571 |
return false; |
|
3572 |
} |
|
3573 |
} |
|
3574 |
return true; |
|
3575 |
}, |
|
3576 |
||
3577 |
getItems: function(match) {
|
|
3578 |
return Item._getItems(this._children, match, this._matrix); |
|
3579 |
}, |
|
3580 |
||
3581 |
getItem: function(match) {
|
|
3582 |
return Item._getItems(this._children, match, this._matrix, null, true) |
|
3583 |
[0] || null; |
|
3584 |
}, |
|
3585 |
||
3586 |
statics: {
|
|
3587 |
_getItems: function _getItems(children, match, matrix, param, |
|
3588 |
firstOnly) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3589 |
if (!param && typeof match === 'object') {
|
| 442 | 3590 |
var overlapping = match.overlapping, |
3591 |
inside = match.inside, |
|
3592 |
bounds = overlapping || inside, |
|
| 598 | 3593 |
rect = bounds && Rectangle.read([bounds]); |
| 442 | 3594 |
param = {
|
3595 |
items: [], |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3596 |
inside: !!inside, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3597 |
overlapping: !!overlapping, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3598 |
rect: rect, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3599 |
path: overlapping && new Path.Rectangle({
|
| 442 | 3600 |
rectangle: rect, |
3601 |
insert: false |
|
3602 |
}) |
|
3603 |
}; |
|
3604 |
if (bounds) |
|
3605 |
match = Base.set({}, match,
|
|
3606 |
{ inside: true, overlapping: true });
|
|
3607 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3608 |
var items = param && param.items, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3609 |
rect = param && param.rect; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3610 |
matrix = rect && (matrix || new Matrix()); |
| 442 | 3611 |
for (var i = 0, l = children && children.length; i < l; i++) {
|
3612 |
var child = children[i], |
|
3613 |
childMatrix = matrix && matrix.chain(child._matrix), |
|
3614 |
add = true; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3615 |
if (rect) {
|
| 442 | 3616 |
var bounds = child.getBounds(childMatrix); |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3617 |
if (!rect.intersects(bounds)) |
| 442 | 3618 |
continue; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3619 |
if (!(param.inside && rect.contains(bounds)) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3620 |
&& !(param.overlapping && (bounds.contains(rect) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
3621 |
|| param.path.intersects(child, childMatrix)))) |
| 442 | 3622 |
add = false; |
3623 |
} |
|
3624 |
if (add && child.matches(match)) {
|
|
3625 |
items.push(child); |
|
3626 |
if (firstOnly) |
|
3627 |
break; |
|
3628 |
} |
|
3629 |
_getItems(child._children, match, |
|
3630 |
childMatrix, param, |
|
3631 |
firstOnly); |
|
3632 |
if (firstOnly && items.length > 0) |
|
3633 |
break; |
|
3634 |
} |
|
3635 |
return items; |
|
3636 |
} |
|
3637 |
} |
|
3638 |
}, {
|
|
3639 |
||
3640 |
importJSON: function(json) {
|
|
3641 |
var res = Base.importJSON(json, this); |
|
3642 |
return res !== this |
|
3643 |
? this.addChild(res) |
|
3644 |
: res; |
|
3645 |
}, |
|
3646 |
||
3647 |
addChild: function(item, _preserve) {
|
|
3648 |
return this.insertChild(undefined, item, _preserve); |
|
3649 |
}, |
|
3650 |
||
3651 |
insertChild: function(index, item, _preserve) {
|
|
3652 |
var res = item ? this.insertChildren(index, [item], _preserve) : null; |
|
3653 |
return res && res[0]; |
|
3654 |
}, |
|
3655 |
||
3656 |
addChildren: function(items, _preserve) {
|
|
3657 |
return this.insertChildren(this._children.length, items, _preserve); |
|
3658 |
}, |
|
3659 |
||
3660 |
insertChildren: function(index, items, _preserve, _proto) {
|
|
3661 |
var children = this._children; |
|
3662 |
if (children && items && items.length > 0) {
|
|
3663 |
items = Array.prototype.slice.apply(items); |
|
3664 |
for (var i = items.length - 1; i >= 0; i--) {
|
|
3665 |
var item = items[i]; |
|
3666 |
if (_proto && !(item instanceof _proto)) {
|
|
3667 |
items.splice(i, 1); |
|
3668 |
} else {
|
|
3669 |
var shift = item._parent === this && item._index < index; |
|
3670 |
if (item._remove(false, true) && shift) |
|
3671 |
index--; |
|
3672 |
} |
|
3673 |
} |
|
3674 |
Base.splice(children, items, index, 0); |
|
3675 |
var project = this._project, |
|
3676 |
notifySelf = project && project._changes; |
|
3677 |
for (var i = 0, l = items.length; i < l; i++) {
|
|
3678 |
var item = items[i]; |
|
3679 |
item._parent = this; |
|
3680 |
item._setProject(this._project, true); |
|
3681 |
if (item._name) |
|
3682 |
item.setName(item._name); |
|
3683 |
if (notifySelf) |
|
3684 |
this._changed(5); |
|
3685 |
} |
|
3686 |
this._changed(11); |
|
3687 |
} else {
|
|
3688 |
items = null; |
|
3689 |
} |
|
3690 |
return items; |
|
3691 |
}, |
|
3692 |
||
3693 |
_insertSibling: function(index, item, _preserve) {
|
|
3694 |
return this._parent |
|
3695 |
? this._parent.insertChild(index, item, _preserve) |
|
3696 |
: null; |
|
3697 |
}, |
|
3698 |
||
3699 |
insertAbove: function(item, _preserve) {
|
|
3700 |
return item._insertSibling(item._index + 1, this, _preserve); |
|
3701 |
}, |
|
3702 |
||
3703 |
insertBelow: function(item, _preserve) {
|
|
3704 |
return item._insertSibling(item._index, this, _preserve); |
|
3705 |
}, |
|
3706 |
||
3707 |
sendToBack: function() {
|
|
3708 |
return (this._parent || this instanceof Layer && this._project) |
|
3709 |
.insertChild(0, this); |
|
3710 |
}, |
|
3711 |
||
3712 |
bringToFront: function() {
|
|
3713 |
return (this._parent || this instanceof Layer && this._project) |
|
3714 |
.addChild(this); |
|
3715 |
}, |
|
3716 |
||
3717 |
appendTop: '#addChild', |
|
3718 |
||
3719 |
appendBottom: function(item) {
|
|
3720 |
return this.insertChild(0, item); |
|
3721 |
}, |
|
3722 |
||
3723 |
moveAbove: '#insertAbove', |
|
3724 |
||
3725 |
moveBelow: '#insertBelow', |
|
3726 |
||
3727 |
reduce: function() {
|
|
3728 |
if (this._children && this._children.length === 1) {
|
|
3729 |
var child = this._children[0].reduce(); |
|
3730 |
child.insertAbove(this); |
|
3731 |
child.setStyle(this._style); |
|
3732 |
this.remove(); |
|
3733 |
return child; |
|
3734 |
} |
|
3735 |
return this; |
|
3736 |
}, |
|
3737 |
||
3738 |
_removeNamed: function() {
|
|
3739 |
var parent = this._parent; |
|
3740 |
if (parent) {
|
|
3741 |
var children = parent._children, |
|
3742 |
namedChildren = parent._namedChildren, |
|
3743 |
name = this._name, |
|
3744 |
namedArray = namedChildren[name], |
|
3745 |
index = namedArray ? namedArray.indexOf(this) : -1; |
|
3746 |
if (index !== -1) {
|
|
3747 |
if (children[name] == this) |
|
3748 |
delete children[name]; |
|
3749 |
namedArray.splice(index, 1); |
|
3750 |
if (namedArray.length) {
|
|
3751 |
children[name] = namedArray[namedArray.length - 1]; |
|
3752 |
} else {
|
|
3753 |
delete namedChildren[name]; |
|
3754 |
} |
|
3755 |
} |
|
3756 |
} |
|
3757 |
}, |
|
3758 |
||
3759 |
_remove: function(notifySelf, notifyParent) {
|
|
3760 |
var parent = this._parent; |
|
3761 |
if (parent) {
|
|
3762 |
if (this._name) |
|
3763 |
this._removeNamed(); |
|
3764 |
if (this._index != null) |
|
3765 |
Base.splice(parent._children, null, this._index, 1); |
|
3766 |
this._installEvents(false); |
|
3767 |
if (notifySelf) {
|
|
3768 |
var project = this._project; |
|
3769 |
if (project && project._changes) |
|
3770 |
this._changed(5); |
|
3771 |
} |
|
3772 |
if (notifyParent) |
|
3773 |
parent._changed(11); |
|
3774 |
this._parent = null; |
|
3775 |
return true; |
|
3776 |
} |
|
3777 |
return false; |
|
3778 |
}, |
|
3779 |
||
3780 |
remove: function() {
|
|
3781 |
return this._remove(true, true); |
|
3782 |
}, |
|
3783 |
||
3784 |
replaceWith: function(item) {
|
|
3785 |
var ok = item && item.insertBelow(this); |
|
3786 |
if (ok) |
|
3787 |
this.remove(); |
|
3788 |
return ok; |
|
3789 |
}, |
|
3790 |
||
3791 |
removeChildren: function(from, to) {
|
|
3792 |
if (!this._children) |
|
3793 |
return null; |
|
3794 |
from = from || 0; |
|
3795 |
to = Base.pick(to, this._children.length); |
|
3796 |
var removed = Base.splice(this._children, null, from, to - from); |
|
3797 |
for (var i = removed.length - 1; i >= 0; i--) {
|
|
3798 |
removed[i]._remove(true, false); |
|
3799 |
} |
|
3800 |
if (removed.length > 0) |
|
3801 |
this._changed(11); |
|
3802 |
return removed; |
|
3803 |
}, |
|
3804 |
||
3805 |
clear: '#removeChildren', |
|
3806 |
||
3807 |
reverseChildren: function() {
|
|
3808 |
if (this._children) {
|
|
3809 |
this._children.reverse(); |
|
3810 |
for (var i = 0, l = this._children.length; i < l; i++) |
|
3811 |
this._children[i]._index = i; |
|
3812 |
this._changed(11); |
|
3813 |
} |
|
3814 |
}, |
|
3815 |
||
3816 |
isEmpty: function() {
|
|
3817 |
return !this._children || this._children.length === 0; |
|
3818 |
}, |
|
3819 |
||
3820 |
isEditable: function() {
|
|
3821 |
var item = this; |
|
3822 |
while (item) {
|
|
3823 |
if (!item._visible || item._locked) |
|
3824 |
return false; |
|
3825 |
item = item._parent; |
|
3826 |
} |
|
3827 |
return true; |
|
3828 |
}, |
|
3829 |
||
3830 |
hasFill: function() {
|
|
3831 |
return this.getStyle().hasFill(); |
|
3832 |
}, |
|
3833 |
||
3834 |
hasStroke: function() {
|
|
3835 |
return this.getStyle().hasStroke(); |
|
3836 |
}, |
|
3837 |
||
3838 |
hasShadow: function() {
|
|
3839 |
return this.getStyle().hasShadow(); |
|
3840 |
}, |
|
3841 |
||
3842 |
_getOrder: function(item) {
|
|
3843 |
function getList(item) {
|
|
3844 |
var list = []; |
|
3845 |
do {
|
|
3846 |
list.unshift(item); |
|
3847 |
} while (item = item._parent); |
|
3848 |
return list; |
|
3849 |
} |
|
3850 |
var list1 = getList(this), |
|
3851 |
list2 = getList(item); |
|
3852 |
for (var i = 0, l = Math.min(list1.length, list2.length); i < l; i++) {
|
|
3853 |
if (list1[i] != list2[i]) {
|
|
3854 |
return list1[i]._index < list2[i]._index ? 1 : -1; |
|
3855 |
} |
|
3856 |
} |
|
3857 |
return 0; |
|
3858 |
}, |
|
3859 |
||
3860 |
hasChildren: function() {
|
|
3861 |
return this._children && this._children.length > 0; |
|
3862 |
}, |
|
3863 |
||
3864 |
isInserted: function() {
|
|
3865 |
return this._parent ? this._parent.isInserted() : false; |
|
3866 |
}, |
|
3867 |
||
3868 |
isAbove: function(item) {
|
|
3869 |
return this._getOrder(item) === -1; |
|
3870 |
}, |
|
3871 |
||
3872 |
isBelow: function(item) {
|
|
3873 |
return this._getOrder(item) === 1; |
|
3874 |
}, |
|
3875 |
||
3876 |
isParent: function(item) {
|
|
3877 |
return this._parent === item; |
|
3878 |
}, |
|
3879 |
||
3880 |
isChild: function(item) {
|
|
3881 |
return item && item._parent === this; |
|
3882 |
}, |
|
3883 |
||
3884 |
isDescendant: function(item) {
|
|
3885 |
var parent = this; |
|
3886 |
while (parent = parent._parent) {
|
|
3887 |
if (parent == item) |
|
3888 |
return true; |
|
3889 |
} |
|
3890 |
return false; |
|
3891 |
}, |
|
3892 |
||
3893 |
isAncestor: function(item) {
|
|
3894 |
return item ? item.isDescendant(this) : false; |
|
3895 |
}, |
|
3896 |
||
| 598 | 3897 |
isSibling: function(item) {
|
3898 |
return this._parent === item._parent; |
|
3899 |
}, |
|
3900 |
||
| 442 | 3901 |
isGroupedWith: function(item) {
|
3902 |
var parent = this._parent; |
|
3903 |
while (parent) {
|
|
3904 |
if (parent._parent |
|
3905 |
&& /^(Group|Layer|CompoundPath)$/.test(parent._class) |
|
3906 |
&& item.isDescendant(parent)) |
|
3907 |
return true; |
|
3908 |
parent = parent._parent; |
|
3909 |
} |
|
3910 |
return false; |
|
3911 |
}, |
|
3912 |
||
3913 |
translate: function() {
|
|
3914 |
var mx = new Matrix(); |
|
3915 |
return this.transform(mx.translate.apply(mx, arguments)); |
|
3916 |
}, |
|
3917 |
||
3918 |
rotate: function(angle ) {
|
|
3919 |
return this.transform(new Matrix().rotate(angle, |
|
3920 |
Point.read(arguments, 1, { readNull: true })
|
|
3921 |
|| this.getPosition(true))); |
|
3922 |
} |
|
3923 |
}, Base.each(['scale', 'shear', 'skew'], function(name) {
|
|
3924 |
this[name] = function() {
|
|
3925 |
var point = Point.read(arguments), |
|
3926 |
center = Point.read(arguments, 0, { readNull: true });
|
|
3927 |
return this.transform(new Matrix()[name](point, |
|
3928 |
center || this.getPosition(true))); |
|
3929 |
}; |
|
3930 |
}, {
|
|
3931 |
||
3932 |
}), {
|
|
3933 |
transform: function(matrix, _applyMatrix, _applyRecursively, |
|
3934 |
_setApplyMatrix) {
|
|
3935 |
if (matrix && matrix.isIdentity()) |
|
3936 |
matrix = null; |
|
3937 |
var _matrix = this._matrix, |
|
3938 |
applyMatrix = (_applyMatrix || this._applyMatrix) |
|
3939 |
&& ((!_matrix.isIdentity() || matrix) |
|
3940 |
|| _applyMatrix && _applyRecursively && this._children); |
|
3941 |
if (!matrix && !applyMatrix) |
|
3942 |
return this; |
|
3943 |
if (matrix) |
|
3944 |
_matrix.preConcatenate(matrix); |
|
3945 |
if (applyMatrix = applyMatrix && this._transformContent(_matrix, |
|
3946 |
_applyRecursively, _setApplyMatrix)) {
|
|
3947 |
var pivot = this._pivot, |
|
3948 |
style = this._style, |
|
3949 |
fillColor = style.getFillColor(true), |
|
3950 |
strokeColor = style.getStrokeColor(true); |
|
3951 |
if (pivot) |
|
3952 |
_matrix._transformPoint(pivot, pivot, true); |
|
3953 |
if (fillColor) |
|
3954 |
fillColor.transform(_matrix); |
|
3955 |
if (strokeColor) |
|
3956 |
strokeColor.transform(_matrix); |
|
3957 |
_matrix.reset(true); |
|
3958 |
if (_setApplyMatrix && this._canApplyMatrix) |
|
3959 |
this._applyMatrix = true; |
|
3960 |
} |
|
3961 |
var bounds = this._bounds, |
|
3962 |
position = this._position; |
|
3963 |
this._changed(9); |
|
3964 |
var decomp = bounds && matrix && matrix.decompose(); |
|
3965 |
if (decomp && !decomp.shearing && decomp.rotation % 90 === 0) {
|
|
3966 |
for (var key in bounds) {
|
|
3967 |
var rect = bounds[key]; |
|
3968 |
if (applyMatrix || !rect._internal) |
|
3969 |
matrix._transformBounds(rect, rect); |
|
3970 |
} |
|
3971 |
var getter = this._boundsGetter, |
|
3972 |
rect = bounds[getter && getter.getBounds || getter || 'getBounds']; |
|
3973 |
if (rect) |
|
3974 |
this._position = rect.getCenter(true); |
|
3975 |
this._bounds = bounds; |
|
3976 |
} else if (matrix && position) {
|
|
3977 |
this._position = matrix._transformPoint(position, position); |
|
3978 |
} |
|
3979 |
return this; |
|
3980 |
}, |
|
3981 |
||
3982 |
_transformContent: function(matrix, applyRecursively, setApplyMatrix) {
|
|
3983 |
var children = this._children; |
|
3984 |
if (children) {
|
|
3985 |
for (var i = 0, l = children.length; i < l; i++) |
|
3986 |
children[i].transform(matrix, true, applyRecursively, |
|
3987 |
setApplyMatrix); |
|
3988 |
return true; |
|
3989 |
} |
|
3990 |
}, |
|
3991 |
||
3992 |
globalToLocal: function() {
|
|
3993 |
return this.getGlobalMatrix(true)._inverseTransform( |
|
3994 |
Point.read(arguments)); |
|
3995 |
}, |
|
3996 |
||
3997 |
localToGlobal: function() {
|
|
3998 |
return this.getGlobalMatrix(true)._transformPoint( |
|
3999 |
Point.read(arguments)); |
|
4000 |
}, |
|
4001 |
||
4002 |
parentToLocal: function() {
|
|
4003 |
return this._matrix._inverseTransform(Point.read(arguments)); |
|
4004 |
}, |
|
4005 |
||
4006 |
localToParent: function() {
|
|
4007 |
return this._matrix._transformPoint(Point.read(arguments)); |
|
4008 |
}, |
|
4009 |
||
4010 |
fitBounds: function(rectangle, fill) {
|
|
4011 |
rectangle = Rectangle.read(arguments); |
|
4012 |
var bounds = this.getBounds(), |
|
4013 |
itemRatio = bounds.height / bounds.width, |
|
4014 |
rectRatio = rectangle.height / rectangle.width, |
|
4015 |
scale = (fill ? itemRatio > rectRatio : itemRatio < rectRatio) |
|
4016 |
? rectangle.width / bounds.width |
|
4017 |
: rectangle.height / bounds.height, |
|
4018 |
newBounds = new Rectangle(new Point(), |
|
4019 |
new Size(bounds.width * scale, bounds.height * scale)); |
|
4020 |
newBounds.setCenter(rectangle.getCenter()); |
|
4021 |
this.setBounds(newBounds); |
|
4022 |
}, |
|
4023 |
||
4024 |
_setStyles: function(ctx) {
|
|
4025 |
var style = this._style, |
|
4026 |
fillColor = style.getFillColor(), |
|
4027 |
strokeColor = style.getStrokeColor(), |
|
4028 |
shadowColor = style.getShadowColor(); |
|
4029 |
if (fillColor) |
|
4030 |
ctx.fillStyle = fillColor.toCanvasStyle(ctx); |
|
4031 |
if (strokeColor) {
|
|
4032 |
var strokeWidth = style.getStrokeWidth(); |
|
4033 |
if (strokeWidth > 0) {
|
|
4034 |
ctx.strokeStyle = strokeColor.toCanvasStyle(ctx); |
|
4035 |
ctx.lineWidth = strokeWidth; |
|
4036 |
var strokeJoin = style.getStrokeJoin(), |
|
4037 |
strokeCap = style.getStrokeCap(), |
|
4038 |
miterLimit = style.getMiterLimit(); |
|
4039 |
if (strokeJoin) |
|
4040 |
ctx.lineJoin = strokeJoin; |
|
4041 |
if (strokeCap) |
|
4042 |
ctx.lineCap = strokeCap; |
|
4043 |
if (miterLimit) |
|
4044 |
ctx.miterLimit = miterLimit; |
|
4045 |
if (paper.support.nativeDash) {
|
|
4046 |
var dashArray = style.getDashArray(), |
|
4047 |
dashOffset = style.getDashOffset(); |
|
4048 |
if (dashArray && dashArray.length) {
|
|
4049 |
if ('setLineDash' in ctx) {
|
|
4050 |
ctx.setLineDash(dashArray); |
|
4051 |
ctx.lineDashOffset = dashOffset; |
|
4052 |
} else {
|
|
4053 |
ctx.mozDash = dashArray; |
|
4054 |
ctx.mozDashOffset = dashOffset; |
|
4055 |
} |
|
4056 |
} |
|
4057 |
} |
|
4058 |
} |
|
4059 |
} |
|
4060 |
if (shadowColor) {
|
|
4061 |
var shadowBlur = style.getShadowBlur(); |
|
4062 |
if (shadowBlur > 0) {
|
|
4063 |
ctx.shadowColor = shadowColor.toCanvasStyle(ctx); |
|
4064 |
ctx.shadowBlur = shadowBlur; |
|
4065 |
var offset = this.getShadowOffset(); |
|
4066 |
ctx.shadowOffsetX = offset.x; |
|
4067 |
ctx.shadowOffsetY = offset.y; |
|
4068 |
} |
|
4069 |
} |
|
4070 |
}, |
|
4071 |
||
4072 |
draw: function(ctx, param, parentStrokeMatrix) {
|
|
4073 |
var updateVersion = this._updateVersion = this._project._updateVersion; |
|
4074 |
if (!this._visible || this._opacity === 0) |
|
4075 |
return; |
|
4076 |
var matrices = param.matrices, |
|
4077 |
viewMatrix = param.viewMatrix, |
|
4078 |
matrix = this._matrix, |
|
4079 |
globalMatrix = matrices[matrices.length - 1].chain(matrix); |
|
4080 |
if (!globalMatrix.isInvertible()) |
|
4081 |
return; |
|
4082 |
||
4083 |
function getViewMatrix(matrix) {
|
|
4084 |
return viewMatrix ? viewMatrix.chain(matrix) : matrix; |
|
4085 |
} |
|
4086 |
||
4087 |
matrices.push(globalMatrix); |
|
4088 |
if (param.updateMatrix) {
|
|
4089 |
globalMatrix._updateVersion = updateVersion; |
|
4090 |
this._globalMatrix = globalMatrix; |
|
4091 |
} |
|
4092 |
||
4093 |
var blendMode = this._blendMode, |
|
4094 |
opacity = this._opacity, |
|
4095 |
normalBlend = blendMode === 'normal', |
|
4096 |
nativeBlend = BlendMode.nativeModes[blendMode], |
|
4097 |
direct = normalBlend && opacity === 1 |
|
4098 |
|| param.dontStart |
|
4099 |
|| param.clip |
|
4100 |
|| (nativeBlend || normalBlend && opacity < 1) |
|
4101 |
&& this._canComposite(), |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4102 |
pixelRatio = param.pixelRatio || 1, |
| 442 | 4103 |
mainCtx, itemOffset, prevOffset; |
4104 |
if (!direct) {
|
|
4105 |
var bounds = this.getStrokeBounds(getViewMatrix(globalMatrix)); |
|
4106 |
if (!bounds.width || !bounds.height) |
|
4107 |
return; |
|
4108 |
prevOffset = param.offset; |
|
4109 |
itemOffset = param.offset = bounds.getTopLeft().floor(); |
|
4110 |
mainCtx = ctx; |
|
4111 |
ctx = CanvasProvider.getContext(bounds.getSize().ceil().add(1) |
|
4112 |
.multiply(pixelRatio)); |
|
4113 |
if (pixelRatio !== 1) |
|
4114 |
ctx.scale(pixelRatio, pixelRatio); |
|
4115 |
} |
|
4116 |
ctx.save(); |
|
4117 |
var strokeMatrix = parentStrokeMatrix |
|
4118 |
? parentStrokeMatrix.chain(matrix) |
|
4119 |
: !this.getStrokeScaling(true) && getViewMatrix(globalMatrix), |
|
4120 |
clip = !direct && param.clipItem, |
|
4121 |
transform = !strokeMatrix || clip; |
|
4122 |
if (direct) {
|
|
4123 |
ctx.globalAlpha = opacity; |
|
4124 |
if (nativeBlend) |
|
4125 |
ctx.globalCompositeOperation = blendMode; |
|
4126 |
} else if (transform) {
|
|
4127 |
ctx.translate(-itemOffset.x, -itemOffset.y); |
|
4128 |
} |
|
4129 |
if (transform) |
|
4130 |
(direct ? matrix : getViewMatrix(globalMatrix)).applyToContext(ctx); |
|
4131 |
if (clip) |
|
4132 |
param.clipItem.draw(ctx, param.extend({ clip: true }));
|
|
4133 |
if (strokeMatrix) {
|
|
4134 |
ctx.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0); |
|
4135 |
var offset = param.offset; |
|
4136 |
if (offset) |
|
4137 |
ctx.translate(-offset.x, -offset.y); |
|
4138 |
} |
|
4139 |
this._draw(ctx, param, strokeMatrix); |
|
4140 |
ctx.restore(); |
|
4141 |
matrices.pop(); |
|
4142 |
if (param.clip && !param.dontFinish) |
|
4143 |
ctx.clip(); |
|
4144 |
if (!direct) {
|
|
4145 |
BlendMode.process(blendMode, ctx, mainCtx, opacity, |
|
4146 |
itemOffset.subtract(prevOffset).multiply(pixelRatio)); |
|
4147 |
CanvasProvider.release(ctx); |
|
4148 |
param.offset = prevOffset; |
|
4149 |
} |
|
4150 |
}, |
|
4151 |
||
4152 |
_isUpdated: function(updateVersion) {
|
|
4153 |
var parent = this._parent; |
|
4154 |
if (parent instanceof CompoundPath) |
|
4155 |
return parent._isUpdated(updateVersion); |
|
4156 |
var updated = this._updateVersion === updateVersion; |
|
4157 |
if (!updated && parent && parent._visible |
|
4158 |
&& parent._isUpdated(updateVersion)) {
|
|
4159 |
this._updateVersion = updateVersion; |
|
4160 |
updated = true; |
|
4161 |
} |
|
4162 |
return updated; |
|
4163 |
}, |
|
4164 |
||
4165 |
_drawSelection: function(ctx, matrix, size, selectedItems, updateVersion) {
|
|
4166 |
if ((this._drawSelected || this._boundsSelected) |
|
4167 |
&& this._isUpdated(updateVersion)) {
|
|
4168 |
var color = this.getSelectedColor(true) |
|
4169 |
|| this.getLayer().getSelectedColor(true), |
|
4170 |
mx = matrix.chain(this.getGlobalMatrix(true)); |
|
4171 |
ctx.strokeStyle = ctx.fillStyle = color |
|
4172 |
? color.toCanvasStyle(ctx) : '#009dec'; |
|
4173 |
if (this._drawSelected) |
|
4174 |
this._drawSelected(ctx, mx, selectedItems); |
|
4175 |
if (this._boundsSelected) {
|
|
| 598 | 4176 |
var half = size / 2, |
| 442 | 4177 |
coords = mx._transformCorners(this.getInternalBounds()); |
4178 |
ctx.beginPath(); |
|
4179 |
for (var i = 0; i < 8; i++) |
|
4180 |
ctx[i === 0 ? 'moveTo' : 'lineTo'](coords[i], coords[++i]); |
|
4181 |
ctx.closePath(); |
|
4182 |
ctx.stroke(); |
|
4183 |
for (var i = 0; i < 8; i++) |
|
4184 |
ctx.fillRect(coords[i] - half, coords[++i] - half, |
|
4185 |
size, size); |
|
4186 |
} |
|
4187 |
} |
|
4188 |
}, |
|
4189 |
||
4190 |
_canComposite: function() {
|
|
4191 |
return false; |
|
4192 |
} |
|
4193 |
}, Base.each(['down', 'drag', 'up', 'move'], function(name) {
|
|
4194 |
this['removeOn' + Base.capitalize(name)] = function() {
|
|
4195 |
var hash = {};
|
|
4196 |
hash[name] = true; |
|
4197 |
return this.removeOn(hash); |
|
4198 |
}; |
|
4199 |
}, {
|
|
4200 |
||
4201 |
removeOn: function(obj) {
|
|
4202 |
for (var name in obj) {
|
|
4203 |
if (obj[name]) {
|
|
4204 |
var key = 'mouse' + name, |
|
4205 |
project = this._project, |
|
4206 |
sets = project._removeSets = project._removeSets || {};
|
|
4207 |
sets[key] = sets[key] || {};
|
|
4208 |
sets[key][this._id] = this; |
|
4209 |
} |
|
4210 |
} |
|
4211 |
return this; |
|
4212 |
} |
|
4213 |
})); |
|
4214 |
||
4215 |
var Group = Item.extend({
|
|
4216 |
_class: 'Group', |
|
4217 |
_selectChildren: true, |
|
4218 |
_serializeFields: {
|
|
4219 |
children: [] |
|
4220 |
}, |
|
4221 |
||
4222 |
initialize: function Group(arg) {
|
|
4223 |
this._children = []; |
|
4224 |
this._namedChildren = {};
|
|
4225 |
if (!this._initialize(arg)) |
|
4226 |
this.addChildren(Array.isArray(arg) ? arg : arguments); |
|
4227 |
}, |
|
4228 |
||
4229 |
_changed: function _changed(flags) {
|
|
4230 |
_changed.base.call(this, flags); |
|
4231 |
if (flags & 1026) {
|
|
4232 |
this._clipItem = undefined; |
|
4233 |
} |
|
4234 |
}, |
|
4235 |
||
4236 |
_getClipItem: function() {
|
|
4237 |
var clipItem = this._clipItem; |
|
4238 |
if (clipItem === undefined) {
|
|
4239 |
clipItem = null; |
|
4240 |
for (var i = 0, l = this._children.length; i < l; i++) {
|
|
4241 |
var child = this._children[i]; |
|
4242 |
if (child._clipMask) {
|
|
4243 |
clipItem = child; |
|
4244 |
break; |
|
4245 |
} |
|
4246 |
} |
|
4247 |
this._clipItem = clipItem; |
|
4248 |
} |
|
4249 |
return clipItem; |
|
4250 |
}, |
|
4251 |
||
4252 |
isClipped: function() {
|
|
4253 |
return !!this._getClipItem(); |
|
4254 |
}, |
|
4255 |
||
4256 |
setClipped: function(clipped) {
|
|
4257 |
var child = this.getFirstChild(); |
|
4258 |
if (child) |
|
4259 |
child.setClipMask(clipped); |
|
4260 |
}, |
|
4261 |
||
4262 |
_draw: function(ctx, param) {
|
|
4263 |
var clip = param.clip, |
|
4264 |
clipItem = !clip && this._getClipItem(), |
|
4265 |
draw = true; |
|
4266 |
param = param.extend({ clipItem: clipItem, clip: false });
|
|
4267 |
if (clip) {
|
|
4268 |
if (this._currentPath) {
|
|
4269 |
ctx.currentPath = this._currentPath; |
|
4270 |
draw = false; |
|
4271 |
} else {
|
|
4272 |
ctx.beginPath(); |
|
4273 |
param.dontStart = param.dontFinish = true; |
|
4274 |
} |
|
4275 |
} else if (clipItem) {
|
|
4276 |
clipItem.draw(ctx, param.extend({ clip: true }));
|
|
4277 |
} |
|
4278 |
if (draw) {
|
|
4279 |
for (var i = 0, l = this._children.length; i < l; i++) {
|
|
4280 |
var item = this._children[i]; |
|
4281 |
if (item !== clipItem) |
|
4282 |
item.draw(ctx, param); |
|
4283 |
} |
|
4284 |
} |
|
4285 |
if (clip) {
|
|
4286 |
this._currentPath = ctx.currentPath; |
|
4287 |
} |
|
4288 |
} |
|
4289 |
}); |
|
4290 |
||
4291 |
var Layer = Group.extend({
|
|
4292 |
_class: 'Layer', |
|
4293 |
||
4294 |
initialize: function Layer(arg) {
|
|
4295 |
var props = Base.isPlainObject(arg) |
|
4296 |
? new Base(arg) |
|
4297 |
: { children: Array.isArray(arg) ? arg : arguments },
|
|
4298 |
insert = props.insert; |
|
4299 |
props.insert = false; |
|
4300 |
Group.call(this, props); |
|
4301 |
if (insert || insert === undefined) {
|
|
4302 |
this._project.addChild(this); |
|
4303 |
this.activate(); |
|
4304 |
} |
|
4305 |
}, |
|
4306 |
||
4307 |
_remove: function _remove(notifySelf, notifyParent) {
|
|
4308 |
if (this._parent) |
|
4309 |
return _remove.base.call(this, notifySelf, notifyParent); |
|
4310 |
if (this._index != null) {
|
|
4311 |
var project = this._project; |
|
4312 |
if (project._activeLayer === this) |
|
4313 |
project._activeLayer = this.getNextSibling() |
|
4314 |
|| this.getPreviousSibling(); |
|
4315 |
Base.splice(project.layers, null, this._index, 1); |
|
4316 |
this._installEvents(false); |
|
4317 |
if (notifySelf && project._changes) |
|
4318 |
this._changed(5); |
|
4319 |
if (notifyParent) {
|
|
4320 |
project._needsUpdate = true; |
|
4321 |
} |
|
4322 |
return true; |
|
4323 |
} |
|
4324 |
return false; |
|
4325 |
}, |
|
4326 |
||
4327 |
getNextSibling: function getNextSibling() {
|
|
4328 |
return this._parent ? getNextSibling.base.call(this) |
|
4329 |
: this._project.layers[this._index + 1] || null; |
|
4330 |
}, |
|
4331 |
||
4332 |
getPreviousSibling: function getPreviousSibling() {
|
|
4333 |
return this._parent ? getPreviousSibling.base.call(this) |
|
4334 |
: this._project.layers[this._index - 1] || null; |
|
4335 |
}, |
|
4336 |
||
4337 |
isInserted: function isInserted() {
|
|
4338 |
return this._parent ? isInserted.base.call(this) : this._index != null; |
|
4339 |
}, |
|
4340 |
||
4341 |
activate: function() {
|
|
4342 |
this._project._activeLayer = this; |
|
4343 |
}, |
|
4344 |
||
4345 |
_insertSibling: function _insertSibling(index, item, _preserve) {
|
|
4346 |
return !this._parent |
|
4347 |
? this._project.insertChild(index, item, _preserve) |
|
4348 |
: _insertSibling.base.call(this, index, item, _preserve); |
|
4349 |
} |
|
4350 |
}); |
|
4351 |
||
4352 |
var Shape = Item.extend({
|
|
4353 |
_class: 'Shape', |
|
4354 |
_applyMatrix: false, |
|
4355 |
_canApplyMatrix: false, |
|
4356 |
_boundsSelected: true, |
|
4357 |
_serializeFields: {
|
|
4358 |
type: null, |
|
4359 |
size: null, |
|
4360 |
radius: null |
|
4361 |
}, |
|
4362 |
||
4363 |
initialize: function Shape(props) {
|
|
4364 |
this._initialize(props); |
|
4365 |
}, |
|
4366 |
||
4367 |
_equals: function(item) {
|
|
4368 |
return this._type === item._type |
|
4369 |
&& this._size.equals(item._size) |
|
4370 |
&& Base.equals(this._radius, item._radius); |
|
4371 |
}, |
|
4372 |
||
4373 |
clone: function(insert) {
|
|
4374 |
var copy = new Shape(Item.NO_INSERT); |
|
4375 |
copy.setType(this._type); |
|
4376 |
copy.setSize(this._size); |
|
4377 |
copy.setRadius(this._radius); |
|
4378 |
return this._clone(copy, insert); |
|
4379 |
}, |
|
4380 |
||
4381 |
getType: function() {
|
|
4382 |
return this._type; |
|
4383 |
}, |
|
4384 |
||
4385 |
setType: function(type) {
|
|
4386 |
this._type = type; |
|
4387 |
}, |
|
4388 |
||
4389 |
getShape: '#getType', |
|
4390 |
setShape: '#setType', |
|
4391 |
||
4392 |
getSize: function() {
|
|
4393 |
var size = this._size; |
|
4394 |
return new LinkedSize(size.width, size.height, this, 'setSize'); |
|
4395 |
}, |
|
4396 |
||
4397 |
setSize: function() {
|
|
4398 |
var size = Size.read(arguments); |
|
4399 |
if (!this._size) {
|
|
4400 |
this._size = size.clone(); |
|
4401 |
} else if (!this._size.equals(size)) {
|
|
4402 |
var type = this._type, |
|
4403 |
width = size.width, |
|
4404 |
height = size.height; |
|
4405 |
if (type === 'rectangle') {
|
|
4406 |
var radius = Size.min(this._radius, size.divide(2)); |
|
4407 |
this._radius.set(radius.width, radius.height); |
|
4408 |
} else if (type === 'circle') {
|
|
4409 |
width = height = (width + height) / 2; |
|
4410 |
this._radius = width / 2; |
|
4411 |
} else if (type === 'ellipse') {
|
|
4412 |
this._radius.set(width / 2, height / 2); |
|
4413 |
} |
|
4414 |
this._size.set(width, height); |
|
4415 |
this._changed(9); |
|
4416 |
} |
|
4417 |
}, |
|
4418 |
||
4419 |
getRadius: function() {
|
|
4420 |
var rad = this._radius; |
|
4421 |
return this._type === 'circle' |
|
4422 |
? rad |
|
4423 |
: new LinkedSize(rad.width, rad.height, this, 'setRadius'); |
|
4424 |
}, |
|
4425 |
||
4426 |
setRadius: function(radius) {
|
|
4427 |
var type = this._type; |
|
4428 |
if (type === 'circle') {
|
|
4429 |
if (radius === this._radius) |
|
4430 |
return; |
|
4431 |
var size = radius * 2; |
|
4432 |
this._radius = radius; |
|
4433 |
this._size.set(size, size); |
|
4434 |
} else {
|
|
4435 |
radius = Size.read(arguments); |
|
4436 |
if (!this._radius) {
|
|
4437 |
this._radius = radius.clone(); |
|
4438 |
} else {
|
|
4439 |
if (this._radius.equals(radius)) |
|
4440 |
return; |
|
4441 |
this._radius.set(radius.width, radius.height); |
|
4442 |
if (type === 'rectangle') {
|
|
4443 |
var size = Size.max(this._size, radius.multiply(2)); |
|
4444 |
this._size.set(size.width, size.height); |
|
4445 |
} else if (type === 'ellipse') {
|
|
4446 |
this._size.set(radius.width * 2, radius.height * 2); |
|
4447 |
} |
|
4448 |
} |
|
4449 |
} |
|
4450 |
this._changed(9); |
|
4451 |
}, |
|
4452 |
||
4453 |
isEmpty: function() {
|
|
4454 |
return false; |
|
4455 |
}, |
|
4456 |
||
4457 |
toPath: function(insert) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4458 |
var path = this._clone(new Path[Base.capitalize(this._type)]({
|
| 442 | 4459 |
center: new Point(), |
4460 |
size: this._size, |
|
4461 |
radius: this._radius, |
|
4462 |
insert: false |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4463 |
}), insert); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4464 |
if (paper.settings.applyMatrix) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4465 |
path.setApplyMatrix(true); |
| 442 | 4466 |
return path; |
4467 |
}, |
|
4468 |
||
4469 |
_draw: function(ctx, param, strokeMatrix) {
|
|
4470 |
var style = this._style, |
|
4471 |
hasFill = style.hasFill(), |
|
4472 |
hasStroke = style.hasStroke(), |
|
4473 |
dontPaint = param.dontFinish || param.clip, |
|
4474 |
untransformed = !strokeMatrix; |
|
4475 |
if (hasFill || hasStroke || dontPaint) {
|
|
4476 |
var type = this._type, |
|
4477 |
radius = this._radius, |
|
4478 |
isCircle = type === 'circle'; |
|
4479 |
if (!param.dontStart) |
|
4480 |
ctx.beginPath(); |
|
4481 |
if (untransformed && isCircle) {
|
|
4482 |
ctx.arc(0, 0, radius, 0, Math.PI * 2, true); |
|
4483 |
} else {
|
|
4484 |
var rx = isCircle ? radius : radius.width, |
|
4485 |
ry = isCircle ? radius : radius.height, |
|
4486 |
size = this._size, |
|
4487 |
width = size.width, |
|
4488 |
height = size.height; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4489 |
if (untransformed && type === 'rectangle' && rx === 0 && ry === 0) {
|
| 442 | 4490 |
ctx.rect(-width / 2, -height / 2, width, height); |
4491 |
} else {
|
|
4492 |
var x = width / 2, |
|
4493 |
y = height / 2, |
|
4494 |
kappa = 1 - 0.5522847498307936, |
|
4495 |
cx = rx * kappa, |
|
4496 |
cy = ry * kappa, |
|
4497 |
c = [ |
|
4498 |
-x, -y + ry, |
|
4499 |
-x, -y + cy, |
|
4500 |
-x + cx, -y, |
|
4501 |
-x + rx, -y, |
|
4502 |
x - rx, -y, |
|
4503 |
x - cx, -y, |
|
4504 |
x, -y + cy, |
|
4505 |
x, -y + ry, |
|
4506 |
x, y - ry, |
|
4507 |
x, y - cy, |
|
4508 |
x - cx, y, |
|
4509 |
x - rx, y, |
|
4510 |
-x + rx, y, |
|
4511 |
-x + cx, y, |
|
4512 |
-x, y - cy, |
|
4513 |
-x, y - ry |
|
4514 |
]; |
|
4515 |
if (strokeMatrix) |
|
4516 |
strokeMatrix.transform(c, c, 32); |
|
4517 |
ctx.moveTo(c[0], c[1]); |
|
4518 |
ctx.bezierCurveTo(c[2], c[3], c[4], c[5], c[6], c[7]); |
|
4519 |
if (x !== rx) |
|
4520 |
ctx.lineTo(c[8], c[9]); |
|
4521 |
ctx.bezierCurveTo(c[10], c[11], c[12], c[13], c[14], c[15]); |
|
4522 |
if (y !== ry) |
|
4523 |
ctx.lineTo(c[16], c[17]); |
|
4524 |
ctx.bezierCurveTo(c[18], c[19], c[20], c[21], c[22], c[23]); |
|
4525 |
if (x !== rx) |
|
4526 |
ctx.lineTo(c[24], c[25]); |
|
4527 |
ctx.bezierCurveTo(c[26], c[27], c[28], c[29], c[30], c[31]); |
|
4528 |
} |
|
4529 |
} |
|
4530 |
ctx.closePath(); |
|
4531 |
} |
|
4532 |
if (!dontPaint && (hasFill || hasStroke)) {
|
|
4533 |
this._setStyles(ctx); |
|
4534 |
if (hasFill) {
|
|
4535 |
ctx.fill(style.getWindingRule()); |
|
4536 |
ctx.shadowColor = 'rgba(0,0,0,0)'; |
|
4537 |
} |
|
4538 |
if (hasStroke) |
|
4539 |
ctx.stroke(); |
|
4540 |
} |
|
4541 |
}, |
|
4542 |
||
4543 |
_canComposite: function() {
|
|
4544 |
return !(this.hasFill() && this.hasStroke()); |
|
4545 |
}, |
|
4546 |
||
4547 |
_getBounds: function(getter, matrix) {
|
|
4548 |
var rect = new Rectangle(this._size).setCenter(0, 0); |
|
4549 |
if (getter !== 'getBounds' && this.hasStroke()) |
|
4550 |
rect = rect.expand(this.getStrokeWidth()); |
|
4551 |
return matrix ? matrix._transformBounds(rect) : rect; |
|
4552 |
} |
|
4553 |
}, |
|
4554 |
new function() {
|
|
4555 |
function getCornerCenter(that, point, expand) {
|
|
4556 |
var radius = that._radius; |
|
4557 |
if (!radius.isZero()) {
|
|
4558 |
var halfSize = that._size.divide(2); |
|
4559 |
for (var i = 0; i < 4; i++) {
|
|
4560 |
var dir = new Point(i & 1 ? 1 : -1, i > 1 ? 1 : -1), |
|
4561 |
corner = dir.multiply(halfSize), |
|
4562 |
center = corner.subtract(dir.multiply(radius)), |
|
4563 |
rect = new Rectangle(corner, center); |
|
4564 |
if ((expand ? rect.expand(expand) : rect).contains(point)) |
|
4565 |
return center; |
|
4566 |
} |
|
4567 |
} |
|
4568 |
} |
|
4569 |
||
4570 |
function getEllipseRadius(point, radius) {
|
|
4571 |
var angle = point.getAngleInRadians(), |
|
4572 |
width = radius.width * 2, |
|
4573 |
height = radius.height * 2, |
|
4574 |
x = width * Math.sin(angle), |
|
4575 |
y = height * Math.cos(angle); |
|
4576 |
return width * height / (2 * Math.sqrt(x * x + y * y)); |
|
4577 |
} |
|
4578 |
||
4579 |
return {
|
|
4580 |
_contains: function _contains(point) {
|
|
4581 |
if (this._type === 'rectangle') {
|
|
4582 |
var center = getCornerCenter(this, point); |
|
4583 |
return center |
|
4584 |
? point.subtract(center).divide(this._radius) |
|
4585 |
.getLength() <= 1 |
|
4586 |
: _contains.base.call(this, point); |
|
4587 |
} else {
|
|
4588 |
return point.divide(this.size).getLength() <= 0.5; |
|
4589 |
} |
|
4590 |
}, |
|
4591 |
||
4592 |
_hitTestSelf: function _hitTestSelf(point, options) {
|
|
4593 |
var hit = false; |
|
4594 |
if (this.hasStroke()) {
|
|
4595 |
var type = this._type, |
|
4596 |
radius = this._radius, |
|
4597 |
strokeWidth = this.getStrokeWidth() + 2 * options.tolerance; |
|
4598 |
if (type === 'rectangle') {
|
|
4599 |
var center = getCornerCenter(this, point, strokeWidth); |
|
4600 |
if (center) {
|
|
4601 |
var pt = point.subtract(center); |
|
4602 |
hit = 2 * Math.abs(pt.getLength() |
|
4603 |
- getEllipseRadius(pt, radius)) <= strokeWidth; |
|
4604 |
} else {
|
|
4605 |
var rect = new Rectangle(this._size).setCenter(0, 0), |
|
4606 |
outer = rect.expand(strokeWidth), |
|
4607 |
inner = rect.expand(-strokeWidth); |
|
4608 |
hit = outer._containsPoint(point) |
|
4609 |
&& !inner._containsPoint(point); |
|
4610 |
} |
|
4611 |
} else {
|
|
4612 |
if (type === 'ellipse') |
|
4613 |
radius = getEllipseRadius(point, radius); |
|
4614 |
hit = 2 * Math.abs(point.getLength() - radius) |
|
4615 |
<= strokeWidth; |
|
4616 |
} |
|
4617 |
} |
|
4618 |
return hit |
|
4619 |
? new HitResult('stroke', this)
|
|
4620 |
: _hitTestSelf.base.apply(this, arguments); |
|
4621 |
} |
|
4622 |
}; |
|
4623 |
}, {
|
|
4624 |
||
4625 |
statics: new function() {
|
|
4626 |
function createShape(type, point, size, radius, args) {
|
|
4627 |
var item = new Shape(Base.getNamed(args)); |
|
4628 |
item._type = type; |
|
4629 |
item._size = size; |
|
4630 |
item._radius = radius; |
|
4631 |
return item.translate(point); |
|
4632 |
} |
|
4633 |
||
4634 |
return {
|
|
4635 |
Circle: function() {
|
|
4636 |
var center = Point.readNamed(arguments, 'center'), |
|
4637 |
radius = Base.readNamed(arguments, 'radius'); |
|
4638 |
return createShape('circle', center, new Size(radius * 2), radius,
|
|
4639 |
arguments); |
|
4640 |
}, |
|
4641 |
||
4642 |
Rectangle: function() {
|
|
4643 |
var rect = Rectangle.readNamed(arguments, 'rectangle'), |
|
4644 |
radius = Size.min(Size.readNamed(arguments, 'radius'), |
|
4645 |
rect.getSize(true).divide(2)); |
|
4646 |
return createShape('rectangle', rect.getCenter(true),
|
|
4647 |
rect.getSize(true), radius, arguments); |
|
4648 |
}, |
|
4649 |
||
4650 |
Ellipse: function() {
|
|
4651 |
var ellipse = Shape._readEllipse(arguments), |
|
4652 |
radius = ellipse.radius; |
|
4653 |
return createShape('ellipse', ellipse.center, radius.multiply(2),
|
|
4654 |
radius, arguments); |
|
4655 |
}, |
|
4656 |
||
4657 |
_readEllipse: function(args) {
|
|
4658 |
var center, |
|
4659 |
radius; |
|
4660 |
if (Base.hasNamed(args, 'radius')) {
|
|
4661 |
center = Point.readNamed(args, 'center'); |
|
4662 |
radius = Size.readNamed(args, 'radius'); |
|
4663 |
} else {
|
|
4664 |
var rect = Rectangle.readNamed(args, 'rectangle'); |
|
4665 |
center = rect.getCenter(true); |
|
4666 |
radius = rect.getSize(true).divide(2); |
|
4667 |
} |
|
4668 |
return { center: center, radius: radius };
|
|
4669 |
} |
|
4670 |
}; |
|
4671 |
}}); |
|
4672 |
||
4673 |
var Raster = Item.extend({
|
|
4674 |
_class: 'Raster', |
|
4675 |
_applyMatrix: false, |
|
4676 |
_canApplyMatrix: false, |
|
4677 |
_boundsGetter: 'getBounds', |
|
4678 |
_boundsSelected: true, |
|
4679 |
_serializeFields: {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4680 |
crossOrigin: null, |
| 442 | 4681 |
source: null |
4682 |
}, |
|
4683 |
||
4684 |
initialize: function Raster(object, position) {
|
|
4685 |
if (!this._initialize(object, |
|
4686 |
position !== undefined && Point.read(arguments, 1))) {
|
|
4687 |
if (typeof object === 'string') {
|
|
4688 |
this.setSource(object); |
|
4689 |
} else {
|
|
4690 |
this.setImage(object); |
|
4691 |
} |
|
4692 |
} |
|
4693 |
if (!this._size) {
|
|
4694 |
this._size = new Size(); |
|
4695 |
this._loaded = false; |
|
4696 |
} |
|
4697 |
}, |
|
4698 |
||
4699 |
_equals: function(item) {
|
|
4700 |
return this.getSource() === item.getSource(); |
|
4701 |
}, |
|
4702 |
||
4703 |
clone: function(insert) {
|
|
4704 |
var copy = new Raster(Item.NO_INSERT), |
|
4705 |
image = this._image, |
|
4706 |
canvas = this._canvas; |
|
4707 |
if (image) {
|
|
4708 |
copy.setImage(image); |
|
4709 |
} else if (canvas) {
|
|
4710 |
var copyCanvas = CanvasProvider.getCanvas(this._size); |
|
4711 |
copyCanvas.getContext('2d').drawImage(canvas, 0, 0);
|
|
4712 |
copy.setImage(copyCanvas); |
|
4713 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4714 |
copy._crossOrigin = this._crossOrigin; |
| 442 | 4715 |
return this._clone(copy, insert); |
4716 |
}, |
|
4717 |
||
4718 |
getSize: function() {
|
|
4719 |
var size = this._size; |
|
4720 |
return new LinkedSize(size ? size.width : 0, size ? size.height : 0, |
|
4721 |
this, 'setSize'); |
|
4722 |
}, |
|
4723 |
||
4724 |
setSize: function() {
|
|
4725 |
var size = Size.read(arguments); |
|
4726 |
if (!size.equals(this._size)) {
|
|
4727 |
if (size.width > 0 && size.height > 0) {
|
|
4728 |
var element = this.getElement(); |
|
4729 |
this.setImage(CanvasProvider.getCanvas(size)); |
|
4730 |
if (element) |
|
4731 |
this.getContext(true).drawImage(element, 0, 0, |
|
4732 |
size.width, size.height); |
|
4733 |
} else {
|
|
4734 |
if (this._canvas) |
|
4735 |
CanvasProvider.release(this._canvas); |
|
4736 |
this._size = size.clone(); |
|
4737 |
} |
|
4738 |
} |
|
4739 |
}, |
|
4740 |
||
4741 |
getWidth: function() {
|
|
4742 |
return this._size ? this._size.width : 0; |
|
4743 |
}, |
|
4744 |
||
4745 |
setWidth: function(width) {
|
|
4746 |
this.setSize(width, this.getHeight()); |
|
4747 |
}, |
|
4748 |
||
4749 |
getHeight: function() {
|
|
4750 |
return this._size ? this._size.height : 0; |
|
4751 |
}, |
|
4752 |
||
4753 |
setHeight: function(height) {
|
|
4754 |
this.setSize(this.getWidth(), height); |
|
4755 |
}, |
|
4756 |
||
4757 |
isEmpty: function() {
|
|
4758 |
var size = this._size; |
|
4759 |
return !size || size.width === 0 && size.height === 0; |
|
4760 |
}, |
|
4761 |
||
4762 |
getResolution: function() {
|
|
4763 |
var matrix = this._matrix, |
|
4764 |
orig = new Point(0, 0).transform(matrix), |
|
4765 |
u = new Point(1, 0).transform(matrix).subtract(orig), |
|
4766 |
v = new Point(0, 1).transform(matrix).subtract(orig); |
|
4767 |
return new Size( |
|
4768 |
72 / u.getLength(), |
|
4769 |
72 / v.getLength() |
|
4770 |
); |
|
4771 |
}, |
|
4772 |
||
4773 |
getPpi: '#getResolution', |
|
4774 |
||
4775 |
getImage: function() {
|
|
4776 |
return this._image; |
|
4777 |
}, |
|
4778 |
||
4779 |
setImage: function(image) {
|
|
4780 |
if (this._canvas) |
|
4781 |
CanvasProvider.release(this._canvas); |
|
4782 |
if (image && image.getContext) {
|
|
4783 |
this._image = null; |
|
4784 |
this._canvas = image; |
|
4785 |
this._loaded = true; |
|
4786 |
} else {
|
|
4787 |
this._image = image; |
|
4788 |
this._canvas = null; |
|
4789 |
this._loaded = image && image.complete; |
|
4790 |
} |
|
4791 |
this._size = new Size( |
|
4792 |
image ? image.naturalWidth || image.width : 0, |
|
4793 |
image ? image.naturalHeight || image.height : 0); |
|
4794 |
this._context = null; |
|
4795 |
this._changed(521); |
|
4796 |
}, |
|
4797 |
||
4798 |
getCanvas: function() {
|
|
4799 |
if (!this._canvas) {
|
|
4800 |
var ctx = CanvasProvider.getContext(this._size); |
|
4801 |
try {
|
|
4802 |
if (this._image) |
|
4803 |
ctx.drawImage(this._image, 0, 0); |
|
4804 |
this._canvas = ctx.canvas; |
|
4805 |
} catch (e) {
|
|
4806 |
CanvasProvider.release(ctx); |
|
4807 |
} |
|
4808 |
} |
|
4809 |
return this._canvas; |
|
4810 |
}, |
|
4811 |
||
4812 |
setCanvas: '#setImage', |
|
4813 |
||
4814 |
getContext: function(modify) {
|
|
4815 |
if (!this._context) |
|
4816 |
this._context = this.getCanvas().getContext('2d');
|
|
4817 |
if (modify) {
|
|
4818 |
this._image = null; |
|
4819 |
this._changed(513); |
|
4820 |
} |
|
4821 |
return this._context; |
|
4822 |
}, |
|
4823 |
||
4824 |
setContext: function(context) {
|
|
4825 |
this._context = context; |
|
4826 |
}, |
|
4827 |
||
4828 |
getSource: function() {
|
|
4829 |
return this._image && this._image.src || this.toDataURL(); |
|
4830 |
}, |
|
4831 |
||
4832 |
setSource: function(src) {
|
|
4833 |
var that = this, |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4834 |
crossOrigin = this._crossOrigin, |
| 442 | 4835 |
image; |
4836 |
||
4837 |
function loaded() {
|
|
4838 |
var view = that.getView(); |
|
4839 |
if (view) {
|
|
4840 |
paper = view._scope; |
|
4841 |
that.setImage(image); |
|
4842 |
that.emit('load');
|
|
4843 |
view.update(); |
|
4844 |
} |
|
4845 |
} |
|
4846 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4847 |
image = document.getElementById(src) || new Image(); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4848 |
if (crossOrigin) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4849 |
image.crossOrigin = crossOrigin; |
| 442 | 4850 |
if (image.naturalWidth && image.naturalHeight) {
|
4851 |
setTimeout(loaded, 0); |
|
4852 |
} else {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4853 |
DomEvent.add(image, { load: loaded });
|
| 442 | 4854 |
if (!image.src) |
4855 |
image.src = src; |
|
4856 |
} |
|
4857 |
this.setImage(image); |
|
4858 |
}, |
|
4859 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4860 |
getCrossOrigin: function() {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4861 |
return this._image && this._image.crossOrigin || this._crossOrigin || ''; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4862 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4863 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4864 |
setCrossOrigin: function(crossOrigin) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4865 |
this._crossOrigin = crossOrigin; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4866 |
if (this._image) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4867 |
this._image.crossOrigin = crossOrigin; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4868 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
4869 |
|
| 442 | 4870 |
getElement: function() {
|
4871 |
return this._canvas || this._loaded && this._image; |
|
4872 |
} |
|
4873 |
}, {
|
|
4874 |
beans: false, |
|
4875 |
||
4876 |
getSubCanvas: function() {
|
|
4877 |
var rect = Rectangle.read(arguments), |
|
4878 |
ctx = CanvasProvider.getContext(rect.getSize()); |
|
4879 |
ctx.drawImage(this.getCanvas(), rect.x, rect.y, |
|
4880 |
rect.width, rect.height, 0, 0, rect.width, rect.height); |
|
4881 |
return ctx.canvas; |
|
4882 |
}, |
|
4883 |
||
4884 |
getSubRaster: function() {
|
|
4885 |
var rect = Rectangle.read(arguments), |
|
4886 |
raster = new Raster(Item.NO_INSERT); |
|
4887 |
raster.setImage(this.getSubCanvas(rect)); |
|
4888 |
raster.translate(rect.getCenter().subtract(this.getSize().divide(2))); |
|
4889 |
raster._matrix.preConcatenate(this._matrix); |
|
4890 |
raster.insertAbove(this); |
|
4891 |
return raster; |
|
4892 |
}, |
|
4893 |
||
4894 |
toDataURL: function() {
|
|
4895 |
var src = this._image && this._image.src; |
|
4896 |
if (/^data:/.test(src)) |
|
4897 |
return src; |
|
4898 |
var canvas = this.getCanvas(); |
|
| 598 | 4899 |
return canvas ? canvas.toDataURL.apply(canvas, arguments) : null; |
| 442 | 4900 |
}, |
4901 |
||
4902 |
drawImage: function(image ) {
|
|
4903 |
var point = Point.read(arguments, 1); |
|
4904 |
this.getContext(true).drawImage(image, point.x, point.y); |
|
4905 |
}, |
|
4906 |
||
4907 |
getAverageColor: function(object) {
|
|
4908 |
var bounds, path; |
|
4909 |
if (!object) {
|
|
4910 |
bounds = this.getBounds(); |
|
4911 |
} else if (object instanceof PathItem) {
|
|
4912 |
path = object; |
|
4913 |
bounds = object.getBounds(); |
|
4914 |
} else if (object.width) {
|
|
4915 |
bounds = new Rectangle(object); |
|
4916 |
} else if (object.x) {
|
|
4917 |
bounds = new Rectangle(object.x - 0.5, object.y - 0.5, 1, 1); |
|
4918 |
} |
|
4919 |
var sampleSize = 32, |
|
4920 |
width = Math.min(bounds.width, sampleSize), |
|
4921 |
height = Math.min(bounds.height, sampleSize); |
|
4922 |
var ctx = Raster._sampleContext; |
|
4923 |
if (!ctx) {
|
|
4924 |
ctx = Raster._sampleContext = CanvasProvider.getContext( |
|
4925 |
new Size(sampleSize)); |
|
4926 |
} else {
|
|
4927 |
ctx.clearRect(0, 0, sampleSize + 1, sampleSize + 1); |
|
4928 |
} |
|
4929 |
ctx.save(); |
|
4930 |
var matrix = new Matrix() |
|
4931 |
.scale(width / bounds.width, height / bounds.height) |
|
4932 |
.translate(-bounds.x, -bounds.y); |
|
4933 |
matrix.applyToContext(ctx); |
|
4934 |
if (path) |
|
4935 |
path.draw(ctx, new Base({ clip: true, matrices: [matrix] }));
|
|
4936 |
this._matrix.applyToContext(ctx); |
|
4937 |
var element = this.getElement(), |
|
4938 |
size = this._size; |
|
4939 |
if (element) |
|
4940 |
ctx.drawImage(element, -size.width / 2, -size.height / 2); |
|
4941 |
ctx.restore(); |
|
4942 |
var pixels = ctx.getImageData(0.5, 0.5, Math.ceil(width), |
|
4943 |
Math.ceil(height)).data, |
|
4944 |
channels = [0, 0, 0], |
|
4945 |
total = 0; |
|
4946 |
for (var i = 0, l = pixels.length; i < l; i += 4) {
|
|
4947 |
var alpha = pixels[i + 3]; |
|
4948 |
total += alpha; |
|
4949 |
alpha /= 255; |
|
4950 |
channels[0] += pixels[i] * alpha; |
|
4951 |
channels[1] += pixels[i + 1] * alpha; |
|
4952 |
channels[2] += pixels[i + 2] * alpha; |
|
4953 |
} |
|
4954 |
for (var i = 0; i < 3; i++) |
|
4955 |
channels[i] /= total; |
|
4956 |
return total ? Color.read(channels) : null; |
|
4957 |
}, |
|
4958 |
||
4959 |
getPixel: function() {
|
|
4960 |
var point = Point.read(arguments); |
|
4961 |
var data = this.getContext().getImageData(point.x, point.y, 1, 1).data; |
|
4962 |
return new Color('rgb', [data[0] / 255, data[1] / 255, data[2] / 255],
|
|
4963 |
data[3] / 255); |
|
4964 |
}, |
|
4965 |
||
4966 |
setPixel: function() {
|
|
4967 |
var point = Point.read(arguments), |
|
4968 |
color = Color.read(arguments), |
|
4969 |
components = color._convert('rgb'),
|
|
4970 |
alpha = color._alpha, |
|
4971 |
ctx = this.getContext(true), |
|
4972 |
imageData = ctx.createImageData(1, 1), |
|
4973 |
data = imageData.data; |
|
4974 |
data[0] = components[0] * 255; |
|
4975 |
data[1] = components[1] * 255; |
|
4976 |
data[2] = components[2] * 255; |
|
4977 |
data[3] = alpha != null ? alpha * 255 : 255; |
|
4978 |
ctx.putImageData(imageData, point.x, point.y); |
|
4979 |
}, |
|
4980 |
||
4981 |
createImageData: function() {
|
|
4982 |
var size = Size.read(arguments); |
|
4983 |
return this.getContext().createImageData(size.width, size.height); |
|
4984 |
}, |
|
4985 |
||
4986 |
getImageData: function() {
|
|
4987 |
var rect = Rectangle.read(arguments); |
|
4988 |
if (rect.isEmpty()) |
|
4989 |
rect = new Rectangle(this._size); |
|
4990 |
return this.getContext().getImageData(rect.x, rect.y, |
|
4991 |
rect.width, rect.height); |
|
4992 |
}, |
|
4993 |
||
4994 |
setImageData: function(data ) {
|
|
4995 |
var point = Point.read(arguments, 1); |
|
4996 |
this.getContext(true).putImageData(data, point.x, point.y); |
|
4997 |
}, |
|
4998 |
||
4999 |
_getBounds: function(getter, matrix) {
|
|
5000 |
var rect = new Rectangle(this._size).setCenter(0, 0); |
|
5001 |
return matrix ? matrix._transformBounds(rect) : rect; |
|
5002 |
}, |
|
5003 |
||
5004 |
_hitTestSelf: function(point) {
|
|
5005 |
if (this._contains(point)) {
|
|
5006 |
var that = this; |
|
5007 |
return new HitResult('pixel', that, {
|
|
5008 |
offset: point.add(that._size.divide(2)).round(), |
|
5009 |
color: {
|
|
5010 |
get: function() {
|
|
5011 |
return that.getPixel(this.offset); |
|
5012 |
} |
|
5013 |
} |
|
5014 |
}); |
|
5015 |
} |
|
5016 |
}, |
|
5017 |
||
5018 |
_draw: function(ctx) {
|
|
5019 |
var element = this.getElement(); |
|
5020 |
if (element) {
|
|
5021 |
ctx.globalAlpha = this._opacity; |
|
5022 |
ctx.drawImage(element, |
|
5023 |
-this._size.width / 2, -this._size.height / 2); |
|
5024 |
} |
|
5025 |
}, |
|
5026 |
||
5027 |
_canComposite: function() {
|
|
5028 |
return true; |
|
5029 |
} |
|
5030 |
}); |
|
5031 |
||
5032 |
var PlacedSymbol = Item.extend({
|
|
5033 |
_class: 'PlacedSymbol', |
|
5034 |
_applyMatrix: false, |
|
5035 |
_canApplyMatrix: false, |
|
5036 |
_boundsGetter: { getBounds: 'getStrokeBounds' },
|
|
5037 |
_boundsSelected: true, |
|
5038 |
_serializeFields: {
|
|
5039 |
symbol: null |
|
5040 |
}, |
|
5041 |
||
5042 |
initialize: function PlacedSymbol(arg0, arg1) {
|
|
5043 |
if (!this._initialize(arg0, |
|
5044 |
arg1 !== undefined && Point.read(arguments, 1))) |
|
5045 |
this.setSymbol(arg0 instanceof Symbol ? arg0 : new Symbol(arg0)); |
|
5046 |
}, |
|
5047 |
||
5048 |
_equals: function(item) {
|
|
5049 |
return this._symbol === item._symbol; |
|
5050 |
}, |
|
5051 |
||
5052 |
getSymbol: function() {
|
|
5053 |
return this._symbol; |
|
5054 |
}, |
|
5055 |
||
5056 |
setSymbol: function(symbol) {
|
|
5057 |
this._symbol = symbol; |
|
5058 |
this._changed(9); |
|
5059 |
}, |
|
5060 |
||
5061 |
clone: function(insert) {
|
|
5062 |
var copy = new PlacedSymbol(Item.NO_INSERT); |
|
5063 |
copy.setSymbol(this._symbol); |
|
5064 |
return this._clone(copy, insert); |
|
5065 |
}, |
|
5066 |
||
5067 |
isEmpty: function() {
|
|
5068 |
return this._symbol._definition.isEmpty(); |
|
5069 |
}, |
|
5070 |
||
5071 |
_getBounds: function(getter, matrix, cacheItem) {
|
|
5072 |
var definition = this.symbol._definition; |
|
5073 |
return definition._getCachedBounds(getter, |
|
5074 |
matrix && matrix.chain(definition._matrix), cacheItem); |
|
5075 |
}, |
|
5076 |
||
5077 |
_hitTestSelf: function(point, options) {
|
|
5078 |
var res = this._symbol._definition._hitTest(point, options); |
|
5079 |
if (res) |
|
5080 |
res.item = this; |
|
5081 |
return res; |
|
5082 |
}, |
|
5083 |
||
5084 |
_draw: function(ctx, param) {
|
|
5085 |
this.symbol._definition.draw(ctx, param); |
|
5086 |
} |
|
5087 |
||
5088 |
}); |
|
5089 |
||
5090 |
var HitResult = Base.extend({
|
|
5091 |
_class: 'HitResult', |
|
5092 |
||
5093 |
initialize: function HitResult(type, item, values) {
|
|
5094 |
this.type = type; |
|
5095 |
this.item = item; |
|
5096 |
if (values) {
|
|
5097 |
values.enumerable = true; |
|
5098 |
this.inject(values); |
|
5099 |
} |
|
5100 |
}, |
|
5101 |
||
5102 |
statics: {
|
|
5103 |
getOptions: function(options) {
|
|
5104 |
return new Base({
|
|
5105 |
type: null, |
|
5106 |
tolerance: paper.settings.hitTolerance, |
|
5107 |
fill: !options, |
|
5108 |
stroke: !options, |
|
5109 |
segments: !options, |
|
5110 |
handles: false, |
|
5111 |
ends: false, |
|
5112 |
center: false, |
|
5113 |
bounds: false, |
|
5114 |
guides: false, |
|
5115 |
selected: false |
|
5116 |
}, options); |
|
5117 |
} |
|
5118 |
} |
|
5119 |
}); |
|
5120 |
||
5121 |
var Segment = Base.extend({
|
|
5122 |
_class: 'Segment', |
|
5123 |
beans: true, |
|
5124 |
||
5125 |
initialize: function Segment(arg0, arg1, arg2, arg3, arg4, arg5) {
|
|
5126 |
var count = arguments.length, |
|
5127 |
point, handleIn, handleOut; |
|
5128 |
if (count === 0) {
|
|
5129 |
} else if (count === 1) {
|
|
| 598 | 5130 |
if ('point' in arg0) {
|
| 442 | 5131 |
point = arg0.point; |
5132 |
handleIn = arg0.handleIn; |
|
5133 |
handleOut = arg0.handleOut; |
|
5134 |
} else {
|
|
5135 |
point = arg0; |
|
5136 |
} |
|
5137 |
} else if (count === 2 && typeof arg0 === 'number') {
|
|
5138 |
point = arguments; |
|
5139 |
} else if (count <= 3) {
|
|
5140 |
point = arg0; |
|
5141 |
handleIn = arg1; |
|
5142 |
handleOut = arg2; |
|
5143 |
} else {
|
|
5144 |
point = arg0 !== undefined ? [ arg0, arg1 ] : null; |
|
5145 |
handleIn = arg2 !== undefined ? [ arg2, arg3 ] : null; |
|
5146 |
handleOut = arg4 !== undefined ? [ arg4, arg5 ] : null; |
|
5147 |
} |
|
5148 |
new SegmentPoint(point, this, '_point'); |
|
5149 |
new SegmentPoint(handleIn, this, '_handleIn'); |
|
5150 |
new SegmentPoint(handleOut, this, '_handleOut'); |
|
5151 |
}, |
|
5152 |
||
5153 |
_serialize: function(options) {
|
|
| 598 | 5154 |
return Base.serialize(this.hasHandles() |
5155 |
? [this._point, this._handleIn, this._handleOut] |
|
5156 |
: this._point, |
|
| 442 | 5157 |
options, true); |
5158 |
}, |
|
5159 |
||
5160 |
_changed: function(point) {
|
|
5161 |
var path = this._path; |
|
5162 |
if (!path) |
|
5163 |
return; |
|
5164 |
var curves = path._curves, |
|
5165 |
index = this._index, |
|
5166 |
curve; |
|
5167 |
if (curves) {
|
|
5168 |
if ((!point || point === this._point || point === this._handleIn) |
|
5169 |
&& (curve = index > 0 ? curves[index - 1] : path._closed |
|
5170 |
? curves[curves.length - 1] : null)) |
|
5171 |
curve._changed(); |
|
5172 |
if ((!point || point === this._point || point === this._handleOut) |
|
5173 |
&& (curve = curves[index])) |
|
5174 |
curve._changed(); |
|
5175 |
} |
|
5176 |
path._changed(25); |
|
5177 |
}, |
|
5178 |
||
5179 |
getPoint: function() {
|
|
5180 |
return this._point; |
|
5181 |
}, |
|
5182 |
||
5183 |
setPoint: function() {
|
|
5184 |
var point = Point.read(arguments); |
|
5185 |
this._point.set(point.x, point.y); |
|
5186 |
}, |
|
5187 |
||
5188 |
getHandleIn: function() {
|
|
5189 |
return this._handleIn; |
|
5190 |
}, |
|
5191 |
||
5192 |
setHandleIn: function() {
|
|
5193 |
var point = Point.read(arguments); |
|
5194 |
this._handleIn.set(point.x, point.y); |
|
5195 |
}, |
|
5196 |
||
5197 |
getHandleOut: function() {
|
|
5198 |
return this._handleOut; |
|
5199 |
}, |
|
5200 |
||
5201 |
setHandleOut: function() {
|
|
5202 |
var point = Point.read(arguments); |
|
5203 |
this._handleOut.set(point.x, point.y); |
|
5204 |
}, |
|
5205 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5206 |
hasHandles: function() {
|
| 598 | 5207 |
return !this._handleIn.isZero() || !this._handleOut.isZero(); |
5208 |
}, |
|
5209 |
||
5210 |
clearHandles: function() {
|
|
5211 |
this._handleIn.set(0, 0); |
|
5212 |
this._handleOut.set(0, 0); |
|
5213 |
}, |
|
| 442 | 5214 |
|
5215 |
_selectionState: 0, |
|
5216 |
||
5217 |
isSelected: function(_point) {
|
|
5218 |
var state = this._selectionState; |
|
5219 |
return !_point ? !!(state & 7) |
|
5220 |
: _point === this._point ? !!(state & 4) |
|
5221 |
: _point === this._handleIn ? !!(state & 1) |
|
5222 |
: _point === this._handleOut ? !!(state & 2) |
|
5223 |
: false; |
|
5224 |
}, |
|
5225 |
||
5226 |
setSelected: function(selected, _point) {
|
|
5227 |
var path = this._path, |
|
5228 |
selected = !!selected, |
|
5229 |
state = this._selectionState, |
|
5230 |
oldState = state, |
|
5231 |
flag = !_point ? 7 |
|
5232 |
: _point === this._point ? 4 |
|
5233 |
: _point === this._handleIn ? 1 |
|
5234 |
: _point === this._handleOut ? 2 |
|
5235 |
: 0; |
|
5236 |
if (selected) {
|
|
5237 |
state |= flag; |
|
5238 |
} else {
|
|
5239 |
state &= ~flag; |
|
5240 |
} |
|
5241 |
this._selectionState = state; |
|
5242 |
if (path && state !== oldState) {
|
|
5243 |
path._updateSelection(this, oldState, state); |
|
5244 |
path._changed(129); |
|
5245 |
} |
|
5246 |
}, |
|
5247 |
||
5248 |
getIndex: function() {
|
|
5249 |
return this._index !== undefined ? this._index : null; |
|
5250 |
}, |
|
5251 |
||
5252 |
getPath: function() {
|
|
5253 |
return this._path || null; |
|
5254 |
}, |
|
5255 |
||
5256 |
getCurve: function() {
|
|
5257 |
var path = this._path, |
|
5258 |
index = this._index; |
|
5259 |
if (path) {
|
|
5260 |
if (index > 0 && !path._closed |
|
5261 |
&& index === path._segments.length - 1) |
|
5262 |
index--; |
|
5263 |
return path.getCurves()[index] || null; |
|
5264 |
} |
|
5265 |
return null; |
|
5266 |
}, |
|
5267 |
||
5268 |
getLocation: function() {
|
|
5269 |
var curve = this.getCurve(); |
|
5270 |
return curve |
|
5271 |
? new CurveLocation(curve, this === curve._segment1 ? 0 : 1) |
|
5272 |
: null; |
|
5273 |
}, |
|
5274 |
||
5275 |
getNext: function() {
|
|
5276 |
var segments = this._path && this._path._segments; |
|
5277 |
return segments && (segments[this._index + 1] |
|
5278 |
|| this._path._closed && segments[0]) || null; |
|
5279 |
}, |
|
5280 |
||
5281 |
getPrevious: function() {
|
|
5282 |
var segments = this._path && this._path._segments; |
|
5283 |
return segments && (segments[this._index - 1] |
|
5284 |
|| this._path._closed && segments[segments.length - 1]) || null; |
|
5285 |
}, |
|
5286 |
||
| 598 | 5287 |
isFirst: function() {
|
5288 |
return this._index === 0; |
|
5289 |
}, |
|
5290 |
||
5291 |
isLast: function() {
|
|
5292 |
var path = this._path; |
|
5293 |
return path && this._index === path._segments.length - 1 || false; |
|
5294 |
}, |
|
5295 |
||
| 442 | 5296 |
reverse: function() {
|
| 598 | 5297 |
var handleIn = this._handleIn, |
5298 |
handleOut = this._handleOut, |
|
5299 |
inX = handleIn._x, |
|
5300 |
inY = handleIn._y; |
|
5301 |
handleIn.set(handleOut._x, handleOut._y); |
|
5302 |
handleOut.set(inX, inY); |
|
5303 |
}, |
|
5304 |
||
5305 |
reversed: function() {
|
|
| 442 | 5306 |
return new Segment(this._point, this._handleOut, this._handleIn); |
5307 |
}, |
|
5308 |
||
5309 |
remove: function() {
|
|
5310 |
return this._path ? !!this._path.removeSegment(this._index) : false; |
|
5311 |
}, |
|
5312 |
||
5313 |
clone: function() {
|
|
5314 |
return new Segment(this._point, this._handleIn, this._handleOut); |
|
5315 |
}, |
|
5316 |
||
5317 |
equals: function(segment) {
|
|
5318 |
return segment === this || segment && this._class === segment._class |
|
5319 |
&& this._point.equals(segment._point) |
|
5320 |
&& this._handleIn.equals(segment._handleIn) |
|
5321 |
&& this._handleOut.equals(segment._handleOut) |
|
5322 |
|| false; |
|
5323 |
}, |
|
5324 |
||
5325 |
toString: function() {
|
|
5326 |
var parts = [ 'point: ' + this._point ]; |
|
5327 |
if (!this._handleIn.isZero()) |
|
5328 |
parts.push('handleIn: ' + this._handleIn);
|
|
5329 |
if (!this._handleOut.isZero()) |
|
5330 |
parts.push('handleOut: ' + this._handleOut);
|
|
5331 |
return '{ ' + parts.join(', ') + ' }';
|
|
5332 |
}, |
|
5333 |
||
5334 |
transform: function(matrix) {
|
|
5335 |
this._transformCoordinates(matrix, new Array(6), true); |
|
5336 |
this._changed(); |
|
5337 |
}, |
|
5338 |
||
5339 |
_transformCoordinates: function(matrix, coords, change) {
|
|
5340 |
var point = this._point, |
|
5341 |
handleIn = !change || !this._handleIn.isZero() |
|
5342 |
? this._handleIn : null, |
|
5343 |
handleOut = !change || !this._handleOut.isZero() |
|
5344 |
? this._handleOut : null, |
|
5345 |
x = point._x, |
|
5346 |
y = point._y, |
|
5347 |
i = 2; |
|
5348 |
coords[0] = x; |
|
5349 |
coords[1] = y; |
|
5350 |
if (handleIn) {
|
|
5351 |
coords[i++] = handleIn._x + x; |
|
5352 |
coords[i++] = handleIn._y + y; |
|
5353 |
} |
|
5354 |
if (handleOut) {
|
|
5355 |
coords[i++] = handleOut._x + x; |
|
5356 |
coords[i++] = handleOut._y + y; |
|
5357 |
} |
|
5358 |
if (matrix) {
|
|
5359 |
matrix._transformCoordinates(coords, coords, i / 2); |
|
5360 |
x = coords[0]; |
|
5361 |
y = coords[1]; |
|
5362 |
if (change) {
|
|
5363 |
point._x = x; |
|
5364 |
point._y = y; |
|
5365 |
i = 2; |
|
5366 |
if (handleIn) {
|
|
5367 |
handleIn._x = coords[i++] - x; |
|
5368 |
handleIn._y = coords[i++] - y; |
|
5369 |
} |
|
5370 |
if (handleOut) {
|
|
5371 |
handleOut._x = coords[i++] - x; |
|
5372 |
handleOut._y = coords[i++] - y; |
|
5373 |
} |
|
5374 |
} else {
|
|
5375 |
if (!handleIn) {
|
|
5376 |
coords[i++] = x; |
|
5377 |
coords[i++] = y; |
|
5378 |
} |
|
5379 |
if (!handleOut) {
|
|
5380 |
coords[i++] = x; |
|
5381 |
coords[i++] = y; |
|
5382 |
} |
|
5383 |
} |
|
5384 |
} |
|
5385 |
return coords; |
|
5386 |
} |
|
5387 |
}); |
|
5388 |
||
5389 |
var SegmentPoint = Point.extend({
|
|
5390 |
initialize: function SegmentPoint(point, owner, key) {
|
|
5391 |
var x, y, selected; |
|
5392 |
if (!point) {
|
|
5393 |
x = y = 0; |
|
5394 |
} else if ((x = point[0]) !== undefined) {
|
|
5395 |
y = point[1]; |
|
5396 |
} else {
|
|
5397 |
var pt = point; |
|
5398 |
if ((x = pt.x) === undefined) {
|
|
5399 |
pt = Point.read(arguments); |
|
5400 |
x = pt.x; |
|
5401 |
} |
|
5402 |
y = pt.y; |
|
5403 |
selected = pt.selected; |
|
5404 |
} |
|
5405 |
this._x = x; |
|
5406 |
this._y = y; |
|
5407 |
this._owner = owner; |
|
5408 |
owner[key] = this; |
|
5409 |
if (selected) |
|
5410 |
this.setSelected(true); |
|
5411 |
}, |
|
5412 |
||
5413 |
set: function(x, y) {
|
|
5414 |
this._x = x; |
|
5415 |
this._y = y; |
|
5416 |
this._owner._changed(this); |
|
5417 |
return this; |
|
5418 |
}, |
|
5419 |
||
5420 |
_serialize: function(options) {
|
|
5421 |
var f = options.formatter, |
|
5422 |
x = f.number(this._x), |
|
5423 |
y = f.number(this._y); |
|
5424 |
return this.isSelected() |
|
5425 |
? { x: x, y: y, selected: true }
|
|
5426 |
: [x, y]; |
|
5427 |
}, |
|
5428 |
||
5429 |
getX: function() {
|
|
5430 |
return this._x; |
|
5431 |
}, |
|
5432 |
||
5433 |
setX: function(x) {
|
|
5434 |
this._x = x; |
|
5435 |
this._owner._changed(this); |
|
5436 |
}, |
|
5437 |
||
5438 |
getY: function() {
|
|
5439 |
return this._y; |
|
5440 |
}, |
|
5441 |
||
5442 |
setY: function(y) {
|
|
5443 |
this._y = y; |
|
5444 |
this._owner._changed(this); |
|
5445 |
}, |
|
5446 |
||
5447 |
isZero: function() {
|
|
5448 |
return Numerical.isZero(this._x) && Numerical.isZero(this._y); |
|
5449 |
}, |
|
5450 |
||
5451 |
setSelected: function(selected) {
|
|
5452 |
this._owner.setSelected(selected, this); |
|
5453 |
}, |
|
5454 |
||
5455 |
isSelected: function() {
|
|
5456 |
return this._owner.isSelected(this); |
|
5457 |
} |
|
5458 |
}); |
|
5459 |
||
5460 |
var Curve = Base.extend({
|
|
5461 |
_class: 'Curve', |
|
5462 |
||
5463 |
initialize: function Curve(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
|
|
| 598 | 5464 |
var count = arguments.length, |
5465 |
seg1, seg2, |
|
5466 |
point1, point2, |
|
5467 |
handle1, handle2; |
|
| 442 | 5468 |
if (count === 3) {
|
5469 |
this._path = arg0; |
|
| 598 | 5470 |
seg1 = arg1; |
5471 |
seg2 = arg2; |
|
| 442 | 5472 |
} else if (count === 0) {
|
| 598 | 5473 |
seg1 = new Segment(); |
5474 |
seg2 = new Segment(); |
|
| 442 | 5475 |
} else if (count === 1) {
|
| 598 | 5476 |
if ('segment1' in arg0) {
|
5477 |
seg1 = new Segment(arg0.segment1); |
|
5478 |
seg2 = new Segment(arg0.segment2); |
|
5479 |
} else if ('point1' in arg0) {
|
|
5480 |
point1 = arg0.point1; |
|
5481 |
handle1 = arg0.handle1; |
|
5482 |
handle2 = arg0.handle2; |
|
5483 |
point2 = arg0.point2; |
|
5484 |
} else if (Array.isArray(arg0)) {
|
|
5485 |
point1 = [arg0[0], arg0[1]]; |
|
5486 |
point2 = [arg0[6], arg0[7]]; |
|
5487 |
handle1 = [arg0[2] - arg0[0], arg0[3] - arg0[1]]; |
|
5488 |
handle2 = [arg0[4] - arg0[6], arg0[5] - arg0[7]]; |
|
5489 |
} |
|
| 442 | 5490 |
} else if (count === 2) {
|
| 598 | 5491 |
seg1 = new Segment(arg0); |
5492 |
seg2 = new Segment(arg1); |
|
5493 |
} else if (count === 4) {
|
|
5494 |
point1 = arg0; |
|
5495 |
handle1 = arg1; |
|
5496 |
handle2 = arg2; |
|
5497 |
point2 = arg3; |
|
5498 |
} else if (count === 8) {
|
|
5499 |
point1 = [arg0, arg1]; |
|
5500 |
point2 = [arg6, arg7]; |
|
5501 |
handle1 = [arg2 - arg0, arg3 - arg1]; |
|
5502 |
handle2 = [arg4 - arg6, arg5 - arg7]; |
|
5503 |
} |
|
5504 |
this._segment1 = seg1 || new Segment(point1, null, handle1); |
|
5505 |
this._segment2 = seg2 || new Segment(point2, handle2, null); |
|
5506 |
}, |
|
5507 |
||
5508 |
_serialize: function(options) {
|
|
5509 |
return Base.serialize(this.hasHandles() |
|
5510 |
? [this.getPoint1(), this.getHandle1(), this.getHandle2(), |
|
5511 |
this.getPoint2()] |
|
5512 |
: [this.getPoint1(), this.getPoint2()], |
|
5513 |
options, true); |
|
| 442 | 5514 |
}, |
5515 |
||
5516 |
_changed: function() {
|
|
5517 |
this._length = this._bounds = undefined; |
|
5518 |
}, |
|
5519 |
||
| 598 | 5520 |
clone: function() {
|
5521 |
return new Curve(this._segment1, this._segment2); |
|
5522 |
}, |
|
5523 |
||
5524 |
toString: function() {
|
|
5525 |
var parts = [ 'point1: ' + this._segment1._point ]; |
|
5526 |
if (!this._segment1._handleOut.isZero()) |
|
5527 |
parts.push('handle1: ' + this._segment1._handleOut);
|
|
5528 |
if (!this._segment2._handleIn.isZero()) |
|
5529 |
parts.push('handle2: ' + this._segment2._handleIn);
|
|
5530 |
parts.push('point2: ' + this._segment2._point);
|
|
5531 |
return '{ ' + parts.join(', ') + ' }';
|
|
5532 |
}, |
|
5533 |
||
5534 |
remove: function() {
|
|
5535 |
var removed = false; |
|
5536 |
if (this._path) {
|
|
5537 |
var segment2 = this._segment2, |
|
5538 |
handleOut = segment2._handleOut; |
|
5539 |
removed = segment2.remove(); |
|
5540 |
if (removed) |
|
5541 |
this._segment1._handleOut.set(handleOut.x, handleOut.y); |
|
5542 |
} |
|
5543 |
return removed; |
|
5544 |
}, |
|
5545 |
||
| 442 | 5546 |
getPoint1: function() {
|
5547 |
return this._segment1._point; |
|
5548 |
}, |
|
5549 |
||
5550 |
setPoint1: function() {
|
|
5551 |
var point = Point.read(arguments); |
|
5552 |
this._segment1._point.set(point.x, point.y); |
|
5553 |
}, |
|
5554 |
||
5555 |
getPoint2: function() {
|
|
5556 |
return this._segment2._point; |
|
5557 |
}, |
|
5558 |
||
5559 |
setPoint2: function() {
|
|
5560 |
var point = Point.read(arguments); |
|
5561 |
this._segment2._point.set(point.x, point.y); |
|
5562 |
}, |
|
5563 |
||
5564 |
getHandle1: function() {
|
|
5565 |
return this._segment1._handleOut; |
|
5566 |
}, |
|
5567 |
||
5568 |
setHandle1: function() {
|
|
5569 |
var point = Point.read(arguments); |
|
5570 |
this._segment1._handleOut.set(point.x, point.y); |
|
5571 |
}, |
|
5572 |
||
5573 |
getHandle2: function() {
|
|
5574 |
return this._segment2._handleIn; |
|
5575 |
}, |
|
5576 |
||
5577 |
setHandle2: function() {
|
|
5578 |
var point = Point.read(arguments); |
|
5579 |
this._segment2._handleIn.set(point.x, point.y); |
|
5580 |
}, |
|
5581 |
||
5582 |
getSegment1: function() {
|
|
5583 |
return this._segment1; |
|
5584 |
}, |
|
5585 |
||
5586 |
getSegment2: function() {
|
|
5587 |
return this._segment2; |
|
5588 |
}, |
|
5589 |
||
5590 |
getPath: function() {
|
|
5591 |
return this._path; |
|
5592 |
}, |
|
5593 |
||
5594 |
getIndex: function() {
|
|
5595 |
return this._segment1._index; |
|
5596 |
}, |
|
5597 |
||
5598 |
getNext: function() {
|
|
5599 |
var curves = this._path && this._path._curves; |
|
5600 |
return curves && (curves[this._segment1._index + 1] |
|
5601 |
|| this._path._closed && curves[0]) || null; |
|
5602 |
}, |
|
5603 |
||
5604 |
getPrevious: function() {
|
|
5605 |
var curves = this._path && this._path._curves; |
|
5606 |
return curves && (curves[this._segment1._index - 1] |
|
5607 |
|| this._path._closed && curves[curves.length - 1]) || null; |
|
5608 |
}, |
|
5609 |
||
| 598 | 5610 |
isFirst: function() {
|
5611 |
return this._segment1._index === 0; |
|
5612 |
}, |
|
5613 |
||
5614 |
isLast: function() {
|
|
5615 |
var path = this._path; |
|
5616 |
return path && this._segment1._index === path._curves.length - 1 |
|
5617 |
|| false; |
|
5618 |
}, |
|
5619 |
||
| 442 | 5620 |
isSelected: function() {
|
5621 |
return this.getPoint1().isSelected() |
|
5622 |
&& this.getHandle2().isSelected() |
|
5623 |
&& this.getHandle2().isSelected() |
|
5624 |
&& this.getPoint2().isSelected(); |
|
5625 |
}, |
|
5626 |
||
5627 |
setSelected: function(selected) {
|
|
5628 |
this.getPoint1().setSelected(selected); |
|
5629 |
this.getHandle1().setSelected(selected); |
|
5630 |
this.getHandle2().setSelected(selected); |
|
5631 |
this.getPoint2().setSelected(selected); |
|
5632 |
}, |
|
5633 |
||
5634 |
getValues: function(matrix) {
|
|
5635 |
return Curve.getValues(this._segment1, this._segment2, matrix); |
|
5636 |
}, |
|
5637 |
||
5638 |
getPoints: function() {
|
|
5639 |
var coords = this.getValues(), |
|
5640 |
points = []; |
|
5641 |
for (var i = 0; i < 8; i += 2) |
|
5642 |
points.push(new Point(coords[i], coords[i + 1])); |
|
5643 |
return points; |
|
5644 |
}, |
|
5645 |
||
5646 |
getLength: function() {
|
|
| 598 | 5647 |
if (this._length == null) |
5648 |
this._length = Curve.getLength(this.getValues(), 0, 1); |
|
| 442 | 5649 |
return this._length; |
5650 |
}, |
|
5651 |
||
5652 |
getArea: function() {
|
|
5653 |
return Curve.getArea(this.getValues()); |
|
5654 |
}, |
|
5655 |
||
| 598 | 5656 |
getLine: function() {
|
5657 |
return new Line(this._segment1._point, this._segment2._point); |
|
5658 |
}, |
|
5659 |
||
| 442 | 5660 |
getPart: function(from, to) {
|
5661 |
return new Curve(Curve.getPart(this.getValues(), from, to)); |
|
5662 |
}, |
|
5663 |
||
5664 |
getPartLength: function(from, to) {
|
|
5665 |
return Curve.getLength(this.getValues(), from, to); |
|
5666 |
}, |
|
5667 |
||
5668 |
getIntersections: function(curve) {
|
|
| 598 | 5669 |
return Curve._getIntersections(this.getValues(), |
5670 |
curve && curve !== this ? curve.getValues() : null, |
|
5671 |
this, curve, [], {});
|
|
| 442 | 5672 |
}, |
5673 |
||
5674 |
_getParameter: function(offset, isParameter) {
|
|
5675 |
return isParameter |
|
5676 |
? offset |
|
5677 |
: offset && offset.curve === this |
|
5678 |
? offset.parameter |
|
5679 |
: offset === undefined && isParameter === undefined |
|
5680 |
? 0.5 |
|
5681 |
: this.getParameterAt(offset, 0); |
|
5682 |
}, |
|
5683 |
||
| 598 | 5684 |
divide: function(offset, isParameter, _setHandles) {
|
| 442 | 5685 |
var parameter = this._getParameter(offset, isParameter), |
| 598 | 5686 |
tMin = 4e-7, |
5687 |
tMax = 1 - tMin, |
|
| 442 | 5688 |
res = null; |
| 598 | 5689 |
if (parameter >= tMin && parameter <= tMax) {
|
| 442 | 5690 |
var parts = Curve.subdivide(this.getValues(), parameter), |
5691 |
left = parts[0], |
|
| 598 | 5692 |
right = parts[1], |
5693 |
setHandles = _setHandles || this.hasHandles(), |
|
5694 |
segment1 = this._segment1, |
|
5695 |
segment2 = this._segment2, |
|
5696 |
path = this._path; |
|
5697 |
if (setHandles) {
|
|
5698 |
segment1._handleOut.set(left[2] - left[0], |
|
| 442 | 5699 |
left[3] - left[1]); |
| 598 | 5700 |
segment2._handleIn.set(right[4] - right[6], |
| 442 | 5701 |
right[5] - right[7]); |
5702 |
} |
|
5703 |
var x = left[6], y = left[7], |
|
5704 |
segment = new Segment(new Point(x, y), |
|
| 598 | 5705 |
setHandles && new Point(left[4] - x, left[5] - y), |
5706 |
setHandles && new Point(right[2] - x, right[3] - y)); |
|
5707 |
if (path) {
|
|
5708 |
path.insert(segment1._index + 1, segment); |
|
5709 |
res = this.getNext(); |
|
| 442 | 5710 |
} else {
|
5711 |
this._segment2 = segment; |
|
| 598 | 5712 |
res = new Curve(segment, segment2); |
| 442 | 5713 |
} |
5714 |
} |
|
5715 |
return res; |
|
5716 |
}, |
|
5717 |
||
5718 |
split: function(offset, isParameter) {
|
|
5719 |
return this._path |
|
5720 |
? this._path.split(this._segment1._index, |
|
5721 |
this._getParameter(offset, isParameter)) |
|
5722 |
: null; |
|
5723 |
}, |
|
5724 |
||
| 598 | 5725 |
reversed: function() {
|
5726 |
return new Curve(this._segment2.reversed(), this._segment1.reversed()); |
|
5727 |
}, |
|
5728 |
||
5729 |
clearHandles: function() {
|
|
5730 |
this._segment1._handleOut.set(0, 0); |
|
5731 |
this._segment2._handleIn.set(0, 0); |
|
| 442 | 5732 |
}, |
5733 |
||
5734 |
statics: {
|
|
5735 |
getValues: function(segment1, segment2, matrix) {
|
|
5736 |
var p1 = segment1._point, |
|
5737 |
h1 = segment1._handleOut, |
|
5738 |
h2 = segment2._handleIn, |
|
5739 |
p2 = segment2._point, |
|
5740 |
values = [ |
|
5741 |
p1._x, p1._y, |
|
5742 |
p1._x + h1._x, p1._y + h1._y, |
|
5743 |
p2._x + h2._x, p2._y + h2._y, |
|
5744 |
p2._x, p2._y |
|
5745 |
]; |
|
5746 |
if (matrix) |
|
5747 |
matrix._transformCoordinates(values, values, 4); |
|
5748 |
return values; |
|
5749 |
}, |
|
5750 |
||
5751 |
subdivide: function(v, t) {
|
|
5752 |
var p1x = v[0], p1y = v[1], |
|
5753 |
c1x = v[2], c1y = v[3], |
|
5754 |
c2x = v[4], c2y = v[5], |
|
5755 |
p2x = v[6], p2y = v[7]; |
|
5756 |
if (t === undefined) |
|
5757 |
t = 0.5; |
|
5758 |
var u = 1 - t, |
|
5759 |
p3x = u * p1x + t * c1x, p3y = u * p1y + t * c1y, |
|
5760 |
p4x = u * c1x + t * c2x, p4y = u * c1y + t * c2y, |
|
5761 |
p5x = u * c2x + t * p2x, p5y = u * c2y + t * p2y, |
|
5762 |
p6x = u * p3x + t * p4x, p6y = u * p3y + t * p4y, |
|
5763 |
p7x = u * p4x + t * p5x, p7y = u * p4y + t * p5y, |
|
5764 |
p8x = u * p6x + t * p7x, p8y = u * p6y + t * p7y; |
|
5765 |
return [ |
|
5766 |
[p1x, p1y, p3x, p3y, p6x, p6y, p8x, p8y], |
|
5767 |
[p8x, p8y, p7x, p7y, p5x, p5y, p2x, p2y] |
|
5768 |
]; |
|
5769 |
}, |
|
5770 |
||
5771 |
solveCubic: function (v, coord, val, roots, min, max) {
|
|
5772 |
var p1 = v[coord], |
|
5773 |
c1 = v[coord + 2], |
|
5774 |
c2 = v[coord + 4], |
|
5775 |
p2 = v[coord + 6], |
|
5776 |
c = 3 * (c1 - p1), |
|
5777 |
b = 3 * (c2 - c1) - c, |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5778 |
a = p2 - p1 - c - b; |
| 442 | 5779 |
return Numerical.solveCubic(a, b, c, p1 - val, roots, min, max); |
5780 |
}, |
|
5781 |
||
| 598 | 5782 |
getParameterOf: function(v, point) {
|
5783 |
var p1 = new Point(v[0], v[1]), |
|
5784 |
p2 = new Point(v[6], v[7]), |
|
5785 |
epsilon = 1e-12, |
|
5786 |
t = point.isClose(p1, epsilon) ? 0 |
|
5787 |
: point.isClose(p2, epsilon) ? 1 |
|
5788 |
: null; |
|
5789 |
if (t !== null) |
|
5790 |
return t; |
|
5791 |
var coords = [point.x, point.y], |
|
5792 |
roots = [], |
|
5793 |
geomEpsilon = 2e-7; |
|
5794 |
for (var c = 0; c < 2; c++) {
|
|
5795 |
var count = Curve.solveCubic(v, c, coords[c], roots, 0, 1); |
|
5796 |
for (var i = 0; i < count; i++) {
|
|
5797 |
t = roots[i]; |
|
5798 |
if (point.isClose(Curve.getPoint(v, t), geomEpsilon)) |
|
5799 |
return t; |
|
5800 |
} |
|
5801 |
} |
|
5802 |
return point.isClose(p1, geomEpsilon) ? 0 |
|
5803 |
: point.isClose(p2, geomEpsilon) ? 1 |
|
5804 |
: null; |
|
5805 |
}, |
|
5806 |
||
5807 |
getNearestParameter: function(v, point) {
|
|
5808 |
if (Curve.isStraight(v)) {
|
|
5809 |
var p1x = v[0], p1y = v[1], |
|
5810 |
p2x = v[6], p2y = v[7], |
|
5811 |
vx = p2x - p1x, vy = p2y - p1y, |
|
5812 |
det = vx * vx + vy * vy; |
|
5813 |
if (det === 0) |
|
5814 |
return 0; |
|
5815 |
var u = ((point.x - p1x) * vx + (point.y - p1y) * vy) / det; |
|
5816 |
return u < 1e-12 ? 0 |
|
5817 |
: u > 0.999999999999 ? 1 |
|
5818 |
: Curve.getParameterOf(v, |
|
5819 |
new Point(p1x + u * vx, p1y + u * vy)); |
|
5820 |
} |
|
5821 |
||
5822 |
var count = 100, |
|
5823 |
minDist = Infinity, |
|
5824 |
minT = 0; |
|
5825 |
||
5826 |
function refine(t) {
|
|
5827 |
if (t >= 0 && t <= 1) {
|
|
5828 |
var dist = point.getDistance(Curve.getPoint(v, t), true); |
|
5829 |
if (dist < minDist) {
|
|
5830 |
minDist = dist; |
|
5831 |
minT = t; |
|
5832 |
return true; |
|
5833 |
} |
|
5834 |
} |
|
5835 |
} |
|
5836 |
||
5837 |
for (var i = 0; i <= count; i++) |
|
5838 |
refine(i / count); |
|
5839 |
||
5840 |
var step = 1 / (count * 2); |
|
5841 |
while (step > 4e-7) {
|
|
5842 |
if (!refine(minT - step) && !refine(minT + step)) |
|
5843 |
step /= 2; |
|
5844 |
} |
|
5845 |
return minT; |
|
| 442 | 5846 |
}, |
5847 |
||
5848 |
getPart: function(v, from, to) {
|
|
| 598 | 5849 |
var flip = from > to; |
5850 |
if (flip) {
|
|
5851 |
var tmp = from; |
|
5852 |
from = to; |
|
5853 |
to = tmp; |
|
5854 |
} |
|
| 442 | 5855 |
if (from > 0) |
5856 |
v = Curve.subdivide(v, from)[1]; |
|
5857 |
if (to < 1) |
|
5858 |
v = Curve.subdivide(v, (to - from) / (1 - from))[0]; |
|
| 598 | 5859 |
return flip |
5860 |
? [v[6], v[7], v[4], v[5], v[2], v[3], v[0], v[1]] |
|
5861 |
: v; |
|
| 442 | 5862 |
}, |
5863 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5864 |
hasHandles: function(v) {
|
| 442 | 5865 |
var isZero = Numerical.isZero; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5866 |
return !(isZero(v[0] - v[2]) && isZero(v[1] - v[3]) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5867 |
&& isZero(v[4] - v[6]) && isZero(v[5] - v[7])); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5868 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5869 |
|
| 442 | 5870 |
isFlatEnough: function(v, tolerance) {
|
5871 |
var p1x = v[0], p1y = v[1], |
|
5872 |
c1x = v[2], c1y = v[3], |
|
5873 |
c2x = v[4], c2y = v[5], |
|
5874 |
p2x = v[6], p2y = v[7], |
|
5875 |
ux = 3 * c1x - 2 * p1x - p2x, |
|
5876 |
uy = 3 * c1y - 2 * p1y - p2y, |
|
5877 |
vx = 3 * c2x - 2 * p2x - p1x, |
|
5878 |
vy = 3 * c2y - 2 * p2y - p1y; |
|
5879 |
return Math.max(ux * ux, vx * vx) + Math.max(uy * uy, vy * vy) |
|
5880 |
< 10 * tolerance * tolerance; |
|
5881 |
}, |
|
5882 |
||
5883 |
getArea: function(v) {
|
|
5884 |
var p1x = v[0], p1y = v[1], |
|
| 598 | 5885 |
p2x = v[6], p2y = v[7], |
5886 |
h1x = (v[2] + p1x) / 2, |
|
5887 |
h1y = (v[3] + p1y) / 2, |
|
5888 |
h2x = (v[4] + v[6]) / 2, |
|
5889 |
h2y = (v[5] + v[7]) / 2; |
|
5890 |
return 6 * ((p1x - h1x) * (h1y + p1y) |
|
5891 |
+ (h1x - h2x) * (h2y + h1y) |
|
5892 |
+ (h2x - p2x) * (p2y + h2y)) / 10; |
|
| 442 | 5893 |
}, |
5894 |
||
5895 |
getBounds: function(v) {
|
|
5896 |
var min = v.slice(0, 2), |
|
5897 |
max = min.slice(), |
|
5898 |
roots = [0, 0]; |
|
5899 |
for (var i = 0; i < 2; i++) |
|
5900 |
Curve._addBounds(v[i], v[i + 2], v[i + 4], v[i + 6], |
|
5901 |
i, 0, min, max, roots); |
|
5902 |
return new Rectangle(min[0], min[1], max[0] - min[0], max[1] - min[1]); |
|
5903 |
}, |
|
5904 |
||
5905 |
_addBounds: function(v0, v1, v2, v3, coord, padding, min, max, roots) {
|
|
5906 |
function add(value, padding) {
|
|
5907 |
var left = value - padding, |
|
5908 |
right = value + padding; |
|
5909 |
if (left < min[coord]) |
|
5910 |
min[coord] = left; |
|
5911 |
if (right > max[coord]) |
|
5912 |
max[coord] = right; |
|
5913 |
} |
|
5914 |
var a = 3 * (v1 - v2) - v0 + v3, |
|
5915 |
b = 2 * (v0 + v2) - 4 * v1, |
|
5916 |
c = v1 - v0, |
|
5917 |
count = Numerical.solveQuadratic(a, b, c, roots), |
|
| 598 | 5918 |
tMin = 4e-7, |
| 442 | 5919 |
tMax = 1 - tMin; |
5920 |
add(v3, 0); |
|
5921 |
for (var i = 0; i < count; i++) {
|
|
5922 |
var t = roots[i], |
|
5923 |
u = 1 - t; |
|
5924 |
if (tMin < t && t < tMax) |
|
5925 |
add(u * u * u * v0 |
|
5926 |
+ 3 * u * u * t * v1 |
|
5927 |
+ 3 * u * t * t * v2 |
|
5928 |
+ t * t * t * v3, |
|
5929 |
padding); |
|
5930 |
} |
|
5931 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5932 |
}}, Base.each( |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
5933 |
['getBounds', 'getStrokeBounds', 'getHandleBounds', 'getRoughBounds'], |
| 442 | 5934 |
function(name) {
|
5935 |
this[name] = function() {
|
|
5936 |
if (!this._bounds) |
|
5937 |
this._bounds = {};
|
|
5938 |
var bounds = this._bounds[name]; |
|
5939 |
if (!bounds) {
|
|
| 598 | 5940 |
var path = this._path; |
5941 |
bounds = this._bounds[name] = Path[name]( |
|
5942 |
[this._segment1, this._segment2], false, |
|
5943 |
path && path.getStyle()); |
|
| 442 | 5944 |
} |
5945 |
return bounds.clone(); |
|
5946 |
}; |
|
5947 |
}, |
|
5948 |
{
|
|
5949 |
||
| 598 | 5950 |
}), Base.each({
|
5951 |
isStraight: function(l, h1, h2) {
|
|
5952 |
if (h1.isZero() && h2.isZero()) {
|
|
5953 |
return true; |
|
5954 |
} else if (l.isZero()) {
|
|
5955 |
return false; |
|
5956 |
} else if (h1.isCollinear(l) && h2.isCollinear(l)) {
|
|
5957 |
var div = l.dot(l), |
|
5958 |
p1 = l.dot(h1) / div, |
|
5959 |
p2 = l.dot(h2) / div; |
|
5960 |
return p1 >= 0 && p1 <= 1 && p2 <= 0 && p2 >= -1; |
|
5961 |
} |
|
5962 |
return false; |
|
5963 |
}, |
|
5964 |
||
5965 |
isLinear: function(l, h1, h2) {
|
|
5966 |
var third = l.divide(3); |
|
5967 |
return h1.equals(third) && h2.negate().equals(third); |
|
5968 |
} |
|
5969 |
}, function(test, name) {
|
|
5970 |
this[name] = function() {
|
|
5971 |
var seg1 = this._segment1, |
|
5972 |
seg2 = this._segment2; |
|
5973 |
return test(seg2._point.subtract(seg1._point), |
|
5974 |
seg1._handleOut, seg2._handleIn); |
|
5975 |
}; |
|
5976 |
||
5977 |
this.statics[name] = function(v) {
|
|
5978 |
var p1x = v[0], p1y = v[1], |
|
5979 |
p2x = v[6], p2y = v[7]; |
|
5980 |
return test(new Point(p2x - p1x, p2y - p1y), |
|
5981 |
new Point(v[2] - p1x, v[3] - p1y), |
|
5982 |
new Point(v[4] - p2x, v[5] - p2y)); |
|
5983 |
}; |
|
5984 |
}, {
|
|
5985 |
statics: {},
|
|
5986 |
||
5987 |
hasHandles: function() {
|
|
5988 |
return !this._segment1._handleOut.isZero() |
|
5989 |
|| !this._segment2._handleIn.isZero(); |
|
5990 |
}, |
|
5991 |
||
5992 |
isCollinear: function(curve) {
|
|
5993 |
return curve && this.isStraight() && curve.isStraight() |
|
5994 |
&& this.getLine().isCollinear(curve.getLine()); |
|
5995 |
}, |
|
5996 |
||
5997 |
isHorizontal: function() {
|
|
5998 |
return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).y) |
|
5999 |
< 1e-7; |
|
6000 |
}, |
|
6001 |
||
6002 |
isVertical: function() {
|
|
6003 |
return this.isStraight() && Math.abs(this.getTangentAt(0.5, true).x) |
|
6004 |
< 1e-7; |
|
6005 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6006 |
}), {
|
| 442 | 6007 |
beans: false, |
6008 |
||
6009 |
getParameterAt: function(offset, start) {
|
|
6010 |
return Curve.getParameterAt(this.getValues(), offset, start); |
|
6011 |
}, |
|
6012 |
||
6013 |
getParameterOf: function() {
|
|
| 598 | 6014 |
return Curve.getParameterOf(this.getValues(), Point.read(arguments)); |
| 442 | 6015 |
}, |
6016 |
||
6017 |
getLocationAt: function(offset, isParameter) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6018 |
var t = isParameter ? offset : this.getParameterAt(offset); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6019 |
return t != null && t >= 0 && t <= 1 |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6020 |
? new CurveLocation(this, t) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6021 |
: null; |
| 442 | 6022 |
}, |
6023 |
||
6024 |
getLocationOf: function() {
|
|
6025 |
return this.getLocationAt(this.getParameterOf(Point.read(arguments)), |
|
6026 |
true); |
|
6027 |
}, |
|
6028 |
||
6029 |
getOffsetOf: function() {
|
|
6030 |
var loc = this.getLocationOf.apply(this, arguments); |
|
6031 |
return loc ? loc.getOffset() : null; |
|
6032 |
}, |
|
6033 |
||
6034 |
getNearestLocation: function() {
|
|
6035 |
var point = Point.read(arguments), |
|
6036 |
values = this.getValues(), |
|
| 598 | 6037 |
t = Curve.getNearestParameter(values, point), |
6038 |
pt = Curve.getPoint(values, t); |
|
6039 |
return new CurveLocation(this, t, pt, null, point.getDistance(pt)); |
|
| 442 | 6040 |
}, |
6041 |
||
6042 |
getNearestPoint: function() {
|
|
6043 |
return this.getNearestLocation.apply(this, arguments).getPoint(); |
|
6044 |
} |
|
6045 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6046 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6047 |
new function() {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6048 |
var methods = ['getPoint', 'getTangent', 'getNormal', 'getWeightedTangent', |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6049 |
'getWeightedNormal', 'getCurvature']; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6050 |
return Base.each(methods, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6051 |
function(name) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6052 |
this[name + 'At'] = function(offset, isParameter) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6053 |
var values = this.getValues(); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6054 |
return Curve[name](values, isParameter ? offset |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6055 |
: Curve.getParameterAt(values, offset, 0)); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6056 |
}; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6057 |
}, {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6058 |
statics: {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6059 |
evaluateMethods: methods |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6060 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6061 |
}) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6062 |
}, |
| 442 | 6063 |
new function() {
|
6064 |
||
6065 |
function getLengthIntegrand(v) {
|
|
6066 |
var p1x = v[0], p1y = v[1], |
|
6067 |
c1x = v[2], c1y = v[3], |
|
6068 |
c2x = v[4], c2y = v[5], |
|
6069 |
p2x = v[6], p2y = v[7], |
|
6070 |
||
6071 |
ax = 9 * (c1x - c2x) + 3 * (p2x - p1x), |
|
6072 |
bx = 6 * (p1x + c2x) - 12 * c1x, |
|
6073 |
cx = 3 * (c1x - p1x), |
|
6074 |
||
6075 |
ay = 9 * (c1y - c2y) + 3 * (p2y - p1y), |
|
6076 |
by = 6 * (p1y + c2y) - 12 * c1y, |
|
6077 |
cy = 3 * (c1y - p1y); |
|
6078 |
||
6079 |
return function(t) {
|
|
6080 |
var dx = (ax * t + bx) * t + cx, |
|
6081 |
dy = (ay * t + by) * t + cy; |
|
6082 |
return Math.sqrt(dx * dx + dy * dy); |
|
6083 |
}; |
|
6084 |
} |
|
6085 |
||
6086 |
function getIterations(a, b) {
|
|
6087 |
return Math.max(2, Math.min(16, Math.ceil(Math.abs(b - a) * 32))); |
|
6088 |
} |
|
6089 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6090 |
function evaluate(v, t, type, normalized) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6091 |
if (t == null || t < 0 || t > 1) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6092 |
return null; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6093 |
var p1x = v[0], p1y = v[1], |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6094 |
c1x = v[2], c1y = v[3], |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6095 |
c2x = v[4], c2y = v[5], |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6096 |
p2x = v[6], p2y = v[7], |
| 598 | 6097 |
tMin = 4e-7, |
6098 |
tMax = 1 - tMin, |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6099 |
x, y; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6100 |
|
| 598 | 6101 |
if (type === 0 && (t < tMin || t > tMax)) {
|
6102 |
var isZero = t < tMin; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6103 |
x = isZero ? p1x : p2x; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6104 |
y = isZero ? p1y : p2y; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6105 |
} else {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6106 |
var cx = 3 * (c1x - p1x), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6107 |
bx = 3 * (c2x - c1x) - cx, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6108 |
ax = p2x - p1x - cx - bx, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6109 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6110 |
cy = 3 * (c1y - p1y), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6111 |
by = 3 * (c2y - c1y) - cy, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6112 |
ay = p2y - p1y - cy - by; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6113 |
if (type === 0) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6114 |
x = ((ax * t + bx) * t + cx) * t + p1x; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6115 |
y = ((ay * t + by) * t + cy) * t + p1y; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6116 |
} else {
|
| 598 | 6117 |
if (t < tMin) {
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6118 |
x = cx; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6119 |
y = cy; |
| 598 | 6120 |
} else if (t > tMax) {
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6121 |
x = 3 * (p2x - c2x); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6122 |
y = 3 * (p2y - c2y); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6123 |
} else {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6124 |
x = (3 * ax * t + 2 * bx) * t + cx; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6125 |
y = (3 * ay * t + 2 * by) * t + cy; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6126 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6127 |
if (normalized) {
|
| 598 | 6128 |
if (x === 0 && y === 0 && (t < tMin || t > tMax)) {
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6129 |
x = c2x - c1x; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6130 |
y = c2y - c1y; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6131 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6132 |
var len = Math.sqrt(x * x + y * y); |
| 598 | 6133 |
if (len) {
|
6134 |
x /= len; |
|
6135 |
y /= len; |
|
6136 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6137 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6138 |
if (type === 3) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6139 |
var x2 = 6 * ax * t + 2 * bx, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6140 |
y2 = 6 * ay * t + 2 * by, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6141 |
d = Math.pow(x * x + y * y, 3 / 2); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6142 |
x = d !== 0 ? (x * y2 - y * x2) / d : 0; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6143 |
y = 0; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6144 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6145 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6146 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6147 |
return type === 2 ? new Point(y, -x) : new Point(x, y); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6148 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6149 |
|
| 598 | 6150 |
return { statics: {
|
| 442 | 6151 |
|
6152 |
getLength: function(v, a, b) {
|
|
6153 |
if (a === undefined) |
|
6154 |
a = 0; |
|
6155 |
if (b === undefined) |
|
6156 |
b = 1; |
|
| 598 | 6157 |
if (a === 0 && b === 1 && Curve.isStraight(v)) {
|
| 442 | 6158 |
var dx = v[6] - v[0], |
6159 |
dy = v[7] - v[1]; |
|
6160 |
return Math.sqrt(dx * dx + dy * dy); |
|
6161 |
} |
|
6162 |
var ds = getLengthIntegrand(v); |
|
6163 |
return Numerical.integrate(ds, a, b, getIterations(a, b)); |
|
6164 |
}, |
|
6165 |
||
6166 |
getParameterAt: function(v, offset, start) {
|
|
6167 |
if (start === undefined) |
|
6168 |
start = offset < 0 ? 1 : 0 |
|
6169 |
if (offset === 0) |
|
6170 |
return start; |
|
| 598 | 6171 |
var abs = Math.abs, |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6172 |
forward = offset > 0, |
| 442 | 6173 |
a = forward ? start : 0, |
6174 |
b = forward ? 1 : start, |
|
6175 |
ds = getLengthIntegrand(v), |
|
6176 |
rangeLength = Numerical.integrate(ds, a, b, |
|
6177 |
getIterations(a, b)); |
|
| 598 | 6178 |
if (abs(offset - rangeLength) < 1e-12) {
|
| 442 | 6179 |
return forward ? b : a; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6180 |
} else if (abs(offset) > rangeLength) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6181 |
return null; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6182 |
} |
| 442 | 6183 |
var guess = offset / rangeLength, |
6184 |
length = 0; |
|
6185 |
function f(t) {
|
|
6186 |
length += Numerical.integrate(ds, start, t, |
|
6187 |
getIterations(start, t)); |
|
6188 |
start = t; |
|
6189 |
return length - offset; |
|
6190 |
} |
|
| 598 | 6191 |
return Numerical.findRoot(f, ds, start + guess, a, b, 32, |
6192 |
1e-12); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6193 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6194 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6195 |
getPoint: function(v, t) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6196 |
return evaluate(v, t, 0, false); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6197 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6198 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6199 |
getTangent: function(v, t) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6200 |
return evaluate(v, t, 1, true); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6201 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6202 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6203 |
getWeightedTangent: function(v, t) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6204 |
return evaluate(v, t, 1, false); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6205 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6206 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6207 |
getNormal: function(v, t) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6208 |
return evaluate(v, t, 2, true); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6209 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6210 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6211 |
getWeightedNormal: function(v, t) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6212 |
return evaluate(v, t, 2, false); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6213 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6214 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6215 |
getCurvature: function(v, t) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6216 |
return evaluate(v, t, 3, false).x; |
| 442 | 6217 |
} |
| 598 | 6218 |
}}; |
6219 |
}, |
|
6220 |
new function() {
|
|
6221 |
||
6222 |
function addLocation(locations, param, v1, c1, t1, p1, v2, c2, t2, p2, |
|
6223 |
overlap) {
|
|
6224 |
var startConnected = param.startConnected, |
|
6225 |
endConnected = param.endConnected, |
|
6226 |
tMin = 4e-7, |
|
6227 |
tMax = 1 - tMin; |
|
6228 |
if (t1 == null) |
|
6229 |
t1 = Curve.getParameterOf(v1, p1); |
|
6230 |
if (t1 !== null && t1 >= (startConnected ? tMin : 0) && |
|
6231 |
t1 <= (endConnected ? tMax : 1)) {
|
|
6232 |
if (t2 == null) |
|
6233 |
t2 = Curve.getParameterOf(v2, p2); |
|
6234 |
if (t2 !== null && t2 >= (endConnected ? tMin : 0) && |
|
6235 |
t2 <= (startConnected ? tMax : 1)) {
|
|
6236 |
var renormalize = param.renormalize; |
|
6237 |
if (renormalize) {
|
|
6238 |
var res = renormalize(t1, t2); |
|
6239 |
t1 = res[0]; |
|
6240 |
t2 = res[1]; |
|
6241 |
} |
|
6242 |
var loc1 = new CurveLocation(c1, t1, |
|
6243 |
p1 || Curve.getPoint(v1, t1), overlap), |
|
6244 |
loc2 = new CurveLocation(c2, t2, |
|
6245 |
p2 || Curve.getPoint(v2, t2), overlap), |
|
6246 |
flip = loc1.getPath() === loc2.getPath() |
|
6247 |
&& loc1.getIndex() > loc2.getIndex(), |
|
6248 |
loc = flip ? loc2 : loc1, |
|
6249 |
include = param.include; |
|
6250 |
loc1._intersection = loc2; |
|
6251 |
loc2._intersection = loc1; |
|
6252 |
if (!include || include(loc)) {
|
|
6253 |
CurveLocation.insert(locations, loc, true); |
|
6254 |
} |
|
6255 |
} |
|
6256 |
} |
|
6257 |
} |
|
6258 |
||
6259 |
function addCurveIntersections(v1, v2, c1, c2, locations, param, |
|
| 442 | 6260 |
tMin, tMax, uMin, uMax, oldTDiff, reverse, recursion) {
|
| 598 | 6261 |
if (++recursion >= 24) |
| 442 | 6262 |
return; |
6263 |
var q0x = v2[0], q0y = v2[1], q3x = v2[6], q3y = v2[7], |
|
6264 |
getSignedDistance = Line.getSignedDistance, |
|
| 598 | 6265 |
d1 = getSignedDistance(q0x, q0y, q3x, q3y, v2[2], v2[3]), |
6266 |
d2 = getSignedDistance(q0x, q0y, q3x, q3y, v2[4], v2[5]), |
|
| 442 | 6267 |
factor = d1 * d2 > 0 ? 3 / 4 : 4 / 9, |
6268 |
dMin = factor * Math.min(0, d1, d2), |
|
6269 |
dMax = factor * Math.max(0, d1, d2), |
|
6270 |
dp0 = getSignedDistance(q0x, q0y, q3x, q3y, v1[0], v1[1]), |
|
6271 |
dp1 = getSignedDistance(q0x, q0y, q3x, q3y, v1[2], v1[3]), |
|
6272 |
dp2 = getSignedDistance(q0x, q0y, q3x, q3y, v1[4], v1[5]), |
|
6273 |
dp3 = getSignedDistance(q0x, q0y, q3x, q3y, v1[6], v1[7]), |
|
| 598 | 6274 |
hull = getConvexHull(dp0, dp1, dp2, dp3), |
6275 |
top = hull[0], |
|
6276 |
bottom = hull[1], |
|
6277 |
tMinClip, |
|
6278 |
tMaxClip; |
|
6279 |
if ((tMinClip = clipConvexHull(top, bottom, dMin, dMax)) == null || |
|
6280 |
(tMaxClip = clipConvexHull(top.reverse(), bottom.reverse(), |
|
6281 |
dMin, dMax)) == null) |
|
6282 |
return; |
|
6283 |
v1 = Curve.getPart(v1, tMinClip, tMaxClip); |
|
6284 |
var tDiff = tMaxClip - tMinClip, |
|
6285 |
tMinNew = tMin + (tMax - tMin) * tMinClip, |
|
6286 |
tMaxNew = tMin + (tMax - tMin) * tMaxClip; |
|
| 442 | 6287 |
if (oldTDiff > 0.5 && tDiff > 0.5) {
|
6288 |
if (tMaxNew - tMinNew > uMax - uMin) {
|
|
6289 |
var parts = Curve.subdivide(v1, 0.5), |
|
6290 |
t = tMinNew + (tMaxNew - tMinNew) / 2; |
|
6291 |
addCurveIntersections( |
|
| 598 | 6292 |
v2, parts[0], c2, c1, locations, param, |
6293 |
uMin, uMax, tMinNew, t, tDiff, !reverse, recursion); |
|
| 442 | 6294 |
addCurveIntersections( |
| 598 | 6295 |
v2, parts[1], c2, c1, locations, param, |
| 442 | 6296 |
uMin, uMax, t, tMaxNew, tDiff, !reverse, recursion); |
6297 |
} else {
|
|
6298 |
var parts = Curve.subdivide(v2, 0.5), |
|
6299 |
t = uMin + (uMax - uMin) / 2; |
|
6300 |
addCurveIntersections( |
|
| 598 | 6301 |
parts[0], v1, c2, c1, locations, param, |
6302 |
uMin, t, tMinNew, tMaxNew, tDiff, !reverse, recursion); |
|
| 442 | 6303 |
addCurveIntersections( |
| 598 | 6304 |
parts[1], v1, c2, c1, locations, param, |
| 442 | 6305 |
t, uMax, tMinNew, tMaxNew, tDiff, !reverse, recursion); |
6306 |
} |
|
| 598 | 6307 |
} else if (Math.max(uMax - uMin, tMaxNew - tMinNew) |
6308 |
< 1e-7) {
|
|
| 442 | 6309 |
var t1 = tMinNew + (tMaxNew - tMinNew) / 2, |
6310 |
t2 = uMin + (uMax - uMin) / 2; |
|
| 598 | 6311 |
v1 = c1.getValues(); |
6312 |
v2 = c2.getValues(); |
|
6313 |
addLocation(locations, param, |
|
6314 |
reverse ? v2 : v1, reverse ? c2 : c1, reverse ? t2 : t1, null, |
|
6315 |
reverse ? v1 : v2, reverse ? c1 : c2, reverse ? t1 : t2, null); |
|
6316 |
} else if (tDiff > 1e-12) {
|
|
6317 |
addCurveIntersections(v2, v1, c2, c1, locations, param, |
|
6318 |
uMin, uMax, tMinNew, tMaxNew, tDiff, !reverse, recursion); |
|
| 442 | 6319 |
} |
6320 |
} |
|
6321 |
||
6322 |
function getConvexHull(dq0, dq1, dq2, dq3) {
|
|
6323 |
var p0 = [ 0, dq0 ], |
|
6324 |
p1 = [ 1 / 3, dq1 ], |
|
6325 |
p2 = [ 2 / 3, dq2 ], |
|
6326 |
p3 = [ 1, dq3 ], |
|
| 598 | 6327 |
dist1 = dq1 - (2 * dq0 + dq3) / 3, |
6328 |
dist2 = dq2 - (dq0 + 2 * dq3) / 3, |
|
| 442 | 6329 |
hull; |
6330 |
if (dist1 * dist2 < 0) {
|
|
6331 |
hull = [[p0, p1, p3], [p0, p2, p3]]; |
|
6332 |
} else {
|
|
| 598 | 6333 |
var distRatio = dist1 / dist2; |
6334 |
hull = [ |
|
6335 |
distRatio >= 2 ? [p0, p1, p3] |
|
6336 |
: distRatio <= .5 ? [p0, p2, p3] |
|
6337 |
: [p0, p1, p2, p3], |
|
6338 |
[p0, p3] |
|
6339 |
]; |
|
6340 |
} |
|
6341 |
return (dist1 || dist2) < 0 ? hull.reverse() : hull; |
|
| 442 | 6342 |
} |
6343 |
||
6344 |
function clipConvexHull(hullTop, hullBottom, dMin, dMax) {
|
|
6345 |
if (hullTop[0][1] < dMin) {
|
|
6346 |
return clipConvexHullPart(hullTop, true, dMin); |
|
6347 |
} else if (hullBottom[0][1] > dMax) {
|
|
6348 |
return clipConvexHullPart(hullBottom, false, dMax); |
|
6349 |
} else {
|
|
6350 |
return hullTop[0][0]; |
|
6351 |
} |
|
6352 |
} |
|
6353 |
||
6354 |
function clipConvexHullPart(part, top, threshold) {
|
|
6355 |
var px = part[0][0], |
|
6356 |
py = part[0][1]; |
|
6357 |
for (var i = 1, l = part.length; i < l; i++) {
|
|
6358 |
var qx = part[i][0], |
|
6359 |
qy = part[i][1]; |
|
| 598 | 6360 |
if (top ? qy >= threshold : qy <= threshold) {
|
6361 |
return qy === threshold ? qx |
|
6362 |
: px + (threshold - py) * (qx - px) / (qy - py); |
|
6363 |
} |
|
| 442 | 6364 |
px = qx; |
6365 |
py = qy; |
|
6366 |
} |
|
6367 |
return null; |
|
6368 |
} |
|
6369 |
||
| 598 | 6370 |
function addCurveLineIntersections(v1, v2, c1, c2, locations, param) {
|
6371 |
var flip = Curve.isStraight(v1), |
|
| 442 | 6372 |
vc = flip ? v2 : v1, |
6373 |
vl = flip ? v1 : v2, |
|
6374 |
lx1 = vl[0], ly1 = vl[1], |
|
6375 |
lx2 = vl[6], ly2 = vl[7], |
|
6376 |
ldx = lx2 - lx1, |
|
6377 |
ldy = ly2 - ly1, |
|
6378 |
angle = Math.atan2(-ldy, ldx), |
|
6379 |
sin = Math.sin(angle), |
|
6380 |
cos = Math.cos(angle), |
|
6381 |
rvc = []; |
|
6382 |
for(var i = 0; i < 8; i += 2) {
|
|
6383 |
var x = vc[i] - lx1, |
|
6384 |
y = vc[i + 1] - ly1; |
|
6385 |
rvc.push( |
|
6386 |
x * cos - y * sin, |
|
| 598 | 6387 |
x * sin + y * cos); |
| 442 | 6388 |
} |
6389 |
var roots = [], |
|
6390 |
count = Curve.solveCubic(rvc, 1, 0, roots, 0, 1); |
|
6391 |
for (var i = 0; i < count; i++) {
|
|
6392 |
var tc = roots[i], |
|
| 598 | 6393 |
pc = Curve.getPoint(vc, tc), |
6394 |
tl = Curve.getParameterOf(vl, pc); |
|
6395 |
if (tl !== null) {
|
|
6396 |
var pl = Curve.getPoint(vl, tl), |
|
| 442 | 6397 |
t1 = flip ? tl : tc, |
6398 |
t2 = flip ? tc : tl; |
|
| 598 | 6399 |
if (!param.endConnected || t2 > Numerical.CURVETIME_EPSILON) {
|
6400 |
addLocation(locations, param, |
|
6401 |
v1, c1, t1, flip ? pl : pc, |
|
6402 |
v2, c2, t2, flip ? pc : pl); |
|
6403 |
} |
|
6404 |
} |
|
6405 |
} |
|
6406 |
} |
|
6407 |
||
6408 |
function addLineIntersection(v1, v2, c1, c2, locations, param) {
|
|
6409 |
var pt = Line.intersect( |
|
| 442 | 6410 |
v1[0], v1[1], v1[6], v1[7], |
6411 |
v2[0], v2[1], v2[6], v2[7]); |
|
| 598 | 6412 |
if (pt) {
|
6413 |
addLocation(locations, param, v1, c1, null, pt, v2, c2, null, pt); |
|
| 442 | 6414 |
} |
6415 |
} |
|
6416 |
||
6417 |
return { statics: {
|
|
| 598 | 6418 |
_getIntersections: function(v1, v2, c1, c2, locations, param) {
|
6419 |
if (!v2) {
|
|
6420 |
return Curve._getSelfIntersection(v1, c1, locations, param); |
|
6421 |
} |
|
6422 |
var c1p1x = v1[0], c1p1y = v1[1], |
|
6423 |
c1p2x = v1[6], c1p2y = v1[7], |
|
6424 |
c2p1x = v2[0], c2p1y = v2[1], |
|
6425 |
c2p2x = v2[6], c2p2y = v2[7], |
|
6426 |
c1s1x = (3 * v1[2] + c1p1x) / 4, |
|
6427 |
c1s1y = (3 * v1[3] + c1p1y) / 4, |
|
6428 |
c1s2x = (3 * v1[4] + c1p2x) / 4, |
|
6429 |
c1s2y = (3 * v1[5] + c1p2y) / 4, |
|
6430 |
c2s1x = (3 * v2[2] + c2p1x) / 4, |
|
6431 |
c2s1y = (3 * v2[3] + c2p1y) / 4, |
|
6432 |
c2s2x = (3 * v2[4] + c2p2x) / 4, |
|
6433 |
c2s2y = (3 * v2[5] + c2p2y) / 4, |
|
6434 |
min = Math.min, |
|
6435 |
max = Math.max; |
|
6436 |
if (!( max(c1p1x, c1s1x, c1s2x, c1p2x) >= |
|
6437 |
min(c2p1x, c2s1x, c2s2x, c2p2x) && |
|
6438 |
min(c1p1x, c1s1x, c1s2x, c1p2x) <= |
|
6439 |
max(c2p1x, c2s1x, c2s2x, c2p2x) && |
|
6440 |
max(c1p1y, c1s1y, c1s2y, c1p2y) >= |
|
6441 |
min(c2p1y, c2s1y, c2s2y, c2p2y) && |
|
6442 |
min(c1p1y, c1s1y, c1s2y, c1p2y) <= |
|
6443 |
max(c2p1y, c2s1y, c2s2y, c2p2y))) |
|
6444 |
return locations; |
|
6445 |
if (!param.startConnected && !param.endConnected) {
|
|
6446 |
var overlaps = Curve.getOverlaps(v1, v2); |
|
6447 |
if (overlaps) {
|
|
6448 |
for (var i = 0; i < 2; i++) {
|
|
6449 |
var overlap = overlaps[i]; |
|
6450 |
addLocation(locations, param, |
|
6451 |
v1, c1, overlap[0], null, |
|
6452 |
v2, c2, overlap[1], null, true); |
|
6453 |
} |
|
6454 |
return locations; |
|
6455 |
} |
|
6456 |
} |
|
6457 |
||
6458 |
var straight1 = Curve.isStraight(v1), |
|
6459 |
straight2 = Curve.isStraight(v2), |
|
6460 |
straight = straight1 && straight2, |
|
6461 |
epsilon = 1e-12, |
|
6462 |
before = locations.length; |
|
6463 |
(straight |
|
| 442 | 6464 |
? addLineIntersection |
| 598 | 6465 |
: straight1 || straight2 |
| 442 | 6466 |
? addCurveLineIntersections |
6467 |
: addCurveIntersections)( |
|
| 598 | 6468 |
v1, v2, c1, c2, locations, param, |
| 442 | 6469 |
0, 1, 0, 1, 0, false, 0); |
| 598 | 6470 |
if (straight && locations.length > before) |
6471 |
return locations; |
|
6472 |
var c1p1 = new Point(c1p1x, c1p1y), |
|
6473 |
c1p2 = new Point(c1p2x, c1p2y), |
|
6474 |
c2p1 = new Point(c2p1x, c2p1y), |
|
6475 |
c2p2 = new Point(c2p2x, c2p2y); |
|
6476 |
if (c1p1.isClose(c2p1, epsilon)) |
|
6477 |
addLocation(locations, param, v1, c1, 0, c1p1, v2, c2, 0, c2p1); |
|
6478 |
if (!param.startConnected && c1p1.isClose(c2p2, epsilon)) |
|
6479 |
addLocation(locations, param, v1, c1, 0, c1p1, v2, c2, 1, c2p2); |
|
6480 |
if (!param.endConnected && c1p2.isClose(c2p1, epsilon)) |
|
6481 |
addLocation(locations, param, v1, c1, 1, c1p2, v2, c2, 0, c2p1); |
|
6482 |
if (c1p2.isClose(c2p2, epsilon)) |
|
6483 |
addLocation(locations, param, v1, c1, 1, c1p2, v2, c2, 1, c2p2); |
|
| 442 | 6484 |
return locations; |
6485 |
}, |
|
6486 |
||
| 598 | 6487 |
_getSelfIntersection: function(v1, c1, locations, param) {
|
6488 |
var p1x = v1[0], p1y = v1[1], |
|
6489 |
h1x = v1[2], h1y = v1[3], |
|
6490 |
h2x = v1[4], h2y = v1[5], |
|
6491 |
p2x = v1[6], p2y = v1[7]; |
|
6492 |
var line = new Line(p1x, p1y, p2x, p2y, false), |
|
6493 |
side1 = line.getSide(new Point(h1x, h1y), true), |
|
6494 |
side2 = line.getSide(new Point(h2x, h2y), true); |
|
6495 |
if (side1 === side2) {
|
|
6496 |
var edgeSum = (p1x - h2x) * (h1y - p2y) |
|
6497 |
+ (h1x - p2x) * (h2y - p1y); |
|
6498 |
if (edgeSum * side1 > 0) |
|
6499 |
return locations; |
|
6500 |
} |
|
6501 |
var ax = p2x - 3 * h2x + 3 * h1x - p1x, |
|
6502 |
bx = h2x - 2 * h1x + p1x, |
|
6503 |
cx = h1x - p1x, |
|
6504 |
ay = p2y - 3 * h2y + 3 * h1y - p1y, |
|
6505 |
by = h2y - 2 * h1y + p1y, |
|
6506 |
cy = h1y - p1y, |
|
6507 |
ac = ay * cx - ax * cy, |
|
6508 |
ab = ay * bx - ax * by, |
|
6509 |
bc = by * cx - bx * cy; |
|
6510 |
if (ac * ac - 4 * ab * bc < 0) {
|
|
6511 |
var roots = [], |
|
6512 |
tSplit, |
|
6513 |
count = Numerical.solveCubic( |
|
6514 |
ax * ax + ay * ay, |
|
6515 |
3 * (ax * bx + ay * by), |
|
6516 |
2 * (bx * bx + by * by) + ax * cx + ay * cy, |
|
6517 |
bx * cx + by * cy, |
|
6518 |
roots, 0, 1); |
|
6519 |
if (count > 0) {
|
|
6520 |
for (var i = 0, maxCurvature = 0; i < count; i++) {
|
|
6521 |
var curvature = Math.abs( |
|
6522 |
c1.getCurvatureAt(roots[i], true)); |
|
6523 |
if (curvature > maxCurvature) {
|
|
6524 |
maxCurvature = curvature; |
|
6525 |
tSplit = roots[i]; |
|
6526 |
} |
|
| 442 | 6527 |
} |
| 598 | 6528 |
var parts = Curve.subdivide(v1, tSplit); |
6529 |
param.endConnected = true; |
|
6530 |
param.renormalize = function(t1, t2) {
|
|
6531 |
return [t1 * tSplit, t2 * (1 - tSplit) + tSplit]; |
|
6532 |
}; |
|
6533 |
Curve._getIntersections(parts[0], parts[1], c1, c1, |
|
6534 |
locations, param); |
|
6535 |
} |
|
| 442 | 6536 |
} |
6537 |
return locations; |
|
| 598 | 6538 |
}, |
6539 |
||
6540 |
getOverlaps: function(v1, v2) {
|
|
6541 |
var abs = Math.abs, |
|
6542 |
timeEpsilon = 4e-7, |
|
6543 |
geomEpsilon = 2e-7, |
|
6544 |
straight1 = Curve.isStraight(v1), |
|
6545 |
straight2 = Curve.isStraight(v2), |
|
6546 |
straight = straight1 && straight2; |
|
6547 |
||
6548 |
function getLineLengthSquared(v) {
|
|
6549 |
var x = v[6] - v[0], |
|
6550 |
y = v[7] - v[1]; |
|
6551 |
return x * x + y * y; |
|
6552 |
} |
|
6553 |
||
6554 |
if (straight) {
|
|
6555 |
var flip = getLineLengthSquared(v1) < getLineLengthSquared(v2), |
|
6556 |
l1 = flip ? v2 : v1, |
|
6557 |
l2 = flip ? v1 : v2, |
|
6558 |
line = new Line(l1[0], l1[1], l1[6], l1[7]); |
|
6559 |
if (line.getDistance(new Point(l2[0], l2[1])) > geomEpsilon || |
|
6560 |
line.getDistance(new Point(l2[6], l2[7])) > geomEpsilon) |
|
6561 |
return null; |
|
6562 |
} else if (straight1 ^ straight2) {
|
|
6563 |
return null; |
|
6564 |
} |
|
6565 |
||
6566 |
var v = [v1, v2], |
|
6567 |
pairs = []; |
|
6568 |
for (var i = 0, t1 = 0; |
|
6569 |
i < 2 && pairs.length < 2; |
|
6570 |
i += t1 === 0 ? 0 : 1, t1 = t1 ^ 1) {
|
|
6571 |
var t2 = Curve.getParameterOf(v[i ^ 1], new Point( |
|
6572 |
v[i][t1 === 0 ? 0 : 6], |
|
6573 |
v[i][t1 === 0 ? 1 : 7])); |
|
6574 |
if (t2 != null) {
|
|
6575 |
var pair = i === 0 ? [t1, t2] : [t2, t1]; |
|
6576 |
if (pairs.length === 0 || |
|
6577 |
abs(pair[0] - pairs[0][0]) > timeEpsilon && |
|
6578 |
abs(pair[1] - pairs[0][1]) > timeEpsilon) |
|
6579 |
pairs.push(pair); |
|
6580 |
} |
|
6581 |
if (i === 1 && pairs.length === 0) |
|
6582 |
break; |
|
6583 |
} |
|
6584 |
if (pairs.length !== 2) {
|
|
6585 |
pairs = null; |
|
6586 |
} else if (!straight) {
|
|
6587 |
var o1 = Curve.getPart(v1, pairs[0][0], pairs[1][0]), |
|
6588 |
o2 = Curve.getPart(v2, pairs[0][1], pairs[1][1]); |
|
6589 |
if (abs(o2[2] - o1[2]) > geomEpsilon || |
|
6590 |
abs(o2[3] - o1[3]) > geomEpsilon || |
|
6591 |
abs(o2[4] - o1[4]) > geomEpsilon || |
|
6592 |
abs(o2[5] - o1[5]) > geomEpsilon) |
|
6593 |
pairs = null; |
|
6594 |
} |
|
6595 |
return pairs; |
|
| 442 | 6596 |
} |
6597 |
}}; |
|
6598 |
}); |
|
6599 |
||
6600 |
var CurveLocation = Base.extend({
|
|
6601 |
_class: 'CurveLocation', |
|
6602 |
beans: true, |
|
6603 |
||
| 598 | 6604 |
initialize: function CurveLocation(curve, parameter, point, |
6605 |
_overlap, _distance) {
|
|
6606 |
if (parameter > 0.9999996) {
|
|
6607 |
var next = curve.getNext(); |
|
6608 |
if (next) {
|
|
6609 |
parameter = 0; |
|
6610 |
curve = next; |
|
6611 |
} |
|
6612 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6613 |
this._id = UID.get(CurveLocation); |
| 598 | 6614 |
this._setCurve(curve); |
6615 |
this._parameter = parameter; |
|
6616 |
this._point = point || curve.getPointAt(parameter, true); |
|
6617 |
this._overlap = _overlap; |
|
6618 |
this._distance = _distance; |
|
6619 |
this._intersection = this._next = this._prev = null; |
|
6620 |
}, |
|
6621 |
||
6622 |
_setCurve: function(curve) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6623 |
var path = curve._path; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6624 |
this._version = path ? path._version : 0; |
| 442 | 6625 |
this._curve = curve; |
| 598 | 6626 |
this._segment = null; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6627 |
this._segment1 = curve._segment1; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6628 |
this._segment2 = curve._segment2; |
| 442 | 6629 |
}, |
6630 |
||
| 598 | 6631 |
_setSegment: function(segment) {
|
6632 |
this._setCurve(segment.getCurve()); |
|
6633 |
this._segment = segment; |
|
6634 |
this._parameter = segment === this._segment1 ? 0 : 1; |
|
6635 |
this._point = segment._point.clone(); |
|
6636 |
}, |
|
6637 |
||
6638 |
getSegment: function() {
|
|
6639 |
var curve = this.getCurve(), |
|
6640 |
segment = this._segment; |
|
6641 |
if (!segment) {
|
|
6642 |
var parameter = this.getParameter(); |
|
6643 |
if (parameter === 0) {
|
|
6644 |
segment = curve._segment1; |
|
6645 |
} else if (parameter === 1) {
|
|
6646 |
segment = curve._segment2; |
|
6647 |
} else if (parameter != null) {
|
|
6648 |
segment = curve.getPartLength(0, parameter) |
|
| 442 | 6649 |
< curve.getPartLength(parameter, 1) |
6650 |
? curve._segment1 |
|
6651 |
: curve._segment2; |
|
6652 |
} |
|
| 598 | 6653 |
this._segment = segment; |
6654 |
} |
|
6655 |
return segment; |
|
| 442 | 6656 |
}, |
6657 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6658 |
getCurve: function() {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6659 |
var curve = this._curve, |
| 598 | 6660 |
path = curve && curve._path, |
6661 |
that = this; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6662 |
if (path && path._version !== this._version) {
|
| 598 | 6663 |
curve = this._parameter = this._curve = this._offset = null; |
6664 |
} |
|
6665 |
||
6666 |
function trySegment(segment) {
|
|
6667 |
var curve = segment && segment.getCurve(); |
|
6668 |
if (curve && (that._parameter = curve.getParameterOf(that._point)) |
|
6669 |
!= null) {
|
|
6670 |
that._setCurve(curve); |
|
6671 |
that._segment = segment; |
|
6672 |
return curve; |
|
6673 |
} |
|
6674 |
} |
|
6675 |
||
6676 |
return curve |
|
6677 |
|| trySegment(this._segment) |
|
6678 |
|| trySegment(this._segment1) |
|
6679 |
|| trySegment(this._segment2.getPrevious()); |
|
| 442 | 6680 |
}, |
6681 |
||
6682 |
getPath: function() {
|
|
6683 |
var curve = this.getCurve(); |
|
6684 |
return curve && curve._path; |
|
6685 |
}, |
|
6686 |
||
6687 |
getIndex: function() {
|
|
6688 |
var curve = this.getCurve(); |
|
6689 |
return curve && curve.getIndex(); |
|
6690 |
}, |
|
6691 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6692 |
getParameter: function() {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6693 |
var curve = this.getCurve(), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6694 |
parameter = this._parameter; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6695 |
return curve && parameter == null |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6696 |
? this._parameter = curve.getParameterOf(this._point) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6697 |
: parameter; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6698 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6699 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6700 |
getPoint: function() {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6701 |
return this._point; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6702 |
}, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6703 |
|
| 442 | 6704 |
getOffset: function() {
|
| 598 | 6705 |
var offset = this._offset; |
6706 |
if (offset == null) {
|
|
6707 |
offset = 0; |
|
6708 |
var path = this.getPath(), |
|
6709 |
index = this.getIndex(); |
|
6710 |
if (path && index != null) {
|
|
6711 |
var curves = path.getCurves(); |
|
6712 |
for (var i = 0; i < index; i++) |
|
6713 |
offset += curves[i].getLength(); |
|
6714 |
} |
|
6715 |
this._offset = offset += this.getCurveOffset(); |
|
6716 |
} |
|
6717 |
return offset; |
|
| 442 | 6718 |
}, |
6719 |
||
6720 |
getCurveOffset: function() {
|
|
6721 |
var curve = this.getCurve(), |
|
6722 |
parameter = this.getParameter(); |
|
6723 |
return parameter != null && curve && curve.getPartLength(0, parameter); |
|
6724 |
}, |
|
6725 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6726 |
getIntersection: function() {
|
| 598 | 6727 |
return this._intersection; |
| 442 | 6728 |
}, |
6729 |
||
6730 |
getDistance: function() {
|
|
6731 |
return this._distance; |
|
6732 |
}, |
|
6733 |
||
6734 |
divide: function() {
|
|
| 598 | 6735 |
var curve = this.getCurve(), |
6736 |
res = null; |
|
6737 |
if (curve) {
|
|
6738 |
res = curve.divide(this.getParameter(), true); |
|
6739 |
if (res) |
|
6740 |
this._setSegment(res._segment1); |
|
6741 |
} |
|
6742 |
return res; |
|
| 442 | 6743 |
}, |
6744 |
||
6745 |
split: function() {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6746 |
var curve = this.getCurve(); |
| 598 | 6747 |
return curve ? curve.split(this.getParameter(), true) : null; |
6748 |
}, |
|
6749 |
||
6750 |
equals: function(loc, _ignoreOther) {
|
|
6751 |
var res = this === loc, |
|
6752 |
epsilon = 2e-7; |
|
6753 |
if (!res && loc instanceof CurveLocation |
|
6754 |
&& this.getPath() === loc.getPath() |
|
6755 |
&& this.getPoint().isClose(loc.getPoint(), epsilon)) {
|
|
6756 |
var c1 = this.getCurve(), |
|
6757 |
c2 = loc.getCurve(), |
|
6758 |
abs = Math.abs, |
|
6759 |
diff = abs( |
|
6760 |
((c1.isLast() && c2.isFirst() ? -1 : c1.getIndex()) |
|
6761 |
+ this.getParameter()) - |
|
6762 |
((c2.isLast() && c1.isFirst() ? -1 : c2.getIndex()) |
|
6763 |
+ loc.getParameter())); |
|
6764 |
res = (diff < 4e-7 |
|
6765 |
|| ((diff = abs(this.getOffset() - loc.getOffset())) < epsilon |
|
6766 |
|| abs(this.getPath().getLength() - diff) < epsilon)) |
|
6767 |
&& (_ignoreOther |
|
6768 |
|| (!this._intersection && !loc._intersection |
|
6769 |
|| this._intersection && this._intersection.equals( |
|
6770 |
loc._intersection, true))); |
|
6771 |
} |
|
6772 |
return res; |
|
| 442 | 6773 |
}, |
6774 |
||
6775 |
toString: function() {
|
|
6776 |
var parts = [], |
|
6777 |
point = this.getPoint(), |
|
6778 |
f = Formatter.instance; |
|
6779 |
if (point) |
|
6780 |
parts.push('point: ' + point);
|
|
6781 |
var index = this.getIndex(); |
|
6782 |
if (index != null) |
|
6783 |
parts.push('index: ' + index);
|
|
6784 |
var parameter = this.getParameter(); |
|
6785 |
if (parameter != null) |
|
6786 |
parts.push('parameter: ' + f.number(parameter));
|
|
6787 |
if (this._distance != null) |
|
6788 |
parts.push('distance: ' + f.number(this._distance));
|
|
6789 |
return '{ ' + parts.join(', ') + ' }';
|
|
| 598 | 6790 |
}, |
6791 |
||
6792 |
isTouching: function() {
|
|
6793 |
var inter = this._intersection; |
|
6794 |
if (inter && this.getTangent().isCollinear(inter.getTangent())) {
|
|
6795 |
var curve1 = this.getCurve(), |
|
6796 |
curve2 = inter.getCurve(); |
|
6797 |
return !(curve1.isStraight() && curve2.isStraight() |
|
6798 |
&& curve1.getLine().intersect(curve2.getLine())); |
|
6799 |
} |
|
6800 |
return false; |
|
6801 |
}, |
|
6802 |
||
6803 |
isCrossing: function() {
|
|
6804 |
var inter = this._intersection; |
|
6805 |
if (!inter) |
|
6806 |
return false; |
|
6807 |
var t1 = this.getParameter(), |
|
6808 |
t2 = inter.getParameter(), |
|
6809 |
tMin = 4e-7, |
|
6810 |
tMax = 1 - tMin; |
|
6811 |
if (t1 >= tMin && t1 <= tMax || t2 >= tMin && t2 <= tMax) |
|
6812 |
return !this.isTouching(); |
|
6813 |
var c2 = this.getCurve(), |
|
6814 |
c1 = c2.getPrevious(), |
|
6815 |
c4 = inter.getCurve(), |
|
6816 |
c3 = c4.getPrevious(), |
|
6817 |
PI = Math.PI; |
|
6818 |
if (!c1 || !c3) |
|
6819 |
return false; |
|
6820 |
||
6821 |
function isInRange(angle, min, max) {
|
|
6822 |
return min < max |
|
6823 |
? angle > min && angle < max |
|
6824 |
: angle > min && angle <= PI || angle >= -PI && angle < max; |
|
6825 |
} |
|
6826 |
||
6827 |
var a1 = c1.getTangentAt(tMax, true).negate().getAngleInRadians(), |
|
6828 |
a2 = c2.getTangentAt(tMin, true).getAngleInRadians(), |
|
6829 |
a3 = c3.getTangentAt(tMax, true).negate().getAngleInRadians(), |
|
6830 |
a4 = c4.getTangentAt(tMin, true).getAngleInRadians(); |
|
6831 |
||
6832 |
return (isInRange(a3, a1, a2) ^ isInRange(a4, a1, a2)) |
|
6833 |
&& (isInRange(a3, a2, a1) ^ isInRange(a4, a2, a1)); |
|
6834 |
}, |
|
6835 |
||
6836 |
isOverlap: function() {
|
|
6837 |
return !!this._overlap; |
|
| 442 | 6838 |
} |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
6839 |
}, Base.each(Curve.evaluateMethods, function(name) {
|
| 598 | 6840 |
var get = name + 'At'; |
6841 |
this[name] = function() {
|
|
6842 |
var parameter = this.getParameter(), |
|
6843 |
curve = this.getCurve(); |
|
6844 |
return parameter != null && curve && curve[get](parameter, true); |
|
6845 |
}; |
|
6846 |
}, {
|
|
6847 |
preserve: true |
|
6848 |
}), |
|
6849 |
new function() {
|
|
6850 |
||
6851 |
function insert(locations, loc, merge) {
|
|
6852 |
var length = locations.length, |
|
6853 |
l = 0, |
|
6854 |
r = length - 1; |
|
6855 |
||
6856 |
function search(index, dir) {
|
|
6857 |
for (var i = index + dir; i >= -1 && i <= length; i += dir) {
|
|
6858 |
var loc2 = locations[((i % length) + length) % length]; |
|
6859 |
if (!loc.getPoint().isClose(loc2.getPoint(), |
|
6860 |
2e-7)) |
|
6861 |
break; |
|
6862 |
if (loc.equals(loc2)) |
|
6863 |
return loc2; |
|
6864 |
} |
|
6865 |
return null; |
|
6866 |
} |
|
6867 |
||
6868 |
while (l <= r) {
|
|
6869 |
var m = (l + r) >>> 1, |
|
6870 |
loc2 = locations[m], |
|
6871 |
found; |
|
6872 |
if (merge && (found = loc.equals(loc2) ? loc2 |
|
6873 |
: (search(m, -1) || search(m, 1)))) {
|
|
6874 |
if (loc._overlap) {
|
|
6875 |
found._overlap = found._intersection._overlap = true; |
|
6876 |
} |
|
6877 |
return found; |
|
6878 |
} |
|
6879 |
var path1 = loc.getPath(), |
|
6880 |
path2 = loc2.getPath(), |
|
6881 |
diff = path1 === path2 |
|
6882 |
? (loc.getIndex() + loc.getParameter()) |
|
6883 |
- (loc2.getIndex() + loc2.getParameter()) |
|
6884 |
: path1._id - path2._id; |
|
6885 |
if (diff < 0) {
|
|
6886 |
r = m - 1; |
|
6887 |
} else {
|
|
6888 |
l = m + 1; |
|
6889 |
} |
|
6890 |
} |
|
6891 |
locations.splice(l, 0, loc); |
|
6892 |
return loc; |
|
6893 |
} |
|
6894 |
||
6895 |
return { statics: {
|
|
6896 |
insert: insert, |
|
6897 |
||
6898 |
expand: function(locations) {
|
|
6899 |
var expanded = locations.slice(); |
|
6900 |
for (var i = 0, l = locations.length; i < l; i++) {
|
|
6901 |
insert(expanded, locations[i]._intersection, false); |
|
6902 |
} |
|
6903 |
return expanded; |
|
6904 |
} |
|
6905 |
}}; |
|
6906 |
}); |
|
| 442 | 6907 |
|
6908 |
var PathItem = Item.extend({
|
|
6909 |
_class: 'PathItem', |
|
6910 |
||
6911 |
initialize: function PathItem() {
|
|
6912 |
}, |
|
6913 |
||
| 598 | 6914 |
getIntersections: function(path, include, _matrix, _returnFirst) {
|
6915 |
var self = this === path || !path, |
|
| 442 | 6916 |
matrix1 = this._matrix.orNullIfIdentity(), |
| 598 | 6917 |
matrix2 = self ? matrix1 |
6918 |
: (_matrix || path._matrix).orNullIfIdentity(); |
|
6919 |
if (!self && !this.getBounds(matrix1).touches(path.getBounds(matrix2))) |
|
6920 |
return []; |
|
6921 |
var curves1 = this.getCurves(), |
|
6922 |
curves2 = self ? curves1 : path.getCurves(), |
|
| 442 | 6923 |
length1 = curves1.length, |
| 598 | 6924 |
length2 = self ? length1 : curves2.length, |
| 442 | 6925 |
values2 = [], |
| 598 | 6926 |
arrays = [], |
6927 |
locations, |
|
6928 |
path; |
|
| 442 | 6929 |
for (var i = 0; i < length2; i++) |
6930 |
values2[i] = curves2[i].getValues(matrix2); |
|
6931 |
for (var i = 0; i < length1; i++) {
|
|
6932 |
var curve1 = curves1[i], |
|
| 598 | 6933 |
values1 = self ? values2[i] : curve1.getValues(matrix1), |
6934 |
path1 = curve1.getPath(); |
|
6935 |
if (path1 !== path) {
|
|
6936 |
path = path1; |
|
6937 |
locations = []; |
|
6938 |
arrays.push(locations); |
|
6939 |
} |
|
6940 |
if (self) {
|
|
6941 |
Curve._getSelfIntersection(values1, curve1, locations, {
|
|
6942 |
include: include, |
|
6943 |
startConnected: length1 === 1 && |
|
6944 |
curve1.getPoint1().equals(curve1.getPoint2()) |
|
6945 |
}); |
|
6946 |
} |
|
6947 |
for (var j = self ? i + 1 : 0; j < length2; j++) {
|
|
6948 |
if (_returnFirst && locations.length) |
|
6949 |
return locations; |
|
6950 |
var curve2 = curves2[j]; |
|
6951 |
Curve._getIntersections( |
|
6952 |
values1, values2[j], curve1, curve2, locations, |
|
6953 |
{
|
|
6954 |
include: include, |
|
6955 |
startConnected: self && curve1.getPrevious() === curve2, |
|
6956 |
endConnected: self && curve1.getNext() === curve2 |
|
6957 |
} |
|
| 442 | 6958 |
); |
6959 |
} |
|
6960 |
} |
|
| 598 | 6961 |
locations = []; |
6962 |
for (var i = 0, l = arrays.length; i < l; i++) {
|
|
6963 |
locations.push.apply(locations, arrays[i]); |
|
6964 |
} |
|
6965 |
return locations; |
|
6966 |
}, |
|
6967 |
||
6968 |
getCrossings: function(path) {
|
|
6969 |
return this.getIntersections(path, function(inter) {
|
|
6970 |
return inter.isCrossing(); |
|
6971 |
}); |
|
| 442 | 6972 |
}, |
6973 |
||
6974 |
_asPathItem: function() {
|
|
6975 |
return this; |
|
6976 |
}, |
|
6977 |
||
6978 |
setPathData: function(data) {
|
|
6979 |
||
6980 |
var parts = data.match(/[mlhvcsqtaz][^mlhvcsqtaz]*/ig), |
|
6981 |
coords, |
|
6982 |
relative = false, |
|
6983 |
previous, |
|
6984 |
control, |
|
6985 |
current = new Point(), |
|
6986 |
start = new Point(); |
|
6987 |
||
6988 |
function getCoord(index, coord) {
|
|
6989 |
var val = +coords[index]; |
|
6990 |
if (relative) |
|
6991 |
val += current[coord]; |
|
6992 |
return val; |
|
6993 |
} |
|
6994 |
||
6995 |
function getPoint(index) {
|
|
6996 |
return new Point( |
|
6997 |
getCoord(index, 'x'), |
|
6998 |
getCoord(index + 1, 'y') |
|
6999 |
); |
|
7000 |
} |
|
7001 |
||
7002 |
this.clear(); |
|
7003 |
||
7004 |
for (var i = 0, l = parts && parts.length; i < l; i++) {
|
|
7005 |
var part = parts[i], |
|
7006 |
command = part[0], |
|
7007 |
lower = command.toLowerCase(); |
|
7008 |
coords = part.match(/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g); |
|
7009 |
var length = coords && coords.length; |
|
7010 |
relative = command === lower; |
|
7011 |
if (previous === 'z' && !/[mz]/.test(lower)) |
|
7012 |
this.moveTo(current = start); |
|
7013 |
switch (lower) {
|
|
7014 |
case 'm': |
|
7015 |
case 'l': |
|
7016 |
var move = lower === 'm'; |
|
7017 |
for (var j = 0; j < length; j += 2) |
|
7018 |
this[j === 0 && move ? 'moveTo' : 'lineTo']( |
|
7019 |
current = getPoint(j)); |
|
7020 |
control = current; |
|
7021 |
if (move) |
|
7022 |
start = current; |
|
7023 |
break; |
|
7024 |
case 'h': |
|
7025 |
case 'v': |
|
7026 |
var coord = lower === 'h' ? 'x' : 'y'; |
|
7027 |
for (var j = 0; j < length; j++) {
|
|
7028 |
current[coord] = getCoord(j, coord); |
|
7029 |
this.lineTo(current); |
|
7030 |
} |
|
7031 |
control = current; |
|
7032 |
break; |
|
7033 |
case 'c': |
|
7034 |
for (var j = 0; j < length; j += 6) {
|
|
7035 |
this.cubicCurveTo( |
|
7036 |
getPoint(j), |
|
7037 |
control = getPoint(j + 2), |
|
7038 |
current = getPoint(j + 4)); |
|
7039 |
} |
|
7040 |
break; |
|
7041 |
case 's': |
|
7042 |
for (var j = 0; j < length; j += 4) {
|
|
7043 |
this.cubicCurveTo( |
|
7044 |
/[cs]/.test(previous) |
|
7045 |
? current.multiply(2).subtract(control) |
|
7046 |
: current, |
|
7047 |
control = getPoint(j), |
|
7048 |
current = getPoint(j + 2)); |
|
7049 |
previous = lower; |
|
7050 |
} |
|
7051 |
break; |
|
7052 |
case 'q': |
|
7053 |
for (var j = 0; j < length; j += 4) {
|
|
7054 |
this.quadraticCurveTo( |
|
7055 |
control = getPoint(j), |
|
7056 |
current = getPoint(j + 2)); |
|
7057 |
} |
|
7058 |
break; |
|
7059 |
case 't': |
|
7060 |
for (var j = 0; j < length; j += 2) {
|
|
7061 |
this.quadraticCurveTo( |
|
7062 |
control = (/[qt]/.test(previous) |
|
7063 |
? current.multiply(2).subtract(control) |
|
7064 |
: current), |
|
7065 |
current = getPoint(j)); |
|
7066 |
previous = lower; |
|
7067 |
} |
|
7068 |
break; |
|
7069 |
case 'a': |
|
7070 |
for (var j = 0; j < length; j += 7) {
|
|
7071 |
this.arcTo(current = getPoint(j + 5), |
|
7072 |
new Size(+coords[j], +coords[j + 1]), |
|
7073 |
+coords[j + 2], +coords[j + 4], +coords[j + 3]); |
|
7074 |
} |
|
7075 |
break; |
|
7076 |
case 'z': |
|
7077 |
this.closePath(true); |
|
7078 |
break; |
|
7079 |
} |
|
7080 |
previous = lower; |
|
7081 |
} |
|
7082 |
}, |
|
7083 |
||
7084 |
_canComposite: function() {
|
|
7085 |
return !(this.hasFill() && this.hasStroke()); |
|
7086 |
}, |
|
7087 |
||
7088 |
_contains: function(point) {
|
|
7089 |
var winding = this._getWinding(point, false, true); |
|
7090 |
return !!(this.getWindingRule() === 'evenodd' ? winding & 1 : winding); |
|
7091 |
} |
|
7092 |
||
7093 |
}); |
|
7094 |
||
7095 |
var Path = PathItem.extend({
|
|
7096 |
_class: 'Path', |
|
7097 |
_serializeFields: {
|
|
7098 |
segments: [], |
|
7099 |
closed: false |
|
7100 |
}, |
|
7101 |
||
7102 |
initialize: function Path(arg) {
|
|
7103 |
this._closed = false; |
|
7104 |
this._segments = []; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7105 |
this._version = 0; |
| 442 | 7106 |
var segments = Array.isArray(arg) |
7107 |
? typeof arg[0] === 'object' |
|
7108 |
? arg |
|
7109 |
: arguments |
|
7110 |
: arg && (arg.size === undefined && (arg.x !== undefined |
|
7111 |
|| arg.point !== undefined)) |
|
7112 |
? arguments |
|
7113 |
: null; |
|
7114 |
if (segments && segments.length > 0) {
|
|
7115 |
this.setSegments(segments); |
|
7116 |
} else {
|
|
7117 |
this._curves = undefined; |
|
7118 |
this._selectedSegmentState = 0; |
|
7119 |
if (!segments && typeof arg === 'string') {
|
|
7120 |
this.setPathData(arg); |
|
7121 |
arg = null; |
|
7122 |
} |
|
7123 |
} |
|
7124 |
this._initialize(!segments && arg); |
|
7125 |
}, |
|
7126 |
||
7127 |
_equals: function(item) {
|
|
7128 |
return this._closed === item._closed |
|
7129 |
&& Base.equals(this._segments, item._segments); |
|
7130 |
}, |
|
7131 |
||
7132 |
clone: function(insert) {
|
|
7133 |
var copy = new Path(Item.NO_INSERT); |
|
7134 |
copy.setSegments(this._segments); |
|
7135 |
copy._closed = this._closed; |
|
7136 |
if (this._clockwise !== undefined) |
|
7137 |
copy._clockwise = this._clockwise; |
|
7138 |
return this._clone(copy, insert); |
|
7139 |
}, |
|
7140 |
||
7141 |
_changed: function _changed(flags) {
|
|
7142 |
_changed.base.call(this, flags); |
|
7143 |
if (flags & 8) {
|
|
7144 |
var parent = this._parent; |
|
7145 |
if (parent) |
|
7146 |
parent._currentPath = undefined; |
|
| 598 | 7147 |
this._length = this._area = this._clockwise = this._monoCurves = |
7148 |
undefined; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7149 |
if (flags & 16) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7150 |
this._version++; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7151 |
} else if (this._curves) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7152 |
for (var i = 0, l = this._curves.length; i < l; i++) |
| 442 | 7153 |
this._curves[i]._changed(); |
7154 |
} |
|
7155 |
} else if (flags & 32) {
|
|
7156 |
this._bounds = undefined; |
|
7157 |
} |
|
7158 |
}, |
|
7159 |
||
7160 |
getStyle: function() {
|
|
7161 |
var parent = this._parent; |
|
7162 |
return (parent instanceof CompoundPath ? parent : this)._style; |
|
7163 |
}, |
|
7164 |
||
7165 |
getSegments: function() {
|
|
7166 |
return this._segments; |
|
7167 |
}, |
|
7168 |
||
7169 |
setSegments: function(segments) {
|
|
7170 |
var fullySelected = this.isFullySelected(); |
|
7171 |
this._segments.length = 0; |
|
7172 |
this._selectedSegmentState = 0; |
|
7173 |
this._curves = undefined; |
|
7174 |
if (segments && segments.length > 0) |
|
7175 |
this._add(Segment.readAll(segments)); |
|
7176 |
if (fullySelected) |
|
7177 |
this.setFullySelected(true); |
|
7178 |
}, |
|
7179 |
||
7180 |
getFirstSegment: function() {
|
|
7181 |
return this._segments[0]; |
|
7182 |
}, |
|
7183 |
||
7184 |
getLastSegment: function() {
|
|
7185 |
return this._segments[this._segments.length - 1]; |
|
7186 |
}, |
|
7187 |
||
7188 |
getCurves: function() {
|
|
7189 |
var curves = this._curves, |
|
7190 |
segments = this._segments; |
|
7191 |
if (!curves) {
|
|
7192 |
var length = this._countCurves(); |
|
7193 |
curves = this._curves = new Array(length); |
|
7194 |
for (var i = 0; i < length; i++) |
|
7195 |
curves[i] = new Curve(this, segments[i], |
|
7196 |
segments[i + 1] || segments[0]); |
|
7197 |
} |
|
7198 |
return curves; |
|
7199 |
}, |
|
7200 |
||
7201 |
getFirstCurve: function() {
|
|
7202 |
return this.getCurves()[0]; |
|
7203 |
}, |
|
7204 |
||
7205 |
getLastCurve: function() {
|
|
7206 |
var curves = this.getCurves(); |
|
7207 |
return curves[curves.length - 1]; |
|
7208 |
}, |
|
7209 |
||
7210 |
isClosed: function() {
|
|
7211 |
return this._closed; |
|
7212 |
}, |
|
7213 |
||
7214 |
setClosed: function(closed) {
|
|
7215 |
if (this._closed != (closed = !!closed)) {
|
|
7216 |
this._closed = closed; |
|
7217 |
if (this._curves) {
|
|
7218 |
var length = this._curves.length = this._countCurves(); |
|
7219 |
if (closed) |
|
7220 |
this._curves[length - 1] = new Curve(this, |
|
7221 |
this._segments[length - 1], this._segments[0]); |
|
7222 |
} |
|
7223 |
this._changed(25); |
|
7224 |
} |
|
7225 |
} |
|
7226 |
}, {
|
|
7227 |
beans: true, |
|
7228 |
||
7229 |
getPathData: function(_matrix, _precision) {
|
|
7230 |
var segments = this._segments, |
|
7231 |
length = segments.length, |
|
7232 |
f = new Formatter(_precision), |
|
7233 |
coords = new Array(6), |
|
7234 |
first = true, |
|
7235 |
curX, curY, |
|
7236 |
prevX, prevY, |
|
7237 |
inX, inY, |
|
7238 |
outX, outY, |
|
7239 |
parts = []; |
|
7240 |
||
7241 |
function addSegment(segment, skipLine) {
|
|
7242 |
segment._transformCoordinates(_matrix, coords, false); |
|
7243 |
curX = coords[0]; |
|
7244 |
curY = coords[1]; |
|
7245 |
if (first) {
|
|
7246 |
parts.push('M' + f.pair(curX, curY));
|
|
7247 |
first = false; |
|
7248 |
} else {
|
|
7249 |
inX = coords[2]; |
|
7250 |
inY = coords[3]; |
|
7251 |
if (inX === curX && inY === curY |
|
7252 |
&& outX === prevX && outY === prevY) {
|
|
7253 |
if (!skipLine) |
|
7254 |
parts.push('l' + f.pair(curX - prevX, curY - prevY));
|
|
7255 |
} else {
|
|
7256 |
parts.push('c' + f.pair(outX - prevX, outY - prevY)
|
|
7257 |
+ ' ' + f.pair(inX - prevX, inY - prevY) |
|
7258 |
+ ' ' + f.pair(curX - prevX, curY - prevY)); |
|
7259 |
} |
|
7260 |
} |
|
7261 |
prevX = curX; |
|
7262 |
prevY = curY; |
|
7263 |
outX = coords[4]; |
|
7264 |
outY = coords[5]; |
|
7265 |
} |
|
7266 |
||
7267 |
if (length === 0) |
|
7268 |
return ''; |
|
7269 |
||
7270 |
for (var i = 0; i < length; i++) |
|
7271 |
addSegment(segments[i]); |
|
7272 |
if (this._closed && length > 0) {
|
|
7273 |
addSegment(segments[0], true); |
|
7274 |
parts.push('z');
|
|
7275 |
} |
|
7276 |
return parts.join('');
|
|
7277 |
} |
|
7278 |
}, {
|
|
7279 |
||
7280 |
isEmpty: function() {
|
|
7281 |
return this._segments.length === 0; |
|
7282 |
}, |
|
7283 |
||
7284 |
_transformContent: function(matrix) {
|
|
7285 |
var coords = new Array(6); |
|
7286 |
for (var i = 0, l = this._segments.length; i < l; i++) |
|
7287 |
this._segments[i]._transformCoordinates(matrix, coords, true); |
|
7288 |
return true; |
|
7289 |
}, |
|
7290 |
||
7291 |
_add: function(segs, index) {
|
|
7292 |
var segments = this._segments, |
|
7293 |
curves = this._curves, |
|
7294 |
amount = segs.length, |
|
7295 |
append = index == null, |
|
7296 |
index = append ? segments.length : index; |
|
7297 |
for (var i = 0; i < amount; i++) {
|
|
7298 |
var segment = segs[i]; |
|
7299 |
if (segment._path) |
|
7300 |
segment = segs[i] = segment.clone(); |
|
7301 |
segment._path = this; |
|
7302 |
segment._index = index + i; |
|
7303 |
if (segment._selectionState) |
|
7304 |
this._updateSelection(segment, 0, segment._selectionState); |
|
7305 |
} |
|
7306 |
if (append) {
|
|
7307 |
segments.push.apply(segments, segs); |
|
7308 |
} else {
|
|
7309 |
segments.splice.apply(segments, [index, 0].concat(segs)); |
|
7310 |
for (var i = index + amount, l = segments.length; i < l; i++) |
|
7311 |
segments[i]._index = i; |
|
7312 |
} |
|
| 598 | 7313 |
if (curves) {
|
7314 |
var total = this._countCurves(), |
|
7315 |
from = index + amount - 1 === total ? index - 1 : index, |
|
| 442 | 7316 |
start = from, |
| 598 | 7317 |
to = Math.min(from + amount, total); |
| 442 | 7318 |
if (segs._curves) {
|
7319 |
curves.splice.apply(curves, [from, 0].concat(segs._curves)); |
|
7320 |
start += segs._curves.length; |
|
7321 |
} |
|
7322 |
for (var i = start; i < to; i++) |
|
7323 |
curves.splice(i, 0, new Curve(this, null, null)); |
|
7324 |
this._adjustCurves(from, to); |
|
7325 |
} |
|
7326 |
this._changed(25); |
|
7327 |
return segs; |
|
7328 |
}, |
|
7329 |
||
7330 |
_adjustCurves: function(from, to) {
|
|
7331 |
var segments = this._segments, |
|
7332 |
curves = this._curves, |
|
7333 |
curve; |
|
7334 |
for (var i = from; i < to; i++) {
|
|
7335 |
curve = curves[i]; |
|
7336 |
curve._path = this; |
|
7337 |
curve._segment1 = segments[i]; |
|
7338 |
curve._segment2 = segments[i + 1] || segments[0]; |
|
7339 |
curve._changed(); |
|
7340 |
} |
|
7341 |
if (curve = curves[this._closed && from === 0 ? segments.length - 1 |
|
7342 |
: from - 1]) {
|
|
7343 |
curve._segment2 = segments[from] || segments[0]; |
|
7344 |
curve._changed(); |
|
7345 |
} |
|
7346 |
if (curve = curves[to]) {
|
|
7347 |
curve._segment1 = segments[to]; |
|
7348 |
curve._changed(); |
|
7349 |
} |
|
7350 |
}, |
|
7351 |
||
7352 |
_countCurves: function() {
|
|
7353 |
var length = this._segments.length; |
|
7354 |
return !this._closed && length > 0 ? length - 1 : length; |
|
7355 |
}, |
|
7356 |
||
7357 |
add: function(segment1 ) {
|
|
7358 |
return arguments.length > 1 && typeof segment1 !== 'number' |
|
7359 |
? this._add(Segment.readAll(arguments)) |
|
7360 |
: this._add([ Segment.read(arguments) ])[0]; |
|
7361 |
}, |
|
7362 |
||
7363 |
insert: function(index, segment1 ) {
|
|
7364 |
return arguments.length > 2 && typeof segment1 !== 'number' |
|
7365 |
? this._add(Segment.readAll(arguments, 1), index) |
|
7366 |
: this._add([ Segment.read(arguments, 1) ], index)[0]; |
|
7367 |
}, |
|
7368 |
||
7369 |
addSegment: function() {
|
|
7370 |
return this._add([ Segment.read(arguments) ])[0]; |
|
7371 |
}, |
|
7372 |
||
7373 |
insertSegment: function(index ) {
|
|
7374 |
return this._add([ Segment.read(arguments, 1) ], index)[0]; |
|
7375 |
}, |
|
7376 |
||
7377 |
addSegments: function(segments) {
|
|
7378 |
return this._add(Segment.readAll(segments)); |
|
7379 |
}, |
|
7380 |
||
7381 |
insertSegments: function(index, segments) {
|
|
7382 |
return this._add(Segment.readAll(segments), index); |
|
7383 |
}, |
|
7384 |
||
7385 |
removeSegment: function(index) {
|
|
7386 |
return this.removeSegments(index, index + 1)[0] || null; |
|
7387 |
}, |
|
7388 |
||
7389 |
removeSegments: function(from, to, _includeCurves) {
|
|
7390 |
from = from || 0; |
|
7391 |
to = Base.pick(to, this._segments.length); |
|
7392 |
var segments = this._segments, |
|
7393 |
curves = this._curves, |
|
7394 |
count = segments.length, |
|
7395 |
removed = segments.splice(from, to - from), |
|
7396 |
amount = removed.length; |
|
7397 |
if (!amount) |
|
7398 |
return removed; |
|
7399 |
for (var i = 0; i < amount; i++) {
|
|
7400 |
var segment = removed[i]; |
|
7401 |
if (segment._selectionState) |
|
7402 |
this._updateSelection(segment, segment._selectionState, 0); |
|
7403 |
segment._index = segment._path = null; |
|
7404 |
} |
|
7405 |
for (var i = from, l = segments.length; i < l; i++) |
|
7406 |
segments[i]._index = i; |
|
7407 |
if (curves) {
|
|
7408 |
var index = from > 0 && to === count + (this._closed ? 1 : 0) |
|
7409 |
? from - 1 |
|
7410 |
: from, |
|
7411 |
curves = curves.splice(index, amount); |
|
7412 |
if (_includeCurves) |
|
7413 |
removed._curves = curves.slice(1); |
|
7414 |
this._adjustCurves(index, index); |
|
7415 |
} |
|
7416 |
this._changed(25); |
|
7417 |
return removed; |
|
7418 |
}, |
|
7419 |
||
7420 |
clear: '#removeSegments', |
|
7421 |
||
| 598 | 7422 |
hasHandles: function() {
|
7423 |
var segments = this._segments; |
|
7424 |
for (var i = 0, l = segments.length; i < l; i++) {
|
|
7425 |
if (segments[i].hasHandles()) |
|
7426 |
return true; |
|
7427 |
} |
|
7428 |
return false; |
|
7429 |
}, |
|
7430 |
||
7431 |
clearHandles: function() {
|
|
7432 |
var segments = this._segments; |
|
7433 |
for (var i = 0, l = segments.length; i < l; i++) |
|
7434 |
segments[i].clearHandles(); |
|
7435 |
}, |
|
7436 |
||
| 442 | 7437 |
getLength: function() {
|
7438 |
if (this._length == null) {
|
|
| 598 | 7439 |
var curves = this.getCurves(), |
7440 |
length = 0; |
|
| 442 | 7441 |
for (var i = 0, l = curves.length; i < l; i++) |
| 598 | 7442 |
length += curves[i].getLength(); |
7443 |
this._length = length; |
|
| 442 | 7444 |
} |
7445 |
return this._length; |
|
7446 |
}, |
|
7447 |
||
7448 |
getArea: function() {
|
|
| 598 | 7449 |
if (this._area == null) {
|
7450 |
var segments = this._segments, |
|
7451 |
count = segments.length, |
|
7452 |
last = count - 1, |
|
7453 |
area = 0; |
|
7454 |
for (var i = 0, l = this._closed ? count : last; i < l; i++) {
|
|
7455 |
area += Curve.getArea(Curve.getValues( |
|
7456 |
segments[i], segments[i < last ? i + 1 : 0])); |
|
7457 |
} |
|
7458 |
this._area = area; |
|
7459 |
} |
|
7460 |
return this._area; |
|
7461 |
}, |
|
7462 |
||
7463 |
isClockwise: function() {
|
|
7464 |
if (this._clockwise !== undefined) |
|
7465 |
return this._clockwise; |
|
7466 |
return this.getArea() >= 0; |
|
7467 |
}, |
|
7468 |
||
7469 |
setClockwise: function(clockwise) {
|
|
7470 |
if (this.isClockwise() != (clockwise = !!clockwise)) |
|
7471 |
this.reverse(); |
|
7472 |
this._clockwise = clockwise; |
|
| 442 | 7473 |
}, |
7474 |
||
7475 |
isFullySelected: function() {
|
|
7476 |
var length = this._segments.length; |
|
7477 |
return this._selected && length > 0 && this._selectedSegmentState |
|
7478 |
=== length * 7; |
|
7479 |
}, |
|
7480 |
||
7481 |
setFullySelected: function(selected) {
|
|
7482 |
if (selected) |
|
7483 |
this._selectSegments(true); |
|
7484 |
this.setSelected(selected); |
|
7485 |
}, |
|
7486 |
||
7487 |
setSelected: function setSelected(selected) {
|
|
7488 |
if (!selected) |
|
7489 |
this._selectSegments(false); |
|
7490 |
setSelected.base.call(this, selected); |
|
7491 |
}, |
|
7492 |
||
7493 |
_selectSegments: function(selected) {
|
|
7494 |
var length = this._segments.length; |
|
7495 |
this._selectedSegmentState = selected |
|
7496 |
? length * 7 : 0; |
|
7497 |
for (var i = 0; i < length; i++) |
|
7498 |
this._segments[i]._selectionState = selected |
|
7499 |
? 7 : 0; |
|
7500 |
}, |
|
7501 |
||
7502 |
_updateSelection: function(segment, oldState, newState) {
|
|
7503 |
segment._selectionState = newState; |
|
7504 |
var total = this._selectedSegmentState += newState - oldState; |
|
7505 |
if (total > 0) |
|
7506 |
this.setSelected(true); |
|
7507 |
}, |
|
7508 |
||
7509 |
flatten: function(maxDistance) {
|
|
7510 |
var iterator = new PathIterator(this, 64, 0.1), |
|
7511 |
pos = 0, |
|
7512 |
step = iterator.length / Math.ceil(iterator.length / maxDistance), |
|
7513 |
end = iterator.length + (this._closed ? -step : step) / 2; |
|
7514 |
var segments = []; |
|
7515 |
while (pos <= end) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7516 |
segments.push(new Segment(iterator.getPointAt(pos))); |
| 442 | 7517 |
pos += step; |
7518 |
} |
|
7519 |
this.setSegments(segments); |
|
7520 |
}, |
|
7521 |
||
7522 |
reduce: function() {
|
|
7523 |
var curves = this.getCurves(); |
|
7524 |
for (var i = curves.length - 1; i >= 0; i--) {
|
|
7525 |
var curve = curves[i]; |
|
| 598 | 7526 |
if (!curve.hasHandles() && (curve.getLength() === 0 |
7527 |
|| curve.isCollinear(curve.getNext()))) |
|
| 442 | 7528 |
curve.remove(); |
7529 |
} |
|
7530 |
return this; |
|
7531 |
}, |
|
7532 |
||
7533 |
simplify: function(tolerance) {
|
|
7534 |
if (this._segments.length > 2) {
|
|
7535 |
var fitter = new PathFitter(this, tolerance || 2.5); |
|
7536 |
this.setSegments(fitter.fit()); |
|
7537 |
} |
|
7538 |
}, |
|
7539 |
||
7540 |
split: function(index, parameter) {
|
|
7541 |
if (parameter === null) |
|
7542 |
return null; |
|
7543 |
if (arguments.length === 1) {
|
|
7544 |
var arg = index; |
|
7545 |
if (typeof arg === 'number') |
|
7546 |
arg = this.getLocationAt(arg); |
|
7547 |
if (!arg) |
|
7548 |
return null |
|
7549 |
index = arg.index; |
|
7550 |
parameter = arg.parameter; |
|
7551 |
} |
|
| 598 | 7552 |
var tMin = 4e-7, |
7553 |
tMax = 1 - tMin; |
|
7554 |
if (parameter >= tMax) {
|
|
| 442 | 7555 |
index++; |
7556 |
parameter--; |
|
7557 |
} |
|
7558 |
var curves = this.getCurves(); |
|
7559 |
if (index >= 0 && index < curves.length) {
|
|
| 598 | 7560 |
if (parameter >= tMin) {
|
| 442 | 7561 |
curves[index++].divide(parameter, true); |
7562 |
} |
|
7563 |
var segs = this.removeSegments(index, this._segments.length, true), |
|
7564 |
path; |
|
7565 |
if (this._closed) {
|
|
7566 |
this.setClosed(false); |
|
7567 |
path = this; |
|
7568 |
} else {
|
|
| 598 | 7569 |
path = new Path(Item.NO_INSERT); |
7570 |
path.insertAbove(this, true); |
|
7571 |
this._clone(path); |
|
| 442 | 7572 |
} |
7573 |
path._add(segs, 0); |
|
7574 |
this.addSegment(segs[0]); |
|
7575 |
return path; |
|
7576 |
} |
|
7577 |
return null; |
|
7578 |
}, |
|
7579 |
||
7580 |
reverse: function() {
|
|
7581 |
this._segments.reverse(); |
|
7582 |
for (var i = 0, l = this._segments.length; i < l; i++) {
|
|
7583 |
var segment = this._segments[i]; |
|
7584 |
var handleIn = segment._handleIn; |
|
7585 |
segment._handleIn = segment._handleOut; |
|
7586 |
segment._handleOut = handleIn; |
|
7587 |
segment._index = i; |
|
7588 |
} |
|
7589 |
this._curves = null; |
|
7590 |
if (this._clockwise !== undefined) |
|
7591 |
this._clockwise = !this._clockwise; |
|
7592 |
this._changed(9); |
|
7593 |
}, |
|
7594 |
||
7595 |
join: function(path) {
|
|
7596 |
if (path) {
|
|
7597 |
var segments = path._segments, |
|
7598 |
last1 = this.getLastSegment(), |
|
7599 |
last2 = path.getLastSegment(); |
|
7600 |
if (!last2) |
|
7601 |
return this; |
|
7602 |
if (last1 && last1._point.equals(last2._point)) |
|
7603 |
path.reverse(); |
|
7604 |
var first2 = path.getFirstSegment(); |
|
7605 |
if (last1 && last1._point.equals(first2._point)) {
|
|
7606 |
last1.setHandleOut(first2._handleOut); |
|
7607 |
this._add(segments.slice(1)); |
|
7608 |
} else {
|
|
7609 |
var first1 = this.getFirstSegment(); |
|
7610 |
if (first1 && first1._point.equals(first2._point)) |
|
7611 |
path.reverse(); |
|
7612 |
last2 = path.getLastSegment(); |
|
7613 |
if (first1 && first1._point.equals(last2._point)) {
|
|
7614 |
first1.setHandleIn(last2._handleIn); |
|
7615 |
this._add(segments.slice(0, segments.length - 1), 0); |
|
7616 |
} else {
|
|
7617 |
this._add(segments.slice()); |
|
7618 |
} |
|
7619 |
} |
|
| 598 | 7620 |
if (path._closed) |
| 442 | 7621 |
this._add([segments[0]]); |
7622 |
path.remove(); |
|
7623 |
} |
|
7624 |
var first = this.getFirstSegment(), |
|
7625 |
last = this.getLastSegment(); |
|
7626 |
if (first !== last && first._point.equals(last._point)) {
|
|
7627 |
first.setHandleIn(last._handleIn); |
|
7628 |
last.remove(); |
|
7629 |
this.setClosed(true); |
|
7630 |
} |
|
7631 |
return this; |
|
7632 |
}, |
|
7633 |
||
7634 |
toShape: function(insert) {
|
|
7635 |
if (!this._closed) |
|
7636 |
return null; |
|
7637 |
||
7638 |
var segments = this._segments, |
|
7639 |
type, |
|
7640 |
size, |
|
7641 |
radius, |
|
7642 |
topCenter; |
|
7643 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7644 |
function isCollinear(i, j) {
|
| 598 | 7645 |
var seg1 = segments[i], |
7646 |
seg2 = seg1.getNext(), |
|
7647 |
seg3 = segments[j], |
|
7648 |
seg4 = seg3.getNext(); |
|
7649 |
return seg1._handleOut.isZero() && seg2._handleIn.isZero() |
|
7650 |
&& seg3._handleOut.isZero() && seg4._handleIn.isZero() |
|
7651 |
&& seg2._point.subtract(seg1._point).isCollinear( |
|
7652 |
seg4._point.subtract(seg3._point)); |
|
| 442 | 7653 |
} |
7654 |
||
7655 |
function isOrthogonal(i) {
|
|
| 598 | 7656 |
var seg2 = segments[i], |
7657 |
seg1 = seg2.getPrevious(), |
|
7658 |
seg3 = seg2.getNext(); |
|
7659 |
return seg1._handleOut.isZero() && seg2._handleIn.isZero() |
|
7660 |
&& seg2._handleOut.isZero() && seg3._handleIn.isZero() |
|
7661 |
&& seg2._point.subtract(seg1._point).isOrthogonal( |
|
7662 |
seg3._point.subtract(seg2._point)); |
|
| 442 | 7663 |
} |
7664 |
||
7665 |
function isArc(i) {
|
|
| 598 | 7666 |
var seg1 = segments[i], |
7667 |
seg2 = seg1.getNext(), |
|
7668 |
handle1 = seg1._handleOut, |
|
7669 |
handle2 = seg2._handleIn, |
|
7670 |
kappa = 0.5522847498307936; |
|
7671 |
if (handle1.isOrthogonal(handle2)) {
|
|
7672 |
var pt1 = seg1._point, |
|
7673 |
pt2 = seg2._point, |
|
7674 |
corner = new Line(pt1, handle1, true).intersect( |
|
7675 |
new Line(pt2, handle2, true), true); |
|
7676 |
return corner && Numerical.isZero(handle1.getLength() / |
|
7677 |
corner.subtract(pt1).getLength() - kappa) |
|
7678 |
&& Numerical.isZero(handle2.getLength() / |
|
7679 |
corner.subtract(pt2).getLength() - kappa); |
|
7680 |
} |
|
7681 |
return false; |
|
| 442 | 7682 |
} |
7683 |
||
7684 |
function getDistance(i, j) {
|
|
7685 |
return segments[i]._point.getDistance(segments[j]._point); |
|
7686 |
} |
|
7687 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7688 |
if (!this.hasHandles() && segments.length === 4 |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7689 |
&& isCollinear(0, 2) && isCollinear(1, 3) && isOrthogonal(1)) {
|
| 442 | 7690 |
type = Shape.Rectangle; |
7691 |
size = new Size(getDistance(0, 3), getDistance(0, 1)); |
|
7692 |
topCenter = segments[1]._point.add(segments[2]._point).divide(2); |
|
7693 |
} else if (segments.length === 8 && isArc(0) && isArc(2) && isArc(4) |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7694 |
&& isArc(6) && isCollinear(1, 5) && isCollinear(3, 7)) {
|
| 442 | 7695 |
type = Shape.Rectangle; |
7696 |
size = new Size(getDistance(1, 6), getDistance(0, 3)); |
|
7697 |
radius = size.subtract(new Size(getDistance(0, 7), |
|
7698 |
getDistance(1, 2))).divide(2); |
|
7699 |
topCenter = segments[3]._point.add(segments[4]._point).divide(2); |
|
7700 |
} else if (segments.length === 4 |
|
7701 |
&& isArc(0) && isArc(1) && isArc(2) && isArc(3)) {
|
|
7702 |
if (Numerical.isZero(getDistance(0, 2) - getDistance(1, 3))) {
|
|
7703 |
type = Shape.Circle; |
|
7704 |
radius = getDistance(0, 2) / 2; |
|
7705 |
} else {
|
|
7706 |
type = Shape.Ellipse; |
|
7707 |
radius = new Size(getDistance(2, 0) / 2, getDistance(3, 1) / 2); |
|
7708 |
} |
|
7709 |
topCenter = segments[1]._point; |
|
7710 |
} |
|
7711 |
||
7712 |
if (type) {
|
|
7713 |
var center = this.getPosition(true), |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7714 |
shape = this._clone(new type({
|
| 442 | 7715 |
center: center, |
7716 |
size: size, |
|
7717 |
radius: radius, |
|
7718 |
insert: false |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7719 |
}), insert, false); |
| 442 | 7720 |
shape.rotate(topCenter.subtract(center).getAngle() + 90); |
7721 |
return shape; |
|
7722 |
} |
|
7723 |
return null; |
|
7724 |
}, |
|
7725 |
||
7726 |
_hitTestSelf: function(point, options) {
|
|
7727 |
var that = this, |
|
7728 |
style = this.getStyle(), |
|
7729 |
segments = this._segments, |
|
7730 |
numSegments = segments.length, |
|
7731 |
closed = this._closed, |
|
7732 |
tolerancePadding = options._tolerancePadding, |
|
7733 |
strokePadding = tolerancePadding, |
|
7734 |
join, cap, miterLimit, |
|
7735 |
area, loc, res, |
|
7736 |
hitStroke = options.stroke && style.hasStroke(), |
|
7737 |
hitFill = options.fill && style.hasFill(), |
|
7738 |
hitCurves = options.curves, |
|
7739 |
radius = hitStroke |
|
7740 |
? style.getStrokeWidth() / 2 |
|
7741 |
: hitFill && options.tolerance > 0 || hitCurves |
|
7742 |
? 0 : null; |
|
7743 |
if (radius !== null) {
|
|
7744 |
if (radius > 0) {
|
|
7745 |
join = style.getStrokeJoin(); |
|
7746 |
cap = style.getStrokeCap(); |
|
7747 |
miterLimit = radius * style.getMiterLimit(); |
|
7748 |
strokePadding = tolerancePadding.add(new Point(radius, radius)); |
|
7749 |
} else {
|
|
7750 |
join = cap = 'round'; |
|
7751 |
} |
|
7752 |
} |
|
7753 |
||
7754 |
function isCloseEnough(pt, padding) {
|
|
7755 |
return point.subtract(pt).divide(padding).length <= 1; |
|
7756 |
} |
|
7757 |
||
7758 |
function checkSegmentPoint(seg, pt, name) {
|
|
7759 |
if (!options.selected || pt.isSelected()) {
|
|
7760 |
var anchor = seg._point; |
|
7761 |
if (pt !== anchor) |
|
7762 |
pt = pt.add(anchor); |
|
7763 |
if (isCloseEnough(pt, strokePadding)) {
|
|
7764 |
return new HitResult(name, that, {
|
|
7765 |
segment: seg, |
|
7766 |
point: pt |
|
7767 |
}); |
|
7768 |
} |
|
7769 |
} |
|
7770 |
} |
|
7771 |
||
7772 |
function checkSegmentPoints(seg, ends) {
|
|
7773 |
return (ends || options.segments) |
|
7774 |
&& checkSegmentPoint(seg, seg._point, 'segment') |
|
7775 |
|| (!ends && options.handles) && ( |
|
7776 |
checkSegmentPoint(seg, seg._handleIn, 'handle-in') || |
|
7777 |
checkSegmentPoint(seg, seg._handleOut, 'handle-out')); |
|
7778 |
} |
|
7779 |
||
7780 |
function addToArea(point) {
|
|
7781 |
area.add(point); |
|
7782 |
} |
|
7783 |
||
7784 |
function checkSegmentStroke(segment) {
|
|
7785 |
if (join !== 'round' || cap !== 'round') {
|
|
7786 |
area = new Path({ internal: true, closed: true });
|
|
7787 |
if (closed || segment._index > 0 |
|
7788 |
&& segment._index < numSegments - 1) {
|
|
7789 |
if (join !== 'round' && (segment._handleIn.isZero() |
|
7790 |
|| segment._handleOut.isZero())) |
|
7791 |
Path._addBevelJoin(segment, join, radius, miterLimit, |
|
7792 |
addToArea, true); |
|
7793 |
} else if (cap !== 'round') {
|
|
7794 |
Path._addSquareCap(segment, cap, radius, addToArea, true); |
|
7795 |
} |
|
7796 |
if (!area.isEmpty()) {
|
|
7797 |
var loc; |
|
7798 |
return area.contains(point) |
|
7799 |
|| (loc = area.getNearestLocation(point)) |
|
7800 |
&& isCloseEnough(loc.getPoint(), tolerancePadding); |
|
7801 |
} |
|
7802 |
} |
|
7803 |
return isCloseEnough(segment._point, strokePadding); |
|
7804 |
} |
|
7805 |
||
7806 |
if (options.ends && !options.segments && !closed) {
|
|
7807 |
if (res = checkSegmentPoints(segments[0], true) |
|
7808 |
|| checkSegmentPoints(segments[numSegments - 1], true)) |
|
7809 |
return res; |
|
7810 |
} else if (options.segments || options.handles) {
|
|
7811 |
for (var i = 0; i < numSegments; i++) |
|
7812 |
if (res = checkSegmentPoints(segments[i])) |
|
7813 |
return res; |
|
7814 |
} |
|
7815 |
if (radius !== null) {
|
|
7816 |
loc = this.getNearestLocation(point); |
|
7817 |
if (loc) {
|
|
7818 |
var parameter = loc.getParameter(); |
|
7819 |
if (parameter === 0 || parameter === 1 && numSegments > 1) {
|
|
7820 |
if (!checkSegmentStroke(loc.getSegment())) |
|
7821 |
loc = null; |
|
7822 |
} else if (!isCloseEnough(loc.getPoint(), strokePadding)) {
|
|
7823 |
loc = null; |
|
7824 |
} |
|
7825 |
} |
|
7826 |
if (!loc && join === 'miter' && numSegments > 1) {
|
|
7827 |
for (var i = 0; i < numSegments; i++) {
|
|
7828 |
var segment = segments[i]; |
|
7829 |
if (point.getDistance(segment._point) <= miterLimit |
|
7830 |
&& checkSegmentStroke(segment)) {
|
|
7831 |
loc = segment.getLocation(); |
|
7832 |
break; |
|
7833 |
} |
|
7834 |
} |
|
7835 |
} |
|
7836 |
} |
|
7837 |
return !loc && hitFill && this._contains(point) |
|
7838 |
|| loc && !hitStroke && !hitCurves |
|
7839 |
? new HitResult('fill', this)
|
|
7840 |
: loc |
|
7841 |
? new HitResult(hitStroke ? 'stroke' : 'curve', this, {
|
|
7842 |
location: loc, |
|
7843 |
point: loc.getPoint() |
|
7844 |
}) |
|
7845 |
: null; |
|
7846 |
} |
|
7847 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7848 |
}, Base.each(Curve.evaluateMethods, |
| 442 | 7849 |
function(name) {
|
7850 |
this[name + 'At'] = function(offset, isParameter) {
|
|
7851 |
var loc = this.getLocationAt(offset, isParameter); |
|
7852 |
return loc && loc[name](); |
|
7853 |
}; |
|
7854 |
}, |
|
7855 |
{
|
|
7856 |
beans: false, |
|
7857 |
||
7858 |
getLocationOf: function() {
|
|
7859 |
var point = Point.read(arguments), |
|
7860 |
curves = this.getCurves(); |
|
7861 |
for (var i = 0, l = curves.length; i < l; i++) {
|
|
7862 |
var loc = curves[i].getLocationOf(point); |
|
7863 |
if (loc) |
|
7864 |
return loc; |
|
7865 |
} |
|
7866 |
return null; |
|
7867 |
}, |
|
7868 |
||
7869 |
getOffsetOf: function() {
|
|
7870 |
var loc = this.getLocationOf.apply(this, arguments); |
|
7871 |
return loc ? loc.getOffset() : null; |
|
7872 |
}, |
|
7873 |
||
7874 |
getLocationAt: function(offset, isParameter) {
|
|
7875 |
var curves = this.getCurves(), |
|
7876 |
length = 0; |
|
7877 |
if (isParameter) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7878 |
var index = ~~offset, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7879 |
curve = curves[index]; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
7880 |
return curve ? curve.getLocationAt(offset - index, true) : null; |
| 442 | 7881 |
} |
7882 |
for (var i = 0, l = curves.length; i < l; i++) {
|
|
7883 |
var start = length, |
|
7884 |
curve = curves[i]; |
|
7885 |
length += curve.getLength(); |
|
7886 |
if (length > offset) {
|
|
7887 |
return curve.getLocationAt(offset - start); |
|
7888 |
} |
|
7889 |
} |
|
| 598 | 7890 |
if (curves.length > 0 && offset <= this.getLength()) |
| 442 | 7891 |
return new CurveLocation(curves[curves.length - 1], 1); |
7892 |
return null; |
|
7893 |
}, |
|
7894 |
||
7895 |
getNearestLocation: function() {
|
|
7896 |
var point = Point.read(arguments), |
|
7897 |
curves = this.getCurves(), |
|
7898 |
minDist = Infinity, |
|
7899 |
minLoc = null; |
|
7900 |
for (var i = 0, l = curves.length; i < l; i++) {
|
|
7901 |
var loc = curves[i].getNearestLocation(point); |
|
7902 |
if (loc._distance < minDist) {
|
|
7903 |
minDist = loc._distance; |
|
7904 |
minLoc = loc; |
|
7905 |
} |
|
7906 |
} |
|
7907 |
return minLoc; |
|
7908 |
}, |
|
7909 |
||
7910 |
getNearestPoint: function() {
|
|
7911 |
return this.getNearestLocation.apply(this, arguments).getPoint(); |
|
7912 |
} |
|
| 598 | 7913 |
}), |
7914 |
new function() {
|
|
| 442 | 7915 |
|
7916 |
function drawHandles(ctx, segments, matrix, size) {
|
|
7917 |
var half = size / 2; |
|
7918 |
||
7919 |
function drawHandle(index) {
|
|
7920 |
var hX = coords[index], |
|
7921 |
hY = coords[index + 1]; |
|
7922 |
if (pX != hX || pY != hY) {
|
|
7923 |
ctx.beginPath(); |
|
7924 |
ctx.moveTo(pX, pY); |
|
7925 |
ctx.lineTo(hX, hY); |
|
7926 |
ctx.stroke(); |
|
7927 |
ctx.beginPath(); |
|
7928 |
ctx.arc(hX, hY, half, 0, Math.PI * 2, true); |
|
7929 |
ctx.fill(); |
|
7930 |
} |
|
7931 |
} |
|
7932 |
||
7933 |
var coords = new Array(6); |
|
7934 |
for (var i = 0, l = segments.length; i < l; i++) {
|
|
7935 |
var segment = segments[i]; |
|
7936 |
segment._transformCoordinates(matrix, coords, false); |
|
7937 |
var state = segment._selectionState, |
|
7938 |
pX = coords[0], |
|
7939 |
pY = coords[1]; |
|
7940 |
if (state & 1) |
|
7941 |
drawHandle(2); |
|
7942 |
if (state & 2) |
|
7943 |
drawHandle(4); |
|
7944 |
ctx.fillRect(pX - half, pY - half, size, size); |
|
7945 |
if (!(state & 4)) {
|
|
7946 |
var fillStyle = ctx.fillStyle; |
|
7947 |
ctx.fillStyle = '#ffffff'; |
|
7948 |
ctx.fillRect(pX - half + 1, pY - half + 1, size - 2, size - 2); |
|
7949 |
ctx.fillStyle = fillStyle; |
|
7950 |
} |
|
7951 |
} |
|
7952 |
} |
|
7953 |
||
7954 |
function drawSegments(ctx, path, matrix) {
|
|
7955 |
var segments = path._segments, |
|
7956 |
length = segments.length, |
|
7957 |
coords = new Array(6), |
|
7958 |
first = true, |
|
7959 |
curX, curY, |
|
7960 |
prevX, prevY, |
|
7961 |
inX, inY, |
|
7962 |
outX, outY; |
|
7963 |
||
7964 |
function drawSegment(segment) {
|
|
7965 |
if (matrix) {
|
|
7966 |
segment._transformCoordinates(matrix, coords, false); |
|
7967 |
curX = coords[0]; |
|
7968 |
curY = coords[1]; |
|
7969 |
} else {
|
|
7970 |
var point = segment._point; |
|
7971 |
curX = point._x; |
|
7972 |
curY = point._y; |
|
7973 |
} |
|
7974 |
if (first) {
|
|
7975 |
ctx.moveTo(curX, curY); |
|
7976 |
first = false; |
|
7977 |
} else {
|
|
7978 |
if (matrix) {
|
|
7979 |
inX = coords[2]; |
|
7980 |
inY = coords[3]; |
|
7981 |
} else {
|
|
7982 |
var handle = segment._handleIn; |
|
7983 |
inX = curX + handle._x; |
|
7984 |
inY = curY + handle._y; |
|
7985 |
} |
|
7986 |
if (inX === curX && inY === curY |
|
7987 |
&& outX === prevX && outY === prevY) {
|
|
7988 |
ctx.lineTo(curX, curY); |
|
7989 |
} else {
|
|
7990 |
ctx.bezierCurveTo(outX, outY, inX, inY, curX, curY); |
|
7991 |
} |
|
7992 |
} |
|
7993 |
prevX = curX; |
|
7994 |
prevY = curY; |
|
7995 |
if (matrix) {
|
|
7996 |
outX = coords[4]; |
|
7997 |
outY = coords[5]; |
|
7998 |
} else {
|
|
7999 |
var handle = segment._handleOut; |
|
8000 |
outX = prevX + handle._x; |
|
8001 |
outY = prevY + handle._y; |
|
8002 |
} |
|
8003 |
} |
|
8004 |
||
8005 |
for (var i = 0; i < length; i++) |
|
8006 |
drawSegment(segments[i]); |
|
8007 |
if (path._closed && length > 0) |
|
8008 |
drawSegment(segments[0]); |
|
8009 |
} |
|
8010 |
||
8011 |
return {
|
|
8012 |
_draw: function(ctx, param, strokeMatrix) {
|
|
8013 |
var dontStart = param.dontStart, |
|
8014 |
dontPaint = param.dontFinish || param.clip, |
|
8015 |
style = this.getStyle(), |
|
8016 |
hasFill = style.hasFill(), |
|
8017 |
hasStroke = style.hasStroke(), |
|
8018 |
dashArray = style.getDashArray(), |
|
8019 |
dashLength = !paper.support.nativeDash && hasStroke |
|
8020 |
&& dashArray && dashArray.length; |
|
8021 |
||
8022 |
if (!dontStart) |
|
8023 |
ctx.beginPath(); |
|
8024 |
||
8025 |
if (!dontStart && this._currentPath) {
|
|
8026 |
ctx.currentPath = this._currentPath; |
|
8027 |
} else if (hasFill || hasStroke && !dashLength || dontPaint) {
|
|
8028 |
drawSegments(ctx, this, strokeMatrix); |
|
8029 |
if (this._closed) |
|
8030 |
ctx.closePath(); |
|
8031 |
if (!dontStart) |
|
8032 |
this._currentPath = ctx.currentPath; |
|
8033 |
} |
|
8034 |
||
8035 |
function getOffset(i) {
|
|
8036 |
return dashArray[((i % dashLength) + dashLength) % dashLength]; |
|
8037 |
} |
|
8038 |
||
8039 |
if (!dontPaint && (hasFill || hasStroke)) {
|
|
8040 |
this._setStyles(ctx); |
|
8041 |
if (hasFill) {
|
|
8042 |
ctx.fill(style.getWindingRule()); |
|
8043 |
ctx.shadowColor = 'rgba(0,0,0,0)'; |
|
8044 |
} |
|
8045 |
if (hasStroke) {
|
|
8046 |
if (dashLength) {
|
|
8047 |
if (!dontStart) |
|
8048 |
ctx.beginPath(); |
|
8049 |
var iterator = new PathIterator(this, 32, 0.25, |
|
8050 |
strokeMatrix), |
|
8051 |
length = iterator.length, |
|
8052 |
from = -style.getDashOffset(), to, |
|
8053 |
i = 0; |
|
8054 |
from = from % length; |
|
8055 |
while (from > 0) {
|
|
8056 |
from -= getOffset(i--) + getOffset(i--); |
|
8057 |
} |
|
8058 |
while (from < length) {
|
|
8059 |
to = from + getOffset(i++); |
|
8060 |
if (from > 0 || to > 0) |
|
8061 |
iterator.drawPart(ctx, |
|
8062 |
Math.max(from, 0), Math.max(to, 0)); |
|
8063 |
from = to + getOffset(i++); |
|
8064 |
} |
|
8065 |
} |
|
8066 |
ctx.stroke(); |
|
8067 |
} |
|
8068 |
} |
|
8069 |
}, |
|
8070 |
||
8071 |
_drawSelected: function(ctx, matrix) {
|
|
8072 |
ctx.beginPath(); |
|
8073 |
drawSegments(ctx, this, matrix); |
|
8074 |
ctx.stroke(); |
|
8075 |
drawHandles(ctx, this._segments, matrix, paper.settings.handleSize); |
|
8076 |
} |
|
8077 |
}; |
|
| 598 | 8078 |
}, |
8079 |
new function() {
|
|
| 442 | 8080 |
function getFirstControlPoints(rhs) {
|
8081 |
var n = rhs.length, |
|
8082 |
x = [], |
|
8083 |
tmp = [], |
|
8084 |
b = 2; |
|
8085 |
x[0] = rhs[0] / b; |
|
8086 |
for (var i = 1; i < n; i++) {
|
|
8087 |
tmp[i] = 1 / b; |
|
8088 |
b = (i < n - 1 ? 4 : 2) - tmp[i]; |
|
8089 |
x[i] = (rhs[i] - x[i - 1]) / b; |
|
8090 |
} |
|
8091 |
for (var i = 1; i < n; i++) {
|
|
8092 |
x[n - i - 1] -= tmp[n - i] * x[n - i]; |
|
8093 |
} |
|
8094 |
return x; |
|
8095 |
} |
|
8096 |
||
8097 |
return {
|
|
8098 |
smooth: function() {
|
|
8099 |
var segments = this._segments, |
|
8100 |
size = segments.length, |
|
8101 |
closed = this._closed, |
|
8102 |
n = size, |
|
8103 |
overlap = 0; |
|
8104 |
if (size <= 2) |
|
8105 |
return; |
|
8106 |
if (closed) {
|
|
8107 |
overlap = Math.min(size, 4); |
|
8108 |
n += Math.min(size, overlap) * 2; |
|
8109 |
} |
|
8110 |
var knots = []; |
|
8111 |
for (var i = 0; i < size; i++) |
|
8112 |
knots[i + overlap] = segments[i]._point; |
|
8113 |
if (closed) {
|
|
8114 |
for (var i = 0; i < overlap; i++) {
|
|
8115 |
knots[i] = segments[i + size - overlap]._point; |
|
8116 |
knots[i + size + overlap] = segments[i]._point; |
|
8117 |
} |
|
8118 |
} else {
|
|
8119 |
n--; |
|
8120 |
} |
|
8121 |
var rhs = []; |
|
8122 |
||
8123 |
for (var i = 1; i < n - 1; i++) |
|
8124 |
rhs[i] = 4 * knots[i]._x + 2 * knots[i + 1]._x; |
|
8125 |
rhs[0] = knots[0]._x + 2 * knots[1]._x; |
|
8126 |
rhs[n - 1] = 3 * knots[n - 1]._x; |
|
8127 |
var x = getFirstControlPoints(rhs); |
|
8128 |
||
8129 |
for (var i = 1; i < n - 1; i++) |
|
8130 |
rhs[i] = 4 * knots[i]._y + 2 * knots[i + 1]._y; |
|
8131 |
rhs[0] = knots[0]._y + 2 * knots[1]._y; |
|
8132 |
rhs[n - 1] = 3 * knots[n - 1]._y; |
|
8133 |
var y = getFirstControlPoints(rhs); |
|
8134 |
||
8135 |
if (closed) {
|
|
8136 |
for (var i = 0, j = size; i < overlap; i++, j++) {
|
|
8137 |
var f1 = i / overlap, |
|
8138 |
f2 = 1 - f1, |
|
8139 |
ie = i + overlap, |
|
8140 |
je = j + overlap; |
|
8141 |
x[j] = x[i] * f1 + x[j] * f2; |
|
8142 |
y[j] = y[i] * f1 + y[j] * f2; |
|
8143 |
x[je] = x[ie] * f2 + x[je] * f1; |
|
8144 |
y[je] = y[ie] * f2 + y[je] * f1; |
|
8145 |
} |
|
8146 |
n--; |
|
8147 |
} |
|
8148 |
var handleIn = null; |
|
8149 |
for (var i = overlap; i <= n - overlap; i++) {
|
|
8150 |
var segment = segments[i - overlap]; |
|
8151 |
if (handleIn) |
|
8152 |
segment.setHandleIn(handleIn.subtract(segment._point)); |
|
8153 |
if (i < n) {
|
|
8154 |
segment.setHandleOut( |
|
8155 |
new Point(x[i], y[i]).subtract(segment._point)); |
|
8156 |
handleIn = i < n - 1 |
|
8157 |
? new Point( |
|
8158 |
2 * knots[i + 1]._x - x[i + 1], |
|
8159 |
2 * knots[i + 1]._y - y[i + 1]) |
|
8160 |
: new Point( |
|
8161 |
(knots[n]._x + x[n - 1]) / 2, |
|
8162 |
(knots[n]._y + y[n - 1]) / 2); |
|
8163 |
} |
|
8164 |
} |
|
8165 |
if (closed && handleIn) {
|
|
8166 |
var segment = this._segments[0]; |
|
8167 |
segment.setHandleIn(handleIn.subtract(segment._point)); |
|
8168 |
} |
|
8169 |
} |
|
8170 |
}; |
|
| 598 | 8171 |
}, |
8172 |
new function() {
|
|
| 442 | 8173 |
function getCurrentSegment(that) {
|
8174 |
var segments = that._segments; |
|
8175 |
if (segments.length === 0) |
|
8176 |
throw new Error('Use a moveTo() command first');
|
|
8177 |
return segments[segments.length - 1]; |
|
8178 |
} |
|
8179 |
||
8180 |
return {
|
|
8181 |
moveTo: function() {
|
|
8182 |
var segments = this._segments; |
|
8183 |
if (segments.length === 1) |
|
8184 |
this.removeSegment(0); |
|
8185 |
if (!segments.length) |
|
8186 |
this._add([ new Segment(Point.read(arguments)) ]); |
|
8187 |
}, |
|
8188 |
||
8189 |
moveBy: function() {
|
|
8190 |
throw new Error('moveBy() is unsupported on Path items.');
|
|
8191 |
}, |
|
8192 |
||
8193 |
lineTo: function() {
|
|
8194 |
this._add([ new Segment(Point.read(arguments)) ]); |
|
8195 |
}, |
|
8196 |
||
8197 |
cubicCurveTo: function() {
|
|
8198 |
var handle1 = Point.read(arguments), |
|
8199 |
handle2 = Point.read(arguments), |
|
8200 |
to = Point.read(arguments), |
|
8201 |
current = getCurrentSegment(this); |
|
8202 |
current.setHandleOut(handle1.subtract(current._point)); |
|
8203 |
this._add([ new Segment(to, handle2.subtract(to)) ]); |
|
8204 |
}, |
|
8205 |
||
8206 |
quadraticCurveTo: function() {
|
|
8207 |
var handle = Point.read(arguments), |
|
8208 |
to = Point.read(arguments), |
|
8209 |
current = getCurrentSegment(this)._point; |
|
8210 |
this.cubicCurveTo( |
|
8211 |
handle.add(current.subtract(handle).multiply(1 / 3)), |
|
8212 |
handle.add(to.subtract(handle).multiply(1 / 3)), |
|
8213 |
to |
|
8214 |
); |
|
8215 |
}, |
|
8216 |
||
8217 |
curveTo: function() {
|
|
8218 |
var through = Point.read(arguments), |
|
8219 |
to = Point.read(arguments), |
|
8220 |
t = Base.pick(Base.read(arguments), 0.5), |
|
8221 |
t1 = 1 - t, |
|
8222 |
current = getCurrentSegment(this)._point, |
|
8223 |
handle = through.subtract(current.multiply(t1 * t1)) |
|
8224 |
.subtract(to.multiply(t * t)).divide(2 * t * t1); |
|
8225 |
if (handle.isNaN()) |
|
8226 |
throw new Error( |
|
8227 |
'Cannot put a curve through points with parameter = ' + t); |
|
8228 |
this.quadraticCurveTo(handle, to); |
|
8229 |
}, |
|
8230 |
||
8231 |
arcTo: function() {
|
|
8232 |
var current = getCurrentSegment(this), |
|
8233 |
from = current._point, |
|
8234 |
to = Point.read(arguments), |
|
8235 |
through, |
|
8236 |
peek = Base.peek(arguments), |
|
8237 |
clockwise = Base.pick(peek, true), |
|
8238 |
center, extent, vector, matrix; |
|
8239 |
if (typeof clockwise === 'boolean') {
|
|
8240 |
var middle = from.add(to).divide(2), |
|
8241 |
through = middle.add(middle.subtract(from).rotate( |
|
8242 |
clockwise ? -90 : 90)); |
|
8243 |
} else if (Base.remain(arguments) <= 2) {
|
|
8244 |
through = to; |
|
8245 |
to = Point.read(arguments); |
|
8246 |
} else {
|
|
8247 |
var radius = Size.read(arguments); |
|
8248 |
if (radius.isZero()) |
|
8249 |
return this.lineTo(to); |
|
8250 |
var rotation = Base.read(arguments), |
|
8251 |
clockwise = !!Base.read(arguments), |
|
8252 |
large = !!Base.read(arguments), |
|
8253 |
middle = from.add(to).divide(2), |
|
8254 |
pt = from.subtract(middle).rotate(-rotation), |
|
8255 |
x = pt.x, |
|
8256 |
y = pt.y, |
|
8257 |
abs = Math.abs, |
|
8258 |
rx = abs(radius.width), |
|
8259 |
ry = abs(radius.height), |
|
8260 |
rxSq = rx * rx, |
|
8261 |
rySq = ry * ry, |
|
8262 |
xSq = x * x, |
|
8263 |
ySq = y * y; |
|
8264 |
var factor = Math.sqrt(xSq / rxSq + ySq / rySq); |
|
8265 |
if (factor > 1) {
|
|
8266 |
rx *= factor; |
|
8267 |
ry *= factor; |
|
8268 |
rxSq = rx * rx; |
|
8269 |
rySq = ry * ry; |
|
8270 |
} |
|
8271 |
factor = (rxSq * rySq - rxSq * ySq - rySq * xSq) / |
|
8272 |
(rxSq * ySq + rySq * xSq); |
|
| 598 | 8273 |
if (abs(factor) < 1e-12) |
| 442 | 8274 |
factor = 0; |
8275 |
if (factor < 0) |
|
8276 |
throw new Error( |
|
8277 |
'Cannot create an arc with the given arguments'); |
|
8278 |
center = new Point(rx * y / ry, -ry * x / rx) |
|
8279 |
.multiply((large === clockwise ? -1 : 1) |
|
8280 |
* Math.sqrt(factor)) |
|
8281 |
.rotate(rotation).add(middle); |
|
8282 |
matrix = new Matrix().translate(center).rotate(rotation) |
|
8283 |
.scale(rx, ry); |
|
8284 |
vector = matrix._inverseTransform(from); |
|
8285 |
extent = vector.getDirectedAngle(matrix._inverseTransform(to)); |
|
8286 |
if (!clockwise && extent > 0) |
|
8287 |
extent -= 360; |
|
8288 |
else if (clockwise && extent < 0) |
|
8289 |
extent += 360; |
|
8290 |
} |
|
8291 |
if (through) {
|
|
8292 |
var l1 = new Line(from.add(through).divide(2), |
|
8293 |
through.subtract(from).rotate(90), true), |
|
8294 |
l2 = new Line(through.add(to).divide(2), |
|
8295 |
to.subtract(through).rotate(90), true), |
|
8296 |
line = new Line(from, to), |
|
8297 |
throughSide = line.getSide(through); |
|
8298 |
center = l1.intersect(l2, true); |
|
8299 |
if (!center) {
|
|
8300 |
if (!throughSide) |
|
8301 |
return this.lineTo(to); |
|
8302 |
throw new Error( |
|
8303 |
'Cannot create an arc with the given arguments'); |
|
8304 |
} |
|
8305 |
vector = from.subtract(center); |
|
8306 |
extent = vector.getDirectedAngle(to.subtract(center)); |
|
8307 |
var centerSide = line.getSide(center); |
|
8308 |
if (centerSide === 0) {
|
|
8309 |
extent = throughSide * Math.abs(extent); |
|
8310 |
} else if (throughSide === centerSide) {
|
|
8311 |
extent += extent < 0 ? 360 : -360; |
|
8312 |
} |
|
8313 |
} |
|
8314 |
var ext = Math.abs(extent), |
|
8315 |
count = ext >= 360 ? 4 : Math.ceil(ext / 90), |
|
8316 |
inc = extent / count, |
|
8317 |
half = inc * Math.PI / 360, |
|
8318 |
z = 4 / 3 * Math.sin(half) / (1 + Math.cos(half)), |
|
8319 |
segments = []; |
|
8320 |
for (var i = 0; i <= count; i++) {
|
|
8321 |
var pt = to, |
|
8322 |
out = null; |
|
8323 |
if (i < count) {
|
|
8324 |
out = vector.rotate(90).multiply(z); |
|
8325 |
if (matrix) {
|
|
8326 |
pt = matrix._transformPoint(vector); |
|
8327 |
out = matrix._transformPoint(vector.add(out)) |
|
8328 |
.subtract(pt); |
|
8329 |
} else {
|
|
8330 |
pt = center.add(vector); |
|
8331 |
} |
|
8332 |
} |
|
8333 |
if (i === 0) {
|
|
8334 |
current.setHandleOut(out); |
|
8335 |
} else {
|
|
8336 |
var _in = vector.rotate(-90).multiply(z); |
|
8337 |
if (matrix) {
|
|
8338 |
_in = matrix._transformPoint(vector.add(_in)) |
|
8339 |
.subtract(pt); |
|
8340 |
} |
|
8341 |
segments.push(new Segment(pt, _in, out)); |
|
8342 |
} |
|
8343 |
vector = vector.rotate(inc); |
|
8344 |
} |
|
8345 |
this._add(segments); |
|
8346 |
}, |
|
8347 |
||
8348 |
lineBy: function() {
|
|
8349 |
var to = Point.read(arguments), |
|
8350 |
current = getCurrentSegment(this)._point; |
|
8351 |
this.lineTo(current.add(to)); |
|
8352 |
}, |
|
8353 |
||
8354 |
curveBy: function() {
|
|
8355 |
var through = Point.read(arguments), |
|
8356 |
to = Point.read(arguments), |
|
8357 |
parameter = Base.read(arguments), |
|
8358 |
current = getCurrentSegment(this)._point; |
|
8359 |
this.curveTo(current.add(through), current.add(to), parameter); |
|
8360 |
}, |
|
8361 |
||
8362 |
cubicCurveBy: function() {
|
|
8363 |
var handle1 = Point.read(arguments), |
|
8364 |
handle2 = Point.read(arguments), |
|
8365 |
to = Point.read(arguments), |
|
8366 |
current = getCurrentSegment(this)._point; |
|
8367 |
this.cubicCurveTo(current.add(handle1), current.add(handle2), |
|
8368 |
current.add(to)); |
|
8369 |
}, |
|
8370 |
||
8371 |
quadraticCurveBy: function() {
|
|
8372 |
var handle = Point.read(arguments), |
|
8373 |
to = Point.read(arguments), |
|
8374 |
current = getCurrentSegment(this)._point; |
|
8375 |
this.quadraticCurveTo(current.add(handle), current.add(to)); |
|
8376 |
}, |
|
8377 |
||
8378 |
arcBy: function() {
|
|
8379 |
var current = getCurrentSegment(this)._point, |
|
8380 |
point = current.add(Point.read(arguments)), |
|
8381 |
clockwise = Base.pick(Base.peek(arguments), true); |
|
8382 |
if (typeof clockwise === 'boolean') {
|
|
8383 |
this.arcTo(point, clockwise); |
|
8384 |
} else {
|
|
8385 |
this.arcTo(point, current.add(Point.read(arguments))); |
|
8386 |
} |
|
8387 |
}, |
|
8388 |
||
8389 |
closePath: function(join) {
|
|
8390 |
this.setClosed(true); |
|
8391 |
if (join) |
|
8392 |
this.join(); |
|
8393 |
} |
|
8394 |
}; |
|
8395 |
}, {
|
|
8396 |
||
8397 |
_getBounds: function(getter, matrix) {
|
|
8398 |
return Path[getter](this._segments, this._closed, this.getStyle(), |
|
8399 |
matrix); |
|
8400 |
}, |
|
8401 |
||
8402 |
statics: {
|
|
8403 |
getBounds: function(segments, closed, style, matrix, strokePadding) {
|
|
8404 |
var first = segments[0]; |
|
8405 |
if (!first) |
|
8406 |
return new Rectangle(); |
|
8407 |
var coords = new Array(6), |
|
8408 |
prevCoords = first._transformCoordinates(matrix, new Array(6), false), |
|
8409 |
min = prevCoords.slice(0, 2), |
|
8410 |
max = min.slice(), |
|
8411 |
roots = new Array(2); |
|
8412 |
||
8413 |
function processSegment(segment) {
|
|
8414 |
segment._transformCoordinates(matrix, coords, false); |
|
8415 |
for (var i = 0; i < 2; i++) {
|
|
8416 |
Curve._addBounds( |
|
8417 |
prevCoords[i], |
|
8418 |
prevCoords[i + 4], |
|
8419 |
coords[i + 2], |
|
8420 |
coords[i], |
|
8421 |
i, strokePadding ? strokePadding[i] : 0, min, max, roots); |
|
8422 |
} |
|
8423 |
var tmp = prevCoords; |
|
8424 |
prevCoords = coords; |
|
8425 |
coords = tmp; |
|
8426 |
} |
|
8427 |
||
8428 |
for (var i = 1, l = segments.length; i < l; i++) |
|
8429 |
processSegment(segments[i]); |
|
8430 |
if (closed) |
|
8431 |
processSegment(first); |
|
8432 |
return new Rectangle(min[0], min[1], max[0] - min[0], max[1] - min[1]); |
|
8433 |
}, |
|
8434 |
||
8435 |
getStrokeBounds: function(segments, closed, style, matrix) {
|
|
8436 |
if (!style.hasStroke()) |
|
8437 |
return Path.getBounds(segments, closed, style, matrix); |
|
8438 |
var length = segments.length - (closed ? 0 : 1), |
|
8439 |
radius = style.getStrokeWidth() / 2, |
|
8440 |
padding = Path._getPenPadding(radius, matrix), |
|
8441 |
bounds = Path.getBounds(segments, closed, style, matrix, padding), |
|
8442 |
join = style.getStrokeJoin(), |
|
8443 |
cap = style.getStrokeCap(), |
|
8444 |
miterLimit = radius * style.getMiterLimit(); |
|
8445 |
var joinBounds = new Rectangle(new Size(padding).multiply(2)); |
|
8446 |
||
8447 |
function add(point) {
|
|
8448 |
bounds = bounds.include(matrix |
|
8449 |
? matrix._transformPoint(point, point) : point); |
|
8450 |
} |
|
8451 |
||
8452 |
function addRound(segment) {
|
|
8453 |
bounds = bounds.unite(joinBounds.setCenter(matrix |
|
8454 |
? matrix._transformPoint(segment._point) : segment._point)); |
|
8455 |
} |
|
8456 |
||
8457 |
function addJoin(segment, join) {
|
|
8458 |
var handleIn = segment._handleIn, |
|
8459 |
handleOut = segment._handleOut; |
|
8460 |
if (join === 'round' || !handleIn.isZero() && !handleOut.isZero() |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
8461 |
&& handleIn.isCollinear(handleOut)) {
|
| 442 | 8462 |
addRound(segment); |
8463 |
} else {
|
|
8464 |
Path._addBevelJoin(segment, join, radius, miterLimit, add); |
|
8465 |
} |
|
8466 |
} |
|
8467 |
||
8468 |
function addCap(segment, cap) {
|
|
8469 |
if (cap === 'round') {
|
|
8470 |
addRound(segment); |
|
8471 |
} else {
|
|
8472 |
Path._addSquareCap(segment, cap, radius, add); |
|
8473 |
} |
|
8474 |
} |
|
8475 |
||
8476 |
for (var i = 1; i < length; i++) |
|
8477 |
addJoin(segments[i], join); |
|
8478 |
if (closed) {
|
|
8479 |
addJoin(segments[0], join); |
|
8480 |
} else if (length > 0) {
|
|
8481 |
addCap(segments[0], cap); |
|
8482 |
addCap(segments[segments.length - 1], cap); |
|
8483 |
} |
|
8484 |
return bounds; |
|
8485 |
}, |
|
8486 |
||
8487 |
_getPenPadding: function(radius, matrix) {
|
|
8488 |
if (!matrix) |
|
8489 |
return [radius, radius]; |
|
8490 |
var mx = matrix.shiftless(), |
|
8491 |
hor = mx.transform(new Point(radius, 0)), |
|
8492 |
ver = mx.transform(new Point(0, radius)), |
|
8493 |
phi = hor.getAngleInRadians(), |
|
8494 |
a = hor.getLength(), |
|
8495 |
b = ver.getLength(); |
|
8496 |
var sin = Math.sin(phi), |
|
8497 |
cos = Math.cos(phi), |
|
8498 |
tan = Math.tan(phi), |
|
8499 |
tx = -Math.atan(b * tan / a), |
|
8500 |
ty = Math.atan(b / (tan * a)); |
|
8501 |
return [Math.abs(a * Math.cos(tx) * cos - b * Math.sin(tx) * sin), |
|
8502 |
Math.abs(b * Math.sin(ty) * cos + a * Math.cos(ty) * sin)]; |
|
8503 |
}, |
|
8504 |
||
8505 |
_addBevelJoin: function(segment, join, radius, miterLimit, addPoint, area) {
|
|
8506 |
var curve2 = segment.getCurve(), |
|
8507 |
curve1 = curve2.getPrevious(), |
|
8508 |
point = curve2.getPointAt(0, true), |
|
8509 |
normal1 = curve1.getNormalAt(1, true), |
|
8510 |
normal2 = curve2.getNormalAt(0, true), |
|
8511 |
step = normal1.getDirectedAngle(normal2) < 0 ? -radius : radius; |
|
8512 |
normal1.setLength(step); |
|
8513 |
normal2.setLength(step); |
|
8514 |
if (area) {
|
|
8515 |
addPoint(point); |
|
8516 |
addPoint(point.add(normal1)); |
|
8517 |
} |
|
8518 |
if (join === 'miter') {
|
|
8519 |
var corner = new Line( |
|
8520 |
point.add(normal1), |
|
8521 |
new Point(-normal1.y, normal1.x), true |
|
8522 |
).intersect(new Line( |
|
8523 |
point.add(normal2), |
|
8524 |
new Point(-normal2.y, normal2.x), true |
|
8525 |
), true); |
|
8526 |
if (corner && point.getDistance(corner) <= miterLimit) {
|
|
8527 |
addPoint(corner); |
|
8528 |
if (!area) |
|
8529 |
return; |
|
8530 |
} |
|
8531 |
} |
|
8532 |
if (!area) |
|
8533 |
addPoint(point.add(normal1)); |
|
8534 |
addPoint(point.add(normal2)); |
|
8535 |
}, |
|
8536 |
||
8537 |
_addSquareCap: function(segment, cap, radius, addPoint, area) {
|
|
8538 |
var point = segment._point, |
|
8539 |
loc = segment.getLocation(), |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
8540 |
normal = loc.getNormal().multiply(radius); |
| 442 | 8541 |
if (area) {
|
8542 |
addPoint(point.subtract(normal)); |
|
8543 |
addPoint(point.add(normal)); |
|
8544 |
} |
|
8545 |
if (cap === 'square') |
|
8546 |
point = point.add(normal.rotate(loc.getParameter() === 0 ? -90 : 90)); |
|
8547 |
addPoint(point.add(normal)); |
|
8548 |
addPoint(point.subtract(normal)); |
|
8549 |
}, |
|
8550 |
||
8551 |
getHandleBounds: function(segments, closed, style, matrix, strokePadding, |
|
8552 |
joinPadding) {
|
|
8553 |
var coords = new Array(6), |
|
8554 |
x1 = Infinity, |
|
8555 |
x2 = -x1, |
|
8556 |
y1 = x1, |
|
8557 |
y2 = x2; |
|
8558 |
for (var i = 0, l = segments.length; i < l; i++) {
|
|
8559 |
var segment = segments[i]; |
|
8560 |
segment._transformCoordinates(matrix, coords, false); |
|
8561 |
for (var j = 0; j < 6; j += 2) {
|
|
8562 |
var padding = j === 0 ? joinPadding : strokePadding, |
|
8563 |
paddingX = padding ? padding[0] : 0, |
|
8564 |
paddingY = padding ? padding[1] : 0, |
|
8565 |
x = coords[j], |
|
8566 |
y = coords[j + 1], |
|
8567 |
xn = x - paddingX, |
|
8568 |
xx = x + paddingX, |
|
8569 |
yn = y - paddingY, |
|
8570 |
yx = y + paddingY; |
|
8571 |
if (xn < x1) x1 = xn; |
|
8572 |
if (xx > x2) x2 = xx; |
|
8573 |
if (yn < y1) y1 = yn; |
|
8574 |
if (yx > y2) y2 = yx; |
|
8575 |
} |
|
8576 |
} |
|
8577 |
return new Rectangle(x1, y1, x2 - x1, y2 - y1); |
|
8578 |
}, |
|
8579 |
||
8580 |
getRoughBounds: function(segments, closed, style, matrix) {
|
|
8581 |
var strokeRadius = style.hasStroke() ? style.getStrokeWidth() / 2 : 0, |
|
8582 |
joinRadius = strokeRadius; |
|
8583 |
if (strokeRadius > 0) {
|
|
8584 |
if (style.getStrokeJoin() === 'miter') |
|
8585 |
joinRadius = strokeRadius * style.getMiterLimit(); |
|
8586 |
if (style.getStrokeCap() === 'square') |
|
8587 |
joinRadius = Math.max(joinRadius, strokeRadius * Math.sqrt(2)); |
|
8588 |
} |
|
8589 |
return Path.getHandleBounds(segments, closed, style, matrix, |
|
8590 |
Path._getPenPadding(strokeRadius, matrix), |
|
8591 |
Path._getPenPadding(joinRadius, matrix)); |
|
8592 |
} |
|
8593 |
}}); |
|
8594 |
||
8595 |
Path.inject({ statics: new function() {
|
|
8596 |
||
8597 |
var kappa = 0.5522847498307936, |
|
8598 |
ellipseSegments = [ |
|
8599 |
new Segment([-1, 0], [0, kappa ], [0, -kappa]), |
|
8600 |
new Segment([0, -1], [-kappa, 0], [kappa, 0 ]), |
|
8601 |
new Segment([1, 0], [0, -kappa], [0, kappa ]), |
|
8602 |
new Segment([0, 1], [kappa, 0 ], [-kappa, 0]) |
|
8603 |
]; |
|
8604 |
||
8605 |
function createPath(segments, closed, args) {
|
|
8606 |
var props = Base.getNamed(args), |
|
8607 |
path = new Path(props && props.insert === false && Item.NO_INSERT); |
|
8608 |
path._add(segments); |
|
8609 |
path._closed = closed; |
|
8610 |
return path.set(props); |
|
8611 |
} |
|
8612 |
||
8613 |
function createEllipse(center, radius, args) {
|
|
8614 |
var segments = new Array(4); |
|
8615 |
for (var i = 0; i < 4; i++) {
|
|
8616 |
var segment = ellipseSegments[i]; |
|
8617 |
segments[i] = new Segment( |
|
8618 |
segment._point.multiply(radius).add(center), |
|
8619 |
segment._handleIn.multiply(radius), |
|
8620 |
segment._handleOut.multiply(radius) |
|
8621 |
); |
|
8622 |
} |
|
8623 |
return createPath(segments, true, args); |
|
8624 |
} |
|
8625 |
||
8626 |
return {
|
|
8627 |
Line: function() {
|
|
8628 |
return createPath([ |
|
8629 |
new Segment(Point.readNamed(arguments, 'from')), |
|
8630 |
new Segment(Point.readNamed(arguments, 'to')) |
|
8631 |
], false, arguments); |
|
8632 |
}, |
|
8633 |
||
8634 |
Circle: function() {
|
|
8635 |
var center = Point.readNamed(arguments, 'center'), |
|
8636 |
radius = Base.readNamed(arguments, 'radius'); |
|
8637 |
return createEllipse(center, new Size(radius), arguments); |
|
8638 |
}, |
|
8639 |
||
8640 |
Rectangle: function() {
|
|
8641 |
var rect = Rectangle.readNamed(arguments, 'rectangle'), |
|
8642 |
radius = Size.readNamed(arguments, 'radius', 0, |
|
8643 |
{ readNull: true }),
|
|
8644 |
bl = rect.getBottomLeft(true), |
|
8645 |
tl = rect.getTopLeft(true), |
|
8646 |
tr = rect.getTopRight(true), |
|
8647 |
br = rect.getBottomRight(true), |
|
8648 |
segments; |
|
8649 |
if (!radius || radius.isZero()) {
|
|
8650 |
segments = [ |
|
8651 |
new Segment(bl), |
|
8652 |
new Segment(tl), |
|
8653 |
new Segment(tr), |
|
8654 |
new Segment(br) |
|
8655 |
]; |
|
8656 |
} else {
|
|
8657 |
radius = Size.min(radius, rect.getSize(true).divide(2)); |
|
8658 |
var rx = radius.width, |
|
8659 |
ry = radius.height, |
|
8660 |
hx = rx * kappa, |
|
8661 |
hy = ry * kappa; |
|
8662 |
segments = [ |
|
8663 |
new Segment(bl.add(rx, 0), null, [-hx, 0]), |
|
8664 |
new Segment(bl.subtract(0, ry), [0, hy]), |
|
8665 |
new Segment(tl.add(0, ry), null, [0, -hy]), |
|
8666 |
new Segment(tl.add(rx, 0), [-hx, 0], null), |
|
8667 |
new Segment(tr.subtract(rx, 0), null, [hx, 0]), |
|
8668 |
new Segment(tr.add(0, ry), [0, -hy], null), |
|
8669 |
new Segment(br.subtract(0, ry), null, [0, hy]), |
|
8670 |
new Segment(br.subtract(rx, 0), [hx, 0]) |
|
8671 |
]; |
|
8672 |
} |
|
8673 |
return createPath(segments, true, arguments); |
|
8674 |
}, |
|
8675 |
||
8676 |
RoundRectangle: '#Rectangle', |
|
8677 |
||
8678 |
Ellipse: function() {
|
|
8679 |
var ellipse = Shape._readEllipse(arguments); |
|
8680 |
return createEllipse(ellipse.center, ellipse.radius, arguments); |
|
8681 |
}, |
|
8682 |
||
8683 |
Oval: '#Ellipse', |
|
8684 |
||
8685 |
Arc: function() {
|
|
8686 |
var from = Point.readNamed(arguments, 'from'), |
|
8687 |
through = Point.readNamed(arguments, 'through'), |
|
8688 |
to = Point.readNamed(arguments, 'to'), |
|
8689 |
props = Base.getNamed(arguments), |
|
8690 |
path = new Path(props && props.insert === false |
|
8691 |
&& Item.NO_INSERT); |
|
8692 |
path.moveTo(from); |
|
8693 |
path.arcTo(through, to); |
|
8694 |
return path.set(props); |
|
8695 |
}, |
|
8696 |
||
8697 |
RegularPolygon: function() {
|
|
8698 |
var center = Point.readNamed(arguments, 'center'), |
|
8699 |
sides = Base.readNamed(arguments, 'sides'), |
|
8700 |
radius = Base.readNamed(arguments, 'radius'), |
|
8701 |
step = 360 / sides, |
|
8702 |
three = !(sides % 3), |
|
8703 |
vector = new Point(0, three ? -radius : radius), |
|
8704 |
offset = three ? -1 : 0.5, |
|
8705 |
segments = new Array(sides); |
|
8706 |
for (var i = 0; i < sides; i++) |
|
8707 |
segments[i] = new Segment(center.add( |
|
8708 |
vector.rotate((i + offset) * step))); |
|
8709 |
return createPath(segments, true, arguments); |
|
8710 |
}, |
|
8711 |
||
8712 |
Star: function() {
|
|
8713 |
var center = Point.readNamed(arguments, 'center'), |
|
8714 |
points = Base.readNamed(arguments, 'points') * 2, |
|
8715 |
radius1 = Base.readNamed(arguments, 'radius1'), |
|
8716 |
radius2 = Base.readNamed(arguments, 'radius2'), |
|
8717 |
step = 360 / points, |
|
8718 |
vector = new Point(0, -1), |
|
8719 |
segments = new Array(points); |
|
8720 |
for (var i = 0; i < points; i++) |
|
8721 |
segments[i] = new Segment(center.add(vector.rotate(step * i) |
|
8722 |
.multiply(i % 2 ? radius2 : radius1))); |
|
8723 |
return createPath(segments, true, arguments); |
|
8724 |
} |
|
8725 |
}; |
|
8726 |
}}); |
|
8727 |
||
8728 |
var CompoundPath = PathItem.extend({
|
|
8729 |
_class: 'CompoundPath', |
|
8730 |
_serializeFields: {
|
|
8731 |
children: [] |
|
8732 |
}, |
|
8733 |
||
8734 |
initialize: function CompoundPath(arg) {
|
|
8735 |
this._children = []; |
|
8736 |
this._namedChildren = {};
|
|
8737 |
if (!this._initialize(arg)) {
|
|
8738 |
if (typeof arg === 'string') {
|
|
8739 |
this.setPathData(arg); |
|
8740 |
} else {
|
|
8741 |
this.addChildren(Array.isArray(arg) ? arg : arguments); |
|
8742 |
} |
|
8743 |
} |
|
8744 |
}, |
|
8745 |
||
8746 |
insertChildren: function insertChildren(index, items, _preserve) {
|
|
| 598 | 8747 |
for (var i = items.length - 1; i >= 0; i--) {
|
8748 |
var item = items[i]; |
|
8749 |
if (item instanceof CompoundPath) {
|
|
8750 |
items.splice.apply(items, [i, 1].concat(item.removeChildren())); |
|
8751 |
item.remove(); |
|
8752 |
} |
|
8753 |
} |
|
| 442 | 8754 |
items = insertChildren.base.call(this, index, items, _preserve, Path); |
8755 |
for (var i = 0, l = !_preserve && items && items.length; i < l; i++) {
|
|
8756 |
var item = items[i]; |
|
8757 |
if (item._clockwise === undefined) |
|
8758 |
item.setClockwise(item._index === 0); |
|
8759 |
} |
|
8760 |
return items; |
|
8761 |
}, |
|
8762 |
||
8763 |
reverse: function() {
|
|
8764 |
var children = this._children; |
|
8765 |
for (var i = 0, l = children.length; i < l; i++) |
|
8766 |
children[i].reverse(); |
|
8767 |
}, |
|
8768 |
||
8769 |
smooth: function() {
|
|
8770 |
for (var i = 0, l = this._children.length; i < l; i++) |
|
8771 |
this._children[i].smooth(); |
|
8772 |
}, |
|
8773 |
||
8774 |
reduce: function reduce() {
|
|
| 598 | 8775 |
var children = this._children; |
8776 |
for (var i = children.length - 1; i >= 0; i--) {
|
|
8777 |
var path = children[i].reduce(); |
|
8778 |
if (path.isEmpty()) |
|
8779 |
children.splice(i, 1); |
|
8780 |
} |
|
8781 |
if (children.length === 0) {
|
|
| 442 | 8782 |
var path = new Path(Item.NO_INSERT); |
8783 |
path.insertAbove(this); |
|
8784 |
path.setStyle(this._style); |
|
8785 |
this.remove(); |
|
8786 |
return path; |
|
| 598 | 8787 |
} |
8788 |
return reduce.base.call(this); |
|
| 442 | 8789 |
}, |
8790 |
||
8791 |
isClockwise: function() {
|
|
8792 |
var child = this.getFirstChild(); |
|
8793 |
return child && child.isClockwise(); |
|
8794 |
}, |
|
8795 |
||
8796 |
setClockwise: function(clockwise) {
|
|
8797 |
if (this.isClockwise() !== !!clockwise) |
|
8798 |
this.reverse(); |
|
8799 |
}, |
|
8800 |
||
8801 |
getFirstSegment: function() {
|
|
8802 |
var first = this.getFirstChild(); |
|
8803 |
return first && first.getFirstSegment(); |
|
8804 |
}, |
|
8805 |
||
8806 |
getLastSegment: function() {
|
|
8807 |
var last = this.getLastChild(); |
|
8808 |
return last && last.getLastSegment(); |
|
8809 |
}, |
|
8810 |
||
8811 |
getCurves: function() {
|
|
8812 |
var children = this._children, |
|
8813 |
curves = []; |
|
8814 |
for (var i = 0, l = children.length; i < l; i++) |
|
8815 |
curves.push.apply(curves, children[i].getCurves()); |
|
8816 |
return curves; |
|
8817 |
}, |
|
8818 |
||
8819 |
getFirstCurve: function() {
|
|
8820 |
var first = this.getFirstChild(); |
|
8821 |
return first && first.getFirstCurve(); |
|
8822 |
}, |
|
8823 |
||
8824 |
getLastCurve: function() {
|
|
8825 |
var last = this.getLastChild(); |
|
8826 |
return last && last.getFirstCurve(); |
|
8827 |
}, |
|
8828 |
||
8829 |
getArea: function() {
|
|
8830 |
var children = this._children, |
|
8831 |
area = 0; |
|
8832 |
for (var i = 0, l = children.length; i < l; i++) |
|
8833 |
area += children[i].getArea(); |
|
8834 |
return area; |
|
8835 |
} |
|
8836 |
}, {
|
|
8837 |
beans: true, |
|
8838 |
||
8839 |
getPathData: function(_matrix, _precision) {
|
|
8840 |
var children = this._children, |
|
8841 |
paths = []; |
|
8842 |
for (var i = 0, l = children.length; i < l; i++) {
|
|
8843 |
var child = children[i], |
|
8844 |
mx = child._matrix; |
|
8845 |
paths.push(child.getPathData(_matrix && !mx.isIdentity() |
|
| 598 | 8846 |
? _matrix.chain(mx) : _matrix, _precision)); |
| 442 | 8847 |
} |
8848 |
return paths.join(' ');
|
|
8849 |
} |
|
8850 |
}, {
|
|
8851 |
_getChildHitTestOptions: function(options) {
|
|
8852 |
return options.class === Path || options.type === 'path' |
|
8853 |
? options |
|
8854 |
: new Base(options, { fill: false });
|
|
8855 |
}, |
|
8856 |
||
8857 |
_draw: function(ctx, param, strokeMatrix) {
|
|
8858 |
var children = this._children; |
|
8859 |
if (children.length === 0) |
|
8860 |
return; |
|
8861 |
||
8862 |
if (this._currentPath) {
|
|
8863 |
ctx.currentPath = this._currentPath; |
|
8864 |
} else {
|
|
8865 |
param = param.extend({ dontStart: true, dontFinish: true });
|
|
8866 |
ctx.beginPath(); |
|
8867 |
for (var i = 0, l = children.length; i < l; i++) |
|
8868 |
children[i].draw(ctx, param, strokeMatrix); |
|
8869 |
this._currentPath = ctx.currentPath; |
|
8870 |
} |
|
8871 |
||
8872 |
if (!param.clip) {
|
|
8873 |
this._setStyles(ctx); |
|
8874 |
var style = this._style; |
|
8875 |
if (style.hasFill()) {
|
|
8876 |
ctx.fill(style.getWindingRule()); |
|
8877 |
ctx.shadowColor = 'rgba(0,0,0,0)'; |
|
8878 |
} |
|
8879 |
if (style.hasStroke()) |
|
8880 |
ctx.stroke(); |
|
8881 |
} |
|
8882 |
}, |
|
8883 |
||
8884 |
_drawSelected: function(ctx, matrix, selectedItems) {
|
|
8885 |
var children = this._children; |
|
8886 |
for (var i = 0, l = children.length; i < l; i++) {
|
|
8887 |
var child = children[i], |
|
8888 |
mx = child._matrix; |
|
8889 |
if (!selectedItems[child._id]) |
|
8890 |
child._drawSelected(ctx, mx.isIdentity() ? matrix |
|
8891 |
: matrix.chain(mx)); |
|
8892 |
} |
|
8893 |
} |
|
| 598 | 8894 |
}, |
8895 |
new function() {
|
|
| 442 | 8896 |
function getCurrentPath(that, check) {
|
8897 |
var children = that._children; |
|
8898 |
if (check && children.length === 0) |
|
8899 |
throw new Error('Use a moveTo() command first');
|
|
8900 |
return children[children.length - 1]; |
|
8901 |
} |
|
8902 |
||
8903 |
var fields = {
|
|
8904 |
moveTo: function() {
|
|
8905 |
var current = getCurrentPath(this), |
|
| 598 | 8906 |
path = current && current.isEmpty() ? current |
8907 |
: new Path(Item.NO_INSERT); |
|
| 442 | 8908 |
if (path !== current) |
8909 |
this.addChild(path); |
|
8910 |
path.moveTo.apply(path, arguments); |
|
8911 |
}, |
|
8912 |
||
8913 |
moveBy: function() {
|
|
8914 |
var current = getCurrentPath(this, true), |
|
8915 |
last = current && current.getLastSegment(), |
|
8916 |
point = Point.read(arguments); |
|
8917 |
this.moveTo(last ? point.add(last._point) : point); |
|
8918 |
}, |
|
8919 |
||
8920 |
closePath: function(join) {
|
|
8921 |
getCurrentPath(this, true).closePath(join); |
|
8922 |
} |
|
8923 |
}; |
|
8924 |
||
8925 |
Base.each(['lineTo', 'cubicCurveTo', 'quadraticCurveTo', 'curveTo', 'arcTo', |
|
8926 |
'lineBy', 'cubicCurveBy', 'quadraticCurveBy', 'curveBy', 'arcBy'], |
|
8927 |
function(key) {
|
|
8928 |
fields[key] = function() {
|
|
8929 |
var path = getCurrentPath(this, true); |
|
8930 |
path[key].apply(path, arguments); |
|
8931 |
}; |
|
8932 |
} |
|
8933 |
); |
|
8934 |
||
8935 |
return fields; |
|
8936 |
}); |
|
8937 |
||
8938 |
PathItem.inject(new function() {
|
|
8939 |
var operators = {
|
|
8940 |
unite: function(w) {
|
|
8941 |
return w === 1 || w === 0; |
|
8942 |
}, |
|
8943 |
||
8944 |
intersect: function(w) {
|
|
8945 |
return w === 2; |
|
8946 |
}, |
|
8947 |
||
8948 |
subtract: function(w) {
|
|
8949 |
return w === 1; |
|
8950 |
}, |
|
8951 |
||
8952 |
exclude: function(w) {
|
|
8953 |
return w === 1; |
|
8954 |
} |
|
8955 |
}; |
|
8956 |
||
| 598 | 8957 |
function preparePath(path, resolve) {
|
8958 |
var res = path.clone(false).reduce().transform(null, true, true); |
|
8959 |
return resolve ? res.resolveCrossings().reorient() : res; |
|
8960 |
} |
|
8961 |
||
8962 |
function finishBoolean(ctor, paths, path1, path2, reduce) {
|
|
8963 |
var result = new ctor(Item.NO_INSERT); |
|
8964 |
result.addChildren(paths, true); |
|
8965 |
if (reduce) |
|
8966 |
result = result.reduce(); |
|
8967 |
result.insertAbove(path2 && path1.isSibling(path2) |
|
8968 |
&& path1.getIndex() < path2.getIndex() |
|
8969 |
? path2 : path1); |
|
8970 |
result.setStyle(path1._style); |
|
8971 |
return result; |
|
8972 |
} |
|
8973 |
||
| 442 | 8974 |
function computeBoolean(path1, path2, operation) {
|
| 598 | 8975 |
if (!path1._children && !path1._closed) |
8976 |
return computeOpenBoolean(path1, path2, operation); |
|
8977 |
var _path1 = preparePath(path1, true), |
|
8978 |
_path2 = path2 && path1 !== path2 && preparePath(path2, true); |
|
| 442 | 8979 |
if (_path2 && /^(subtract|exclude)$/.test(operation) |
8980 |
^ (_path2.isClockwise() !== _path1.isClockwise())) |
|
8981 |
_path2.reverse(); |
|
| 598 | 8982 |
var intersections = CurveLocation.expand( |
8983 |
_path1.getIntersections(_path2, function(inter) {
|
|
8984 |
return _path2 && inter.isOverlap() || inter.isCrossing(); |
|
8985 |
}) |
|
8986 |
); |
|
8987 |
divideLocations(intersections); |
|
8988 |
||
8989 |
var segments = [], |
|
8990 |
monoCurves = []; |
|
| 442 | 8991 |
|
8992 |
function collect(paths) {
|
|
8993 |
for (var i = 0, l = paths.length; i < l; i++) {
|
|
8994 |
var path = paths[i]; |
|
8995 |
segments.push.apply(segments, path._segments); |
|
8996 |
monoCurves.push.apply(monoCurves, path._getMonoCurves()); |
|
8997 |
} |
|
8998 |
} |
|
8999 |
||
9000 |
collect(_path1._children || [_path1]); |
|
9001 |
if (_path2) |
|
9002 |
collect(_path2._children || [_path2]); |
|
| 598 | 9003 |
for (var i = 0, l = intersections.length; i < l; i++) {
|
9004 |
propagateWinding(intersections[i]._segment, _path1, _path2, |
|
9005 |
monoCurves, operation); |
|
9006 |
} |
|
| 442 | 9007 |
for (var i = 0, l = segments.length; i < l; i++) {
|
9008 |
var segment = segments[i]; |
|
| 598 | 9009 |
if (segment._winding == null) {
|
9010 |
propagateWinding(segment, _path1, _path2, monoCurves, |
|
9011 |
operation); |
|
9012 |
} |
|
9013 |
} |
|
9014 |
return finishBoolean(CompoundPath, tracePaths(segments, operation), |
|
9015 |
path1, path2, true); |
|
9016 |
} |
|
9017 |
||
9018 |
function computeOpenBoolean(path1, path2, operation) {
|
|
9019 |
if (!path2 || !path2._children && !path2._closed |
|
9020 |
|| !/^(subtract|intersect)$/.test(operation)) |
|
9021 |
return null; |
|
9022 |
var _path1 = preparePath(path1, false), |
|
9023 |
_path2 = preparePath(path2, false), |
|
9024 |
intersections = _path1.getIntersections(_path2, function(inter) {
|
|
9025 |
return inter.isOverlap() || inter.isCrossing(); |
|
9026 |
}), |
|
9027 |
sub = operation === 'subtract', |
|
9028 |
paths = []; |
|
9029 |
||
9030 |
function addPath(path) {
|
|
9031 |
if (_path2.contains(path.getPointAt(path.getLength() / 2)) ^ sub) {
|
|
9032 |
paths.unshift(path); |
|
9033 |
return true; |
|
9034 |
} |
|
9035 |
} |
|
9036 |
||
9037 |
for (var i = intersections.length - 1; i >= 0; i--) {
|
|
9038 |
var path = intersections[i].split(); |
|
9039 |
if (path) {
|
|
9040 |
if (addPath(path)) |
|
9041 |
path.getFirstSegment().setHandleIn(0, 0); |
|
9042 |
_path1.getLastSegment().setHandleOut(0, 0); |
|
9043 |
} |
|
9044 |
} |
|
9045 |
addPath(_path1); |
|
9046 |
return finishBoolean(Group, paths, path1, path2); |
|
9047 |
} |
|
9048 |
||
9049 |
function linkIntersections(from, to) {
|
|
9050 |
var prev = from; |
|
9051 |
while (prev) {
|
|
9052 |
if (prev === to) |
|
9053 |
return; |
|
9054 |
prev = prev._prev; |
|
9055 |
} |
|
9056 |
while (from._next && from._next !== to) |
|
9057 |
from = from._next; |
|
9058 |
if (!from._next) {
|
|
9059 |
while (to._prev) |
|
9060 |
to = to._prev; |
|
9061 |
from._next = to; |
|
9062 |
to._prev = from; |
|
9063 |
} |
|
9064 |
} |
|
9065 |
||
9066 |
function divideLocations(locations) {
|
|
9067 |
var tMin = 4e-7, |
|
| 442 | 9068 |
tMax = 1 - tMin, |
| 598 | 9069 |
noHandles = false, |
9070 |
clearSegments = [], |
|
9071 |
prevCurve, |
|
9072 |
prevT; |
|
9073 |
||
9074 |
for (var i = locations.length - 1; i >= 0; i--) {
|
|
9075 |
var loc = locations[i], |
|
9076 |
curve = loc._curve, |
|
9077 |
t = loc._parameter, |
|
9078 |
origT = t; |
|
9079 |
if (curve !== prevCurve) {
|
|
9080 |
noHandles = !curve.hasHandles(); |
|
9081 |
} else if (prevT > 0) {
|
|
9082 |
t /= prevT; |
|
9083 |
} |
|
9084 |
var segment; |
|
9085 |
if (t < tMin) {
|
|
9086 |
segment = curve._segment1; |
|
9087 |
} else if (t > tMax) {
|
|
9088 |
segment = curve._segment2; |
|
| 442 | 9089 |
} else {
|
| 598 | 9090 |
segment = curve.divide(t, true, true)._segment1; |
9091 |
if (noHandles) |
|
9092 |
clearSegments.push(segment); |
|
9093 |
} |
|
9094 |
loc._setSegment(segment); |
|
9095 |
var inter = segment._intersection, |
|
9096 |
dest = loc._intersection; |
|
9097 |
if (inter) {
|
|
9098 |
linkIntersections(inter, dest); |
|
9099 |
var other = inter; |
|
9100 |
while (other) {
|
|
9101 |
linkIntersections(other._intersection, inter); |
|
9102 |
other = other._next; |
|
9103 |
} |
|
| 442 | 9104 |
} else {
|
| 598 | 9105 |
segment._intersection = dest; |
9106 |
} |
|
9107 |
prevCurve = curve; |
|
9108 |
prevT = origT; |
|
9109 |
} |
|
9110 |
for (var i = 0, l = clearSegments.length; i < l; i++) {
|
|
9111 |
clearSegments[i].clearHandles(); |
|
9112 |
} |
|
| 442 | 9113 |
} |
9114 |
||
9115 |
function getWinding(point, curves, horizontal, testContains) {
|
|
| 598 | 9116 |
var epsilon = 2e-7, |
9117 |
tMin = 4e-7, |
|
| 442 | 9118 |
tMax = 1 - tMin, |
9119 |
px = point.x, |
|
9120 |
py = point.y, |
|
9121 |
windLeft = 0, |
|
9122 |
windRight = 0, |
|
9123 |
roots = [], |
|
9124 |
abs = Math.abs; |
|
9125 |
if (horizontal) {
|
|
9126 |
var yTop = -Infinity, |
|
9127 |
yBottom = Infinity, |
|
| 598 | 9128 |
yBefore = py - epsilon, |
9129 |
yAfter = py + epsilon; |
|
| 442 | 9130 |
for (var i = 0, l = curves.length; i < l; i++) {
|
9131 |
var values = curves[i].values; |
|
9132 |
if (Curve.solveCubic(values, 0, px, roots, 0, 1) > 0) {
|
|
9133 |
for (var j = roots.length - 1; j >= 0; j--) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9134 |
var y = Curve.getPoint(values, roots[j]).y; |
| 442 | 9135 |
if (y < yBefore && y > yTop) {
|
9136 |
yTop = y; |
|
9137 |
} else if (y > yAfter && y < yBottom) {
|
|
9138 |
yBottom = y; |
|
9139 |
} |
|
9140 |
} |
|
9141 |
} |
|
9142 |
} |
|
9143 |
yTop = (yTop + py) / 2; |
|
9144 |
yBottom = (yBottom + py) / 2; |
|
9145 |
if (yTop > -Infinity) |
|
| 598 | 9146 |
windLeft = getWinding(new Point(px, yTop), curves, false, |
9147 |
testContains); |
|
| 442 | 9148 |
if (yBottom < Infinity) |
| 598 | 9149 |
windRight = getWinding(new Point(px, yBottom), curves, false, |
9150 |
testContains); |
|
| 442 | 9151 |
} else {
|
| 598 | 9152 |
var xBefore = px - epsilon, |
9153 |
xAfter = px + epsilon; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9154 |
var startCounted = false, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9155 |
prevCurve, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9156 |
prevT; |
| 442 | 9157 |
for (var i = 0, l = curves.length; i < l; i++) {
|
9158 |
var curve = curves[i], |
|
9159 |
values = curve.values, |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9160 |
winding = curve.winding; |
| 442 | 9161 |
if (winding && (winding === 1 |
9162 |
&& py >= values[1] && py <= values[7] |
|
9163 |
|| py >= values[7] && py <= values[1]) |
|
9164 |
&& Curve.solveCubic(values, 1, py, roots, 0, 1) === 1) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9165 |
var t = roots[0]; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9166 |
if (!( |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9167 |
t > tMax && startCounted && curve.next !== curves[i + 1] |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9168 |
|| t < tMin && prevT > tMax |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9169 |
&& curve.previous === prevCurve)) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9170 |
var x = Curve.getPoint(values, t).x, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9171 |
slope = Curve.getTangent(values, t).y, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9172 |
counted = false; |
| 598 | 9173 |
if (Numerical.isZero(slope) && !Curve.isStraight(values) |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9174 |
|| t < tMin && slope * Curve.getTangent( |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9175 |
curve.previous.values, 1).y < 0 |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9176 |
|| t > tMax && slope * Curve.getTangent( |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9177 |
curve.next.values, 0).y < 0) {
|
| 442 | 9178 |
if (testContains && x >= xBefore && x <= xAfter) {
|
9179 |
++windLeft; |
|
9180 |
++windRight; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9181 |
counted = true; |
| 442 | 9182 |
} |
9183 |
} else if (x <= xBefore) {
|
|
9184 |
windLeft += winding; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9185 |
counted = true; |
| 442 | 9186 |
} else if (x >= xAfter) {
|
9187 |
windRight += winding; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9188 |
counted = true; |
| 442 | 9189 |
} |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9190 |
if (curve.previous !== curves[i - 1]) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9191 |
startCounted = t < tMin && counted; |
| 442 | 9192 |
} |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9193 |
prevCurve = curve; |
| 442 | 9194 |
prevT = t; |
9195 |
} |
|
9196 |
} |
|
9197 |
} |
|
9198 |
return Math.max(abs(windLeft), abs(windRight)); |
|
9199 |
} |
|
9200 |
||
| 598 | 9201 |
function propagateWinding(segment, path1, path2, monoCurves, operation) {
|
9202 |
var epsilon = 2e-7, |
|
9203 |
chain = [], |
|
9204 |
start = segment, |
|
9205 |
totalLength = 0, |
|
9206 |
windingSum = 0; |
|
9207 |
do {
|
|
9208 |
var curve = segment.getCurve(), |
|
9209 |
length = curve.getLength(); |
|
9210 |
chain.push({ segment: segment, curve: curve, length: length });
|
|
9211 |
totalLength += length; |
|
9212 |
segment = segment.getNext(); |
|
9213 |
} while (segment && !segment._intersection && segment !== start); |
|
9214 |
for (var i = 0; i < 3; i++) {
|
|
9215 |
var length = totalLength * (i + 1) / 4; |
|
9216 |
for (var k = 0, m = chain.length; k < m; k++) {
|
|
9217 |
var node = chain[k], |
|
9218 |
curveLength = node.length; |
|
9219 |
if (length <= curveLength) {
|
|
9220 |
if (length < epsilon || curveLength - length < epsilon) |
|
9221 |
length = curveLength / 2; |
|
9222 |
var curve = node.curve, |
|
9223 |
path = curve._path, |
|
9224 |
parent = path._parent, |
|
9225 |
pt = curve.getPointAt(length), |
|
9226 |
hor = curve.isHorizontal(); |
|
9227 |
if (parent instanceof CompoundPath) |
|
9228 |
path = parent; |
|
9229 |
windingSum += operation === 'subtract' && path2 |
|
9230 |
&& (path === path1 && path2._getWinding(pt, hor) |
|
9231 |
|| path === path2 && !path1._getWinding(pt, hor)) |
|
9232 |
? 0 |
|
9233 |
: getWinding(pt, monoCurves, hor); |
|
9234 |
break; |
|
9235 |
} |
|
9236 |
length -= curveLength; |
|
9237 |
} |
|
9238 |
} |
|
9239 |
var winding = Math.round(windingSum / 3); |
|
9240 |
for (var j = chain.length - 1; j >= 0; j--) |
|
9241 |
chain[j].segment._winding = winding; |
|
9242 |
} |
|
9243 |
||
9244 |
function tracePaths(segments, operation) {
|
|
| 442 | 9245 |
var paths = [], |
| 598 | 9246 |
start, |
9247 |
otherStart, |
|
9248 |
operator = operators[operation], |
|
9249 |
overlapWinding = {
|
|
9250 |
unite: { 1: 2 },
|
|
9251 |
intersect: { 2: 1 }
|
|
9252 |
}[operation]; |
|
9253 |
||
9254 |
function isValid(seg, adjusted) {
|
|
9255 |
if (seg._visited) |
|
9256 |
return false; |
|
9257 |
if (!operator) |
|
9258 |
return true; |
|
9259 |
var winding = seg._winding, |
|
9260 |
inter = seg._intersection; |
|
9261 |
if (inter && adjusted && overlapWinding && inter.isOverlap()) |
|
9262 |
winding = overlapWinding[winding] || winding; |
|
9263 |
return operator(winding); |
|
9264 |
} |
|
9265 |
||
9266 |
function isStart(seg) {
|
|
9267 |
return seg === start || seg === otherStart; |
|
9268 |
} |
|
9269 |
||
9270 |
function findBestIntersection(inter, strict) {
|
|
9271 |
if (!inter._next) |
|
9272 |
return inter; |
|
9273 |
while (inter) {
|
|
9274 |
var seg = inter._segment, |
|
9275 |
nextSeg = seg.getNext(), |
|
9276 |
nextInter = nextSeg._intersection; |
|
9277 |
if (isStart(nextSeg) |
|
9278 |
|| !seg._visited && !nextSeg._visited |
|
9279 |
&& (!operator |
|
9280 |
|| (!strict || isValid(seg)) |
|
9281 |
&& (!(strict && nextInter && nextInter.isOverlap()) |
|
9282 |
&& isValid(nextSeg) |
|
9283 |
|| !strict && nextInter |
|
9284 |
&& isValid(nextInter._segment)) |
|
9285 |
)) |
|
9286 |
return inter; |
|
9287 |
inter = inter._next; |
|
9288 |
} |
|
9289 |
return null; |
|
9290 |
} |
|
9291 |
||
9292 |
function findStartSegment(inter, next) {
|
|
9293 |
while (inter) {
|
|
9294 |
var seg = inter._segment; |
|
9295 |
if (isStart(seg)) |
|
9296 |
return seg; |
|
9297 |
inter = inter[next ? '_next' : '_prev']; |
|
9298 |
} |
|
9299 |
} |
|
9300 |
||
9301 |
for (var i = 0, l = segments.length; i < l; i++) {
|
|
9302 |
var seg = segments[i], |
|
9303 |
path = null, |
|
9304 |
finished = false; |
|
9305 |
if (!isValid(seg, true)) |
|
| 442 | 9306 |
continue; |
| 598 | 9307 |
start = otherStart = null; |
9308 |
while (!finished) {
|
|
9309 |
var inter = seg._intersection, |
|
9310 |
handleIn = path && seg._handleIn; |
|
9311 |
inter = inter && (findBestIntersection(inter, true) |
|
9312 |
|| findBestIntersection(inter, false)) || inter; |
|
9313 |
var other = inter && inter._segment; |
|
9314 |
if (other && isValid(other)) |
|
9315 |
seg = other; |
|
9316 |
if (seg._visited) {
|
|
9317 |
finished = isStart(seg); |
|
9318 |
if (!finished && inter) {
|
|
9319 |
var found = findStartSegment(inter, true) |
|
9320 |
|| findStartSegment(inter, false); |
|
9321 |
if (found) {
|
|
9322 |
seg = found; |
|
9323 |
finished = true; |
|
| 442 | 9324 |
} |
9325 |
} |
|
| 598 | 9326 |
break; |
9327 |
} |
|
9328 |
if (!path) {
|
|
9329 |
path = new Path(Item.NO_INSERT); |
|
9330 |
start = seg; |
|
9331 |
otherStart = other; |
|
9332 |
} |
|
9333 |
path.add(new Segment(seg._point, handleIn, seg._handleOut)); |
|
| 442 | 9334 |
seg._visited = true; |
| 598 | 9335 |
seg = seg.getNext(); |
9336 |
finished = isStart(seg); |
|
9337 |
} |
|
9338 |
if (finished) {
|
|
9339 |
path.firstSegment.setHandleIn(seg._handleIn); |
|
| 442 | 9340 |
path.setClosed(true); |
| 598 | 9341 |
} else if (path) {
|
9342 |
console.error('Boolean operation resulted in open path',
|
|
9343 |
'segments =', path._segments.length, |
|
9344 |
'length =', path.getLength()); |
|
9345 |
path = null; |
|
9346 |
} |
|
9347 |
if (path && (path._segments.length > 8 |
|
9348 |
|| !Numerical.isZero(path.getArea()))) {
|
|
| 442 | 9349 |
paths.push(path); |
| 598 | 9350 |
path = null; |
9351 |
} |
|
| 442 | 9352 |
} |
9353 |
return paths; |
|
9354 |
} |
|
9355 |
||
9356 |
return {
|
|
9357 |
_getWinding: function(point, horizontal, testContains) {
|
|
9358 |
return getWinding(point, this._getMonoCurves(), |
|
9359 |
horizontal, testContains); |
|
9360 |
}, |
|
9361 |
||
9362 |
unite: function(path) {
|
|
9363 |
return computeBoolean(this, path, 'unite'); |
|
9364 |
}, |
|
9365 |
||
9366 |
intersect: function(path) {
|
|
9367 |
return computeBoolean(this, path, 'intersect'); |
|
9368 |
}, |
|
9369 |
||
9370 |
subtract: function(path) {
|
|
9371 |
return computeBoolean(this, path, 'subtract'); |
|
9372 |
}, |
|
9373 |
||
9374 |
exclude: function(path) {
|
|
9375 |
return computeBoolean(this, path, 'exclude'); |
|
9376 |
}, |
|
9377 |
||
9378 |
divide: function(path) {
|
|
| 598 | 9379 |
return finishBoolean(Group, |
9380 |
[this.subtract(path), this.intersect(path)], |
|
9381 |
this, path, true); |
|
9382 |
}, |
|
9383 |
||
9384 |
resolveCrossings: function() {
|
|
9385 |
var crossings = this.getCrossings(); |
|
9386 |
if (!crossings.length) |
|
9387 |
return this; |
|
9388 |
divideLocations(CurveLocation.expand(crossings)); |
|
9389 |
var paths = this._children || [this], |
|
9390 |
segments = []; |
|
9391 |
for (var i = 0, l = paths.length; i < l; i++) {
|
|
9392 |
segments.push.apply(segments, paths[i]._segments); |
|
9393 |
} |
|
9394 |
return finishBoolean(CompoundPath, tracePaths(segments), |
|
9395 |
this, null, false); |
|
| 442 | 9396 |
} |
9397 |
}; |
|
9398 |
}); |
|
9399 |
||
9400 |
Path.inject({
|
|
9401 |
_getMonoCurves: function() {
|
|
9402 |
var monoCurves = this._monoCurves, |
|
9403 |
prevCurve; |
|
9404 |
||
9405 |
function insertCurve(v) {
|
|
9406 |
var y0 = v[1], |
|
9407 |
y1 = v[7], |
|
9408 |
curve = {
|
|
9409 |
values: v, |
|
9410 |
winding: y0 === y1 |
|
9411 |
? 0 |
|
9412 |
: y0 > y1 |
|
9413 |
? -1 |
|
9414 |
: 1, |
|
9415 |
previous: prevCurve, |
|
9416 |
next: null |
|
9417 |
}; |
|
9418 |
if (prevCurve) |
|
9419 |
prevCurve.next = curve; |
|
9420 |
monoCurves.push(curve); |
|
9421 |
prevCurve = curve; |
|
9422 |
} |
|
9423 |
||
9424 |
function handleCurve(v) {
|
|
9425 |
if (Curve.getLength(v) === 0) |
|
9426 |
return; |
|
9427 |
var y0 = v[1], |
|
9428 |
y1 = v[3], |
|
9429 |
y2 = v[5], |
|
9430 |
y3 = v[7]; |
|
| 598 | 9431 |
if (Curve.isStraight(v)) {
|
| 442 | 9432 |
insertCurve(v); |
9433 |
} else {
|
|
9434 |
var a = 3 * (y1 - y2) - y0 + y3, |
|
9435 |
b = 2 * (y0 + y2) - 4 * y1, |
|
9436 |
c = y1 - y0, |
|
| 598 | 9437 |
tMin = 4e-7, |
9438 |
tMax = 1 - tMin, |
|
9439 |
roots = [], |
|
9440 |
n = Numerical.solveQuadratic(a, b, c, roots, tMin, tMax); |
|
9441 |
if (n === 0) {
|
|
| 442 | 9442 |
insertCurve(v); |
9443 |
} else {
|
|
9444 |
roots.sort(); |
|
9445 |
var t = roots[0], |
|
9446 |
parts = Curve.subdivide(v, t); |
|
9447 |
insertCurve(parts[0]); |
|
| 598 | 9448 |
if (n > 1) {
|
| 442 | 9449 |
t = (roots[1] - t) / (1 - t); |
9450 |
parts = Curve.subdivide(parts[1], t); |
|
9451 |
insertCurve(parts[0]); |
|
9452 |
} |
|
9453 |
insertCurve(parts[1]); |
|
9454 |
} |
|
9455 |
} |
|
9456 |
} |
|
9457 |
||
9458 |
if (!monoCurves) {
|
|
9459 |
monoCurves = this._monoCurves = []; |
|
9460 |
var curves = this.getCurves(), |
|
9461 |
segments = this._segments; |
|
9462 |
for (var i = 0, l = curves.length; i < l; i++) |
|
9463 |
handleCurve(curves[i].getValues()); |
|
9464 |
if (!this._closed && segments.length > 1) {
|
|
9465 |
var p1 = segments[segments.length - 1]._point, |
|
9466 |
p2 = segments[0]._point, |
|
9467 |
p1x = p1._x, p1y = p1._y, |
|
9468 |
p2x = p2._x, p2y = p2._y; |
|
9469 |
handleCurve([p1x, p1y, p1x, p1y, p2x, p2y, p2x, p2y]); |
|
9470 |
} |
|
9471 |
if (monoCurves.length > 0) {
|
|
9472 |
var first = monoCurves[0], |
|
9473 |
last = monoCurves[monoCurves.length - 1]; |
|
9474 |
first.previous = last; |
|
9475 |
last.next = first; |
|
9476 |
} |
|
9477 |
} |
|
9478 |
return monoCurves; |
|
9479 |
}, |
|
9480 |
||
9481 |
getInteriorPoint: function() {
|
|
9482 |
var bounds = this.getBounds(), |
|
9483 |
point = bounds.getCenter(true); |
|
9484 |
if (!this.contains(point)) {
|
|
9485 |
var curves = this._getMonoCurves(), |
|
9486 |
roots = [], |
|
9487 |
y = point.y, |
|
9488 |
xIntercepts = []; |
|
9489 |
for (var i = 0, l = curves.length; i < l; i++) {
|
|
9490 |
var values = curves[i].values; |
|
9491 |
if ((curves[i].winding === 1 |
|
9492 |
&& y >= values[1] && y <= values[7] |
|
9493 |
|| y >= values[7] && y <= values[1]) |
|
9494 |
&& Curve.solveCubic(values, 1, y, roots, 0, 1) > 0) {
|
|
9495 |
for (var j = roots.length - 1; j >= 0; j--) |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9496 |
xIntercepts.push(Curve.getPoint(values, roots[j]).x); |
| 442 | 9497 |
} |
9498 |
if (xIntercepts.length > 1) |
|
9499 |
break; |
|
9500 |
} |
|
9501 |
point.x = (xIntercepts[0] + xIntercepts[1]) / 2; |
|
9502 |
} |
|
9503 |
return point; |
|
9504 |
}, |
|
9505 |
||
9506 |
reorient: function() {
|
|
9507 |
this.setClockwise(true); |
|
9508 |
return this; |
|
9509 |
} |
|
9510 |
}); |
|
9511 |
||
9512 |
CompoundPath.inject({
|
|
9513 |
_getMonoCurves: function() {
|
|
9514 |
var children = this._children, |
|
9515 |
monoCurves = []; |
|
9516 |
for (var i = 0, l = children.length; i < l; i++) |
|
9517 |
monoCurves.push.apply(monoCurves, children[i]._getMonoCurves()); |
|
9518 |
return monoCurves; |
|
9519 |
}, |
|
9520 |
||
9521 |
reorient: function() {
|
|
9522 |
var children = this.removeChildren().sort(function(a, b) {
|
|
9523 |
return b.getBounds().getArea() - a.getBounds().getArea(); |
|
9524 |
}); |
|
9525 |
if (children.length > 0) {
|
|
9526 |
this.addChildren(children); |
|
9527 |
var clockwise = children[0].isClockwise(); |
|
9528 |
for (var i = 1, l = children.length; i < l; i++) {
|
|
9529 |
var point = children[i].getInteriorPoint(), |
|
9530 |
counters = 0; |
|
9531 |
for (var j = i - 1; j >= 0; j--) {
|
|
9532 |
if (children[j].contains(point)) |
|
9533 |
counters++; |
|
9534 |
} |
|
9535 |
children[i].setClockwise(counters % 2 === 0 && clockwise); |
|
9536 |
} |
|
9537 |
} |
|
9538 |
return this; |
|
9539 |
} |
|
9540 |
}); |
|
9541 |
||
9542 |
var PathIterator = Base.extend({
|
|
9543 |
_class: 'PathIterator', |
|
9544 |
||
9545 |
initialize: function(path, maxRecursion, tolerance, matrix) {
|
|
9546 |
var curves = [], |
|
9547 |
parts = [], |
|
9548 |
length = 0, |
|
9549 |
minDifference = 1 / (maxRecursion || 32), |
|
9550 |
segments = path._segments, |
|
9551 |
segment1 = segments[0], |
|
9552 |
segment2; |
|
9553 |
||
9554 |
function addCurve(segment1, segment2) {
|
|
9555 |
var curve = Curve.getValues(segment1, segment2, matrix); |
|
9556 |
curves.push(curve); |
|
9557 |
computeParts(curve, segment1._index, 0, 1); |
|
9558 |
} |
|
9559 |
||
9560 |
function computeParts(curve, index, minT, maxT) {
|
|
9561 |
if ((maxT - minT) > minDifference |
|
9562 |
&& !Curve.isFlatEnough(curve, tolerance || 0.25)) {
|
|
| 598 | 9563 |
var split = Curve.subdivide(curve, 0.5), |
| 442 | 9564 |
halfT = (minT + maxT) / 2; |
9565 |
computeParts(split[0], index, minT, halfT); |
|
9566 |
computeParts(split[1], index, halfT, maxT); |
|
9567 |
} else {
|
|
9568 |
var x = curve[6] - curve[0], |
|
9569 |
y = curve[7] - curve[1], |
|
9570 |
dist = Math.sqrt(x * x + y * y); |
|
| 598 | 9571 |
if (dist > 1e-6) {
|
| 442 | 9572 |
length += dist; |
9573 |
parts.push({
|
|
9574 |
offset: length, |
|
9575 |
value: maxT, |
|
9576 |
index: index |
|
9577 |
}); |
|
9578 |
} |
|
9579 |
} |
|
9580 |
} |
|
9581 |
||
9582 |
for (var i = 1, l = segments.length; i < l; i++) {
|
|
9583 |
segment2 = segments[i]; |
|
9584 |
addCurve(segment1, segment2); |
|
9585 |
segment1 = segment2; |
|
9586 |
} |
|
9587 |
if (path._closed) |
|
9588 |
addCurve(segment2, segments[0]); |
|
9589 |
||
9590 |
this.curves = curves; |
|
9591 |
this.parts = parts; |
|
9592 |
this.length = length; |
|
9593 |
this.index = 0; |
|
9594 |
}, |
|
9595 |
||
9596 |
getParameterAt: function(offset) {
|
|
9597 |
var i, j = this.index; |
|
9598 |
for (;;) {
|
|
9599 |
i = j; |
|
9600 |
if (j == 0 || this.parts[--j].offset < offset) |
|
9601 |
break; |
|
9602 |
} |
|
9603 |
for (var l = this.parts.length; i < l; i++) {
|
|
9604 |
var part = this.parts[i]; |
|
9605 |
if (part.offset >= offset) {
|
|
9606 |
this.index = i; |
|
9607 |
var prev = this.parts[i - 1]; |
|
9608 |
var prevVal = prev && prev.index == part.index ? prev.value : 0, |
|
9609 |
prevLen = prev ? prev.offset : 0; |
|
9610 |
return {
|
|
9611 |
value: prevVal + (part.value - prevVal) |
|
9612 |
* (offset - prevLen) / (part.offset - prevLen), |
|
9613 |
index: part.index |
|
9614 |
}; |
|
9615 |
} |
|
9616 |
} |
|
9617 |
var part = this.parts[this.parts.length - 1]; |
|
9618 |
return {
|
|
9619 |
value: 1, |
|
9620 |
index: part.index |
|
9621 |
}; |
|
9622 |
}, |
|
9623 |
||
9624 |
drawPart: function(ctx, from, to) {
|
|
9625 |
from = this.getParameterAt(from); |
|
9626 |
to = this.getParameterAt(to); |
|
9627 |
for (var i = from.index; i <= to.index; i++) {
|
|
9628 |
var curve = Curve.getPart(this.curves[i], |
|
9629 |
i == from.index ? from.value : 0, |
|
9630 |
i == to.index ? to.value : 1); |
|
9631 |
if (i == from.index) |
|
9632 |
ctx.moveTo(curve[0], curve[1]); |
|
9633 |
ctx.bezierCurveTo.apply(ctx, curve.slice(2)); |
|
9634 |
} |
|
9635 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9636 |
}, Base.each(Curve.evaluateMethods, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9637 |
function(name) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9638 |
this[name + 'At'] = function(offset, weighted) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9639 |
var param = this.getParameterAt(offset); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9640 |
return Curve[name](this.curves[param.index], param.value, weighted); |
| 442 | 9641 |
}; |
9642 |
}, {})
|
|
9643 |
); |
|
9644 |
||
9645 |
var PathFitter = Base.extend({
|
|
9646 |
initialize: function(path, error) {
|
|
9647 |
var points = this.points = [], |
|
9648 |
segments = path._segments, |
|
9649 |
prev; |
|
9650 |
for (var i = 0, l = segments.length; i < l; i++) {
|
|
9651 |
var point = segments[i].point.clone(); |
|
9652 |
if (!prev || !prev.equals(point)) {
|
|
9653 |
points.push(point); |
|
9654 |
prev = point; |
|
9655 |
} |
|
9656 |
} |
|
9657 |
||
9658 |
if (path._closed) {
|
|
9659 |
this.closed = true; |
|
9660 |
points.unshift(points[points.length - 1]); |
|
9661 |
points.push(points[1]); |
|
9662 |
} |
|
9663 |
||
9664 |
this.error = error; |
|
9665 |
}, |
|
9666 |
||
9667 |
fit: function() {
|
|
9668 |
var points = this.points, |
|
9669 |
length = points.length, |
|
9670 |
segments = this.segments = length > 0 |
|
9671 |
? [new Segment(points[0])] : []; |
|
9672 |
if (length > 1) |
|
9673 |
this.fitCubic(0, length - 1, |
|
9674 |
points[1].subtract(points[0]).normalize(), |
|
9675 |
points[length - 2].subtract(points[length - 1]).normalize()); |
|
9676 |
||
9677 |
if (this.closed) {
|
|
9678 |
segments.shift(); |
|
9679 |
segments.pop(); |
|
9680 |
} |
|
9681 |
||
9682 |
return segments; |
|
9683 |
}, |
|
9684 |
||
9685 |
fitCubic: function(first, last, tan1, tan2) {
|
|
9686 |
if (last - first == 1) {
|
|
9687 |
var pt1 = this.points[first], |
|
9688 |
pt2 = this.points[last], |
|
9689 |
dist = pt1.getDistance(pt2) / 3; |
|
9690 |
this.addCurve([pt1, pt1.add(tan1.normalize(dist)), |
|
9691 |
pt2.add(tan2.normalize(dist)), pt2]); |
|
9692 |
return; |
|
9693 |
} |
|
9694 |
var uPrime = this.chordLengthParameterize(first, last), |
|
9695 |
maxError = Math.max(this.error, this.error * this.error), |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9696 |
split, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9697 |
parametersInOrder = true; |
| 442 | 9698 |
for (var i = 0; i <= 4; i++) {
|
9699 |
var curve = this.generateBezier(first, last, uPrime, tan1, tan2); |
|
9700 |
var max = this.findMaxError(first, last, curve, uPrime); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9701 |
if (max.error < this.error && parametersInOrder) {
|
| 442 | 9702 |
this.addCurve(curve); |
9703 |
return; |
|
9704 |
} |
|
9705 |
split = max.index; |
|
9706 |
if (max.error >= maxError) |
|
9707 |
break; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9708 |
parametersInOrder = this.reparameterize(first, last, uPrime, curve); |
| 442 | 9709 |
maxError = max.error; |
9710 |
} |
|
9711 |
var V1 = this.points[split - 1].subtract(this.points[split]), |
|
9712 |
V2 = this.points[split].subtract(this.points[split + 1]), |
|
9713 |
tanCenter = V1.add(V2).divide(2).normalize(); |
|
9714 |
this.fitCubic(first, split, tan1, tanCenter); |
|
9715 |
this.fitCubic(split, last, tanCenter.negate(), tan2); |
|
9716 |
}, |
|
9717 |
||
9718 |
addCurve: function(curve) {
|
|
9719 |
var prev = this.segments[this.segments.length - 1]; |
|
9720 |
prev.setHandleOut(curve[1].subtract(curve[0])); |
|
9721 |
this.segments.push( |
|
9722 |
new Segment(curve[3], curve[2].subtract(curve[3]))); |
|
9723 |
}, |
|
9724 |
||
9725 |
generateBezier: function(first, last, uPrime, tan1, tan2) {
|
|
9726 |
var epsilon = 1e-12, |
|
9727 |
pt1 = this.points[first], |
|
9728 |
pt2 = this.points[last], |
|
9729 |
C = [[0, 0], [0, 0]], |
|
9730 |
X = [0, 0]; |
|
9731 |
||
9732 |
for (var i = 0, l = last - first + 1; i < l; i++) {
|
|
9733 |
var u = uPrime[i], |
|
9734 |
t = 1 - u, |
|
9735 |
b = 3 * u * t, |
|
9736 |
b0 = t * t * t, |
|
9737 |
b1 = b * t, |
|
9738 |
b2 = b * u, |
|
9739 |
b3 = u * u * u, |
|
9740 |
a1 = tan1.normalize(b1), |
|
9741 |
a2 = tan2.normalize(b2), |
|
9742 |
tmp = this.points[first + i] |
|
9743 |
.subtract(pt1.multiply(b0 + b1)) |
|
9744 |
.subtract(pt2.multiply(b2 + b3)); |
|
9745 |
C[0][0] += a1.dot(a1); |
|
9746 |
C[0][1] += a1.dot(a2); |
|
9747 |
C[1][0] = C[0][1]; |
|
9748 |
C[1][1] += a2.dot(a2); |
|
9749 |
X[0] += a1.dot(tmp); |
|
9750 |
X[1] += a2.dot(tmp); |
|
9751 |
} |
|
9752 |
||
9753 |
var detC0C1 = C[0][0] * C[1][1] - C[1][0] * C[0][1], |
|
9754 |
alpha1, alpha2; |
|
9755 |
if (Math.abs(detC0C1) > epsilon) {
|
|
9756 |
var detC0X = C[0][0] * X[1] - C[1][0] * X[0], |
|
9757 |
detXC1 = X[0] * C[1][1] - X[1] * C[0][1]; |
|
9758 |
alpha1 = detXC1 / detC0C1; |
|
9759 |
alpha2 = detC0X / detC0C1; |
|
9760 |
} else {
|
|
9761 |
var c0 = C[0][0] + C[0][1], |
|
9762 |
c1 = C[1][0] + C[1][1]; |
|
9763 |
if (Math.abs(c0) > epsilon) {
|
|
9764 |
alpha1 = alpha2 = X[0] / c0; |
|
9765 |
} else if (Math.abs(c1) > epsilon) {
|
|
9766 |
alpha1 = alpha2 = X[1] / c1; |
|
9767 |
} else {
|
|
9768 |
alpha1 = alpha2 = 0; |
|
9769 |
} |
|
9770 |
} |
|
9771 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9772 |
var segLength = pt2.getDistance(pt1), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9773 |
eps = epsilon * segLength, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9774 |
handle1, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9775 |
handle2; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9776 |
if (alpha1 < eps || alpha2 < eps) {
|
| 442 | 9777 |
alpha1 = alpha2 = segLength / 3; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9778 |
} else {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9779 |
var line = pt2.subtract(pt1); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9780 |
handle1 = tan1.normalize(alpha1); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9781 |
handle2 = tan2.normalize(alpha2); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9782 |
if (handle1.dot(line) - handle2.dot(line) > segLength * segLength) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9783 |
alpha1 = alpha2 = segLength / 3; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9784 |
handle1 = handle2 = null; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9785 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9786 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9787 |
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9788 |
return [pt1, pt1.add(handle1 || tan1.normalize(alpha1)), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9789 |
pt2.add(handle2 || tan2.normalize(alpha2)), pt2]; |
| 442 | 9790 |
}, |
9791 |
||
9792 |
reparameterize: function(first, last, u, curve) {
|
|
9793 |
for (var i = first; i <= last; i++) {
|
|
9794 |
u[i - first] = this.findRoot(curve, this.points[i], u[i - first]); |
|
9795 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9796 |
for (var i = 1, l = u.length; i < l; i++) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9797 |
if (u[i] <= u[i - 1]) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9798 |
return false; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9799 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9800 |
return true; |
| 442 | 9801 |
}, |
9802 |
||
9803 |
findRoot: function(curve, point, u) {
|
|
9804 |
var curve1 = [], |
|
9805 |
curve2 = []; |
|
9806 |
for (var i = 0; i <= 2; i++) {
|
|
9807 |
curve1[i] = curve[i + 1].subtract(curve[i]).multiply(3); |
|
9808 |
} |
|
9809 |
for (var i = 0; i <= 1; i++) {
|
|
9810 |
curve2[i] = curve1[i + 1].subtract(curve1[i]).multiply(2); |
|
9811 |
} |
|
9812 |
var pt = this.evaluate(3, curve, u), |
|
9813 |
pt1 = this.evaluate(2, curve1, u), |
|
9814 |
pt2 = this.evaluate(1, curve2, u), |
|
9815 |
diff = pt.subtract(point), |
|
9816 |
df = pt1.dot(pt1) + diff.dot(pt2); |
|
| 598 | 9817 |
if (Math.abs(df) < 1e-6) |
| 442 | 9818 |
return u; |
9819 |
return u - diff.dot(pt1) / df; |
|
9820 |
}, |
|
9821 |
||
9822 |
evaluate: function(degree, curve, t) {
|
|
9823 |
var tmp = curve.slice(); |
|
9824 |
for (var i = 1; i <= degree; i++) {
|
|
9825 |
for (var j = 0; j <= degree - i; j++) {
|
|
9826 |
tmp[j] = tmp[j].multiply(1 - t).add(tmp[j + 1].multiply(t)); |
|
9827 |
} |
|
9828 |
} |
|
9829 |
return tmp[0]; |
|
9830 |
}, |
|
9831 |
||
9832 |
chordLengthParameterize: function(first, last) {
|
|
9833 |
var u = [0]; |
|
9834 |
for (var i = first + 1; i <= last; i++) {
|
|
9835 |
u[i - first] = u[i - first - 1] |
|
9836 |
+ this.points[i].getDistance(this.points[i - 1]); |
|
9837 |
} |
|
9838 |
for (var i = 1, m = last - first; i <= m; i++) {
|
|
9839 |
u[i] /= u[m]; |
|
9840 |
} |
|
9841 |
return u; |
|
9842 |
}, |
|
9843 |
||
9844 |
findMaxError: function(first, last, curve, u) {
|
|
9845 |
var index = Math.floor((last - first + 1) / 2), |
|
9846 |
maxDist = 0; |
|
9847 |
for (var i = first + 1; i < last; i++) {
|
|
9848 |
var P = this.evaluate(3, curve, u[i - first]); |
|
9849 |
var v = P.subtract(this.points[i]); |
|
9850 |
var dist = v.x * v.x + v.y * v.y; |
|
9851 |
if (dist >= maxDist) {
|
|
9852 |
maxDist = dist; |
|
9853 |
index = i; |
|
9854 |
} |
|
9855 |
} |
|
9856 |
return {
|
|
9857 |
error: maxDist, |
|
9858 |
index: index |
|
9859 |
}; |
|
9860 |
} |
|
9861 |
}); |
|
9862 |
||
9863 |
var TextItem = Item.extend({
|
|
9864 |
_class: 'TextItem', |
|
9865 |
_boundsSelected: true, |
|
9866 |
_applyMatrix: false, |
|
9867 |
_canApplyMatrix: false, |
|
9868 |
_serializeFields: {
|
|
9869 |
content: null |
|
9870 |
}, |
|
9871 |
_boundsGetter: 'getBounds', |
|
9872 |
||
9873 |
initialize: function TextItem(arg) {
|
|
9874 |
this._content = ''; |
|
9875 |
this._lines = []; |
|
9876 |
var hasProps = arg && Base.isPlainObject(arg) |
|
9877 |
&& arg.x === undefined && arg.y === undefined; |
|
9878 |
this._initialize(hasProps && arg, !hasProps && Point.read(arguments)); |
|
9879 |
}, |
|
9880 |
||
9881 |
_equals: function(item) {
|
|
9882 |
return this._content === item._content; |
|
9883 |
}, |
|
9884 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9885 |
_clone: function _clone(copy, insert, includeMatrix) {
|
| 442 | 9886 |
copy.setContent(this._content); |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
9887 |
return _clone.base.call(this, copy, insert, includeMatrix); |
| 442 | 9888 |
}, |
9889 |
||
9890 |
getContent: function() {
|
|
9891 |
return this._content; |
|
9892 |
}, |
|
9893 |
||
9894 |
setContent: function(content) {
|
|
9895 |
this._content = '' + content; |
|
9896 |
this._lines = this._content.split(/\r\n|\n|\r/mg); |
|
9897 |
this._changed(265); |
|
9898 |
}, |
|
9899 |
||
9900 |
isEmpty: function() {
|
|
9901 |
return !this._content; |
|
9902 |
}, |
|
9903 |
||
9904 |
getCharacterStyle: '#getStyle', |
|
9905 |
setCharacterStyle: '#setStyle', |
|
9906 |
||
9907 |
getParagraphStyle: '#getStyle', |
|
9908 |
setParagraphStyle: '#setStyle' |
|
9909 |
}); |
|
9910 |
||
9911 |
var PointText = TextItem.extend({
|
|
9912 |
_class: 'PointText', |
|
9913 |
||
9914 |
initialize: function PointText() {
|
|
9915 |
TextItem.apply(this, arguments); |
|
9916 |
}, |
|
9917 |
||
9918 |
clone: function(insert) {
|
|
9919 |
return this._clone(new PointText(Item.NO_INSERT), insert); |
|
9920 |
}, |
|
9921 |
||
9922 |
getPoint: function() {
|
|
9923 |
var point = this._matrix.getTranslation(); |
|
9924 |
return new LinkedPoint(point.x, point.y, this, 'setPoint'); |
|
9925 |
}, |
|
9926 |
||
9927 |
setPoint: function() {
|
|
9928 |
var point = Point.read(arguments); |
|
9929 |
this.translate(point.subtract(this._matrix.getTranslation())); |
|
9930 |
}, |
|
9931 |
||
9932 |
_draw: function(ctx) {
|
|
9933 |
if (!this._content) |
|
9934 |
return; |
|
9935 |
this._setStyles(ctx); |
|
9936 |
var style = this._style, |
|
9937 |
lines = this._lines, |
|
9938 |
leading = style.getLeading(), |
|
9939 |
shadowColor = ctx.shadowColor; |
|
9940 |
ctx.font = style.getFontStyle(); |
|
9941 |
ctx.textAlign = style.getJustification(); |
|
9942 |
for (var i = 0, l = lines.length; i < l; i++) {
|
|
9943 |
ctx.shadowColor = shadowColor; |
|
9944 |
var line = lines[i]; |
|
9945 |
if (style.hasFill()) {
|
|
9946 |
ctx.fillText(line, 0, 0); |
|
9947 |
ctx.shadowColor = 'rgba(0,0,0,0)'; |
|
9948 |
} |
|
9949 |
if (style.hasStroke()) |
|
9950 |
ctx.strokeText(line, 0, 0); |
|
9951 |
ctx.translate(0, leading); |
|
9952 |
} |
|
9953 |
}, |
|
9954 |
||
9955 |
_getBounds: function(getter, matrix) {
|
|
9956 |
var style = this._style, |
|
9957 |
lines = this._lines, |
|
9958 |
numLines = lines.length, |
|
9959 |
justification = style.getJustification(), |
|
9960 |
leading = style.getLeading(), |
|
9961 |
width = this.getView().getTextWidth(style.getFontStyle(), lines), |
|
9962 |
x = 0; |
|
9963 |
if (justification !== 'left') |
|
9964 |
x -= width / (justification === 'center' ? 2: 1); |
|
9965 |
var bounds = new Rectangle(x, |
|
9966 |
numLines ? - 0.75 * leading : 0, |
|
9967 |
width, numLines * leading); |
|
9968 |
return matrix ? matrix._transformBounds(bounds, bounds) : bounds; |
|
9969 |
} |
|
9970 |
}); |
|
9971 |
||
9972 |
var Color = Base.extend(new function() {
|
|
9973 |
var types = {
|
|
9974 |
gray: ['gray'], |
|
9975 |
rgb: ['red', 'green', 'blue'], |
|
9976 |
hsb: ['hue', 'saturation', 'brightness'], |
|
9977 |
hsl: ['hue', 'saturation', 'lightness'], |
|
9978 |
gradient: ['gradient', 'origin', 'destination', 'highlight'] |
|
9979 |
}; |
|
9980 |
||
9981 |
var componentParsers = {},
|
|
9982 |
colorCache = {},
|
|
9983 |
colorCtx; |
|
9984 |
||
9985 |
function fromCSS(string) {
|
|
9986 |
var match = string.match(/^#(\w{1,2})(\w{1,2})(\w{1,2})$/),
|
|
9987 |
components; |
|
9988 |
if (match) {
|
|
9989 |
components = [0, 0, 0]; |
|
9990 |
for (var i = 0; i < 3; i++) {
|
|
9991 |
var value = match[i + 1]; |
|
9992 |
components[i] = parseInt(value.length == 1 |
|
9993 |
? value + value : value, 16) / 255; |
|
9994 |
} |
|
9995 |
} else if (match = string.match(/^rgba?\((.*)\)$/)) {
|
|
9996 |
components = match[1].split(',');
|
|
9997 |
for (var i = 0, l = components.length; i < l; i++) {
|
|
9998 |
var value = +components[i]; |
|
9999 |
components[i] = i < 3 ? value / 255 : value; |
|
10000 |
} |
|
10001 |
} else {
|
|
10002 |
var cached = colorCache[string]; |
|
10003 |
if (!cached) {
|
|
10004 |
if (!colorCtx) {
|
|
10005 |
colorCtx = CanvasProvider.getContext(1, 1); |
|
10006 |
colorCtx.globalCompositeOperation = 'copy'; |
|
10007 |
} |
|
10008 |
colorCtx.fillStyle = 'rgba(0,0,0,0)'; |
|
10009 |
colorCtx.fillStyle = string; |
|
10010 |
colorCtx.fillRect(0, 0, 1, 1); |
|
10011 |
var data = colorCtx.getImageData(0, 0, 1, 1).data; |
|
10012 |
cached = colorCache[string] = [ |
|
10013 |
data[0] / 255, |
|
10014 |
data[1] / 255, |
|
10015 |
data[2] / 255 |
|
10016 |
]; |
|
10017 |
} |
|
10018 |
components = cached.slice(); |
|
10019 |
} |
|
10020 |
return components; |
|
10021 |
} |
|
10022 |
||
10023 |
var hsbIndices = [ |
|
10024 |
[0, 3, 1], |
|
10025 |
[2, 0, 1], |
|
10026 |
[1, 0, 3], |
|
10027 |
[1, 2, 0], |
|
10028 |
[3, 1, 0], |
|
10029 |
[0, 1, 2] |
|
10030 |
]; |
|
10031 |
||
10032 |
var converters = {
|
|
10033 |
'rgb-hsb': function(r, g, b) {
|
|
10034 |
var max = Math.max(r, g, b), |
|
10035 |
min = Math.min(r, g, b), |
|
10036 |
delta = max - min, |
|
10037 |
h = delta === 0 ? 0 |
|
10038 |
: ( max == r ? (g - b) / delta + (g < b ? 6 : 0) |
|
10039 |
: max == g ? (b - r) / delta + 2 |
|
10040 |
: (r - g) / delta + 4) * 60; |
|
10041 |
return [h, max === 0 ? 0 : delta / max, max]; |
|
10042 |
}, |
|
10043 |
||
10044 |
'hsb-rgb': function(h, s, b) {
|
|
10045 |
h = (((h / 60) % 6) + 6) % 6; |
|
10046 |
var i = Math.floor(h), |
|
10047 |
f = h - i, |
|
10048 |
i = hsbIndices[i], |
|
10049 |
v = [ |
|
10050 |
b, |
|
10051 |
b * (1 - s), |
|
10052 |
b * (1 - s * f), |
|
10053 |
b * (1 - s * (1 - f)) |
|
10054 |
]; |
|
10055 |
return [v[i[0]], v[i[1]], v[i[2]]]; |
|
10056 |
}, |
|
10057 |
||
10058 |
'rgb-hsl': function(r, g, b) {
|
|
10059 |
var max = Math.max(r, g, b), |
|
10060 |
min = Math.min(r, g, b), |
|
10061 |
delta = max - min, |
|
10062 |
achromatic = delta === 0, |
|
10063 |
h = achromatic ? 0 |
|
10064 |
: ( max == r ? (g - b) / delta + (g < b ? 6 : 0) |
|
10065 |
: max == g ? (b - r) / delta + 2 |
|
10066 |
: (r - g) / delta + 4) * 60, |
|
10067 |
l = (max + min) / 2, |
|
10068 |
s = achromatic ? 0 : l < 0.5 |
|
10069 |
? delta / (max + min) |
|
10070 |
: delta / (2 - max - min); |
|
10071 |
return [h, s, l]; |
|
10072 |
}, |
|
10073 |
||
10074 |
'hsl-rgb': function(h, s, l) {
|
|
10075 |
h = (((h / 360) % 1) + 1) % 1; |
|
10076 |
if (s === 0) |
|
10077 |
return [l, l, l]; |
|
10078 |
var t3s = [ h + 1 / 3, h, h - 1 / 3 ], |
|
10079 |
t2 = l < 0.5 ? l * (1 + s) : l + s - l * s, |
|
10080 |
t1 = 2 * l - t2, |
|
10081 |
c = []; |
|
10082 |
for (var i = 0; i < 3; i++) {
|
|
10083 |
var t3 = t3s[i]; |
|
10084 |
if (t3 < 0) t3 += 1; |
|
10085 |
if (t3 > 1) t3 -= 1; |
|
10086 |
c[i] = 6 * t3 < 1 |
|
10087 |
? t1 + (t2 - t1) * 6 * t3 |
|
10088 |
: 2 * t3 < 1 |
|
10089 |
? t2 |
|
10090 |
: 3 * t3 < 2 |
|
10091 |
? t1 + (t2 - t1) * ((2 / 3) - t3) * 6 |
|
10092 |
: t1; |
|
10093 |
} |
|
10094 |
return c; |
|
10095 |
}, |
|
10096 |
||
10097 |
'rgb-gray': function(r, g, b) {
|
|
10098 |
return [r * 0.2989 + g * 0.587 + b * 0.114]; |
|
10099 |
}, |
|
10100 |
||
10101 |
'gray-rgb': function(g) {
|
|
10102 |
return [g, g, g]; |
|
10103 |
}, |
|
10104 |
||
10105 |
'gray-hsb': function(g) {
|
|
10106 |
return [0, 0, g]; |
|
10107 |
}, |
|
10108 |
||
10109 |
'gray-hsl': function(g) {
|
|
10110 |
return [0, 0, g]; |
|
10111 |
}, |
|
10112 |
||
10113 |
'gradient-rgb': function() {
|
|
10114 |
return []; |
|
10115 |
}, |
|
10116 |
||
10117 |
'rgb-gradient': function() {
|
|
10118 |
return []; |
|
10119 |
} |
|
10120 |
||
10121 |
}; |
|
10122 |
||
10123 |
return Base.each(types, function(properties, type) {
|
|
10124 |
componentParsers[type] = []; |
|
10125 |
Base.each(properties, function(name, index) {
|
|
10126 |
var part = Base.capitalize(name), |
|
10127 |
hasOverlap = /^(hue|saturation)$/.test(name), |
|
10128 |
parser = componentParsers[type][index] = name === 'gradient' |
|
10129 |
? function(value) {
|
|
10130 |
var current = this._components[0]; |
|
10131 |
value = Gradient.read(Array.isArray(value) ? value |
|
10132 |
: arguments, 0, { readNull: true });
|
|
10133 |
if (current !== value) {
|
|
10134 |
if (current) |
|
10135 |
current._removeOwner(this); |
|
10136 |
if (value) |
|
10137 |
value._addOwner(this); |
|
10138 |
} |
|
10139 |
return value; |
|
10140 |
} |
|
10141 |
: type === 'gradient' |
|
10142 |
? function() {
|
|
10143 |
return Point.read(arguments, 0, {
|
|
10144 |
readNull: name === 'highlight', |
|
10145 |
clone: true |
|
10146 |
}); |
|
10147 |
} |
|
10148 |
: function(value) {
|
|
10149 |
return value == null || isNaN(value) ? 0 : value; |
|
10150 |
}; |
|
10151 |
||
10152 |
this['get' + part] = function() {
|
|
10153 |
return this._type === type |
|
10154 |
|| hasOverlap && /^hs[bl]$/.test(this._type) |
|
10155 |
? this._components[index] |
|
10156 |
: this._convert(type)[index]; |
|
10157 |
}; |
|
10158 |
||
10159 |
this['set' + part] = function(value) {
|
|
10160 |
if (this._type !== type |
|
10161 |
&& !(hasOverlap && /^hs[bl]$/.test(this._type))) {
|
|
10162 |
this._components = this._convert(type); |
|
10163 |
this._properties = types[type]; |
|
10164 |
this._type = type; |
|
10165 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
10166 |
this._components[index] = parser.call(this, value); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
10167 |
this._changed(); |
| 442 | 10168 |
}; |
10169 |
}, this); |
|
10170 |
}, {
|
|
10171 |
_class: 'Color', |
|
10172 |
_readIndex: true, |
|
10173 |
||
10174 |
initialize: function Color(arg) {
|
|
10175 |
var slice = Array.prototype.slice, |
|
10176 |
args = arguments, |
|
10177 |
read = 0, |
|
10178 |
type, |
|
10179 |
components, |
|
10180 |
alpha, |
|
10181 |
values; |
|
10182 |
if (Array.isArray(arg)) {
|
|
10183 |
args = arg; |
|
10184 |
arg = args[0]; |
|
10185 |
} |
|
10186 |
var argType = arg != null && typeof arg; |
|
10187 |
if (argType === 'string' && arg in types) {
|
|
10188 |
type = arg; |
|
10189 |
arg = args[1]; |
|
10190 |
if (Array.isArray(arg)) {
|
|
10191 |
components = arg; |
|
10192 |
alpha = args[2]; |
|
10193 |
} else {
|
|
10194 |
if (this.__read) |
|
10195 |
read = 1; |
|
10196 |
args = slice.call(args, 1); |
|
10197 |
argType = typeof arg; |
|
10198 |
} |
|
10199 |
} |
|
10200 |
if (!components) {
|
|
10201 |
values = argType === 'number' |
|
10202 |
? args |
|
10203 |
: argType === 'object' && arg.length != null |
|
10204 |
? arg |
|
10205 |
: null; |
|
10206 |
if (values) {
|
|
10207 |
if (!type) |
|
10208 |
type = values.length >= 3 |
|
10209 |
? 'rgb' |
|
10210 |
: 'gray'; |
|
10211 |
var length = types[type].length; |
|
10212 |
alpha = values[length]; |
|
10213 |
if (this.__read) |
|
10214 |
read += values === arguments |
|
10215 |
? length + (alpha != null ? 1 : 0) |
|
10216 |
: 1; |
|
10217 |
if (values.length > length) |
|
10218 |
values = slice.call(values, 0, length); |
|
10219 |
} else if (argType === 'string') {
|
|
10220 |
type = 'rgb'; |
|
10221 |
components = fromCSS(arg); |
|
10222 |
if (components.length === 4) {
|
|
10223 |
alpha = components[3]; |
|
10224 |
components.length--; |
|
10225 |
} |
|
10226 |
} else if (argType === 'object') {
|
|
10227 |
if (arg.constructor === Color) {
|
|
10228 |
type = arg._type; |
|
10229 |
components = arg._components.slice(); |
|
10230 |
alpha = arg._alpha; |
|
10231 |
if (type === 'gradient') {
|
|
10232 |
for (var i = 1, l = components.length; i < l; i++) {
|
|
10233 |
var point = components[i]; |
|
10234 |
if (point) |
|
10235 |
components[i] = point.clone(); |
|
10236 |
} |
|
10237 |
} |
|
10238 |
} else if (arg.constructor === Gradient) {
|
|
10239 |
type = 'gradient'; |
|
10240 |
values = args; |
|
10241 |
} else {
|
|
10242 |
type = 'hue' in arg |
|
10243 |
? 'lightness' in arg |
|
10244 |
? 'hsl' |
|
10245 |
: 'hsb' |
|
10246 |
: 'gradient' in arg || 'stops' in arg |
|
10247 |
|| 'radial' in arg |
|
10248 |
? 'gradient' |
|
10249 |
: 'gray' in arg |
|
10250 |
? 'gray' |
|
10251 |
: 'rgb'; |
|
| 598 | 10252 |
var properties = types[type], |
| 442 | 10253 |
parsers = componentParsers[type]; |
10254 |
this._components = components = []; |
|
10255 |
for (var i = 0, l = properties.length; i < l; i++) {
|
|
10256 |
var value = arg[properties[i]]; |
|
10257 |
if (value == null && i === 0 && type === 'gradient' |
|
10258 |
&& 'stops' in arg) {
|
|
10259 |
value = {
|
|
10260 |
stops: arg.stops, |
|
10261 |
radial: arg.radial |
|
10262 |
}; |
|
10263 |
} |
|
10264 |
value = parsers[i].call(this, value); |
|
10265 |
if (value != null) |
|
10266 |
components[i] = value; |
|
10267 |
} |
|
10268 |
alpha = arg.alpha; |
|
10269 |
} |
|
10270 |
} |
|
10271 |
if (this.__read && type) |
|
10272 |
read = 1; |
|
10273 |
} |
|
10274 |
this._type = type || 'rgb'; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
10275 |
this._id = UID.get(Color); |
| 442 | 10276 |
if (!components) {
|
10277 |
this._components = components = []; |
|
10278 |
var parsers = componentParsers[this._type]; |
|
10279 |
for (var i = 0, l = parsers.length; i < l; i++) {
|
|
10280 |
var value = parsers[i].call(this, values && values[i]); |
|
10281 |
if (value != null) |
|
10282 |
components[i] = value; |
|
10283 |
} |
|
10284 |
} |
|
10285 |
this._components = components; |
|
10286 |
this._properties = types[this._type]; |
|
10287 |
this._alpha = alpha; |
|
10288 |
if (this.__read) |
|
10289 |
this.__read = read; |
|
10290 |
}, |
|
10291 |
||
10292 |
_serialize: function(options, dictionary) {
|
|
10293 |
var components = this.getComponents(); |
|
10294 |
return Base.serialize( |
|
10295 |
/^(gray|rgb)$/.test(this._type) |
|
10296 |
? components |
|
10297 |
: [this._type].concat(components), |
|
10298 |
options, true, dictionary); |
|
10299 |
}, |
|
10300 |
||
10301 |
_changed: function() {
|
|
10302 |
this._canvasStyle = null; |
|
10303 |
if (this._owner) |
|
10304 |
this._owner._changed(65); |
|
10305 |
}, |
|
10306 |
||
10307 |
_convert: function(type) {
|
|
10308 |
var converter; |
|
10309 |
return this._type === type |
|
10310 |
? this._components.slice() |
|
10311 |
: (converter = converters[this._type + '-' + type]) |
|
10312 |
? converter.apply(this, this._components) |
|
10313 |
: converters['rgb-' + type].apply(this, |
|
10314 |
converters[this._type + '-rgb'].apply(this, |
|
10315 |
this._components)); |
|
10316 |
}, |
|
10317 |
||
10318 |
convert: function(type) {
|
|
10319 |
return new Color(type, this._convert(type), this._alpha); |
|
10320 |
}, |
|
10321 |
||
10322 |
getType: function() {
|
|
10323 |
return this._type; |
|
10324 |
}, |
|
10325 |
||
10326 |
setType: function(type) {
|
|
10327 |
this._components = this._convert(type); |
|
10328 |
this._properties = types[type]; |
|
10329 |
this._type = type; |
|
10330 |
}, |
|
10331 |
||
10332 |
getComponents: function() {
|
|
10333 |
var components = this._components.slice(); |
|
10334 |
if (this._alpha != null) |
|
10335 |
components.push(this._alpha); |
|
10336 |
return components; |
|
10337 |
}, |
|
10338 |
||
10339 |
getAlpha: function() {
|
|
10340 |
return this._alpha != null ? this._alpha : 1; |
|
10341 |
}, |
|
10342 |
||
10343 |
setAlpha: function(alpha) {
|
|
10344 |
this._alpha = alpha == null ? null : Math.min(Math.max(alpha, 0), 1); |
|
10345 |
this._changed(); |
|
10346 |
}, |
|
10347 |
||
10348 |
hasAlpha: function() {
|
|
10349 |
return this._alpha != null; |
|
10350 |
}, |
|
10351 |
||
10352 |
equals: function(color) {
|
|
10353 |
var col = Base.isPlainValue(color, true) |
|
10354 |
? Color.read(arguments) |
|
10355 |
: color; |
|
10356 |
return col === this || col && this._class === col._class |
|
10357 |
&& this._type === col._type |
|
10358 |
&& this._alpha === col._alpha |
|
10359 |
&& Base.equals(this._components, col._components) |
|
10360 |
|| false; |
|
10361 |
}, |
|
10362 |
||
10363 |
toString: function() {
|
|
10364 |
var properties = this._properties, |
|
10365 |
parts = [], |
|
10366 |
isGradient = this._type === 'gradient', |
|
10367 |
f = Formatter.instance; |
|
10368 |
for (var i = 0, l = properties.length; i < l; i++) {
|
|
10369 |
var value = this._components[i]; |
|
10370 |
if (value != null) |
|
10371 |
parts.push(properties[i] + ': ' |
|
10372 |
+ (isGradient ? value : f.number(value))); |
|
10373 |
} |
|
10374 |
if (this._alpha != null) |
|
10375 |
parts.push('alpha: ' + f.number(this._alpha));
|
|
10376 |
return '{ ' + parts.join(', ') + ' }';
|
|
10377 |
}, |
|
10378 |
||
10379 |
toCSS: function(hex) {
|
|
10380 |
var components = this._convert('rgb'),
|
|
10381 |
alpha = hex || this._alpha == null ? 1 : this._alpha; |
|
10382 |
function convert(val) {
|
|
10383 |
return Math.round((val < 0 ? 0 : val > 1 ? 1 : val) * 255); |
|
10384 |
} |
|
10385 |
components = [ |
|
10386 |
convert(components[0]), |
|
10387 |
convert(components[1]), |
|
10388 |
convert(components[2]) |
|
10389 |
]; |
|
10390 |
if (alpha < 1) |
|
10391 |
components.push(alpha < 0 ? 0 : alpha); |
|
10392 |
return hex |
|
10393 |
? '#' + ((1 << 24) + (components[0] << 16) |
|
10394 |
+ (components[1] << 8) |
|
10395 |
+ components[2]).toString(16).slice(1) |
|
10396 |
: (components.length == 4 ? 'rgba(' : 'rgb(')
|
|
10397 |
+ components.join(',') + ')';
|
|
10398 |
}, |
|
10399 |
||
10400 |
toCanvasStyle: function(ctx) {
|
|
10401 |
if (this._canvasStyle) |
|
10402 |
return this._canvasStyle; |
|
10403 |
if (this._type !== 'gradient') |
|
10404 |
return this._canvasStyle = this.toCSS(); |
|
10405 |
var components = this._components, |
|
10406 |
gradient = components[0], |
|
10407 |
stops = gradient._stops, |
|
10408 |
origin = components[1], |
|
10409 |
destination = components[2], |
|
10410 |
canvasGradient; |
|
10411 |
if (gradient._radial) {
|
|
10412 |
var radius = destination.getDistance(origin), |
|
10413 |
highlight = components[3]; |
|
10414 |
if (highlight) {
|
|
10415 |
var vector = highlight.subtract(origin); |
|
10416 |
if (vector.getLength() > radius) |
|
10417 |
highlight = origin.add(vector.normalize(radius - 0.1)); |
|
10418 |
} |
|
10419 |
var start = highlight || origin; |
|
10420 |
canvasGradient = ctx.createRadialGradient(start.x, start.y, |
|
10421 |
0, origin.x, origin.y, radius); |
|
10422 |
} else {
|
|
10423 |
canvasGradient = ctx.createLinearGradient(origin.x, origin.y, |
|
10424 |
destination.x, destination.y); |
|
10425 |
} |
|
10426 |
for (var i = 0, l = stops.length; i < l; i++) {
|
|
10427 |
var stop = stops[i]; |
|
10428 |
canvasGradient.addColorStop(stop._rampPoint, |
|
10429 |
stop._color.toCanvasStyle()); |
|
10430 |
} |
|
10431 |
return this._canvasStyle = canvasGradient; |
|
10432 |
}, |
|
10433 |
||
10434 |
transform: function(matrix) {
|
|
10435 |
if (this._type === 'gradient') {
|
|
10436 |
var components = this._components; |
|
10437 |
for (var i = 1, l = components.length; i < l; i++) {
|
|
10438 |
var point = components[i]; |
|
10439 |
matrix._transformPoint(point, point, true); |
|
10440 |
} |
|
10441 |
this._changed(); |
|
10442 |
} |
|
10443 |
}, |
|
10444 |
||
10445 |
statics: {
|
|
10446 |
_types: types, |
|
10447 |
||
10448 |
random: function() {
|
|
10449 |
var random = Math.random; |
|
10450 |
return new Color(random(), random(), random()); |
|
10451 |
} |
|
10452 |
} |
|
10453 |
}); |
|
| 598 | 10454 |
}, |
10455 |
new function() {
|
|
| 442 | 10456 |
var operators = {
|
10457 |
add: function(a, b) {
|
|
10458 |
return a + b; |
|
10459 |
}, |
|
10460 |
||
10461 |
subtract: function(a, b) {
|
|
10462 |
return a - b; |
|
10463 |
}, |
|
10464 |
||
10465 |
multiply: function(a, b) {
|
|
10466 |
return a * b; |
|
10467 |
}, |
|
10468 |
||
10469 |
divide: function(a, b) {
|
|
10470 |
return a / b; |
|
10471 |
} |
|
10472 |
}; |
|
10473 |
||
10474 |
return Base.each(operators, function(operator, name) {
|
|
10475 |
this[name] = function(color) {
|
|
10476 |
color = Color.read(arguments); |
|
10477 |
var type = this._type, |
|
10478 |
components1 = this._components, |
|
10479 |
components2 = color._convert(type); |
|
10480 |
for (var i = 0, l = components1.length; i < l; i++) |
|
10481 |
components2[i] = operator(components1[i], components2[i]); |
|
10482 |
return new Color(type, components2, |
|
10483 |
this._alpha != null |
|
10484 |
? operator(this._alpha, color.getAlpha()) |
|
10485 |
: null); |
|
10486 |
}; |
|
10487 |
}, {
|
|
10488 |
}); |
|
10489 |
}); |
|
10490 |
||
10491 |
var Gradient = Base.extend({
|
|
10492 |
_class: 'Gradient', |
|
10493 |
||
10494 |
initialize: function Gradient(stops, radial) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
10495 |
this._id = UID.get(); |
| 442 | 10496 |
if (stops && this._set(stops)) |
10497 |
stops = radial = null; |
|
10498 |
if (!this._stops) |
|
10499 |
this.setStops(stops || ['white', 'black']); |
|
10500 |
if (this._radial == null) |
|
10501 |
this.setRadial(typeof radial === 'string' && radial === 'radial' |
|
10502 |
|| radial || false); |
|
10503 |
}, |
|
10504 |
||
10505 |
_serialize: function(options, dictionary) {
|
|
10506 |
return dictionary.add(this, function() {
|
|
10507 |
return Base.serialize([this._stops, this._radial], |
|
10508 |
options, true, dictionary); |
|
10509 |
}); |
|
10510 |
}, |
|
10511 |
||
10512 |
_changed: function() {
|
|
10513 |
for (var i = 0, l = this._owners && this._owners.length; i < l; i++) |
|
10514 |
this._owners[i]._changed(); |
|
10515 |
}, |
|
10516 |
||
10517 |
_addOwner: function(color) {
|
|
10518 |
if (!this._owners) |
|
10519 |
this._owners = []; |
|
10520 |
this._owners.push(color); |
|
10521 |
}, |
|
10522 |
||
10523 |
_removeOwner: function(color) {
|
|
10524 |
var index = this._owners ? this._owners.indexOf(color) : -1; |
|
10525 |
if (index != -1) {
|
|
10526 |
this._owners.splice(index, 1); |
|
10527 |
if (this._owners.length === 0) |
|
10528 |
this._owners = undefined; |
|
10529 |
} |
|
10530 |
}, |
|
10531 |
||
10532 |
clone: function() {
|
|
10533 |
var stops = []; |
|
10534 |
for (var i = 0, l = this._stops.length; i < l; i++) |
|
10535 |
stops[i] = this._stops[i].clone(); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
10536 |
return new Gradient(stops, this._radial); |
| 442 | 10537 |
}, |
10538 |
||
10539 |
getStops: function() {
|
|
10540 |
return this._stops; |
|
10541 |
}, |
|
10542 |
||
10543 |
setStops: function(stops) {
|
|
10544 |
if (this.stops) {
|
|
10545 |
for (var i = 0, l = this._stops.length; i < l; i++) |
|
10546 |
this._stops[i]._owner = undefined; |
|
10547 |
} |
|
10548 |
if (stops.length < 2) |
|
10549 |
throw new Error( |
|
10550 |
'Gradient stop list needs to contain at least two stops.'); |
|
10551 |
this._stops = GradientStop.readAll(stops, 0, { clone: true });
|
|
10552 |
for (var i = 0, l = this._stops.length; i < l; i++) {
|
|
10553 |
var stop = this._stops[i]; |
|
10554 |
stop._owner = this; |
|
10555 |
if (stop._defaultRamp) |
|
10556 |
stop.setRampPoint(i / (l - 1)); |
|
10557 |
} |
|
10558 |
this._changed(); |
|
10559 |
}, |
|
10560 |
||
10561 |
getRadial: function() {
|
|
10562 |
return this._radial; |
|
10563 |
}, |
|
10564 |
||
10565 |
setRadial: function(radial) {
|
|
10566 |
this._radial = radial; |
|
10567 |
this._changed(); |
|
10568 |
}, |
|
10569 |
||
10570 |
equals: function(gradient) {
|
|
10571 |
if (gradient === this) |
|
10572 |
return true; |
|
10573 |
if (gradient && this._class === gradient._class |
|
10574 |
&& this._stops.length === gradient._stops.length) {
|
|
10575 |
for (var i = 0, l = this._stops.length; i < l; i++) {
|
|
10576 |
if (!this._stops[i].equals(gradient._stops[i])) |
|
10577 |
return false; |
|
10578 |
} |
|
10579 |
return true; |
|
10580 |
} |
|
10581 |
return false; |
|
10582 |
} |
|
10583 |
}); |
|
10584 |
||
10585 |
var GradientStop = Base.extend({
|
|
10586 |
_class: 'GradientStop', |
|
10587 |
||
10588 |
initialize: function GradientStop(arg0, arg1) {
|
|
10589 |
if (arg0) {
|
|
10590 |
var color, rampPoint; |
|
10591 |
if (arg1 === undefined && Array.isArray(arg0)) {
|
|
10592 |
color = arg0[0]; |
|
10593 |
rampPoint = arg0[1]; |
|
10594 |
} else if (arg0.color) {
|
|
10595 |
color = arg0.color; |
|
10596 |
rampPoint = arg0.rampPoint; |
|
10597 |
} else {
|
|
10598 |
color = arg0; |
|
10599 |
rampPoint = arg1; |
|
10600 |
} |
|
10601 |
this.setColor(color); |
|
10602 |
this.setRampPoint(rampPoint); |
|
10603 |
} |
|
10604 |
}, |
|
10605 |
||
10606 |
clone: function() {
|
|
10607 |
return new GradientStop(this._color.clone(), this._rampPoint); |
|
10608 |
}, |
|
10609 |
||
10610 |
_serialize: function(options, dictionary) {
|
|
10611 |
return Base.serialize([this._color, this._rampPoint], options, true, |
|
10612 |
dictionary); |
|
10613 |
}, |
|
10614 |
||
10615 |
_changed: function() {
|
|
10616 |
if (this._owner) |
|
10617 |
this._owner._changed(65); |
|
10618 |
}, |
|
10619 |
||
10620 |
getRampPoint: function() {
|
|
10621 |
return this._rampPoint; |
|
10622 |
}, |
|
10623 |
||
10624 |
setRampPoint: function(rampPoint) {
|
|
10625 |
this._defaultRamp = rampPoint == null; |
|
10626 |
this._rampPoint = rampPoint || 0; |
|
10627 |
this._changed(); |
|
10628 |
}, |
|
10629 |
||
10630 |
getColor: function() {
|
|
10631 |
return this._color; |
|
10632 |
}, |
|
10633 |
||
10634 |
setColor: function(color) {
|
|
10635 |
this._color = Color.read(arguments); |
|
10636 |
if (this._color === color) |
|
10637 |
this._color = color.clone(); |
|
10638 |
this._color._owner = this; |
|
10639 |
this._changed(); |
|
10640 |
}, |
|
10641 |
||
10642 |
equals: function(stop) {
|
|
10643 |
return stop === this || stop && this._class === stop._class |
|
10644 |
&& this._color.equals(stop._color) |
|
10645 |
&& this._rampPoint == stop._rampPoint |
|
10646 |
|| false; |
|
10647 |
} |
|
10648 |
}); |
|
10649 |
||
10650 |
var Style = Base.extend(new function() {
|
|
10651 |
var defaults = {
|
|
10652 |
fillColor: undefined, |
|
10653 |
strokeColor: undefined, |
|
10654 |
strokeWidth: 1, |
|
10655 |
strokeCap: 'butt', |
|
10656 |
strokeJoin: 'miter', |
|
10657 |
strokeScaling: true, |
|
10658 |
miterLimit: 10, |
|
10659 |
dashOffset: 0, |
|
10660 |
dashArray: [], |
|
10661 |
windingRule: 'nonzero', |
|
10662 |
shadowColor: undefined, |
|
10663 |
shadowBlur: 0, |
|
10664 |
shadowOffset: new Point(), |
|
10665 |
selectedColor: undefined, |
|
10666 |
fontFamily: 'sans-serif', |
|
10667 |
fontWeight: 'normal', |
|
10668 |
fontSize: 12, |
|
10669 |
font: 'sans-serif', |
|
10670 |
leading: null, |
|
10671 |
justification: 'left' |
|
10672 |
}; |
|
10673 |
||
10674 |
var flags = {
|
|
10675 |
strokeWidth: 97, |
|
10676 |
strokeCap: 97, |
|
10677 |
strokeJoin: 97, |
|
10678 |
strokeScaling: 105, |
|
10679 |
miterLimit: 97, |
|
10680 |
fontFamily: 9, |
|
10681 |
fontWeight: 9, |
|
10682 |
fontSize: 9, |
|
10683 |
font: 9, |
|
10684 |
leading: 9, |
|
10685 |
justification: 9 |
|
10686 |
}; |
|
10687 |
||
10688 |
var item = { beans: true },
|
|
10689 |
fields = {
|
|
10690 |
_defaults: defaults, |
|
10691 |
_textDefaults: new Base(defaults, {
|
|
10692 |
fillColor: new Color() |
|
10693 |
}), |
|
10694 |
beans: true |
|
10695 |
}; |
|
10696 |
||
10697 |
Base.each(defaults, function(value, key) {
|
|
10698 |
var isColor = /Color$/.test(key), |
|
10699 |
isPoint = key === 'shadowOffset', |
|
10700 |
part = Base.capitalize(key), |
|
10701 |
flag = flags[key], |
|
10702 |
set = 'set' + part, |
|
10703 |
get = 'get' + part; |
|
10704 |
||
10705 |
fields[set] = function(value) {
|
|
10706 |
var owner = this._owner, |
|
10707 |
children = owner && owner._children; |
|
10708 |
if (children && children.length > 0 |
|
10709 |
&& !(owner instanceof CompoundPath)) {
|
|
10710 |
for (var i = 0, l = children.length; i < l; i++) |
|
10711 |
children[i]._style[set](value); |
|
10712 |
} else {
|
|
10713 |
var old = this._values[key]; |
|
10714 |
if (old !== value) {
|
|
10715 |
if (isColor) {
|
|
10716 |
if (old) |
|
10717 |
old._owner = undefined; |
|
10718 |
if (value && value.constructor === Color) {
|
|
10719 |
if (value._owner) |
|
10720 |
value = value.clone(); |
|
10721 |
value._owner = owner; |
|
10722 |
} |
|
10723 |
} |
|
10724 |
this._values[key] = value; |
|
10725 |
if (owner) |
|
10726 |
owner._changed(flag || 65); |
|
10727 |
} |
|
10728 |
} |
|
10729 |
}; |
|
10730 |
||
10731 |
fields[get] = function(_dontMerge) {
|
|
10732 |
var owner = this._owner, |
|
10733 |
children = owner && owner._children, |
|
10734 |
value; |
|
10735 |
if (!children || children.length === 0 || _dontMerge |
|
10736 |
|| owner instanceof CompoundPath) {
|
|
10737 |
var value = this._values[key]; |
|
10738 |
if (value === undefined) {
|
|
10739 |
value = this._defaults[key]; |
|
10740 |
if (value && value.clone) |
|
10741 |
value = value.clone(); |
|
10742 |
} else {
|
|
10743 |
var ctor = isColor ? Color : isPoint ? Point : null; |
|
10744 |
if (ctor && !(value && value.constructor === ctor)) {
|
|
10745 |
this._values[key] = value = ctor.read([value], 0, |
|
10746 |
{ readNull: true, clone: true });
|
|
10747 |
if (value && isColor) |
|
10748 |
value._owner = owner; |
|
10749 |
} |
|
10750 |
} |
|
10751 |
return value; |
|
10752 |
} |
|
10753 |
for (var i = 0, l = children.length; i < l; i++) {
|
|
10754 |
var childValue = children[i]._style[get](); |
|
10755 |
if (i === 0) {
|
|
10756 |
value = childValue; |
|
10757 |
} else if (!Base.equals(value, childValue)) {
|
|
10758 |
return undefined; |
|
10759 |
} |
|
10760 |
} |
|
10761 |
return value; |
|
10762 |
}; |
|
10763 |
||
10764 |
item[get] = function(_dontMerge) {
|
|
10765 |
return this._style[get](_dontMerge); |
|
10766 |
}; |
|
10767 |
||
10768 |
item[set] = function(value) {
|
|
10769 |
this._style[set](value); |
|
10770 |
}; |
|
10771 |
}); |
|
10772 |
||
10773 |
Item.inject(item); |
|
10774 |
return fields; |
|
10775 |
}, {
|
|
10776 |
_class: 'Style', |
|
10777 |
||
10778 |
initialize: function Style(style, _owner, _project) {
|
|
10779 |
this._values = {};
|
|
10780 |
this._owner = _owner; |
|
10781 |
this._project = _owner && _owner._project || _project || paper.project; |
|
10782 |
if (_owner instanceof TextItem) |
|
10783 |
this._defaults = this._textDefaults; |
|
10784 |
if (style) |
|
10785 |
this.set(style); |
|
10786 |
}, |
|
10787 |
||
10788 |
set: function(style) {
|
|
10789 |
var isStyle = style instanceof Style, |
|
10790 |
values = isStyle ? style._values : style; |
|
10791 |
if (values) {
|
|
10792 |
for (var key in values) {
|
|
10793 |
if (key in this._defaults) {
|
|
10794 |
var value = values[key]; |
|
10795 |
this[key] = value && isStyle && value.clone |
|
10796 |
? value.clone() : value; |
|
10797 |
} |
|
10798 |
} |
|
10799 |
} |
|
10800 |
}, |
|
10801 |
||
10802 |
equals: function(style) {
|
|
10803 |
return style === this || style && this._class === style._class |
|
10804 |
&& Base.equals(this._values, style._values) |
|
10805 |
|| false; |
|
10806 |
}, |
|
10807 |
||
10808 |
hasFill: function() {
|
|
10809 |
return !!this.getFillColor(); |
|
10810 |
}, |
|
10811 |
||
10812 |
hasStroke: function() {
|
|
10813 |
return !!this.getStrokeColor() && this.getStrokeWidth() > 0; |
|
10814 |
}, |
|
10815 |
||
10816 |
hasShadow: function() {
|
|
10817 |
return !!this.getShadowColor() && this.getShadowBlur() > 0; |
|
10818 |
}, |
|
10819 |
||
10820 |
getView: function() {
|
|
10821 |
return this._project.getView(); |
|
10822 |
}, |
|
10823 |
||
10824 |
getFontStyle: function() {
|
|
10825 |
var fontSize = this.getFontSize(); |
|
10826 |
return this.getFontWeight() |
|
10827 |
+ ' ' + fontSize + (/[a-z]/i.test(fontSize + '') ? ' ' : 'px ') |
|
10828 |
+ this.getFontFamily(); |
|
10829 |
}, |
|
10830 |
||
10831 |
getFont: '#getFontFamily', |
|
10832 |
setFont: '#setFontFamily', |
|
10833 |
||
10834 |
getLeading: function getLeading() {
|
|
10835 |
var leading = getLeading.base.call(this), |
|
10836 |
fontSize = this.getFontSize(); |
|
10837 |
if (/pt|em|%|px/.test(fontSize)) |
|
10838 |
fontSize = this.getView().getPixelSize(fontSize); |
|
10839 |
return leading != null ? leading : fontSize * 1.2; |
|
10840 |
} |
|
10841 |
||
10842 |
}); |
|
10843 |
||
10844 |
var DomElement = new function() {
|
|
10845 |
function handlePrefix(el, name, set, value) {
|
|
10846 |
var prefixes = ['', 'webkit', 'moz', 'Moz', 'ms', 'o'], |
|
10847 |
suffix = name[0].toUpperCase() + name.substring(1); |
|
10848 |
for (var i = 0; i < 6; i++) {
|
|
10849 |
var prefix = prefixes[i], |
|
10850 |
key = prefix ? prefix + suffix : name; |
|
10851 |
if (key in el) {
|
|
10852 |
if (set) {
|
|
10853 |
el[key] = value; |
|
10854 |
} else {
|
|
10855 |
return el[key]; |
|
10856 |
} |
|
10857 |
break; |
|
10858 |
} |
|
10859 |
} |
|
10860 |
} |
|
10861 |
||
10862 |
return {
|
|
10863 |
getStyles: function(el) {
|
|
10864 |
var doc = el && el.nodeType !== 9 ? el.ownerDocument : el, |
|
10865 |
view = doc && doc.defaultView; |
|
10866 |
return view && view.getComputedStyle(el, ''); |
|
10867 |
}, |
|
10868 |
||
10869 |
getBounds: function(el, viewport) {
|
|
10870 |
var doc = el.ownerDocument, |
|
10871 |
body = doc.body, |
|
10872 |
html = doc.documentElement, |
|
10873 |
rect; |
|
10874 |
try {
|
|
10875 |
rect = el.getBoundingClientRect(); |
|
10876 |
} catch (e) {
|
|
10877 |
rect = { left: 0, top: 0, width: 0, height: 0 };
|
|
10878 |
} |
|
10879 |
var x = rect.left - (html.clientLeft || body.clientLeft || 0), |
|
10880 |
y = rect.top - (html.clientTop || body.clientTop || 0); |
|
10881 |
if (!viewport) {
|
|
10882 |
var view = doc.defaultView; |
|
10883 |
x += view.pageXOffset || html.scrollLeft || body.scrollLeft; |
|
10884 |
y += view.pageYOffset || html.scrollTop || body.scrollTop; |
|
10885 |
} |
|
10886 |
return new Rectangle(x, y, rect.width, rect.height); |
|
10887 |
}, |
|
10888 |
||
10889 |
getViewportBounds: function(el) {
|
|
10890 |
var doc = el.ownerDocument, |
|
10891 |
view = doc.defaultView, |
|
10892 |
html = doc.documentElement; |
|
10893 |
return new Rectangle(0, 0, |
|
10894 |
view.innerWidth || html.clientWidth, |
|
10895 |
view.innerHeight || html.clientHeight |
|
10896 |
); |
|
10897 |
}, |
|
10898 |
||
10899 |
getOffset: function(el, viewport) {
|
|
10900 |
return DomElement.getBounds(el, viewport).getPoint(); |
|
10901 |
}, |
|
10902 |
||
10903 |
getSize: function(el) {
|
|
10904 |
return DomElement.getBounds(el, true).getSize(); |
|
10905 |
}, |
|
10906 |
||
10907 |
isInvisible: function(el) {
|
|
10908 |
return DomElement.getSize(el).equals(new Size(0, 0)); |
|
10909 |
}, |
|
10910 |
||
10911 |
isInView: function(el) {
|
|
10912 |
return !DomElement.isInvisible(el) |
|
10913 |
&& DomElement.getViewportBounds(el).intersects( |
|
10914 |
DomElement.getBounds(el, true)); |
|
10915 |
}, |
|
10916 |
||
10917 |
getPrefixed: function(el, name) {
|
|
10918 |
return handlePrefix(el, name); |
|
10919 |
}, |
|
10920 |
||
10921 |
setPrefixed: function(el, name, value) {
|
|
10922 |
if (typeof name === 'object') {
|
|
10923 |
for (var key in name) |
|
10924 |
handlePrefix(el, key, true, name[key]); |
|
10925 |
} else {
|
|
10926 |
handlePrefix(el, name, true, value); |
|
10927 |
} |
|
10928 |
} |
|
10929 |
}; |
|
10930 |
}; |
|
10931 |
||
10932 |
var DomEvent = {
|
|
10933 |
add: function(el, events) {
|
|
10934 |
for (var type in events) {
|
|
10935 |
var func = events[type], |
|
10936 |
parts = type.split(/[\s,]+/g); |
|
10937 |
for (var i = 0, l = parts.length; i < l; i++) |
|
10938 |
el.addEventListener(parts[i], func, false); |
|
10939 |
} |
|
10940 |
}, |
|
10941 |
||
10942 |
remove: function(el, events) {
|
|
10943 |
for (var type in events) {
|
|
10944 |
var func = events[type], |
|
10945 |
parts = type.split(/[\s,]+/g); |
|
10946 |
for (var i = 0, l = parts.length; i < l; i++) |
|
10947 |
el.removeEventListener(parts[i], func, false); |
|
10948 |
} |
|
10949 |
}, |
|
10950 |
||
10951 |
getPoint: function(event) {
|
|
10952 |
var pos = event.targetTouches |
|
10953 |
? event.targetTouches.length |
|
10954 |
? event.targetTouches[0] |
|
10955 |
: event.changedTouches[0] |
|
10956 |
: event; |
|
10957 |
return new Point( |
|
10958 |
pos.pageX || pos.clientX + document.documentElement.scrollLeft, |
|
10959 |
pos.pageY || pos.clientY + document.documentElement.scrollTop |
|
10960 |
); |
|
10961 |
}, |
|
10962 |
||
10963 |
getTarget: function(event) {
|
|
10964 |
return event.target || event.srcElement; |
|
10965 |
}, |
|
10966 |
||
10967 |
getRelatedTarget: function(event) {
|
|
10968 |
return event.relatedTarget || event.toElement; |
|
10969 |
}, |
|
10970 |
||
10971 |
getOffset: function(event, target) {
|
|
10972 |
return DomEvent.getPoint(event).subtract(DomElement.getOffset( |
|
10973 |
target || DomEvent.getTarget(event))); |
|
10974 |
}, |
|
10975 |
||
10976 |
stop: function(event) {
|
|
10977 |
event.stopPropagation(); |
|
10978 |
event.preventDefault(); |
|
10979 |
} |
|
10980 |
}; |
|
10981 |
||
10982 |
DomEvent.requestAnimationFrame = new function() {
|
|
10983 |
var nativeRequest = DomElement.getPrefixed(window, 'requestAnimationFrame'), |
|
10984 |
requested = false, |
|
10985 |
callbacks = [], |
|
10986 |
focused = true, |
|
10987 |
timer; |
|
10988 |
||
10989 |
DomEvent.add(window, {
|
|
10990 |
focus: function() {
|
|
10991 |
focused = true; |
|
10992 |
}, |
|
10993 |
blur: function() {
|
|
10994 |
focused = false; |
|
10995 |
} |
|
10996 |
}); |
|
10997 |
||
10998 |
function handleCallbacks() {
|
|
10999 |
for (var i = callbacks.length - 1; i >= 0; i--) {
|
|
11000 |
var entry = callbacks[i], |
|
11001 |
func = entry[0], |
|
11002 |
el = entry[1]; |
|
11003 |
if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true' |
|
11004 |
|| focused) && DomElement.isInView(el)) {
|
|
11005 |
callbacks.splice(i, 1); |
|
11006 |
func(); |
|
11007 |
} |
|
11008 |
} |
|
11009 |
if (nativeRequest) {
|
|
11010 |
if (callbacks.length) {
|
|
11011 |
nativeRequest(handleCallbacks); |
|
11012 |
} else {
|
|
11013 |
requested = false; |
|
11014 |
} |
|
11015 |
} |
|
11016 |
} |
|
11017 |
||
11018 |
return function(callback, element) {
|
|
11019 |
callbacks.push([callback, element]); |
|
11020 |
if (nativeRequest) {
|
|
11021 |
if (!requested) {
|
|
11022 |
nativeRequest(handleCallbacks); |
|
11023 |
requested = true; |
|
11024 |
} |
|
11025 |
} else if (!timer) {
|
|
11026 |
timer = setInterval(handleCallbacks, 1000 / 60); |
|
11027 |
} |
|
11028 |
}; |
|
11029 |
}; |
|
11030 |
||
11031 |
var View = Base.extend(Emitter, {
|
|
11032 |
_class: 'View', |
|
11033 |
||
11034 |
initialize: function View(project, element) {
|
|
11035 |
this._project = project; |
|
11036 |
this._scope = project._scope; |
|
11037 |
this._element = element; |
|
11038 |
var size; |
|
11039 |
if (!this._pixelRatio) |
|
11040 |
this._pixelRatio = window.devicePixelRatio || 1; |
|
11041 |
this._id = element.getAttribute('id');
|
|
11042 |
if (this._id == null) |
|
11043 |
element.setAttribute('id', this._id = 'view-' + View._id++);
|
|
11044 |
DomEvent.add(element, this._viewEvents); |
|
11045 |
var none = 'none'; |
|
11046 |
DomElement.setPrefixed(element.style, {
|
|
11047 |
userSelect: none, |
|
11048 |
touchAction: none, |
|
11049 |
touchCallout: none, |
|
11050 |
contentZooming: none, |
|
11051 |
userDrag: none, |
|
11052 |
tapHighlightColor: 'rgba(0,0,0,0)' |
|
11053 |
}); |
|
11054 |
||
11055 |
function getSize(name) {
|
|
11056 |
return element[name] || parseInt(element.getAttribute(name), 10); |
|
11057 |
}; |
|
11058 |
||
11059 |
function getCanvasSize() {
|
|
11060 |
var size = DomElement.getSize(element); |
|
11061 |
return size.isNaN() || size.isZero() |
|
11062 |
? new Size(getSize('width'), getSize('height'))
|
|
11063 |
: size; |
|
11064 |
}; |
|
11065 |
||
11066 |
if (PaperScope.hasAttribute(element, 'resize')) {
|
|
11067 |
var that = this; |
|
11068 |
DomEvent.add(window, this._windowEvents = {
|
|
11069 |
resize: function() {
|
|
11070 |
that.setViewSize(getCanvasSize()); |
|
11071 |
} |
|
11072 |
}); |
|
11073 |
} |
|
11074 |
this._setViewSize(size = getCanvasSize()); |
|
11075 |
if (PaperScope.hasAttribute(element, 'stats') |
|
11076 |
&& typeof Stats !== 'undefined') {
|
|
11077 |
this._stats = new Stats(); |
|
11078 |
var stats = this._stats.domElement, |
|
11079 |
style = stats.style, |
|
11080 |
offset = DomElement.getOffset(element); |
|
11081 |
style.position = 'absolute'; |
|
11082 |
style.left = offset.x + 'px'; |
|
11083 |
style.top = offset.y + 'px'; |
|
11084 |
document.body.appendChild(stats); |
|
11085 |
} |
|
11086 |
View._views.push(this); |
|
11087 |
View._viewsById[this._id] = this; |
|
11088 |
this._viewSize = size; |
|
11089 |
(this._matrix = new Matrix())._owner = this; |
|
11090 |
this._zoom = 1; |
|
11091 |
if (!View._focused) |
|
11092 |
View._focused = this; |
|
11093 |
this._frameItems = {};
|
|
11094 |
this._frameItemCount = 0; |
|
11095 |
}, |
|
11096 |
||
11097 |
remove: function() {
|
|
11098 |
if (!this._project) |
|
11099 |
return false; |
|
11100 |
if (View._focused === this) |
|
11101 |
View._focused = null; |
|
11102 |
View._views.splice(View._views.indexOf(this), 1); |
|
11103 |
delete View._viewsById[this._id]; |
|
11104 |
if (this._project._view === this) |
|
11105 |
this._project._view = null; |
|
11106 |
DomEvent.remove(this._element, this._viewEvents); |
|
11107 |
DomEvent.remove(window, this._windowEvents); |
|
11108 |
this._element = this._project = null; |
|
11109 |
this.off('frame');
|
|
11110 |
this._animate = false; |
|
11111 |
this._frameItems = {};
|
|
11112 |
return true; |
|
11113 |
}, |
|
11114 |
||
| 598 | 11115 |
_events: Base.each(['onResize', 'onMouseDown', 'onMouseUp', 'onMouseMove'], |
11116 |
function(name) {
|
|
11117 |
this[name] = {
|
|
11118 |
install: function(type) {
|
|
11119 |
this._installEvent(type); |
|
11120 |
}, |
|
11121 |
||
11122 |
uninstall: function(type) {
|
|
11123 |
this._uninstallEvent(type); |
|
11124 |
} |
|
11125 |
}; |
|
11126 |
}, {
|
|
11127 |
onFrame: {
|
|
11128 |
install: function() {
|
|
11129 |
this.play(); |
|
11130 |
}, |
|
11131 |
||
11132 |
uninstall: function() {
|
|
11133 |
this.pause(); |
|
11134 |
} |
|
11135 |
} |
|
11136 |
} |
|
11137 |
), |
|
| 442 | 11138 |
|
11139 |
_animate: false, |
|
11140 |
_time: 0, |
|
11141 |
_count: 0, |
|
11142 |
||
11143 |
_requestFrame: function() {
|
|
11144 |
var that = this; |
|
11145 |
DomEvent.requestAnimationFrame(function() {
|
|
11146 |
that._requested = false; |
|
11147 |
if (!that._animate) |
|
11148 |
return; |
|
11149 |
that._requestFrame(); |
|
11150 |
that._handleFrame(); |
|
11151 |
}, this._element); |
|
11152 |
this._requested = true; |
|
11153 |
}, |
|
11154 |
||
11155 |
_handleFrame: function() {
|
|
11156 |
paper = this._scope; |
|
11157 |
var now = Date.now() / 1000, |
|
11158 |
delta = this._before ? now - this._before : 0; |
|
11159 |
this._before = now; |
|
11160 |
this._handlingFrame = true; |
|
11161 |
this.emit('frame', new Base({
|
|
11162 |
delta: delta, |
|
11163 |
time: this._time += delta, |
|
11164 |
count: this._count++ |
|
11165 |
})); |
|
11166 |
if (this._stats) |
|
11167 |
this._stats.update(); |
|
11168 |
this._handlingFrame = false; |
|
11169 |
this.update(); |
|
11170 |
}, |
|
11171 |
||
11172 |
_animateItem: function(item, animate) {
|
|
11173 |
var items = this._frameItems; |
|
11174 |
if (animate) {
|
|
11175 |
items[item._id] = {
|
|
11176 |
item: item, |
|
11177 |
time: 0, |
|
11178 |
count: 0 |
|
11179 |
}; |
|
11180 |
if (++this._frameItemCount === 1) |
|
11181 |
this.on('frame', this._handleFrameItems);
|
|
11182 |
} else {
|
|
11183 |
delete items[item._id]; |
|
11184 |
if (--this._frameItemCount === 0) {
|
|
11185 |
this.off('frame', this._handleFrameItems);
|
|
11186 |
} |
|
11187 |
} |
|
11188 |
}, |
|
11189 |
||
11190 |
_handleFrameItems: function(event) {
|
|
11191 |
for (var i in this._frameItems) {
|
|
11192 |
var entry = this._frameItems[i]; |
|
11193 |
entry.item.emit('frame', new Base(event, {
|
|
11194 |
time: entry.time += event.delta, |
|
11195 |
count: entry.count++ |
|
11196 |
})); |
|
11197 |
} |
|
11198 |
}, |
|
11199 |
||
11200 |
_update: function() {
|
|
11201 |
this._project._needsUpdate = true; |
|
11202 |
if (this._handlingFrame) |
|
11203 |
return; |
|
11204 |
if (this._animate) {
|
|
11205 |
this._handleFrame(); |
|
11206 |
} else {
|
|
11207 |
this.update(); |
|
11208 |
} |
|
11209 |
}, |
|
11210 |
||
11211 |
_changed: function(flags) {
|
|
11212 |
if (flags & 1) |
|
11213 |
this._project._needsUpdate = true; |
|
11214 |
}, |
|
11215 |
||
11216 |
_transform: function(matrix) {
|
|
11217 |
this._matrix.concatenate(matrix); |
|
11218 |
this._bounds = null; |
|
11219 |
this._update(); |
|
11220 |
}, |
|
11221 |
||
11222 |
getElement: function() {
|
|
11223 |
return this._element; |
|
11224 |
}, |
|
11225 |
||
11226 |
getPixelRatio: function() {
|
|
11227 |
return this._pixelRatio; |
|
11228 |
}, |
|
11229 |
||
11230 |
getResolution: function() {
|
|
11231 |
return this._pixelRatio * 72; |
|
11232 |
}, |
|
11233 |
||
11234 |
getViewSize: function() {
|
|
11235 |
var size = this._viewSize; |
|
11236 |
return new LinkedSize(size.width, size.height, this, 'setViewSize'); |
|
11237 |
}, |
|
11238 |
||
11239 |
setViewSize: function() {
|
|
11240 |
var size = Size.read(arguments), |
|
11241 |
delta = size.subtract(this._viewSize); |
|
11242 |
if (delta.isZero()) |
|
11243 |
return; |
|
11244 |
this._viewSize.set(size.width, size.height); |
|
11245 |
this._setViewSize(size); |
|
11246 |
this._bounds = null; |
|
11247 |
this.emit('resize', {
|
|
11248 |
size: size, |
|
11249 |
delta: delta |
|
11250 |
}); |
|
11251 |
this._update(); |
|
11252 |
}, |
|
11253 |
||
11254 |
_setViewSize: function(size) {
|
|
11255 |
var element = this._element; |
|
11256 |
element.width = size.width; |
|
11257 |
element.height = size.height; |
|
11258 |
}, |
|
11259 |
||
11260 |
getBounds: function() {
|
|
11261 |
if (!this._bounds) |
|
11262 |
this._bounds = this._matrix.inverted()._transformBounds( |
|
11263 |
new Rectangle(new Point(), this._viewSize)); |
|
11264 |
return this._bounds; |
|
11265 |
}, |
|
11266 |
||
11267 |
getSize: function() {
|
|
11268 |
return this.getBounds().getSize(); |
|
11269 |
}, |
|
11270 |
||
11271 |
getCenter: function() {
|
|
11272 |
return this.getBounds().getCenter(); |
|
11273 |
}, |
|
11274 |
||
11275 |
setCenter: function() {
|
|
11276 |
var center = Point.read(arguments); |
|
11277 |
this.scrollBy(center.subtract(this.getCenter())); |
|
11278 |
}, |
|
11279 |
||
11280 |
getZoom: function() {
|
|
11281 |
return this._zoom; |
|
11282 |
}, |
|
11283 |
||
11284 |
setZoom: function(zoom) {
|
|
11285 |
this._transform(new Matrix().scale(zoom / this._zoom, |
|
11286 |
this.getCenter())); |
|
11287 |
this._zoom = zoom; |
|
11288 |
}, |
|
11289 |
||
11290 |
isVisible: function() {
|
|
11291 |
return DomElement.isInView(this._element); |
|
11292 |
}, |
|
11293 |
||
11294 |
scrollBy: function() {
|
|
11295 |
this._transform(new Matrix().translate(Point.read(arguments).negate())); |
|
11296 |
}, |
|
11297 |
||
11298 |
play: function() {
|
|
11299 |
this._animate = true; |
|
11300 |
if (!this._requested) |
|
11301 |
this._requestFrame(); |
|
11302 |
}, |
|
11303 |
||
11304 |
pause: function() {
|
|
11305 |
this._animate = false; |
|
11306 |
}, |
|
11307 |
||
11308 |
draw: function() {
|
|
11309 |
this.update(); |
|
11310 |
}, |
|
11311 |
||
11312 |
projectToView: function() {
|
|
11313 |
return this._matrix._transformPoint(Point.read(arguments)); |
|
11314 |
}, |
|
11315 |
||
11316 |
viewToProject: function() {
|
|
11317 |
return this._matrix._inverseTransform(Point.read(arguments)); |
|
11318 |
} |
|
11319 |
||
11320 |
}, {
|
|
11321 |
statics: {
|
|
11322 |
_views: [], |
|
11323 |
_viewsById: {},
|
|
11324 |
_id: 0, |
|
11325 |
||
11326 |
create: function(project, element) {
|
|
11327 |
if (typeof element === 'string') |
|
11328 |
element = document.getElementById(element); |
|
11329 |
return new CanvasView(project, element); |
|
11330 |
} |
|
11331 |
} |
|
| 598 | 11332 |
}, |
11333 |
new function() {
|
|
| 442 | 11334 |
var tool, |
11335 |
prevFocus, |
|
11336 |
tempFocus, |
|
11337 |
dragging = false; |
|
11338 |
||
11339 |
function getView(event) {
|
|
11340 |
var target = DomEvent.getTarget(event); |
|
11341 |
return target.getAttribute && View._viewsById[target.getAttribute('id')];
|
|
11342 |
} |
|
11343 |
||
11344 |
function viewToProject(view, event) {
|
|
11345 |
return view.viewToProject(DomEvent.getOffset(event, view._element)); |
|
11346 |
} |
|
11347 |
||
11348 |
function updateFocus() {
|
|
11349 |
if (!View._focused || !View._focused.isVisible()) {
|
|
11350 |
for (var i = 0, l = View._views.length; i < l; i++) {
|
|
11351 |
var view = View._views[i]; |
|
11352 |
if (view && view.isVisible()) {
|
|
11353 |
View._focused = tempFocus = view; |
|
11354 |
break; |
|
11355 |
} |
|
11356 |
} |
|
11357 |
} |
|
11358 |
} |
|
11359 |
||
11360 |
function handleMouseMove(view, point, event) {
|
|
11361 |
view._handleEvent('mousemove', point, event);
|
|
11362 |
var tool = view._scope.tool; |
|
11363 |
if (tool) {
|
|
11364 |
tool._handleEvent(dragging && tool.responds('mousedrag')
|
|
11365 |
? 'mousedrag' : 'mousemove', point, event); |
|
11366 |
} |
|
11367 |
view.update(); |
|
11368 |
return tool; |
|
11369 |
} |
|
11370 |
||
11371 |
var navigator = window.navigator, |
|
11372 |
mousedown, mousemove, mouseup; |
|
11373 |
if (navigator.pointerEnabled || navigator.msPointerEnabled) {
|
|
11374 |
mousedown = 'pointerdown MSPointerDown'; |
|
11375 |
mousemove = 'pointermove MSPointerMove'; |
|
11376 |
mouseup = 'pointerup pointercancel MSPointerUp MSPointerCancel'; |
|
11377 |
} else {
|
|
11378 |
mousedown = 'touchstart'; |
|
11379 |
mousemove = 'touchmove'; |
|
11380 |
mouseup = 'touchend touchcancel'; |
|
11381 |
if (!('ontouchstart' in window && navigator.userAgent.match(
|
|
11382 |
/mobile|tablet|ip(ad|hone|od)|android|silk/i))) {
|
|
11383 |
mousedown += ' mousedown'; |
|
11384 |
mousemove += ' mousemove'; |
|
11385 |
mouseup += ' mouseup'; |
|
11386 |
} |
|
11387 |
} |
|
11388 |
||
11389 |
var viewEvents = {
|
|
11390 |
'selectstart dragstart': function(event) {
|
|
11391 |
if (dragging) |
|
11392 |
event.preventDefault(); |
|
11393 |
} |
|
11394 |
}; |
|
11395 |
||
11396 |
var docEvents = {
|
|
11397 |
mouseout: function(event) {
|
|
11398 |
var view = View._focused, |
|
11399 |
target = DomEvent.getRelatedTarget(event); |
|
11400 |
if (view && (!target || target.nodeName === 'HTML')) |
|
11401 |
handleMouseMove(view, viewToProject(view, event), event); |
|
11402 |
}, |
|
11403 |
||
11404 |
scroll: updateFocus |
|
11405 |
}; |
|
11406 |
||
11407 |
viewEvents[mousedown] = function(event) {
|
|
11408 |
var view = View._focused = getView(event), |
|
11409 |
point = viewToProject(view, event); |
|
11410 |
dragging = true; |
|
11411 |
view._handleEvent('mousedown', point, event);
|
|
11412 |
if (tool = view._scope.tool) |
|
11413 |
tool._handleEvent('mousedown', point, event);
|
|
11414 |
view.update(); |
|
11415 |
}; |
|
11416 |
||
11417 |
docEvents[mousemove] = function(event) {
|
|
11418 |
var view = View._focused; |
|
11419 |
if (!dragging) {
|
|
11420 |
var target = getView(event); |
|
11421 |
if (target) {
|
|
11422 |
if (view !== target) |
|
11423 |
handleMouseMove(view, viewToProject(view, event), event); |
|
11424 |
prevFocus = view; |
|
11425 |
view = View._focused = tempFocus = target; |
|
11426 |
} else if (tempFocus && tempFocus === view) {
|
|
11427 |
view = View._focused = prevFocus; |
|
11428 |
updateFocus(); |
|
11429 |
} |
|
11430 |
} |
|
11431 |
if (view) {
|
|
11432 |
var point = viewToProject(view, event); |
|
11433 |
if (dragging || view.getBounds().contains(point)) |
|
11434 |
tool = handleMouseMove(view, point, event); |
|
11435 |
} |
|
11436 |
}; |
|
11437 |
||
11438 |
docEvents[mouseup] = function(event) {
|
|
11439 |
var view = View._focused; |
|
11440 |
if (!view || !dragging) |
|
11441 |
return; |
|
11442 |
var point = viewToProject(view, event); |
|
11443 |
dragging = false; |
|
11444 |
view._handleEvent('mouseup', point, event);
|
|
11445 |
if (tool) |
|
11446 |
tool._handleEvent('mouseup', point, event);
|
|
11447 |
view.update(); |
|
11448 |
}; |
|
11449 |
||
11450 |
DomEvent.add(document, docEvents); |
|
11451 |
||
11452 |
DomEvent.add(window, {
|
|
11453 |
load: updateFocus |
|
11454 |
}); |
|
11455 |
||
| 598 | 11456 |
var mouseFlags = {
|
11457 |
mousedown: {
|
|
11458 |
mousedown: 1, |
|
11459 |
mousedrag: 1, |
|
11460 |
click: 1, |
|
11461 |
doubleclick: 1 |
|
11462 |
}, |
|
11463 |
mouseup: {
|
|
11464 |
mouseup: 1, |
|
11465 |
mousedrag: 1, |
|
11466 |
click: 1, |
|
11467 |
doubleclick: 1 |
|
11468 |
}, |
|
11469 |
mousemove: {
|
|
11470 |
mousedrag: 1, |
|
11471 |
mousemove: 1, |
|
11472 |
mouseenter: 1, |
|
11473 |
mouseleave: 1 |
|
11474 |
} |
|
11475 |
}; |
|
11476 |
||
| 442 | 11477 |
return {
|
11478 |
_viewEvents: viewEvents, |
|
11479 |
||
11480 |
_handleEvent: function() {},
|
|
11481 |
||
| 598 | 11482 |
_installEvent: function(type) {
|
11483 |
var counters = this._eventCounters; |
|
11484 |
if (counters) {
|
|
11485 |
for (var key in mouseFlags) {
|
|
11486 |
counters[key] = (counters[key] || 0) |
|
11487 |
+ (mouseFlags[key][type] || 0); |
|
11488 |
} |
|
11489 |
} |
|
11490 |
}, |
|
11491 |
||
11492 |
_uninstallEvent: function(type) {
|
|
11493 |
var counters = this._eventCounters; |
|
11494 |
if (counters) {
|
|
11495 |
for (var key in mouseFlags) |
|
11496 |
counters[key] -= mouseFlags[key][type] || 0; |
|
11497 |
} |
|
11498 |
}, |
|
11499 |
||
| 442 | 11500 |
statics: {
|
11501 |
updateFocus: updateFocus |
|
11502 |
} |
|
11503 |
}; |
|
11504 |
}); |
|
11505 |
||
11506 |
var CanvasView = View.extend({
|
|
11507 |
_class: 'CanvasView', |
|
11508 |
||
11509 |
initialize: function CanvasView(project, canvas) {
|
|
11510 |
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
11511 |
var size = Size.read(arguments, 1); |
|
11512 |
if (size.isZero()) |
|
11513 |
throw new Error( |
|
11514 |
'Cannot create CanvasView with the provided argument: ' |
|
11515 |
+ [].slice.call(arguments, 1)); |
|
11516 |
canvas = CanvasProvider.getCanvas(size); |
|
11517 |
} |
|
11518 |
this._context = canvas.getContext('2d');
|
|
11519 |
this._eventCounters = {};
|
|
11520 |
this._pixelRatio = 1; |
|
11521 |
if (!/^off|false$/.test(PaperScope.getAttribute(canvas, 'hidpi'))) {
|
|
11522 |
var deviceRatio = window.devicePixelRatio || 1, |
|
11523 |
backingStoreRatio = DomElement.getPrefixed(this._context, |
|
11524 |
'backingStorePixelRatio') || 1; |
|
11525 |
this._pixelRatio = deviceRatio / backingStoreRatio; |
|
11526 |
} |
|
11527 |
View.call(this, project, canvas); |
|
11528 |
}, |
|
11529 |
||
11530 |
_setViewSize: function(size) {
|
|
11531 |
var element = this._element, |
|
11532 |
pixelRatio = this._pixelRatio, |
|
11533 |
width = size.width, |
|
11534 |
height = size.height; |
|
11535 |
element.width = width * pixelRatio; |
|
11536 |
element.height = height * pixelRatio; |
|
11537 |
if (pixelRatio !== 1) {
|
|
11538 |
if (!PaperScope.hasAttribute(element, 'resize')) {
|
|
11539 |
var style = element.style; |
|
11540 |
style.width = width + 'px'; |
|
11541 |
style.height = height + 'px'; |
|
11542 |
} |
|
11543 |
this._context.scale(pixelRatio, pixelRatio); |
|
11544 |
} |
|
11545 |
}, |
|
11546 |
||
11547 |
getPixelSize: function(size) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11548 |
var browser = paper.browser, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11549 |
pixels; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11550 |
if (browser && browser.firefox) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11551 |
var parent = this._element.parentNode, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11552 |
temp = document.createElement('div');
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11553 |
temp.style.fontSize = size; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11554 |
parent.appendChild(temp); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11555 |
pixels = parseFloat(DomElement.getStyles(temp).fontSize); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11556 |
parent.removeChild(temp); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11557 |
} else {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11558 |
var ctx = this._context, |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11559 |
prevFont = ctx.font; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11560 |
ctx.font = size + ' serif'; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11561 |
pixels = parseFloat(ctx.font); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11562 |
ctx.font = prevFont; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11563 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11564 |
return pixels; |
| 442 | 11565 |
}, |
11566 |
||
11567 |
getTextWidth: function(font, lines) {
|
|
11568 |
var ctx = this._context, |
|
11569 |
prevFont = ctx.font, |
|
11570 |
width = 0; |
|
11571 |
ctx.font = font; |
|
11572 |
for (var i = 0, l = lines.length; i < l; i++) |
|
11573 |
width = Math.max(width, ctx.measureText(lines[i]).width); |
|
11574 |
ctx.font = prevFont; |
|
11575 |
return width; |
|
11576 |
}, |
|
11577 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11578 |
update: function(force) {
|
| 442 | 11579 |
var project = this._project; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11580 |
if (!project || !force && !project._needsUpdate) |
| 442 | 11581 |
return false; |
11582 |
var ctx = this._context, |
|
11583 |
size = this._viewSize; |
|
11584 |
ctx.clearRect(0, 0, size.width + 1, size.height + 1); |
|
11585 |
project.draw(ctx, this._matrix, this._pixelRatio); |
|
11586 |
project._needsUpdate = false; |
|
11587 |
return true; |
|
11588 |
} |
|
| 598 | 11589 |
}, |
11590 |
new function() {
|
|
| 442 | 11591 |
var downPoint, |
11592 |
lastPoint, |
|
11593 |
overPoint, |
|
11594 |
downItem, |
|
11595 |
lastItem, |
|
11596 |
overItem, |
|
11597 |
dragItem, |
|
11598 |
dblClick, |
|
11599 |
clickTime; |
|
11600 |
||
11601 |
function callEvent(view, type, event, point, target, lastPoint) {
|
|
11602 |
var item = target, |
|
11603 |
mouseEvent; |
|
11604 |
||
11605 |
function call(obj) {
|
|
11606 |
if (obj.responds(type)) {
|
|
11607 |
if (!mouseEvent) {
|
|
11608 |
mouseEvent = new MouseEvent(type, event, point, target, |
|
11609 |
lastPoint ? point.subtract(lastPoint) : null); |
|
11610 |
} |
|
11611 |
if (obj.emit(type, mouseEvent) && mouseEvent.isStopped) {
|
|
11612 |
event.preventDefault(); |
|
11613 |
return true; |
|
11614 |
} |
|
11615 |
} |
|
11616 |
} |
|
11617 |
||
11618 |
while (item) {
|
|
11619 |
if (call(item)) |
|
11620 |
return true; |
|
11621 |
item = item.getParent(); |
|
11622 |
} |
|
11623 |
if (call(view)) |
|
11624 |
return true; |
|
11625 |
return false; |
|
11626 |
} |
|
11627 |
||
11628 |
return {
|
|
11629 |
_handleEvent: function(type, point, event) {
|
|
11630 |
if (!this._eventCounters[type]) |
|
11631 |
return; |
|
11632 |
var project = this._project, |
|
11633 |
hit = project.hitTest(point, {
|
|
11634 |
tolerance: 0, |
|
11635 |
fill: true, |
|
11636 |
stroke: true |
|
11637 |
}), |
|
11638 |
item = hit && hit.item, |
|
11639 |
stopped = false; |
|
11640 |
switch (type) {
|
|
11641 |
case 'mousedown': |
|
11642 |
stopped = callEvent(this, type, event, point, item); |
|
11643 |
dblClick = lastItem == item && (Date.now() - clickTime < 300); |
|
11644 |
downItem = lastItem = item; |
|
11645 |
downPoint = lastPoint = overPoint = point; |
|
11646 |
dragItem = !stopped && item; |
|
11647 |
while (dragItem && !dragItem.responds('mousedrag'))
|
|
11648 |
dragItem = dragItem._parent; |
|
11649 |
break; |
|
11650 |
case 'mouseup': |
|
11651 |
stopped = callEvent(this, type, event, point, item, downPoint); |
|
11652 |
if (dragItem) {
|
|
11653 |
if (lastPoint && !lastPoint.equals(point)) |
|
11654 |
callEvent(this, 'mousedrag', event, point, dragItem, |
|
11655 |
lastPoint); |
|
11656 |
if (item !== dragItem) {
|
|
11657 |
overPoint = point; |
|
11658 |
callEvent(this, 'mousemove', event, point, item, |
|
11659 |
overPoint); |
|
11660 |
} |
|
11661 |
} |
|
11662 |
if (!stopped && item && item === downItem) {
|
|
11663 |
clickTime = Date.now(); |
|
11664 |
callEvent(this, dblClick && downItem.responds('doubleclick')
|
|
11665 |
? 'doubleclick' : 'click', event, downPoint, item); |
|
11666 |
dblClick = false; |
|
11667 |
} |
|
11668 |
downItem = dragItem = null; |
|
11669 |
break; |
|
11670 |
case 'mousemove': |
|
11671 |
if (dragItem) |
|
11672 |
stopped = callEvent(this, 'mousedrag', event, point, |
|
11673 |
dragItem, lastPoint); |
|
11674 |
if (!stopped) {
|
|
11675 |
if (item !== overItem) |
|
11676 |
overPoint = point; |
|
11677 |
stopped = callEvent(this, type, event, point, item, |
|
11678 |
overPoint); |
|
11679 |
} |
|
11680 |
lastPoint = overPoint = point; |
|
11681 |
if (item !== overItem) {
|
|
11682 |
callEvent(this, 'mouseleave', event, point, overItem); |
|
11683 |
overItem = item; |
|
11684 |
callEvent(this, 'mouseenter', event, point, item); |
|
11685 |
} |
|
11686 |
break; |
|
11687 |
} |
|
11688 |
return stopped; |
|
11689 |
} |
|
11690 |
}; |
|
11691 |
}); |
|
11692 |
||
11693 |
var Event = Base.extend({
|
|
11694 |
_class: 'Event', |
|
11695 |
||
11696 |
initialize: function Event(event) {
|
|
11697 |
this.event = event; |
|
11698 |
}, |
|
11699 |
||
11700 |
isPrevented: false, |
|
11701 |
isStopped: false, |
|
11702 |
||
11703 |
preventDefault: function() {
|
|
11704 |
this.isPrevented = true; |
|
11705 |
this.event.preventDefault(); |
|
11706 |
}, |
|
11707 |
||
11708 |
stopPropagation: function() {
|
|
11709 |
this.isStopped = true; |
|
11710 |
this.event.stopPropagation(); |
|
11711 |
}, |
|
11712 |
||
11713 |
stop: function() {
|
|
11714 |
this.stopPropagation(); |
|
11715 |
this.preventDefault(); |
|
11716 |
}, |
|
11717 |
||
11718 |
getModifiers: function() {
|
|
11719 |
return Key.modifiers; |
|
11720 |
} |
|
11721 |
}); |
|
11722 |
||
11723 |
var KeyEvent = Event.extend({
|
|
11724 |
_class: 'KeyEvent', |
|
11725 |
||
11726 |
initialize: function KeyEvent(down, key, character, event) {
|
|
11727 |
Event.call(this, event); |
|
11728 |
this.type = down ? 'keydown' : 'keyup'; |
|
11729 |
this.key = key; |
|
11730 |
this.character = character; |
|
11731 |
}, |
|
11732 |
||
11733 |
toString: function() {
|
|
11734 |
return "{ type: '" + this.type
|
|
11735 |
+ "', key: '" + this.key |
|
11736 |
+ "', character: '" + this.character |
|
11737 |
+ "', modifiers: " + this.getModifiers() |
|
11738 |
+ " }"; |
|
11739 |
} |
|
11740 |
}); |
|
11741 |
||
11742 |
var Key = new function() {
|
|
11743 |
||
11744 |
var specialKeys = {
|
|
11745 |
8: 'backspace', |
|
11746 |
9: 'tab', |
|
11747 |
13: 'enter', |
|
11748 |
16: 'shift', |
|
11749 |
17: 'control', |
|
11750 |
18: 'option', |
|
11751 |
19: 'pause', |
|
11752 |
20: 'caps-lock', |
|
11753 |
27: 'escape', |
|
11754 |
32: 'space', |
|
11755 |
35: 'end', |
|
11756 |
36: 'home', |
|
11757 |
37: 'left', |
|
11758 |
38: 'up', |
|
11759 |
39: 'right', |
|
11760 |
40: 'down', |
|
11761 |
46: 'delete', |
|
11762 |
91: 'command', |
|
11763 |
93: 'command', |
|
11764 |
224: 'command' |
|
11765 |
}, |
|
11766 |
||
11767 |
specialChars = {
|
|
11768 |
9: true, |
|
11769 |
13: true, |
|
11770 |
32: true |
|
11771 |
}, |
|
11772 |
||
11773 |
modifiers = new Base({
|
|
11774 |
shift: false, |
|
11775 |
control: false, |
|
11776 |
option: false, |
|
11777 |
command: false, |
|
11778 |
capsLock: false, |
|
11779 |
space: false |
|
11780 |
}), |
|
11781 |
||
11782 |
charCodeMap = {},
|
|
11783 |
keyMap = {},
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11784 |
commandFixMap, |
| 442 | 11785 |
downCode; |
11786 |
||
11787 |
function handleKey(down, keyCode, charCode, event) {
|
|
11788 |
var character = charCode ? String.fromCharCode(charCode) : '', |
|
11789 |
specialKey = specialKeys[keyCode], |
|
11790 |
key = specialKey || character.toLowerCase(), |
|
11791 |
type = down ? 'keydown' : 'keyup', |
|
11792 |
view = View._focused, |
|
11793 |
scope = view && view.isVisible() && view._scope, |
|
11794 |
tool = scope && scope.tool, |
|
11795 |
name; |
|
11796 |
keyMap[key] = down; |
|
11797 |
if (down) {
|
|
11798 |
charCodeMap[keyCode] = charCode; |
|
11799 |
} else {
|
|
11800 |
delete charCodeMap[keyCode]; |
|
11801 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11802 |
if (specialKey && (name = Base.camelize(specialKey)) in modifiers) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11803 |
modifiers[name] = down; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11804 |
var browser = paper.browser; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11805 |
if (name === 'command' && browser && browser.mac) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11806 |
if (down) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11807 |
commandFixMap = {};
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11808 |
} else {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11809 |
for (var code in commandFixMap) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11810 |
if (code in charCodeMap) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11811 |
handleKey(false, code, commandFixMap[code], event); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11812 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11813 |
commandFixMap = null; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11814 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11815 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11816 |
} else if (down && commandFixMap) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11817 |
commandFixMap[keyCode] = charCode; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
11818 |
} |
| 442 | 11819 |
if (tool && tool.responds(type)) {
|
11820 |
paper = scope; |
|
11821 |
tool.emit(type, new KeyEvent(down, key, character, event)); |
|
11822 |
if (view) |
|
11823 |
view.update(); |
|
11824 |
} |
|
11825 |
} |
|
11826 |
||
11827 |
DomEvent.add(document, {
|
|
11828 |
keydown: function(event) {
|
|
11829 |
var code = event.which || event.keyCode; |
|
11830 |
if (code in specialKeys || modifiers.command) {
|
|
11831 |
handleKey(true, code, |
|
11832 |
code in specialChars || modifiers.command ? code : 0, |
|
11833 |
event); |
|
11834 |
} else {
|
|
11835 |
downCode = code; |
|
11836 |
} |
|
11837 |
}, |
|
11838 |
||
11839 |
keypress: function(event) {
|
|
11840 |
if (downCode != null) {
|
|
11841 |
handleKey(true, downCode, event.which || event.keyCode, event); |
|
11842 |
downCode = null; |
|
11843 |
} |
|
11844 |
}, |
|
11845 |
||
11846 |
keyup: function(event) {
|
|
11847 |
var code = event.which || event.keyCode; |
|
11848 |
if (code in charCodeMap) |
|
11849 |
handleKey(false, code, charCodeMap[code], event); |
|
11850 |
} |
|
11851 |
}); |
|
11852 |
||
11853 |
DomEvent.add(window, {
|
|
11854 |
blur: function(event) {
|
|
11855 |
for (var code in charCodeMap) |
|
11856 |
handleKey(false, code, charCodeMap[code], event); |
|
11857 |
} |
|
11858 |
}); |
|
11859 |
||
11860 |
return {
|
|
11861 |
modifiers: modifiers, |
|
11862 |
||
11863 |
isDown: function(key) {
|
|
11864 |
return !!keyMap[key]; |
|
11865 |
} |
|
11866 |
}; |
|
11867 |
}; |
|
11868 |
||
11869 |
var MouseEvent = Event.extend({
|
|
11870 |
_class: 'MouseEvent', |
|
11871 |
||
11872 |
initialize: function MouseEvent(type, event, point, target, delta) {
|
|
11873 |
Event.call(this, event); |
|
11874 |
this.type = type; |
|
11875 |
this.point = point; |
|
11876 |
this.target = target; |
|
11877 |
this.delta = delta; |
|
11878 |
}, |
|
11879 |
||
11880 |
toString: function() {
|
|
11881 |
return "{ type: '" + this.type
|
|
11882 |
+ "', point: " + this.point |
|
11883 |
+ ', target: ' + this.target |
|
11884 |
+ (this.delta ? ', delta: ' + this.delta : '') |
|
11885 |
+ ', modifiers: ' + this.getModifiers() |
|
11886 |
+ ' }'; |
|
11887 |
} |
|
11888 |
}); |
|
11889 |
||
11890 |
var ToolEvent = Event.extend({
|
|
11891 |
_class: 'ToolEvent', |
|
11892 |
_item: null, |
|
11893 |
||
11894 |
initialize: function ToolEvent(tool, type, event) {
|
|
11895 |
this.tool = tool; |
|
11896 |
this.type = type; |
|
11897 |
this.event = event; |
|
11898 |
}, |
|
11899 |
||
11900 |
_choosePoint: function(point, toolPoint) {
|
|
11901 |
return point ? point : toolPoint ? toolPoint.clone() : null; |
|
11902 |
}, |
|
11903 |
||
11904 |
getPoint: function() {
|
|
11905 |
return this._choosePoint(this._point, this.tool._point); |
|
11906 |
}, |
|
11907 |
||
11908 |
setPoint: function(point) {
|
|
11909 |
this._point = point; |
|
11910 |
}, |
|
11911 |
||
11912 |
getLastPoint: function() {
|
|
11913 |
return this._choosePoint(this._lastPoint, this.tool._lastPoint); |
|
11914 |
}, |
|
11915 |
||
11916 |
setLastPoint: function(lastPoint) {
|
|
11917 |
this._lastPoint = lastPoint; |
|
11918 |
}, |
|
11919 |
||
11920 |
getDownPoint: function() {
|
|
11921 |
return this._choosePoint(this._downPoint, this.tool._downPoint); |
|
11922 |
}, |
|
11923 |
||
11924 |
setDownPoint: function(downPoint) {
|
|
11925 |
this._downPoint = downPoint; |
|
11926 |
}, |
|
11927 |
||
11928 |
getMiddlePoint: function() {
|
|
11929 |
if (!this._middlePoint && this.tool._lastPoint) {
|
|
11930 |
return this.tool._point.add(this.tool._lastPoint).divide(2); |
|
11931 |
} |
|
11932 |
return this._middlePoint; |
|
11933 |
}, |
|
11934 |
||
11935 |
setMiddlePoint: function(middlePoint) {
|
|
11936 |
this._middlePoint = middlePoint; |
|
11937 |
}, |
|
11938 |
||
11939 |
getDelta: function() {
|
|
11940 |
return !this._delta && this.tool._lastPoint |
|
11941 |
? this.tool._point.subtract(this.tool._lastPoint) |
|
11942 |
: this._delta; |
|
11943 |
}, |
|
11944 |
||
11945 |
setDelta: function(delta) {
|
|
11946 |
this._delta = delta; |
|
11947 |
}, |
|
11948 |
||
11949 |
getCount: function() {
|
|
11950 |
return /^mouse(down|up)$/.test(this.type) |
|
11951 |
? this.tool._downCount |
|
11952 |
: this.tool._count; |
|
11953 |
}, |
|
11954 |
||
11955 |
setCount: function(count) {
|
|
11956 |
this.tool[/^mouse(down|up)$/.test(this.type) ? 'downCount' : 'count'] |
|
11957 |
= count; |
|
11958 |
}, |
|
11959 |
||
11960 |
getItem: function() {
|
|
11961 |
if (!this._item) {
|
|
11962 |
var result = this.tool._scope.project.hitTest(this.getPoint()); |
|
11963 |
if (result) {
|
|
11964 |
var item = result.item, |
|
11965 |
parent = item._parent; |
|
11966 |
while (/^(Group|CompoundPath)$/.test(parent._class)) {
|
|
11967 |
item = parent; |
|
11968 |
parent = parent._parent; |
|
11969 |
} |
|
11970 |
this._item = item; |
|
11971 |
} |
|
11972 |
} |
|
11973 |
return this._item; |
|
11974 |
}, |
|
11975 |
||
11976 |
setItem: function(item) {
|
|
11977 |
this._item = item; |
|
11978 |
}, |
|
11979 |
||
11980 |
toString: function() {
|
|
11981 |
return '{ type: ' + this.type
|
|
11982 |
+ ', point: ' + this.getPoint() |
|
11983 |
+ ', count: ' + this.getCount() |
|
11984 |
+ ', modifiers: ' + this.getModifiers() |
|
11985 |
+ ' }'; |
|
11986 |
} |
|
11987 |
}); |
|
11988 |
||
11989 |
var Tool = PaperScopeItem.extend({
|
|
11990 |
_class: 'Tool', |
|
11991 |
_list: 'tools', |
|
11992 |
_reference: 'tool', |
|
11993 |
_events: [ 'onActivate', 'onDeactivate', 'onEditOptions', |
|
11994 |
'onMouseDown', 'onMouseUp', 'onMouseDrag', 'onMouseMove', |
|
11995 |
'onKeyDown', 'onKeyUp' ], |
|
11996 |
||
11997 |
initialize: function Tool(props) {
|
|
11998 |
PaperScopeItem.call(this); |
|
11999 |
this._firstMove = true; |
|
12000 |
this._count = 0; |
|
12001 |
this._downCount = 0; |
|
12002 |
this._set(props); |
|
12003 |
}, |
|
12004 |
||
12005 |
getMinDistance: function() {
|
|
12006 |
return this._minDistance; |
|
12007 |
}, |
|
12008 |
||
12009 |
setMinDistance: function(minDistance) {
|
|
12010 |
this._minDistance = minDistance; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12011 |
if (minDistance != null && this._maxDistance != null |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12012 |
&& minDistance > this._maxDistance) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12013 |
this._maxDistance = minDistance; |
| 442 | 12014 |
} |
12015 |
}, |
|
12016 |
||
12017 |
getMaxDistance: function() {
|
|
12018 |
return this._maxDistance; |
|
12019 |
}, |
|
12020 |
||
12021 |
setMaxDistance: function(maxDistance) {
|
|
12022 |
this._maxDistance = maxDistance; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12023 |
if (this._minDistance != null && maxDistance != null |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12024 |
&& maxDistance < this._minDistance) {
|
| 442 | 12025 |
this._minDistance = maxDistance; |
12026 |
} |
|
12027 |
}, |
|
12028 |
||
12029 |
getFixedDistance: function() {
|
|
12030 |
return this._minDistance == this._maxDistance |
|
12031 |
? this._minDistance : null; |
|
12032 |
}, |
|
12033 |
||
12034 |
setFixedDistance: function(distance) {
|
|
| 598 | 12035 |
this._minDistance = this._maxDistance = distance; |
| 442 | 12036 |
}, |
12037 |
||
12038 |
_updateEvent: function(type, point, minDistance, maxDistance, start, |
|
12039 |
needsChange, matchMaxDistance) {
|
|
12040 |
if (!start) {
|
|
12041 |
if (minDistance != null || maxDistance != null) {
|
|
12042 |
var minDist = minDistance != null ? minDistance : 0, |
|
12043 |
vector = point.subtract(this._point), |
|
12044 |
distance = vector.getLength(); |
|
12045 |
if (distance < minDist) |
|
12046 |
return false; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12047 |
if (maxDistance != null && maxDistance != 0) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12048 |
if (distance > maxDistance) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12049 |
point = this._point.add(vector.normalize(maxDistance)); |
| 442 | 12050 |
} else if (matchMaxDistance) {
|
12051 |
return false; |
|
12052 |
} |
|
12053 |
} |
|
12054 |
} |
|
12055 |
if (needsChange && point.equals(this._point)) |
|
12056 |
return false; |
|
12057 |
} |
|
12058 |
this._lastPoint = start && type == 'mousemove' ? point : this._point; |
|
12059 |
this._point = point; |
|
12060 |
switch (type) {
|
|
12061 |
case 'mousedown': |
|
12062 |
this._lastPoint = this._downPoint; |
|
12063 |
this._downPoint = this._point; |
|
12064 |
this._downCount++; |
|
12065 |
break; |
|
12066 |
case 'mouseup': |
|
12067 |
this._lastPoint = this._downPoint; |
|
12068 |
break; |
|
12069 |
} |
|
12070 |
this._count = start ? 0 : this._count + 1; |
|
12071 |
return true; |
|
12072 |
}, |
|
12073 |
||
12074 |
_fireEvent: function(type, event) {
|
|
12075 |
var sets = paper.project._removeSets; |
|
12076 |
if (sets) {
|
|
12077 |
if (type === 'mouseup') |
|
12078 |
sets.mousedrag = null; |
|
12079 |
var set = sets[type]; |
|
12080 |
if (set) {
|
|
12081 |
for (var id in set) {
|
|
12082 |
var item = set[id]; |
|
12083 |
for (var key in sets) {
|
|
12084 |
var other = sets[key]; |
|
12085 |
if (other && other != set) |
|
12086 |
delete other[item._id]; |
|
12087 |
} |
|
12088 |
item.remove(); |
|
12089 |
} |
|
12090 |
sets[type] = null; |
|
12091 |
} |
|
12092 |
} |
|
12093 |
return this.responds(type) |
|
12094 |
&& this.emit(type, new ToolEvent(this, type, event)); |
|
12095 |
}, |
|
12096 |
||
12097 |
_handleEvent: function(type, point, event) {
|
|
12098 |
paper = this._scope; |
|
12099 |
var called = false; |
|
12100 |
switch (type) {
|
|
12101 |
case 'mousedown': |
|
12102 |
this._updateEvent(type, point, null, null, true, false, false); |
|
12103 |
called = this._fireEvent(type, event); |
|
12104 |
break; |
|
12105 |
case 'mousedrag': |
|
12106 |
var needsChange = false, |
|
12107 |
matchMaxDistance = false; |
|
12108 |
while (this._updateEvent(type, point, this.minDistance, |
|
12109 |
this.maxDistance, false, needsChange, matchMaxDistance)) {
|
|
12110 |
called = this._fireEvent(type, event) || called; |
|
12111 |
needsChange = true; |
|
12112 |
matchMaxDistance = true; |
|
12113 |
} |
|
12114 |
break; |
|
12115 |
case 'mouseup': |
|
12116 |
if (!point.equals(this._point) |
|
12117 |
&& this._updateEvent('mousedrag', point, this.minDistance,
|
|
12118 |
this.maxDistance, false, false, false)) {
|
|
12119 |
called = this._fireEvent('mousedrag', event);
|
|
12120 |
} |
|
12121 |
this._updateEvent(type, point, null, this.maxDistance, false, |
|
12122 |
false, false); |
|
12123 |
called = this._fireEvent(type, event) || called; |
|
12124 |
this._updateEvent(type, point, null, null, true, false, false); |
|
12125 |
this._firstMove = true; |
|
12126 |
break; |
|
12127 |
case 'mousemove': |
|
12128 |
while (this._updateEvent(type, point, this.minDistance, |
|
12129 |
this.maxDistance, this._firstMove, true, false)) {
|
|
12130 |
called = this._fireEvent(type, event) || called; |
|
12131 |
this._firstMove = false; |
|
12132 |
} |
|
12133 |
break; |
|
12134 |
} |
|
12135 |
if (called) |
|
12136 |
event.preventDefault(); |
|
12137 |
return called; |
|
12138 |
} |
|
12139 |
||
12140 |
}); |
|
12141 |
||
12142 |
var Http = {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12143 |
request: function(method, url, callback, async) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12144 |
async = (async === undefined) ? true : async; |
| 442 | 12145 |
var xhr = new (window.ActiveXObject || XMLHttpRequest)( |
12146 |
'Microsoft.XMLHTTP'); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12147 |
xhr.open(method.toUpperCase(), url, async); |
| 442 | 12148 |
if ('overrideMimeType' in xhr)
|
12149 |
xhr.overrideMimeType('text/plain');
|
|
12150 |
xhr.onreadystatechange = function() {
|
|
12151 |
if (xhr.readyState === 4) {
|
|
12152 |
var status = xhr.status; |
|
12153 |
if (status === 0 || status === 200) {
|
|
12154 |
callback.call(xhr, xhr.responseText); |
|
12155 |
} else {
|
|
12156 |
throw new Error('Could not load ' + url + ' (Error '
|
|
12157 |
+ status + ')'); |
|
12158 |
} |
|
12159 |
} |
|
12160 |
}; |
|
12161 |
return xhr.send(null); |
|
12162 |
} |
|
12163 |
}; |
|
12164 |
||
12165 |
var CanvasProvider = {
|
|
12166 |
canvases: [], |
|
12167 |
||
12168 |
getCanvas: function(width, height) {
|
|
12169 |
var canvas, |
|
12170 |
clear = true; |
|
12171 |
if (typeof width === 'object') {
|
|
12172 |
height = width.height; |
|
12173 |
width = width.width; |
|
12174 |
} |
|
12175 |
if (this.canvases.length) {
|
|
12176 |
canvas = this.canvases.pop(); |
|
12177 |
} else {
|
|
12178 |
canvas = document.createElement('canvas');
|
|
12179 |
} |
|
12180 |
var ctx = canvas.getContext('2d');
|
|
12181 |
if (canvas.width === width && canvas.height === height) {
|
|
12182 |
if (clear) |
|
12183 |
ctx.clearRect(0, 0, width + 1, height + 1); |
|
12184 |
} else {
|
|
12185 |
canvas.width = width; |
|
12186 |
canvas.height = height; |
|
12187 |
} |
|
12188 |
ctx.save(); |
|
12189 |
return canvas; |
|
12190 |
}, |
|
12191 |
||
12192 |
getContext: function(width, height) {
|
|
12193 |
return this.getCanvas(width, height).getContext('2d');
|
|
12194 |
}, |
|
12195 |
||
12196 |
release: function(obj) {
|
|
12197 |
var canvas = obj.canvas ? obj.canvas : obj; |
|
12198 |
canvas.getContext('2d').restore();
|
|
12199 |
this.canvases.push(canvas); |
|
12200 |
} |
|
12201 |
}; |
|
12202 |
||
12203 |
var BlendMode = new function() {
|
|
12204 |
var min = Math.min, |
|
12205 |
max = Math.max, |
|
12206 |
abs = Math.abs, |
|
12207 |
sr, sg, sb, sa, |
|
12208 |
br, bg, bb, ba, |
|
12209 |
dr, dg, db; |
|
12210 |
||
12211 |
function getLum(r, g, b) {
|
|
12212 |
return 0.2989 * r + 0.587 * g + 0.114 * b; |
|
12213 |
} |
|
12214 |
||
12215 |
function setLum(r, g, b, l) {
|
|
12216 |
var d = l - getLum(r, g, b); |
|
12217 |
dr = r + d; |
|
12218 |
dg = g + d; |
|
12219 |
db = b + d; |
|
12220 |
var l = getLum(dr, dg, db), |
|
12221 |
mn = min(dr, dg, db), |
|
12222 |
mx = max(dr, dg, db); |
|
12223 |
if (mn < 0) {
|
|
12224 |
var lmn = l - mn; |
|
12225 |
dr = l + (dr - l) * l / lmn; |
|
12226 |
dg = l + (dg - l) * l / lmn; |
|
12227 |
db = l + (db - l) * l / lmn; |
|
12228 |
} |
|
12229 |
if (mx > 255) {
|
|
12230 |
var ln = 255 - l, |
|
12231 |
mxl = mx - l; |
|
12232 |
dr = l + (dr - l) * ln / mxl; |
|
12233 |
dg = l + (dg - l) * ln / mxl; |
|
12234 |
db = l + (db - l) * ln / mxl; |
|
12235 |
} |
|
12236 |
} |
|
12237 |
||
12238 |
function getSat(r, g, b) {
|
|
12239 |
return max(r, g, b) - min(r, g, b); |
|
12240 |
} |
|
12241 |
||
12242 |
function setSat(r, g, b, s) {
|
|
12243 |
var col = [r, g, b], |
|
12244 |
mx = max(r, g, b), |
|
12245 |
mn = min(r, g, b), |
|
12246 |
md; |
|
12247 |
mn = mn === r ? 0 : mn === g ? 1 : 2; |
|
12248 |
mx = mx === r ? 0 : mx === g ? 1 : 2; |
|
12249 |
md = min(mn, mx) === 0 ? max(mn, mx) === 1 ? 2 : 1 : 0; |
|
12250 |
if (col[mx] > col[mn]) {
|
|
12251 |
col[md] = (col[md] - col[mn]) * s / (col[mx] - col[mn]); |
|
12252 |
col[mx] = s; |
|
12253 |
} else {
|
|
12254 |
col[md] = col[mx] = 0; |
|
12255 |
} |
|
12256 |
col[mn] = 0; |
|
12257 |
dr = col[0]; |
|
12258 |
dg = col[1]; |
|
12259 |
db = col[2]; |
|
12260 |
} |
|
12261 |
||
12262 |
var modes = {
|
|
12263 |
multiply: function() {
|
|
12264 |
dr = br * sr / 255; |
|
12265 |
dg = bg * sg / 255; |
|
12266 |
db = bb * sb / 255; |
|
12267 |
}, |
|
12268 |
||
12269 |
screen: function() {
|
|
12270 |
dr = br + sr - (br * sr / 255); |
|
12271 |
dg = bg + sg - (bg * sg / 255); |
|
12272 |
db = bb + sb - (bb * sb / 255); |
|
12273 |
}, |
|
12274 |
||
12275 |
overlay: function() {
|
|
12276 |
dr = br < 128 ? 2 * br * sr / 255 : 255 - 2 * (255 - br) * (255 - sr) / 255; |
|
12277 |
dg = bg < 128 ? 2 * bg * sg / 255 : 255 - 2 * (255 - bg) * (255 - sg) / 255; |
|
12278 |
db = bb < 128 ? 2 * bb * sb / 255 : 255 - 2 * (255 - bb) * (255 - sb) / 255; |
|
12279 |
}, |
|
12280 |
||
12281 |
'soft-light': function() {
|
|
12282 |
var t = sr * br / 255; |
|
12283 |
dr = t + br * (255 - (255 - br) * (255 - sr) / 255 - t) / 255; |
|
12284 |
t = sg * bg / 255; |
|
12285 |
dg = t + bg * (255 - (255 - bg) * (255 - sg) / 255 - t) / 255; |
|
12286 |
t = sb * bb / 255; |
|
12287 |
db = t + bb * (255 - (255 - bb) * (255 - sb) / 255 - t) / 255; |
|
12288 |
}, |
|
12289 |
||
12290 |
'hard-light': function() {
|
|
12291 |
dr = sr < 128 ? 2 * sr * br / 255 : 255 - 2 * (255 - sr) * (255 - br) / 255; |
|
12292 |
dg = sg < 128 ? 2 * sg * bg / 255 : 255 - 2 * (255 - sg) * (255 - bg) / 255; |
|
12293 |
db = sb < 128 ? 2 * sb * bb / 255 : 255 - 2 * (255 - sb) * (255 - bb) / 255; |
|
12294 |
}, |
|
12295 |
||
12296 |
'color-dodge': function() {
|
|
12297 |
dr = br === 0 ? 0 : sr === 255 ? 255 : min(255, 255 * br / (255 - sr)); |
|
12298 |
dg = bg === 0 ? 0 : sg === 255 ? 255 : min(255, 255 * bg / (255 - sg)); |
|
12299 |
db = bb === 0 ? 0 : sb === 255 ? 255 : min(255, 255 * bb / (255 - sb)); |
|
12300 |
}, |
|
12301 |
||
12302 |
'color-burn': function() {
|
|
12303 |
dr = br === 255 ? 255 : sr === 0 ? 0 : max(0, 255 - (255 - br) * 255 / sr); |
|
12304 |
dg = bg === 255 ? 255 : sg === 0 ? 0 : max(0, 255 - (255 - bg) * 255 / sg); |
|
12305 |
db = bb === 255 ? 255 : sb === 0 ? 0 : max(0, 255 - (255 - bb) * 255 / sb); |
|
12306 |
}, |
|
12307 |
||
12308 |
darken: function() {
|
|
12309 |
dr = br < sr ? br : sr; |
|
12310 |
dg = bg < sg ? bg : sg; |
|
12311 |
db = bb < sb ? bb : sb; |
|
12312 |
}, |
|
12313 |
||
12314 |
lighten: function() {
|
|
12315 |
dr = br > sr ? br : sr; |
|
12316 |
dg = bg > sg ? bg : sg; |
|
12317 |
db = bb > sb ? bb : sb; |
|
12318 |
}, |
|
12319 |
||
12320 |
difference: function() {
|
|
12321 |
dr = br - sr; |
|
12322 |
if (dr < 0) |
|
12323 |
dr = -dr; |
|
12324 |
dg = bg - sg; |
|
12325 |
if (dg < 0) |
|
12326 |
dg = -dg; |
|
12327 |
db = bb - sb; |
|
12328 |
if (db < 0) |
|
12329 |
db = -db; |
|
12330 |
}, |
|
12331 |
||
12332 |
exclusion: function() {
|
|
12333 |
dr = br + sr * (255 - br - br) / 255; |
|
12334 |
dg = bg + sg * (255 - bg - bg) / 255; |
|
12335 |
db = bb + sb * (255 - bb - bb) / 255; |
|
12336 |
}, |
|
12337 |
||
12338 |
hue: function() {
|
|
12339 |
setSat(sr, sg, sb, getSat(br, bg, bb)); |
|
12340 |
setLum(dr, dg, db, getLum(br, bg, bb)); |
|
12341 |
}, |
|
12342 |
||
12343 |
saturation: function() {
|
|
12344 |
setSat(br, bg, bb, getSat(sr, sg, sb)); |
|
12345 |
setLum(dr, dg, db, getLum(br, bg, bb)); |
|
12346 |
}, |
|
12347 |
||
12348 |
luminosity: function() {
|
|
12349 |
setLum(br, bg, bb, getLum(sr, sg, sb)); |
|
12350 |
}, |
|
12351 |
||
12352 |
color: function() {
|
|
12353 |
setLum(sr, sg, sb, getLum(br, bg, bb)); |
|
12354 |
}, |
|
12355 |
||
12356 |
add: function() {
|
|
12357 |
dr = min(br + sr, 255); |
|
12358 |
dg = min(bg + sg, 255); |
|
12359 |
db = min(bb + sb, 255); |
|
12360 |
}, |
|
12361 |
||
12362 |
subtract: function() {
|
|
12363 |
dr = max(br - sr, 0); |
|
12364 |
dg = max(bg - sg, 0); |
|
12365 |
db = max(bb - sb, 0); |
|
12366 |
}, |
|
12367 |
||
12368 |
average: function() {
|
|
12369 |
dr = (br + sr) / 2; |
|
12370 |
dg = (bg + sg) / 2; |
|
12371 |
db = (bb + sb) / 2; |
|
12372 |
}, |
|
12373 |
||
12374 |
negation: function() {
|
|
12375 |
dr = 255 - abs(255 - sr - br); |
|
12376 |
dg = 255 - abs(255 - sg - bg); |
|
12377 |
db = 255 - abs(255 - sb - bb); |
|
12378 |
} |
|
12379 |
}; |
|
12380 |
||
12381 |
var nativeModes = this.nativeModes = Base.each([ |
|
12382 |
'source-over', 'source-in', 'source-out', 'source-atop', |
|
12383 |
'destination-over', 'destination-in', 'destination-out', |
|
12384 |
'destination-atop', 'lighter', 'darker', 'copy', 'xor' |
|
12385 |
], function(mode) {
|
|
12386 |
this[mode] = true; |
|
12387 |
}, {});
|
|
12388 |
||
12389 |
var ctx = CanvasProvider.getContext(1, 1); |
|
12390 |
Base.each(modes, function(func, mode) {
|
|
12391 |
var darken = mode === 'darken', |
|
12392 |
ok = false; |
|
12393 |
ctx.save(); |
|
12394 |
try {
|
|
12395 |
ctx.fillStyle = darken ? '#300' : '#a00'; |
|
12396 |
ctx.fillRect(0, 0, 1, 1); |
|
12397 |
ctx.globalCompositeOperation = mode; |
|
12398 |
if (ctx.globalCompositeOperation === mode) {
|
|
12399 |
ctx.fillStyle = darken ? '#a00' : '#300'; |
|
12400 |
ctx.fillRect(0, 0, 1, 1); |
|
12401 |
ok = ctx.getImageData(0, 0, 1, 1).data[0] !== darken ? 170 : 51; |
|
12402 |
} |
|
12403 |
} catch (e) {}
|
|
12404 |
ctx.restore(); |
|
12405 |
nativeModes[mode] = ok; |
|
12406 |
}); |
|
12407 |
CanvasProvider.release(ctx); |
|
12408 |
||
12409 |
this.process = function(mode, srcContext, dstContext, alpha, offset) {
|
|
12410 |
var srcCanvas = srcContext.canvas, |
|
12411 |
normal = mode === 'normal'; |
|
12412 |
if (normal || nativeModes[mode]) {
|
|
12413 |
dstContext.save(); |
|
12414 |
dstContext.setTransform(1, 0, 0, 1, 0, 0); |
|
12415 |
dstContext.globalAlpha = alpha; |
|
12416 |
if (!normal) |
|
12417 |
dstContext.globalCompositeOperation = mode; |
|
12418 |
dstContext.drawImage(srcCanvas, offset.x, offset.y); |
|
12419 |
dstContext.restore(); |
|
12420 |
} else {
|
|
12421 |
var process = modes[mode]; |
|
12422 |
if (!process) |
|
12423 |
return; |
|
12424 |
var dstData = dstContext.getImageData(offset.x, offset.y, |
|
12425 |
srcCanvas.width, srcCanvas.height), |
|
12426 |
dst = dstData.data, |
|
12427 |
src = srcContext.getImageData(0, 0, |
|
12428 |
srcCanvas.width, srcCanvas.height).data; |
|
12429 |
for (var i = 0, l = dst.length; i < l; i += 4) {
|
|
12430 |
sr = src[i]; |
|
12431 |
br = dst[i]; |
|
12432 |
sg = src[i + 1]; |
|
12433 |
bg = dst[i + 1]; |
|
12434 |
sb = src[i + 2]; |
|
12435 |
bb = dst[i + 2]; |
|
12436 |
sa = src[i + 3]; |
|
12437 |
ba = dst[i + 3]; |
|
12438 |
process(); |
|
12439 |
var a1 = sa * alpha / 255, |
|
12440 |
a2 = 1 - a1; |
|
12441 |
dst[i] = a1 * dr + a2 * br; |
|
12442 |
dst[i + 1] = a1 * dg + a2 * bg; |
|
12443 |
dst[i + 2] = a1 * db + a2 * bb; |
|
12444 |
dst[i + 3] = sa * alpha + a2 * ba; |
|
12445 |
} |
|
12446 |
dstContext.putImageData(dstData, offset.x, offset.y); |
|
12447 |
} |
|
12448 |
}; |
|
12449 |
}; |
|
12450 |
||
12451 |
var SVGStyles = Base.each({
|
|
12452 |
fillColor: ['fill', 'color'], |
|
12453 |
strokeColor: ['stroke', 'color'], |
|
12454 |
strokeWidth: ['stroke-width', 'number'], |
|
12455 |
strokeCap: ['stroke-linecap', 'string'], |
|
12456 |
strokeJoin: ['stroke-linejoin', 'string'], |
|
12457 |
strokeScaling: ['vector-effect', 'lookup', {
|
|
12458 |
true: 'none', |
|
12459 |
false: 'non-scaling-stroke' |
|
12460 |
}, function(item, value) {
|
|
12461 |
return !value |
|
12462 |
&& (item instanceof PathItem |
|
12463 |
|| item instanceof Shape |
|
12464 |
|| item instanceof TextItem); |
|
12465 |
}], |
|
12466 |
miterLimit: ['stroke-miterlimit', 'number'], |
|
12467 |
dashArray: ['stroke-dasharray', 'array'], |
|
12468 |
dashOffset: ['stroke-dashoffset', 'number'], |
|
12469 |
fontFamily: ['font-family', 'string'], |
|
12470 |
fontWeight: ['font-weight', 'string'], |
|
12471 |
fontSize: ['font-size', 'number'], |
|
12472 |
justification: ['text-anchor', 'lookup', {
|
|
12473 |
left: 'start', |
|
12474 |
center: 'middle', |
|
12475 |
right: 'end' |
|
12476 |
}], |
|
12477 |
opacity: ['opacity', 'number'], |
|
12478 |
blendMode: ['mix-blend-mode', 'string'] |
|
12479 |
}, function(entry, key) {
|
|
12480 |
var part = Base.capitalize(key), |
|
12481 |
lookup = entry[2]; |
|
12482 |
this[key] = {
|
|
12483 |
type: entry[1], |
|
12484 |
property: key, |
|
12485 |
attribute: entry[0], |
|
12486 |
toSVG: lookup, |
|
12487 |
fromSVG: lookup && Base.each(lookup, function(value, name) {
|
|
12488 |
this[value] = name; |
|
12489 |
}, {}),
|
|
12490 |
exportFilter: entry[3], |
|
12491 |
get: 'get' + part, |
|
12492 |
set: 'set' + part |
|
12493 |
}; |
|
12494 |
}, {});
|
|
12495 |
||
12496 |
var SVGNamespaces = {
|
|
12497 |
href: 'http://www.w3.org/1999/xlink', |
|
12498 |
xlink: 'http://www.w3.org/2000/xmlns' |
|
12499 |
}; |
|
12500 |
||
12501 |
new function() {
|
|
12502 |
var formatter; |
|
12503 |
||
12504 |
function setAttributes(node, attrs) {
|
|
12505 |
for (var key in attrs) {
|
|
12506 |
var val = attrs[key], |
|
12507 |
namespace = SVGNamespaces[key]; |
|
12508 |
if (typeof val === 'number') |
|
12509 |
val = formatter.number(val); |
|
12510 |
if (namespace) {
|
|
12511 |
node.setAttributeNS(namespace, key, val); |
|
12512 |
} else {
|
|
12513 |
node.setAttribute(key, val); |
|
12514 |
} |
|
12515 |
} |
|
12516 |
return node; |
|
12517 |
} |
|
12518 |
||
12519 |
function createElement(tag, attrs) {
|
|
12520 |
return setAttributes( |
|
12521 |
document.createElementNS('http://www.w3.org/2000/svg', tag), attrs);
|
|
12522 |
} |
|
12523 |
||
12524 |
function getTransform(matrix, coordinates, center) {
|
|
12525 |
var attrs = new Base(), |
|
12526 |
trans = matrix.getTranslation(); |
|
12527 |
if (coordinates) {
|
|
12528 |
matrix = matrix.shiftless(); |
|
12529 |
var point = matrix._inverseTransform(trans); |
|
12530 |
attrs[center ? 'cx' : 'x'] = point.x; |
|
12531 |
attrs[center ? 'cy' : 'y'] = point.y; |
|
12532 |
trans = null; |
|
12533 |
} |
|
12534 |
if (!matrix.isIdentity()) {
|
|
12535 |
var decomposed = matrix.decompose(); |
|
12536 |
if (decomposed && !decomposed.shearing) {
|
|
12537 |
var parts = [], |
|
12538 |
angle = decomposed.rotation, |
|
12539 |
scale = decomposed.scaling; |
|
12540 |
if (trans && !trans.isZero()) |
|
12541 |
parts.push('translate(' + formatter.point(trans) + ')');
|
|
12542 |
if (!Numerical.isZero(scale.x - 1) |
|
12543 |
|| !Numerical.isZero(scale.y - 1)) |
|
12544 |
parts.push('scale(' + formatter.point(scale) +')');
|
|
12545 |
if (angle) |
|
12546 |
parts.push('rotate(' + formatter.number(angle) + ')');
|
|
12547 |
attrs.transform = parts.join(' ');
|
|
12548 |
} else {
|
|
12549 |
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
|
|
12550 |
} |
|
12551 |
} |
|
12552 |
return attrs; |
|
12553 |
} |
|
12554 |
||
12555 |
function exportGroup(item, options) {
|
|
12556 |
var attrs = getTransform(item._matrix), |
|
12557 |
children = item._children; |
|
12558 |
var node = createElement('g', attrs);
|
|
12559 |
for (var i = 0, l = children.length; i < l; i++) {
|
|
12560 |
var child = children[i]; |
|
12561 |
var childNode = exportSVG(child, options); |
|
12562 |
if (childNode) {
|
|
12563 |
if (child.isClipMask()) {
|
|
12564 |
var clip = createElement('clipPath');
|
|
12565 |
clip.appendChild(childNode); |
|
12566 |
setDefinition(child, clip, 'clip'); |
|
12567 |
setAttributes(node, {
|
|
12568 |
'clip-path': 'url(#' + clip.id + ')' |
|
12569 |
}); |
|
12570 |
} else {
|
|
12571 |
node.appendChild(childNode); |
|
12572 |
} |
|
12573 |
} |
|
12574 |
} |
|
12575 |
return node; |
|
12576 |
} |
|
12577 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12578 |
function exportRaster(item, options) {
|
| 442 | 12579 |
var attrs = getTransform(item._matrix, true), |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12580 |
size = item.getSize(), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12581 |
image = item.getImage(); |
| 442 | 12582 |
attrs.x -= size.width / 2; |
12583 |
attrs.y -= size.height / 2; |
|
12584 |
attrs.width = size.width; |
|
12585 |
attrs.height = size.height; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12586 |
attrs.href = options.embedImages === false && image && image.src |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12587 |
|| item.toDataURL(); |
| 442 | 12588 |
return createElement('image', attrs);
|
12589 |
} |
|
12590 |
||
12591 |
function exportPath(item, options) {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12592 |
var matchShapes = options.matchShapes; |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12593 |
if (matchShapes) {
|
| 442 | 12594 |
var shape = item.toShape(false); |
12595 |
if (shape) |
|
12596 |
return exportShape(shape, options); |
|
12597 |
} |
|
12598 |
var segments = item._segments, |
|
12599 |
type, |
|
12600 |
attrs = getTransform(item._matrix); |
|
12601 |
if (segments.length === 0) |
|
12602 |
return null; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12603 |
if (matchShapes && !item.hasHandles()) {
|
| 442 | 12604 |
if (segments.length >= 3) {
|
12605 |
type = item._closed ? 'polygon' : 'polyline'; |
|
12606 |
var parts = []; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12607 |
for(var i = 0, l = segments.length; i < l; i++) |
| 442 | 12608 |
parts.push(formatter.point(segments[i]._point)); |
12609 |
attrs.points = parts.join(' ');
|
|
12610 |
} else {
|
|
12611 |
type = 'line'; |
|
12612 |
var first = segments[0]._point, |
|
12613 |
last = segments[segments.length - 1]._point; |
|
12614 |
attrs.set({
|
|
12615 |
x1: first.x, |
|
12616 |
y1: first.y, |
|
12617 |
x2: last.x, |
|
12618 |
y2: last.y |
|
12619 |
}); |
|
12620 |
} |
|
12621 |
} else {
|
|
12622 |
type = 'path'; |
|
12623 |
attrs.d = item.getPathData(null, options.precision); |
|
12624 |
} |
|
12625 |
return createElement(type, attrs); |
|
12626 |
} |
|
12627 |
||
12628 |
function exportShape(item) {
|
|
12629 |
var type = item._type, |
|
12630 |
radius = item._radius, |
|
12631 |
attrs = getTransform(item._matrix, true, type !== 'rectangle'); |
|
12632 |
if (type === 'rectangle') {
|
|
12633 |
type = 'rect'; |
|
12634 |
var size = item._size, |
|
12635 |
width = size.width, |
|
12636 |
height = size.height; |
|
12637 |
attrs.x -= width / 2; |
|
12638 |
attrs.y -= height / 2; |
|
12639 |
attrs.width = width; |
|
12640 |
attrs.height = height; |
|
12641 |
if (radius.isZero()) |
|
12642 |
radius = null; |
|
12643 |
} |
|
12644 |
if (radius) {
|
|
12645 |
if (type === 'circle') {
|
|
12646 |
attrs.r = radius; |
|
12647 |
} else {
|
|
12648 |
attrs.rx = radius.width; |
|
12649 |
attrs.ry = radius.height; |
|
12650 |
} |
|
12651 |
} |
|
12652 |
return createElement(type, attrs); |
|
12653 |
} |
|
12654 |
||
12655 |
function exportCompoundPath(item, options) {
|
|
12656 |
var attrs = getTransform(item._matrix); |
|
12657 |
var data = item.getPathData(null, options.precision); |
|
12658 |
if (data) |
|
12659 |
attrs.d = data; |
|
12660 |
return createElement('path', attrs);
|
|
12661 |
} |
|
12662 |
||
12663 |
function exportPlacedSymbol(item, options) {
|
|
12664 |
var attrs = getTransform(item._matrix, true), |
|
12665 |
symbol = item.getSymbol(), |
|
12666 |
symbolNode = getDefinition(symbol, 'symbol'), |
|
12667 |
definition = symbol.getDefinition(), |
|
12668 |
bounds = definition.getBounds(); |
|
12669 |
if (!symbolNode) {
|
|
12670 |
symbolNode = createElement('symbol', {
|
|
12671 |
viewBox: formatter.rectangle(bounds) |
|
12672 |
}); |
|
12673 |
symbolNode.appendChild(exportSVG(definition, options)); |
|
12674 |
setDefinition(symbol, symbolNode, 'symbol'); |
|
12675 |
} |
|
12676 |
attrs.href = '#' + symbolNode.id; |
|
12677 |
attrs.x += bounds.x; |
|
12678 |
attrs.y += bounds.y; |
|
12679 |
attrs.width = formatter.number(bounds.width); |
|
12680 |
attrs.height = formatter.number(bounds.height); |
|
12681 |
attrs.overflow = 'visible'; |
|
12682 |
return createElement('use', attrs);
|
|
12683 |
} |
|
12684 |
||
12685 |
function exportGradient(color) {
|
|
12686 |
var gradientNode = getDefinition(color, 'color'); |
|
12687 |
if (!gradientNode) {
|
|
12688 |
var gradient = color.getGradient(), |
|
12689 |
radial = gradient._radial, |
|
12690 |
origin = color.getOrigin().transform(), |
|
12691 |
destination = color.getDestination().transform(), |
|
12692 |
attrs; |
|
12693 |
if (radial) {
|
|
12694 |
attrs = {
|
|
12695 |
cx: origin.x, |
|
12696 |
cy: origin.y, |
|
12697 |
r: origin.getDistance(destination) |
|
12698 |
}; |
|
12699 |
var highlight = color.getHighlight(); |
|
12700 |
if (highlight) {
|
|
12701 |
highlight = highlight.transform(); |
|
12702 |
attrs.fx = highlight.x; |
|
12703 |
attrs.fy = highlight.y; |
|
12704 |
} |
|
12705 |
} else {
|
|
12706 |
attrs = {
|
|
12707 |
x1: origin.x, |
|
12708 |
y1: origin.y, |
|
12709 |
x2: destination.x, |
|
12710 |
y2: destination.y |
|
12711 |
}; |
|
12712 |
} |
|
12713 |
attrs.gradientUnits = 'userSpaceOnUse'; |
|
12714 |
gradientNode = createElement( |
|
12715 |
(radial ? 'radial' : 'linear') + 'Gradient', attrs); |
|
12716 |
var stops = gradient._stops; |
|
12717 |
for (var i = 0, l = stops.length; i < l; i++) {
|
|
12718 |
var stop = stops[i], |
|
12719 |
stopColor = stop._color, |
|
12720 |
alpha = stopColor.getAlpha(); |
|
12721 |
attrs = {
|
|
12722 |
offset: stop._rampPoint, |
|
12723 |
'stop-color': stopColor.toCSS(true) |
|
12724 |
}; |
|
12725 |
if (alpha < 1) |
|
12726 |
attrs['stop-opacity'] = alpha; |
|
12727 |
gradientNode.appendChild(createElement('stop', attrs));
|
|
12728 |
} |
|
12729 |
setDefinition(color, gradientNode, 'color'); |
|
12730 |
} |
|
12731 |
return 'url(#' + gradientNode.id + ')'; |
|
12732 |
} |
|
12733 |
||
12734 |
function exportText(item) {
|
|
12735 |
var node = createElement('text', getTransform(item._matrix, true));
|
|
12736 |
node.textContent = item._content; |
|
12737 |
return node; |
|
12738 |
} |
|
12739 |
||
12740 |
var exporters = {
|
|
12741 |
Group: exportGroup, |
|
12742 |
Layer: exportGroup, |
|
12743 |
Raster: exportRaster, |
|
12744 |
Path: exportPath, |
|
12745 |
Shape: exportShape, |
|
12746 |
CompoundPath: exportCompoundPath, |
|
12747 |
PlacedSymbol: exportPlacedSymbol, |
|
12748 |
PointText: exportText |
|
12749 |
}; |
|
12750 |
||
12751 |
function applyStyle(item, node, isRoot) {
|
|
12752 |
var attrs = {},
|
|
12753 |
parent = !isRoot && item.getParent(); |
|
12754 |
||
12755 |
if (item._name != null) |
|
12756 |
attrs.id = item._name; |
|
12757 |
||
12758 |
Base.each(SVGStyles, function(entry) {
|
|
12759 |
var get = entry.get, |
|
12760 |
type = entry.type, |
|
12761 |
value = item[get](); |
|
12762 |
if (entry.exportFilter |
|
12763 |
? entry.exportFilter(item, value) |
|
12764 |
: !parent || !Base.equals(parent[get](), value)) {
|
|
12765 |
if (type === 'color' && value != null) {
|
|
12766 |
var alpha = value.getAlpha(); |
|
12767 |
if (alpha < 1) |
|
12768 |
attrs[entry.attribute + '-opacity'] = alpha; |
|
12769 |
} |
|
12770 |
attrs[entry.attribute] = value == null |
|
12771 |
? 'none' |
|
12772 |
: type === 'number' |
|
12773 |
? formatter.number(value) |
|
12774 |
: type === 'color' |
|
12775 |
? value.gradient |
|
12776 |
? exportGradient(value, item) |
|
12777 |
: value.toCSS(true) |
|
12778 |
: type === 'array' |
|
12779 |
? value.join(',')
|
|
12780 |
: type === 'lookup' |
|
12781 |
? entry.toSVG[value] |
|
12782 |
: value; |
|
12783 |
} |
|
12784 |
}); |
|
12785 |
||
12786 |
if (attrs.opacity === 1) |
|
12787 |
delete attrs.opacity; |
|
12788 |
||
12789 |
if (!item._visible) |
|
12790 |
attrs.visibility = 'hidden'; |
|
12791 |
||
12792 |
return setAttributes(node, attrs); |
|
12793 |
} |
|
12794 |
||
12795 |
var definitions; |
|
12796 |
function getDefinition(item, type) {
|
|
12797 |
if (!definitions) |
|
12798 |
definitions = { ids: {}, svgs: {} };
|
|
12799 |
return item && definitions.svgs[type + '-' + item._id]; |
|
12800 |
} |
|
12801 |
||
12802 |
function setDefinition(item, node, type) {
|
|
12803 |
if (!definitions) |
|
12804 |
getDefinition(); |
|
12805 |
var id = definitions.ids[type] = (definitions.ids[type] || 0) + 1; |
|
12806 |
node.id = type + '-' + id; |
|
12807 |
definitions.svgs[type + '-' + item._id] = node; |
|
12808 |
} |
|
12809 |
||
12810 |
function exportDefinitions(node, options) {
|
|
12811 |
var svg = node, |
|
12812 |
defs = null; |
|
12813 |
if (definitions) {
|
|
12814 |
svg = node.nodeName.toLowerCase() === 'svg' && node; |
|
12815 |
for (var i in definitions.svgs) {
|
|
12816 |
if (!defs) {
|
|
12817 |
if (!svg) {
|
|
12818 |
svg = createElement('svg');
|
|
12819 |
svg.appendChild(node); |
|
12820 |
} |
|
12821 |
defs = svg.insertBefore(createElement('defs'),
|
|
12822 |
svg.firstChild); |
|
12823 |
} |
|
12824 |
defs.appendChild(definitions.svgs[i]); |
|
12825 |
} |
|
12826 |
definitions = null; |
|
12827 |
} |
|
12828 |
return options.asString |
|
12829 |
? new XMLSerializer().serializeToString(svg) |
|
12830 |
: svg; |
|
12831 |
} |
|
12832 |
||
12833 |
function exportSVG(item, options, isRoot) {
|
|
12834 |
var exporter = exporters[item._class], |
|
12835 |
node = exporter && exporter(item, options); |
|
12836 |
if (node) {
|
|
12837 |
var onExport = options.onExport; |
|
12838 |
if (onExport) |
|
12839 |
node = onExport(item, node, options) || node; |
|
12840 |
var data = JSON.stringify(item._data); |
|
12841 |
if (data && data !== '{}' && data !== 'null')
|
|
12842 |
node.setAttribute('data-paper-data', data);
|
|
12843 |
} |
|
12844 |
return node && applyStyle(item, node, isRoot); |
|
12845 |
} |
|
12846 |
||
12847 |
function setOptions(options) {
|
|
12848 |
if (!options) |
|
12849 |
options = {};
|
|
12850 |
formatter = new Formatter(options.precision); |
|
12851 |
return options; |
|
12852 |
} |
|
12853 |
||
12854 |
Item.inject({
|
|
12855 |
exportSVG: function(options) {
|
|
12856 |
options = setOptions(options); |
|
12857 |
return exportDefinitions(exportSVG(this, options, true), options); |
|
12858 |
} |
|
12859 |
}); |
|
12860 |
||
12861 |
Project.inject({
|
|
12862 |
exportSVG: function(options) {
|
|
12863 |
options = setOptions(options); |
|
12864 |
var layers = this.layers, |
|
12865 |
view = this.getView(), |
|
12866 |
size = view.getViewSize(), |
|
12867 |
node = createElement('svg', {
|
|
12868 |
x: 0, |
|
12869 |
y: 0, |
|
12870 |
width: size.width, |
|
12871 |
height: size.height, |
|
12872 |
version: '1.1', |
|
12873 |
xmlns: 'http://www.w3.org/2000/svg', |
|
12874 |
'xmlns:xlink': 'http://www.w3.org/1999/xlink' |
|
12875 |
}), |
|
12876 |
parent = node, |
|
12877 |
matrix = view._matrix; |
|
12878 |
if (!matrix.isIdentity()) |
|
12879 |
parent = node.appendChild( |
|
12880 |
createElement('g', getTransform(matrix)));
|
|
12881 |
for (var i = 0, l = layers.length; i < l; i++) |
|
12882 |
parent.appendChild(exportSVG(layers[i], options, true)); |
|
12883 |
return exportDefinitions(node, options); |
|
12884 |
} |
|
12885 |
}); |
|
12886 |
}; |
|
12887 |
||
12888 |
new function() {
|
|
12889 |
||
12890 |
function getValue(node, name, isString, allowNull) {
|
|
12891 |
var namespace = SVGNamespaces[name], |
|
12892 |
value = namespace |
|
12893 |
? node.getAttributeNS(namespace, name) |
|
12894 |
: node.getAttribute(name); |
|
12895 |
if (value === 'null') |
|
12896 |
value = null; |
|
12897 |
return value == null |
|
12898 |
? allowNull |
|
12899 |
? null |
|
12900 |
: isString |
|
12901 |
? '' |
|
12902 |
: 0 |
|
12903 |
: isString |
|
12904 |
? value |
|
12905 |
: parseFloat(value); |
|
12906 |
} |
|
12907 |
||
12908 |
function getPoint(node, x, y, allowNull) {
|
|
12909 |
x = getValue(node, x, false, allowNull); |
|
12910 |
y = getValue(node, y, false, allowNull); |
|
12911 |
return allowNull && (x == null || y == null) ? null |
|
12912 |
: new Point(x, y); |
|
12913 |
} |
|
12914 |
||
12915 |
function getSize(node, w, h, allowNull) {
|
|
12916 |
w = getValue(node, w, false, allowNull); |
|
12917 |
h = getValue(node, h, false, allowNull); |
|
12918 |
return allowNull && (w == null || h == null) ? null |
|
12919 |
: new Size(w, h); |
|
12920 |
} |
|
12921 |
||
12922 |
function convertValue(value, type, lookup) {
|
|
12923 |
return value === 'none' |
|
12924 |
? null |
|
12925 |
: type === 'number' |
|
12926 |
? parseFloat(value) |
|
12927 |
: type === 'array' |
|
12928 |
? value ? value.split(/[\s,]+/g).map(parseFloat) : [] |
|
12929 |
: type === 'color' |
|
12930 |
? getDefinition(value) || value |
|
12931 |
: type === 'lookup' |
|
12932 |
? lookup[value] |
|
12933 |
: value; |
|
12934 |
} |
|
12935 |
||
12936 |
function importGroup(node, type, options, isRoot) {
|
|
12937 |
var nodes = node.childNodes, |
|
12938 |
isClip = type === 'clippath', |
|
12939 |
item = new Group(), |
|
12940 |
project = item._project, |
|
12941 |
currentStyle = project._currentStyle, |
|
12942 |
children = []; |
|
12943 |
if (!isClip) {
|
|
12944 |
item = applyAttributes(item, node, isRoot); |
|
12945 |
project._currentStyle = item._style.clone(); |
|
12946 |
} |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12947 |
if (isRoot) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12948 |
var defs = node.querySelectorAll('defs');
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12949 |
for (var i = 0, l = defs.length; i < l; i++) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12950 |
importSVG(defs[i], options, false); |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12951 |
} |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12952 |
} |
| 442 | 12953 |
for (var i = 0, l = nodes.length; i < l; i++) {
|
12954 |
var childNode = nodes[i], |
|
12955 |
child; |
|
12956 |
if (childNode.nodeType === 1 |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
12957 |
&& childNode.nodeName.toLowerCase() !== 'defs' |
| 442 | 12958 |
&& (child = importSVG(childNode, options, false)) |
12959 |
&& !(child instanceof Symbol)) |
|
12960 |
children.push(child); |
|
12961 |
} |
|
12962 |
item.addChildren(children); |
|
12963 |
if (isClip) |
|
12964 |
item = applyAttributes(item.reduce(), node, isRoot); |
|
12965 |
project._currentStyle = currentStyle; |
|
12966 |
if (isClip || type === 'defs') {
|
|
12967 |
item.remove(); |
|
12968 |
item = null; |
|
12969 |
} |
|
12970 |
return item; |
|
12971 |
} |
|
12972 |
||
12973 |
function importPoly(node, type) {
|
|
12974 |
var coords = node.getAttribute('points').match(
|
|
12975 |
/[+-]?(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g), |
|
12976 |
points = []; |
|
12977 |
for (var i = 0, l = coords.length; i < l; i += 2) |
|
12978 |
points.push(new Point( |
|
12979 |
parseFloat(coords[i]), |
|
12980 |
parseFloat(coords[i + 1]))); |
|
12981 |
var path = new Path(points); |
|
12982 |
if (type === 'polygon') |
|
12983 |
path.closePath(); |
|
12984 |
return path; |
|
12985 |
} |
|
12986 |
||
12987 |
function importPath(node) {
|
|
12988 |
var data = node.getAttribute('d'),
|
|
12989 |
param = { pathData: data };
|
|
12990 |
return (data.match(/m/gi) || []).length > 1 || /z\S+/i.test(data) |
|
12991 |
? new CompoundPath(param) |
|
12992 |
: new Path(param); |
|
12993 |
} |
|
12994 |
||
12995 |
function importGradient(node, type) {
|
|
12996 |
var id = (getValue(node, 'href', true) || '').substring(1), |
|
12997 |
isRadial = type === 'radialgradient', |
|
12998 |
gradient; |
|
12999 |
if (id) {
|
|
13000 |
gradient = definitions[id].getGradient(); |
|
13001 |
} else {
|
|
13002 |
var nodes = node.childNodes, |
|
13003 |
stops = []; |
|
13004 |
for (var i = 0, l = nodes.length; i < l; i++) {
|
|
13005 |
var child = nodes[i]; |
|
13006 |
if (child.nodeType === 1) |
|
13007 |
stops.push(applyAttributes(new GradientStop(), child)); |
|
13008 |
} |
|
13009 |
gradient = new Gradient(stops, isRadial); |
|
13010 |
} |
|
13011 |
var origin, destination, highlight; |
|
13012 |
if (isRadial) {
|
|
13013 |
origin = getPoint(node, 'cx', 'cy'); |
|
13014 |
destination = origin.add(getValue(node, 'r'), 0); |
|
13015 |
highlight = getPoint(node, 'fx', 'fy', true); |
|
13016 |
} else {
|
|
13017 |
origin = getPoint(node, 'x1', 'y1'); |
|
13018 |
destination = getPoint(node, 'x2', 'y2'); |
|
13019 |
} |
|
13020 |
applyAttributes( |
|
13021 |
new Color(gradient, origin, destination, highlight), node); |
|
13022 |
return null; |
|
13023 |
} |
|
13024 |
||
13025 |
var importers = {
|
|
13026 |
'#document': function (node, type, options, isRoot) {
|
|
13027 |
var nodes = node.childNodes; |
|
13028 |
for (var i = 0, l = nodes.length; i < l; i++) {
|
|
13029 |
var child = nodes[i]; |
|
13030 |
if (child.nodeType === 1) {
|
|
13031 |
var next = child.nextSibling; |
|
13032 |
document.body.appendChild(child); |
|
13033 |
var item = importSVG(child, options, isRoot); |
|
13034 |
if (next) {
|
|
13035 |
node.insertBefore(child, next); |
|
13036 |
} else {
|
|
13037 |
node.appendChild(child); |
|
13038 |
} |
|
13039 |
return item; |
|
13040 |
} |
|
13041 |
} |
|
13042 |
}, |
|
13043 |
g: importGroup, |
|
13044 |
svg: importGroup, |
|
13045 |
clippath: importGroup, |
|
13046 |
polygon: importPoly, |
|
13047 |
polyline: importPoly, |
|
13048 |
path: importPath, |
|
13049 |
lineargradient: importGradient, |
|
13050 |
radialgradient: importGradient, |
|
13051 |
||
13052 |
image: function (node) {
|
|
13053 |
var raster = new Raster(getValue(node, 'href', true)); |
|
13054 |
raster.on('load', function() {
|
|
13055 |
var size = getSize(node, 'width', 'height'); |
|
13056 |
this.setSize(size); |
|
13057 |
var center = this._matrix._transformPoint( |
|
13058 |
getPoint(node, 'x', 'y').add(size.divide(2))); |
|
13059 |
this.translate(center); |
|
13060 |
}); |
|
13061 |
return raster; |
|
13062 |
}, |
|
13063 |
||
13064 |
symbol: function(node, type, options, isRoot) {
|
|
13065 |
return new Symbol(importGroup(node, type, options, isRoot), true); |
|
13066 |
}, |
|
13067 |
||
13068 |
defs: importGroup, |
|
13069 |
||
13070 |
use: function(node) {
|
|
13071 |
var id = (getValue(node, 'href', true) || '').substring(1), |
|
13072 |
definition = definitions[id], |
|
13073 |
point = getPoint(node, 'x', 'y'); |
|
13074 |
return definition |
|
13075 |
? definition instanceof Symbol |
|
13076 |
? definition.place(point) |
|
13077 |
: definition.clone().translate(point) |
|
13078 |
: null; |
|
13079 |
}, |
|
13080 |
||
13081 |
circle: function(node) {
|
|
13082 |
return new Shape.Circle(getPoint(node, 'cx', 'cy'), |
|
13083 |
getValue(node, 'r')); |
|
13084 |
}, |
|
13085 |
||
13086 |
ellipse: function(node) {
|
|
13087 |
return new Shape.Ellipse({
|
|
13088 |
center: getPoint(node, 'cx', 'cy'), |
|
13089 |
radius: getSize(node, 'rx', 'ry') |
|
13090 |
}); |
|
13091 |
}, |
|
13092 |
||
13093 |
rect: function(node) {
|
|
13094 |
var point = getPoint(node, 'x', 'y'), |
|
13095 |
size = getSize(node, 'width', 'height'), |
|
13096 |
radius = getSize(node, 'rx', 'ry'); |
|
13097 |
return new Shape.Rectangle(new Rectangle(point, size), radius); |
|
13098 |
}, |
|
13099 |
||
13100 |
line: function(node) {
|
|
13101 |
return new Path.Line(getPoint(node, 'x1', 'y1'), |
|
13102 |
getPoint(node, 'x2', 'y2')); |
|
13103 |
}, |
|
13104 |
||
13105 |
text: function(node) {
|
|
13106 |
var text = new PointText(getPoint(node, 'x', 'y') |
|
13107 |
.add(getPoint(node, 'dx', 'dy'))); |
|
13108 |
text.setContent(node.textContent.trim() || ''); |
|
13109 |
return text; |
|
13110 |
} |
|
13111 |
}; |
|
13112 |
||
13113 |
function applyTransform(item, value, name, node) {
|
|
13114 |
var transforms = (node.getAttribute(name) || '').split(/\)\s*/g), |
|
13115 |
matrix = new Matrix(); |
|
13116 |
for (var i = 0, l = transforms.length; i < l; i++) {
|
|
13117 |
var transform = transforms[i]; |
|
13118 |
if (!transform) |
|
13119 |
break; |
|
13120 |
var parts = transform.split(/\(\s*/), |
|
13121 |
command = parts[0], |
|
13122 |
v = parts[1].split(/[\s,]+/g); |
|
13123 |
for (var j = 0, m = v.length; j < m; j++) |
|
13124 |
v[j] = parseFloat(v[j]); |
|
13125 |
switch (command) {
|
|
13126 |
case 'matrix': |
|
13127 |
matrix.concatenate( |
|
13128 |
new Matrix(v[0], v[1], v[2], v[3], v[4], v[5])); |
|
13129 |
break; |
|
13130 |
case 'rotate': |
|
13131 |
matrix.rotate(v[0], v[1], v[2]); |
|
13132 |
break; |
|
13133 |
case 'translate': |
|
13134 |
matrix.translate(v[0], v[1]); |
|
13135 |
break; |
|
13136 |
case 'scale': |
|
13137 |
matrix.scale(v); |
|
13138 |
break; |
|
13139 |
case 'skewX': |
|
13140 |
matrix.skew(v[0], 0); |
|
13141 |
break; |
|
13142 |
case 'skewY': |
|
13143 |
matrix.skew(0, v[0]); |
|
13144 |
break; |
|
13145 |
} |
|
13146 |
} |
|
13147 |
item.transform(matrix); |
|
13148 |
} |
|
13149 |
||
13150 |
function applyOpacity(item, value, name) {
|
|
13151 |
var color = item[name === 'fill-opacity' ? 'getFillColor' |
|
13152 |
: 'getStrokeColor'](); |
|
13153 |
if (color) |
|
13154 |
color.setAlpha(parseFloat(value)); |
|
13155 |
} |
|
13156 |
||
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13157 |
var attributes = Base.set(Base.each(SVGStyles, function(entry) {
|
| 442 | 13158 |
this[entry.attribute] = function(item, value) {
|
13159 |
item[entry.set](convertValue(value, entry.type, entry.fromSVG)); |
|
13160 |
if (entry.type === 'color' && item instanceof Shape) {
|
|
13161 |
var color = item[entry.get](); |
|
13162 |
if (color) |
|
13163 |
color.transform(new Matrix().translate( |
|
13164 |
item.getPosition(true).negate())); |
|
13165 |
} |
|
13166 |
}; |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13167 |
}, {}), {
|
| 442 | 13168 |
id: function(item, value) {
|
13169 |
definitions[value] = item; |
|
13170 |
if (item.setName) |
|
13171 |
item.setName(value); |
|
13172 |
}, |
|
13173 |
||
13174 |
'clip-path': function(item, value) {
|
|
13175 |
var clip = getDefinition(value); |
|
13176 |
if (clip) {
|
|
13177 |
clip = clip.clone(); |
|
13178 |
clip.setClipMask(true); |
|
13179 |
if (item instanceof Group) {
|
|
13180 |
item.insertChild(0, clip); |
|
13181 |
} else {
|
|
13182 |
return new Group(clip, item); |
|
13183 |
} |
|
13184 |
} |
|
13185 |
}, |
|
13186 |
||
13187 |
gradientTransform: applyTransform, |
|
13188 |
transform: applyTransform, |
|
13189 |
||
13190 |
'fill-opacity': applyOpacity, |
|
13191 |
'stroke-opacity': applyOpacity, |
|
13192 |
||
13193 |
visibility: function(item, value) {
|
|
13194 |
item.setVisible(value === 'visible'); |
|
13195 |
}, |
|
13196 |
||
13197 |
display: function(item, value) {
|
|
13198 |
item.setVisible(value !== null); |
|
13199 |
}, |
|
13200 |
||
13201 |
'stop-color': function(item, value) {
|
|
13202 |
if (item.setColor) |
|
13203 |
item.setColor(value); |
|
13204 |
}, |
|
13205 |
||
13206 |
'stop-opacity': function(item, value) {
|
|
13207 |
if (item._color) |
|
13208 |
item._color.setAlpha(parseFloat(value)); |
|
13209 |
}, |
|
13210 |
||
13211 |
offset: function(item, value) {
|
|
13212 |
var percentage = value.match(/(.*)%$/); |
|
13213 |
item.setRampPoint(percentage |
|
13214 |
? percentage[1] / 100 |
|
13215 |
: parseFloat(value)); |
|
13216 |
}, |
|
13217 |
||
13218 |
viewBox: function(item, value, name, node, styles) {
|
|
13219 |
var rect = new Rectangle(convertValue(value, 'array')), |
|
13220 |
size = getSize(node, 'width', 'height', true); |
|
13221 |
if (item instanceof Group) {
|
|
13222 |
var scale = size ? rect.getSize().divide(size) : 1, |
|
13223 |
matrix = new Matrix().translate(rect.getPoint()).scale(scale); |
|
13224 |
item.transform(matrix.inverted()); |
|
13225 |
} else if (item instanceof Symbol) {
|
|
13226 |
if (size) |
|
13227 |
rect.setSize(size); |
|
13228 |
var clip = getAttribute(node, 'overflow', styles) != 'visible', |
|
13229 |
group = item._definition; |
|
13230 |
if (clip && !rect.contains(group.getBounds())) {
|
|
13231 |
clip = new Shape.Rectangle(rect).transform(group._matrix); |
|
13232 |
clip.setClipMask(true); |
|
13233 |
group.addChild(clip); |
|
13234 |
} |
|
13235 |
} |
|
13236 |
} |
|
13237 |
}); |
|
13238 |
||
13239 |
function getAttribute(node, name, styles) {
|
|
13240 |
var attr = node.attributes[name], |
|
13241 |
value = attr && attr.value; |
|
13242 |
if (!value) {
|
|
13243 |
var style = Base.camelize(name); |
|
13244 |
value = node.style[style]; |
|
13245 |
if (!value && styles.node[style] !== styles.parent[style]) |
|
13246 |
value = styles.node[style]; |
|
13247 |
} |
|
13248 |
return !value |
|
13249 |
? undefined |
|
13250 |
: value === 'none' |
|
13251 |
? null |
|
13252 |
: value; |
|
13253 |
} |
|
13254 |
||
13255 |
function applyAttributes(item, node, isRoot) {
|
|
13256 |
var styles = {
|
|
13257 |
node: DomElement.getStyles(node) || {},
|
|
13258 |
parent: !isRoot && DomElement.getStyles(node.parentNode) || {}
|
|
13259 |
}; |
|
13260 |
Base.each(attributes, function(apply, name) {
|
|
13261 |
var value = getAttribute(node, name, styles); |
|
13262 |
if (value !== undefined) |
|
13263 |
item = Base.pick(apply(item, value, name, node, styles), item); |
|
13264 |
}); |
|
13265 |
return item; |
|
13266 |
} |
|
13267 |
||
13268 |
var definitions = {};
|
|
13269 |
function getDefinition(value) {
|
|
13270 |
var match = value && value.match(/\((?:#|)([^)']+)/); |
|
13271 |
return match && definitions[match[1]]; |
|
13272 |
} |
|
13273 |
||
13274 |
function importSVG(source, options, isRoot) {
|
|
13275 |
if (!source) |
|
13276 |
return null; |
|
13277 |
if (!options) {
|
|
13278 |
options = {};
|
|
13279 |
} else if (typeof options === 'function') {
|
|
13280 |
options = { onLoad: options };
|
|
13281 |
} |
|
13282 |
||
13283 |
var node = source, |
|
13284 |
scope = paper; |
|
13285 |
||
13286 |
function onLoadCallback(svg) {
|
|
13287 |
paper = scope; |
|
13288 |
var item = importSVG(svg, options, isRoot), |
|
13289 |
onLoad = options.onLoad, |
|
13290 |
view = scope.project && scope.getView(); |
|
13291 |
if (onLoad) |
|
13292 |
onLoad.call(this, item); |
|
13293 |
view.update(); |
|
13294 |
} |
|
13295 |
||
13296 |
if (isRoot) {
|
|
13297 |
if (typeof source === 'string' && !/^.*</.test(source)) {
|
|
13298 |
node = document.getElementById(source); |
|
13299 |
if (node) {
|
|
13300 |
source = null; |
|
13301 |
} else {
|
|
13302 |
return Http.request('get', source, onLoadCallback);
|
|
13303 |
} |
|
13304 |
} else if (typeof File !== 'undefined' && source instanceof File) {
|
|
13305 |
var reader = new FileReader(); |
|
13306 |
reader.onload = function() {
|
|
13307 |
onLoadCallback(reader.result); |
|
13308 |
}; |
|
13309 |
return reader.readAsText(source); |
|
13310 |
} |
|
13311 |
} |
|
13312 |
||
13313 |
if (typeof source === 'string') |
|
13314 |
node = new DOMParser().parseFromString(source, 'image/svg+xml'); |
|
13315 |
if (!node.nodeName) |
|
13316 |
throw new Error('Unsupported SVG source: ' + source);
|
|
13317 |
var type = node.nodeName.toLowerCase(), |
|
13318 |
importer = importers[type], |
|
13319 |
item, |
|
13320 |
data = node.getAttribute && node.getAttribute('data-paper-data'),
|
|
13321 |
settings = scope.settings, |
|
13322 |
applyMatrix = settings.applyMatrix; |
|
13323 |
settings.applyMatrix = false; |
|
13324 |
item = importer && importer(node, type, options, isRoot) || null; |
|
13325 |
settings.applyMatrix = applyMatrix; |
|
13326 |
if (item) {
|
|
13327 |
if (type !== '#document' && !(item instanceof Group)) |
|
13328 |
item = applyAttributes(item, node, isRoot); |
|
13329 |
var onImport = options.onImport; |
|
13330 |
if (onImport) |
|
13331 |
item = onImport(node, item, options) || item; |
|
13332 |
if (options.expandShapes && item instanceof Shape) {
|
|
13333 |
item.remove(); |
|
13334 |
item = item.toPath(); |
|
13335 |
} |
|
13336 |
if (data) |
|
13337 |
item._data = JSON.parse(data); |
|
13338 |
} |
|
13339 |
if (isRoot) {
|
|
13340 |
definitions = {};
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13341 |
if (item && Base.pick(options.applyMatrix, applyMatrix)) |
| 442 | 13342 |
item.matrix.apply(true, true); |
13343 |
} |
|
13344 |
return item; |
|
13345 |
} |
|
13346 |
||
13347 |
Item.inject({
|
|
13348 |
importSVG: function(node, options) {
|
|
13349 |
return this.addChild(importSVG(node, options, true)); |
|
13350 |
} |
|
13351 |
}); |
|
13352 |
||
13353 |
Project.inject({
|
|
13354 |
importSVG: function(node, options) {
|
|
13355 |
this.activate(); |
|
13356 |
return importSVG(node, options, true); |
|
13357 |
} |
|
13358 |
}); |
|
13359 |
}; |
|
13360 |
||
13361 |
Base.exports.PaperScript = (function() {
|
|
13362 |
var exports, define, |
|
13363 |
scope = this; |
|
13364 |
!function(e,r){return"object"==typeof exports&&"object"==typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):(r(e.acorn||(e.acorn={})),void 0)}(this,function(e){"use strict";function r(e){fr=e||{};for(var r in mr)Object.prototype.hasOwnProperty.call(fr,r)||(fr[r]=mr[r]);hr=fr.sourceFile||null}function t(e,r){var t=vr(dr,e);r+=" ("+t.line+":"+t.column+")";var n=new SyntaxError(r);throw n.pos=e,n.loc=t,n.raisedAt=br,n}function n(e){function r(e){if(1==e.length)return t+="return str === "+JSON.stringify(e[0])+";";t+="switch(str){";for(var r=0;r<e.length;++r)t+="case "+JSON.stringify(e[r])+":";t+="return true}return false;"}e=e.split(" ");var t="",n=[];e:for(var a=0;a<e.length;++a){for(var o=0;o<n.length;++o)if(n[o][0].length==e[a].length){n[o].push(e[a]);continue e}n.push([e[a]])}if(n.length>3){n.sort(function(e,r){return r.length-e.length}),t+="switch(str.length){";for(var a=0;a<n.length;++a){var i=n[a];t+="case "+i[0].length+":",r(i)}t+="}"}else r(e);return new Function("str",t)}function a(){this.line=Ar,this.column=br-Sr}function o(){Ar=1,br=Sr=0,Er=!0,u()}function i(e,r){gr=br,fr.locations&&(kr=new a),wr=e,u(),Cr=r,Er=e.beforeExpr}function s(){var e=fr.onComment&&fr.locations&&new a,r=br,n=dr.indexOf("*/",br+=2);if(-1===n&&t(br-2,"Unterminated comment"),br=n+2,fr.locations){Kt.lastIndex=r;for(var o;(o=Kt.exec(dr))&&o.index<br;)++Ar,Sr=o.index+o[0].length}fr.onComment&&fr.onComment(!0,dr.slice(r+2,n),r,br,e,fr.locations&&new a)}function c(){for(var e=br,r=fr.onComment&&fr.locations&&new a,t=dr.charCodeAt(br+=2);pr>br&&10!==t&&13!==t&&8232!==t&&8233!==t;)++br,t=dr.charCodeAt(br);fr.onComment&&fr.onComment(!1,dr.slice(e+2,br),e,br,r,fr.locations&&new a)}function u(){for(;pr>br;){var e=dr.charCodeAt(br);if(32===e)++br;else if(13===e){++br;var r=dr.charCodeAt(br);10===r&&++br,fr.locations&&(++Ar,Sr=br)}else if(10===e||8232===e||8233===e)++br,fr.locations&&(++Ar,Sr=br);else if(e>8&&14>e)++br;else if(47===e){var r=dr.charCodeAt(br+1);if(42===r)s();else{if(47!==r)break;c()}}else if(160===e)++br;else{if(!(e>=5760&&Jt.test(String.fromCharCode(e))))break;++br}}}function l(){var e=dr.charCodeAt(br+1);return e>=48&&57>=e?E(!0):(++br,i(xt))}function f(){var e=dr.charCodeAt(br+1);return Er?(++br,k()):61===e?x(Et,2):x(wt,1)}function d(){var e=dr.charCodeAt(br+1);return 61===e?x(Et,2):x(Dt,1)}function p(e){var r=dr.charCodeAt(br+1);return r===e?x(124===e?Lt:Ut,2):61===r?x(Et,2):x(124===e?Rt:Tt,1)}function h(){var e=dr.charCodeAt(br+1);return 61===e?x(Et,2):x(Vt,1)}function m(e){var r=dr.charCodeAt(br+1);return r===e?45==r&&62==dr.charCodeAt(br+2)&&Gt.test(dr.slice(Lr,br))?(br+=3,c(),u(),g()):x(St,2):61===r?x(Et,2):x(At,1)}function v(e){var r=dr.charCodeAt(br+1),t=1;return r===e?(t=62===e&&62===dr.charCodeAt(br+2)?3:2,61===dr.charCodeAt(br+t)?x(Et,t+1):x(jt,t)):33==r&&60==e&&45==dr.charCodeAt(br+2)&&45==dr.charCodeAt(br+3)?(br+=4,c(),u(),g()):(61===r&&(t=61===dr.charCodeAt(br+2)?3:2),x(Ot,t))}function b(e){var r=dr.charCodeAt(br+1);return 61===r?x(qt,61===dr.charCodeAt(br+2)?3:2):x(61===e?Ct:It,1)}function y(e){switch(e){case 46:return l();case 40:return++br,i(mt);case 41:return++br,i(vt);case 59:return++br,i(yt);case 44:return++br,i(bt);case 91:return++br,i(ft);case 93:return++br,i(dt);case 123:return++br,i(pt);case 125:return++br,i(ht);case 58:return++br,i(gt);case 63:return++br,i(kt);case 48:var r=dr.charCodeAt(br+1);if(120===r||88===r)return C();case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return E(!1);case 34:case 39:return A(e);case 47:return f(e);case 37:case 42:return d();case 124:case 38:return p(e);case 94:return h();case 43:case 45:return m(e);case 60:case 62:return v(e);case 61:case 33:return b(e);case 126:return x(It,1)}return!1}function g(e){if(e?br=yr+1:yr=br,fr.locations&&(xr=new a),e)return k();if(br>=pr)return i(Br);var r=dr.charCodeAt(br);if(Qt(r)||92===r)return L();var n=y(r);if(n===!1){var o=String.fromCharCode(r);if("\\"===o||$t.test(o))return L();t(br,"Unexpected character '"+o+"'")}return n}function x(e,r){var t=dr.slice(br,br+r);br+=r,i(e,t)}function k(){for(var e,r,n="",a=br;;){br>=pr&&t(a,"Unterminated regular expression");var o=dr.charAt(br);if(Gt.test(o)&&t(a,"Unterminated regular expression"),e)e=!1;else{if("["===o)r=!0;else if("]"===o&&r)r=!1;else if("/"===o&&!r)break;e="\\"===o}++br}var n=dr.slice(a,br);++br;var s=I();return s&&!/^[gmsiy]*$/.test(s)&&t(a,"Invalid regexp flag"),i(jr,new RegExp(n,s))}function w(e,r){for(var t=br,n=0,a=0,o=null==r?1/0:r;o>a;++a){var i,s=dr.charCodeAt(br);if(i=s>=97?s-97+10:s>=65?s-65+10:s>=48&&57>=s?s-48:1/0,i>=e)break;++br,n=n*e+i}return br===t||null!=r&&br-t!==r?null:n}function C(){br+=2;var e=w(16);return null==e&&t(yr+2,"Expected hexadecimal number"),Qt(dr.charCodeAt(br))&&t(br,"Identifier directly after number"),i(Or,e)}function E(e){var r=br,n=!1,a=48===dr.charCodeAt(br);e||null!==w(10)||t(r,"Invalid number"),46===dr.charCodeAt(br)&&(++br,w(10),n=!0);var o=dr.charCodeAt(br);(69===o||101===o)&&(o=dr.charCodeAt(++br),(43===o||45===o)&&++br,null===w(10)&&t(r,"Invalid number"),n=!0),Qt(dr.charCodeAt(br))&&t(br,"Identifier directly after number");var s,c=dr.slice(r,br);return n?s=parseFloat(c):a&&1!==c.length?/[89]/.test(c)||Tr?t(r,"Invalid number"):s=parseInt(c,8):s=parseInt(c,10),i(Or,s)}function A(e){br++;for(var r="";;){br>=pr&&t(yr,"Unterminated string constant");var n=dr.charCodeAt(br);if(n===e)return++br,i(Dr,r);if(92===n){n=dr.charCodeAt(++br);var a=/^[0-7]+/.exec(dr.slice(br,br+3));for(a&&(a=a[0]);a&&parseInt(a,8)>255;)a=a.slice(0,a.length-1);if("0"===a&&(a=null),++br,a)Tr&&t(br-2,"Octal literal in strict mode"),r+=String.fromCharCode(parseInt(a,8)),br+=a.length-1;else switch(n){case 110:r+="\n";break;case 114:r+="\r";break;case 120:r+=String.fromCharCode(S(2));break;case 117:r+=String.fromCharCode(S(4));break;case 85:r+=String.fromCharCode(S(8));break;case 116:r+=" ";break;case 98:r+="\b";break;case 118:r+="";break;case 102:r+="\f";break;case 48:r+="\0";break;case 13:10===dr.charCodeAt(br)&&++br;case 10:fr.locations&&(Sr=br,++Ar);break;default:r+=String.fromCharCode(n)}}else(13===n||10===n||8232===n||8233===n)&&t(yr,"Unterminated string constant"),r+=String.fromCharCode(n),++br}}function S(e){var r=w(16,e);return null===r&&t(yr,"Bad character escape sequence"),r}function I(){Bt=!1;for(var e,r=!0,n=br;;){var a=dr.charCodeAt(br);if(Yt(a))Bt&&(e+=dr.charAt(br)),++br;else{if(92!==a)break;Bt||(e=dr.slice(n,br)),Bt=!0,117!=dr.charCodeAt(++br)&&t(br,"Expecting Unicode escape sequence \\uXXXX"),++br;var o=S(4),i=String.fromCharCode(o);i||t(br-1,"Invalid Unicode escape"),(r?Qt(o):Yt(o))||t(br-4,"Invalid Unicode escape"),e+=i}r=!1}return Bt?e:dr.slice(n,br)}function L(){var e=I(),r=Fr;return Bt||(Wt(e)?r=lt[e]:(fr.forbidReserved&&(3===fr.ecmaVersion?Mt:zt)(e)||Tr&&Xt(e))&&t(yr,"The keyword '"+e+"' is reserved")),i(r,e)}function U(){Ir=yr,Lr=gr,Ur=kr,g()}function R(e){if(Tr=e,br=Lr,fr.locations)for(;Sr>br;)Sr=dr.lastIndexOf("\n",Sr-2)+1,--Ar;u(),g()}function V(){this.type=null,this.start=yr,this.end=null}function T(){this.start=xr,this.end=null,null!==hr&&(this.source=hr)}function q(){var e=new V;return fr.locations&&(e.loc=new T),fr.ranges&&(e.range=[yr,0]),e}function O(e){var r=new V;return r.start=e.start,fr.locations&&(r.loc=new T,r.loc.start=e.loc.start),fr.ranges&&(r.range=[e.range[0],0]),r}function j(e,r){return e.type=r,e.end=Lr,fr.locations&&(e.loc.end=Ur),fr.ranges&&(e.range[1]=Lr),e}function D(e){return fr.ecmaVersion>=5&&"ExpressionStatement"===e.type&&"Literal"===e.expression.type&&"use strict"===e.expression.value}function F(e){return wr===e?(U(),!0):void 0}function B(){return!fr.strictSemicolons&&(wr===Br||wr===ht||Gt.test(dr.slice(Lr,yr)))}function M(){F(yt)||B()||X()}function z(e){wr===e?U():X()}function X(){t(yr,"Unexpected token")}function N(e){"Identifier"!==e.type&&"MemberExpression"!==e.type&&t(e.start,"Assigning to rvalue"),Tr&&"Identifier"===e.type&&Nt(e.name)&&t(e.start,"Assigning to "+e.name+" in strict mode")}function W(e){Ir=Lr=br,fr.locations&&(Ur=new a),Rr=Tr=null,Vr=[],g();var r=e||q(),t=!0;for(e||(r.body=[]);wr!==Br;){var n=J();r.body.push(n),t&&D(n)&&R(!0),t=!1}return j(r,"Program")}function J(){(wr===wt||wr===Et&&"/="==Cr)&&g(!0);var e=wr,r=q();switch(e){case Mr:case Nr:U();var n=e===Mr;F(yt)||B()?r.label=null:wr!==Fr?X():(r.label=lr(),M());for(var a=0;a<Vr.length;++a){var o=Vr[a];if(null==r.label||o.name===r.label.name){if(null!=o.kind&&(n||"loop"===o.kind))break;if(r.label&&n)break}}return a===Vr.length&&t(r.start,"Unsyntactic "+e.keyword),j(r,n?"BreakStatement":"ContinueStatement");case Wr:return U(),M(),j(r,"DebuggerStatement");case Pr:return U(),Vr.push(Zt),r.body=J(),Vr.pop(),z(tt),r.test=P(),M(),j(r,"DoWhileStatement");case _r:if(U(),Vr.push(Zt),z(mt),wr===yt)return $(r,null);if(wr===rt){var i=q();return U(),G(i,!0),j(i,"VariableDeclaration"),1===i.declarations.length&&F(ut)?_(r,i):$(r,i)}var i=K(!1,!0);return F(ut)?(N(i),_(r,i)):$(r,i);case Gr:return U(),cr(r,!0);case Kr:return U(),r.test=P(),r.consequent=J(),r.alternate=F(Hr)?J():null,j(r,"IfStatement");case Qr:return Rr||t(yr,"'return' outside of function"),U(),F(yt)||B()?r.argument=null:(r.argument=K(),M()),j(r,"ReturnStatement");case Yr:U(),r.discriminant=P(),r.cases=[],z(pt),Vr.push(en);for(var s,c;wr!=ht;)if(wr===zr||wr===Jr){var u=wr===zr;s&&j(s,"SwitchCase"),r.cases.push(s=q()),s.consequent=[],U(),u?s.test=K():(c&&t(Ir,"Multiple default clauses"),c=!0,s.test=null),z(gt)}else s||X(),s.consequent.push(J());return s&&j(s,"SwitchCase"),U(),Vr.pop(),j(r,"SwitchStatement");case Zr:return U(),Gt.test(dr.slice(Lr,yr))&&t(Lr,"Illegal newline after throw"),r.argument=K(),M(),j(r,"ThrowStatement");case et:if(U(),r.block=H(),r.handler=null,wr===Xr){var l=q();U(),z(mt),l.param=lr(),Tr&&Nt(l.param.name)&&t(l.param.start,"Binding "+l.param.name+" in strict mode"),z(vt),l.guard=null,l.body=H(),r.handler=j(l,"CatchClause")}return r.guardedHandlers=qr,r.finalizer=F($r)?H():null,r.handler||r.finalizer||t(r.start,"Missing catch or finally clause"),j(r,"TryStatement");case rt:return U(),G(r),M(),j(r,"VariableDeclaration");case tt:return U(),r.test=P(),Vr.push(Zt),r.body=J(),Vr.pop(),j(r,"WhileStatement");case nt:return Tr&&t(yr,"'with' in strict mode"),U(),r.object=P(),r.body=J(),j(r,"WithStatement");case pt:return H();case yt:return U(),j(r,"EmptyStatement");default:var f=Cr,d=K();if(e===Fr&&"Identifier"===d.type&&F(gt)){for(var a=0;a<Vr.length;++a)Vr[a].name===f&&t(d.start,"Label '"+f+"' is already declared");var p=wr.isLoop?"loop":wr===Yr?"switch":null;return Vr.push({name:f,kind:p}),r.body=J(),Vr.pop(),r.label=d,j(r,"LabeledStatement")}return r.expression=d,M(),j(r,"ExpressionStatement")}}function P(){z(mt);var e=K();return z(vt),e}function H(e){var r,t=q(),n=!0,a=!1;for(t.body=[],z(pt);!F(ht);){var o=J();t.body.push(o),n&&e&&D(o)&&(r=a,R(a=!0)),n=!1}return a&&!r&&R(!1),j(t,"BlockStatement")}function $(e,r){return e.init=r,z(yt),e.test=wr===yt?null:K(),z(yt),e.update=wr===vt?null:K(),z(vt),e.body=J(),Vr.pop(),j(e,"ForStatement")}function _(e,r){return e.left=r,e.right=K(),z(vt),e.body=J(),Vr.pop(),j(e,"ForInStatement")}function G(e,r){for(e.declarations=[],e.kind="var";;){var n=q();if(n.id=lr(),Tr&&Nt(n.id.name)&&t(n.id.start,"Binding "+n.id.name+" in strict mode"),n.init=F(Ct)?K(!0,r):null,e.declarations.push(j(n,"VariableDeclarator")),!F(bt))break}return e}function K(e,r){var t=Q(r);if(!e&&wr===bt){var n=O(t);for(n.expressions=[t];F(bt);)n.expressions.push(Q(r));return j(n,"SequenceExpression")}return t}function Q(e){var r=Y(e);if(wr.isAssign){var t=O(r);return t.operator=Cr,t.left=r,U(),t.right=Q(e),N(r),j(t,"AssignmentExpression")}return r}function Y(e){var r=Z(e);if(F(kt)){var t=O(r);return t.test=r,t.consequent=K(!0),z(gt),t.alternate=K(!0,e),j(t,"ConditionalExpression")}return r}function Z(e){return er(rr(),-1,e)}function er(e,r,t){var n=wr.binop;if(null!=n&&(!t||wr!==ut)&&n>r){var a=O(e);a.left=e,a.operator=Cr,U(),a.right=er(rr(),n,t);var o=j(a,/&&|\|\|/.test(a.operator)?"LogicalExpression":"BinaryExpression");return er(o,r,t)}return e}function rr(){if(wr.prefix){var e=q(),r=wr.isUpdate;return e.operator=Cr,e.prefix=!0,Er=!0,U(),e.argument=rr(),r?N(e.argument):Tr&&"delete"===e.operator&&"Identifier"===e.argument.type&&t(e.start,"Deleting local variable in strict mode"),j(e,r?"UpdateExpression":"UnaryExpression")}for(var n=tr();wr.postfix&&!B();){var e=O(n);e.operator=Cr,e.prefix=!1,e.argument=n,N(n),U(),n=j(e,"UpdateExpression")}return n}function tr(){return nr(ar())}function nr(e,r){if(F(xt)){var t=O(e);return t.object=e,t.property=lr(!0),t.computed=!1,nr(j(t,"MemberExpression"),r)}if(F(ft)){var t=O(e);return t.object=e,t.property=K(),t.computed=!0,z(dt),nr(j(t,"MemberExpression"),r)}if(!r&&F(mt)){var t=O(e);return t.callee=e,t.arguments=ur(vt,!1),nr(j(t,"CallExpression"),r)}return e}function ar(){switch(wr){case ot:var e=q();return U(),j(e,"ThisExpression");case Fr:return lr();case Or:case Dr:case jr:var e=q();return e.value=Cr,e.raw=dr.slice(yr,gr),U(),j(e,"Literal");case it:case st:case ct:var e=q();return e.value=wr.atomValue,e.raw=wr.keyword,U(),j(e,"Literal");case mt:var r=xr,t=yr;U();var n=K();return n.start=t,n.end=gr,fr.locations&&(n.loc.start=r,n.loc.end=kr),fr.ranges&&(n.range=[t,gr]),z(vt),n;case ft:var e=q();return U(),e.elements=ur(dt,!0,!0),j(e,"ArrayExpression");case pt:return ir();case Gr:var e=q();return U(),cr(e,!1);case at:return or();default:X()}}function or(){var e=q();return U(),e.callee=nr(ar(),!0),e.arguments=F(mt)?ur(vt,!1):qr,j(e,"NewExpression")}function ir(){var e=q(),r=!0,n=!1;for(e.properties=[],U();!F(ht);){if(r)r=!1;else if(z(bt),fr.allowTrailingCommas&&F(ht))break;var a,o={key:sr()},i=!1;if(F(gt)?(o.value=K(!0),a=o.kind="init"):fr.ecmaVersion>=5&&"Identifier"===o.key.type&&("get"===o.key.name||"set"===o.key.name)?(i=n=!0,a=o.kind=o.key.name,o.key=sr(),wr!==mt&&X(),o.value=cr(q(),!1)):X(),"Identifier"===o.key.type&&(Tr||n))for(var s=0;s<e.properties.length;++s){var c=e.properties[s];if(c.key.name===o.key.name){var u=a==c.kind||i&&"init"===c.kind||"init"===a&&("get"===c.kind||"set"===c.kind);u&&!Tr&&"init"===a&&"init"===c.kind&&(u=!1),u&&t(o.key.start,"Redefinition of property")}}e.properties.push(o)}return j(e,"ObjectExpression")}function sr(){return wr===Or||wr===Dr?ar():lr(!0)}function cr(e,r){wr===Fr?e.id=lr():r?X():e.id=null,e.params=[];var n=!0;for(z(mt);!F(vt);)n?n=!1:z(bt),e.params.push(lr());var a=Rr,o=Vr;if(Rr=!0,Vr=[],e.body=H(!0),Rr=a,Vr=o,Tr||e.body.body.length&&D(e.body.body[0]))for(var i=e.id?-1:0;i<e.params.length;++i){var s=0>i?e.id:e.params[i];if((Xt(s.name)||Nt(s.name))&&t(s.start,"Defining '"+s.name+"' in strict mode"),i>=0)for(var c=0;i>c;++c)s.name===e.params[c].name&&t(s.start,"Argument name clash in strict mode")}return j(e,r?"FunctionDeclaration":"FunctionExpression")}function ur(e,r,t){for(var n=[],a=!0;!F(e);){if(a)a=!1;else if(z(bt),r&&fr.allowTrailingCommas&&F(e))break;t&&wr===bt?n.push(null):n.push(K(!0))}return n}function lr(e){var r=q();return r.name=wr===Fr?Cr:e&&!fr.forbidReserved&&wr.keyword||X(),Er=!1,U(),j(r,"Identifier")}e.version="0.4.0";var fr,dr,pr,hr;e.parse=function(e,t){return dr=String(e),pr=dr.length,r(t),o(),W(fr.program)};var mr=e.defaultOptions={ecmaVersion:5,strictSemicolons:!1,allowTrailingCommas:!0,forbidReserved:!1,locations:!1,onComment:null,ranges:!1,program:null,sourceFile:null},vr=e.getLineInfo=function(e,r){for(var t=1,n=0;;){Kt.lastIndex=n;var a=Kt.exec(e);if(!(a&&a.index<r))break;++t,n=a.index+a[0].length}return{line:t,column:r-n}};e.tokenize=function(e,t){function n(e){return g(e),a.start=yr,a.end=gr,a.startLoc=xr,a.endLoc=kr,a.type=wr,a.value=Cr,a}dr=String(e),pr=dr.length,r(t),o();var a={};return n.jumpTo=function(e,r){if(br=e,fr.locations){Ar=1,Sr=Kt.lastIndex=0;for(var t;(t=Kt.exec(dr))&&t.index<e;)++Ar,Sr=t.index+t[0].length}Er=r,u()},n};var br,yr,gr,xr,kr,wr,Cr,Er,Ar,Sr,Ir,Lr,Ur,Rr,Vr,Tr,qr=[],Or={type:"num"},jr={type:"regexp"},Dr={type:"string"},Fr={type:"name"},Br={type:"eof"},Mr={keyword:"break"},zr={keyword:"case",beforeExpr:!0},Xr={keyword:"catch"},Nr={keyword:"continue"},Wr={keyword:"debugger"},Jr={keyword:"default"},Pr={keyword:"do",isLoop:!0},Hr={keyword:"else",beforeExpr:!0},$r={keyword:"finally"},_r={keyword:"for",isLoop:!0},Gr={keyword:"function"},Kr={keyword:"if"},Qr={keyword:"return",beforeExpr:!0},Yr={keyword:"switch"},Zr={keyword:"throw",beforeExpr:!0},et={keyword:"try"},rt={keyword:"var"},tt={keyword:"while",isLoop:!0},nt={keyword:"with"},at={keyword:"new",beforeExpr:!0},ot={keyword:"this"},it={keyword:"null",atomValue:null},st={keyword:"true",atomValue:!0},ct={keyword:"false",atomValue:!1},ut={keyword:"in",binop:7,beforeExpr:!0},lt={"break":Mr,"case":zr,"catch":Xr,"continue":Nr,"debugger":Wr,"default":Jr,"do":Pr,"else":Hr,"finally":$r,"for":_r,"function":Gr,"if":Kr,"return":Qr,"switch":Yr,"throw":Zr,"try":et,"var":rt,"while":tt,"with":nt,"null":it,"true":st,"false":ct,"new":at,"in":ut,"instanceof":{keyword:"instanceof",binop:7,beforeExpr:!0},"this":ot,"typeof":{keyword:"typeof",prefix:!0,beforeExpr:!0},"void":{keyword:"void",prefix:!0,beforeExpr:!0},"delete":{keyword:"delete",prefix:!0,beforeExpr:!0}},ft={type:"[",beforeExpr:!0},dt={type:"]"},pt={type:"{",beforeExpr:!0},ht={type:"}"},mt={type:"(",beforeExpr:!0},vt={type:")"},bt={type:",",beforeExpr:!0},yt={type:";",beforeExpr:!0},gt={type:":",beforeExpr:!0},xt={type:"."},kt={type:"?",beforeExpr:!0},wt={binop:10,beforeExpr:!0},Ct={isAssign:!0,beforeExpr:!0},Et={isAssign:!0,beforeExpr:!0},At={binop:9,prefix:!0,beforeExpr:!0},St={postfix:!0,prefix:!0,isUpdate:!0},It={prefix:!0,beforeExpr:!0},Lt={binop:1,beforeExpr:!0},Ut={binop:2,beforeExpr:!0},Rt={binop:3,beforeExpr:!0},Vt={binop:4,beforeExpr:!0},Tt={binop:5,beforeExpr:!0},qt={binop:6,beforeExpr:!0},Ot={binop:7,beforeExpr:!0},jt={binop:8,beforeExpr:!0},Dt={binop:10,beforeExpr:!0};e.tokTypes={bracketL:ft,bracketR:dt,braceL:pt,braceR:ht,parenL:mt,parenR:vt,comma:bt,semi:yt,colon:gt,dot:xt,question:kt,slash:wt,eq:Ct,name:Fr,eof:Br,num:Or,regexp:jr,string:Dr};for(var Ft in lt)e.tokTypes["_"+Ft]=lt[Ft];var Bt,Mt=n("abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile"),zt=n("class enum extends super const export import"),Xt=n("implements interface let package private protected public static yield"),Nt=n("eval arguments"),Wt=n("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this"),Jt=/[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/,Pt="\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc",Ht="\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\ua980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f",$t=new RegExp("["+Pt+"]"),_t=new RegExp("["+Pt+Ht+"]"),Gt=/[\n\r\u2028\u2029]/,Kt=/\r\n|[\n\r\u2028\u2029]/g,Qt=e.isIdentifierStart=function(e){return 65>e?36===e:91>e?!0:97>e?95===e:123>e?!0:e>=170&&$t.test(String.fromCharCode(e))},Yt=e.isIdentifierChar=function(e){return 48>e?36===e:58>e?!0:65>e?!1:91>e?!0:97>e?95===e:123>e?!0:e>=170&&_t.test(String.fromCharCode(e))},Zt={kind:"loop"},en={kind:"switch"}});
|
|
13365 |
||
13366 |
var binaryOperators = {
|
|
13367 |
'+': '__add', |
|
13368 |
'-': '__subtract', |
|
13369 |
'*': '__multiply', |
|
13370 |
'/': '__divide', |
|
13371 |
'%': '__modulo', |
|
13372 |
'==': 'equals', |
|
13373 |
'!=': 'equals' |
|
13374 |
}; |
|
13375 |
||
13376 |
var unaryOperators = {
|
|
13377 |
'-': '__negate', |
|
13378 |
'+': null |
|
13379 |
}; |
|
13380 |
||
13381 |
var fields = Base.each( |
|
13382 |
['add', 'subtract', 'multiply', 'divide', 'modulo', 'negate'], |
|
13383 |
function(name) {
|
|
13384 |
this['__' + name] = '#' + name; |
|
13385 |
}, |
|
13386 |
{}
|
|
13387 |
); |
|
13388 |
Point.inject(fields); |
|
13389 |
Size.inject(fields); |
|
13390 |
Color.inject(fields); |
|
13391 |
||
13392 |
function __$__(left, operator, right) {
|
|
13393 |
var handler = binaryOperators[operator]; |
|
13394 |
if (left && left[handler]) {
|
|
13395 |
var res = left[handler](right); |
|
13396 |
return operator === '!=' ? !res : res; |
|
13397 |
} |
|
13398 |
switch (operator) {
|
|
13399 |
case '+': return left + right; |
|
13400 |
case '-': return left - right; |
|
13401 |
case '*': return left * right; |
|
13402 |
case '/': return left / right; |
|
13403 |
case '%': return left % right; |
|
13404 |
case '==': return left == right; |
|
13405 |
case '!=': return left != right; |
|
13406 |
} |
|
13407 |
} |
|
13408 |
||
13409 |
function $__(operator, value) {
|
|
13410 |
var handler = unaryOperators[operator]; |
|
13411 |
if (handler && value && value[handler]) |
|
13412 |
return value[handler](); |
|
13413 |
switch (operator) {
|
|
13414 |
case '+': return +value; |
|
13415 |
case '-': return -value; |
|
13416 |
} |
|
13417 |
} |
|
13418 |
||
13419 |
function parse(code, options) {
|
|
13420 |
return scope.acorn.parse(code, options); |
|
13421 |
} |
|
13422 |
||
13423 |
function compile(code, url, options) {
|
|
13424 |
if (!code) |
|
13425 |
return ''; |
|
13426 |
options = options || {};
|
|
13427 |
url = url || ''; |
|
13428 |
||
13429 |
var insertions = []; |
|
13430 |
||
13431 |
function getOffset(offset) {
|
|
13432 |
for (var i = 0, l = insertions.length; i < l; i++) {
|
|
13433 |
var insertion = insertions[i]; |
|
13434 |
if (insertion[0] >= offset) |
|
13435 |
break; |
|
13436 |
offset += insertion[1]; |
|
13437 |
} |
|
13438 |
return offset; |
|
13439 |
} |
|
13440 |
||
13441 |
function getCode(node) {
|
|
13442 |
return code.substring(getOffset(node.range[0]), |
|
13443 |
getOffset(node.range[1])); |
|
13444 |
} |
|
13445 |
||
13446 |
function getBetween(left, right) {
|
|
13447 |
return code.substring(getOffset(left.range[1]), |
|
13448 |
getOffset(right.range[0])); |
|
13449 |
} |
|
13450 |
||
13451 |
function replaceCode(node, str) {
|
|
13452 |
var start = getOffset(node.range[0]), |
|
13453 |
end = getOffset(node.range[1]), |
|
13454 |
insert = 0; |
|
13455 |
for (var i = insertions.length - 1; i >= 0; i--) {
|
|
13456 |
if (start > insertions[i][0]) {
|
|
13457 |
insert = i + 1; |
|
13458 |
break; |
|
13459 |
} |
|
13460 |
} |
|
13461 |
insertions.splice(insert, 0, [start, str.length - end + start]); |
|
13462 |
code = code.substring(0, start) + str + code.substring(end); |
|
13463 |
} |
|
13464 |
||
13465 |
function walkAST(node, parent) {
|
|
13466 |
if (!node) |
|
13467 |
return; |
|
13468 |
for (var key in node) {
|
|
13469 |
if (key === 'range' || key === 'loc') |
|
13470 |
continue; |
|
13471 |
var value = node[key]; |
|
13472 |
if (Array.isArray(value)) {
|
|
13473 |
for (var i = 0, l = value.length; i < l; i++) |
|
13474 |
walkAST(value[i], node); |
|
13475 |
} else if (value && typeof value === 'object') {
|
|
13476 |
walkAST(value, node); |
|
13477 |
} |
|
13478 |
} |
|
13479 |
switch (node.type) {
|
|
13480 |
case 'UnaryExpression': |
|
13481 |
if (node.operator in unaryOperators |
|
13482 |
&& node.argument.type !== 'Literal') {
|
|
13483 |
var arg = getCode(node.argument); |
|
13484 |
replaceCode(node, '$__("' + node.operator + '", '
|
|
13485 |
+ arg + ')'); |
|
13486 |
} |
|
13487 |
break; |
|
13488 |
case 'BinaryExpression': |
|
13489 |
if (node.operator in binaryOperators |
|
13490 |
&& node.left.type !== 'Literal') {
|
|
13491 |
var left = getCode(node.left), |
|
13492 |
right = getCode(node.right), |
|
13493 |
between = getBetween(node.left, node.right), |
|
13494 |
operator = node.operator; |
|
13495 |
replaceCode(node, '__$__(' + left + ','
|
|
13496 |
+ between.replace(new RegExp('\\' + operator),
|
|
13497 |
'"' + operator + '"') |
|
13498 |
+ ', ' + right + ')'); |
|
13499 |
} |
|
13500 |
break; |
|
13501 |
case 'UpdateExpression': |
|
13502 |
case 'AssignmentExpression': |
|
13503 |
var parentType = parent && parent.type; |
|
13504 |
if (!( |
|
13505 |
parentType === 'ForStatement' |
|
13506 |
|| parentType === 'BinaryExpression' |
|
13507 |
&& /^[=!<>]/.test(parent.operator) |
|
13508 |
|| parentType === 'MemberExpression' && parent.computed |
|
13509 |
)) {
|
|
13510 |
if (node.type === 'UpdateExpression') {
|
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13511 |
var arg = getCode(node.argument), |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13512 |
exp = '__$__(' + arg + ', "' + node.operator[0]
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13513 |
+ '", 1)', |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13514 |
str = arg + ' = ' + exp; |
| 442 | 13515 |
if (!node.prefix |
13516 |
&& (parentType === 'AssignmentExpression' |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13517 |
|| parentType === 'VariableDeclarator')) {
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13518 |
if (getCode(parent.left || parent.id) === arg) |
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13519 |
str = exp; |
| 442 | 13520 |
str = arg + '; ' + str; |
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13521 |
} |
| 442 | 13522 |
replaceCode(node, str); |
13523 |
} else {
|
|
13524 |
if (/^.=$/.test(node.operator) |
|
13525 |
&& node.left.type !== 'Literal') {
|
|
13526 |
var left = getCode(node.left), |
|
13527 |
right = getCode(node.right); |
|
13528 |
replaceCode(node, left + ' = __$__(' + left + ', "'
|
|
13529 |
+ node.operator[0] + '", ' + right + ')'); |
|
13530 |
} |
|
13531 |
} |
|
13532 |
} |
|
13533 |
break; |
|
13534 |
} |
|
13535 |
} |
|
13536 |
var sourceMap = null, |
|
13537 |
browser = paper.browser, |
|
13538 |
version = browser.versionNumber, |
|
13539 |
lineBreaks = /\r\n|\n|\r/mg; |
|
13540 |
if (browser.chrome && version >= 30 |
|
13541 |
|| browser.webkit && version >= 537.76 |
|
13542 |
|| browser.firefox && version >= 23) {
|
|
13543 |
var offset = 0; |
|
13544 |
if (window.location.href.indexOf(url) === 0) {
|
|
13545 |
var html = document.getElementsByTagName('html')[0].innerHTML;
|
|
13546 |
offset = html.substr(0, html.indexOf(code) + 1).match( |
|
13547 |
lineBreaks).length + 1; |
|
13548 |
} |
|
13549 |
var mappings = ['AAAA']; |
|
13550 |
mappings.length = (code.match(lineBreaks) || []).length + 1 + offset; |
|
13551 |
sourceMap = {
|
|
13552 |
version: 3, |
|
13553 |
file: url, |
|
13554 |
names:[], |
|
13555 |
mappings: mappings.join(';AACA'),
|
|
13556 |
sourceRoot: '', |
|
13557 |
sources: [url] |
|
13558 |
}; |
|
13559 |
var source = options.source || !url && code; |
|
13560 |
if (source) |
|
13561 |
sourceMap.sourcesContent = [source]; |
|
13562 |
} |
|
13563 |
walkAST(parse(code, { ranges: true }));
|
|
13564 |
if (sourceMap) {
|
|
13565 |
code = new Array(offset + 1).join('\n') + code
|
|
13566 |
+ "\n//# sourceMappingURL=data:application/json;base64," |
|
13567 |
+ (btoa(unescape(encodeURIComponent( |
|
13568 |
JSON.stringify(sourceMap))))) |
|
13569 |
+ "\n//# sourceURL=" + (url || 'paperscript'); |
|
13570 |
} |
|
13571 |
return code; |
|
13572 |
} |
|
13573 |
||
13574 |
function execute(code, scope, url, options) {
|
|
13575 |
paper = scope; |
|
13576 |
var view = scope.getView(), |
|
13577 |
tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/.test(code) |
|
13578 |
? new Tool() |
|
13579 |
: null, |
|
13580 |
toolHandlers = tool ? tool._events : [], |
|
13581 |
handlers = ['onFrame', 'onResize'].concat(toolHandlers), |
|
13582 |
params = [], |
|
13583 |
args = [], |
|
13584 |
func; |
|
13585 |
code = compile(code, url, options); |
|
13586 |
function expose(scope, hidden) {
|
|
13587 |
for (var key in scope) {
|
|
13588 |
if ((hidden || !/^_/.test(key)) && new RegExp('([\\b\\s\\W]|^)'
|
|
13589 |
+ key.replace(/\$/g, '\\$') + '\\b').test(code)) {
|
|
13590 |
params.push(key); |
|
13591 |
args.push(scope[key]); |
|
13592 |
} |
|
13593 |
} |
|
13594 |
} |
|
13595 |
expose({ __$__: __$__, $__: $__, paper: scope, view: view, tool: tool },
|
|
13596 |
true); |
|
13597 |
expose(scope); |
|
13598 |
handlers = Base.each(handlers, function(key) {
|
|
13599 |
if (new RegExp('\\s+' + key + '\\b').test(code)) {
|
|
13600 |
params.push(key); |
|
13601 |
this.push(key + ': ' + key); |
|
13602 |
} |
|
13603 |
}, []).join(', ');
|
|
13604 |
if (handlers) |
|
13605 |
code += '\nreturn { ' + handlers + ' };';
|
|
13606 |
var browser = paper.browser; |
|
13607 |
if (browser.chrome || browser.firefox) {
|
|
13608 |
var script = document.createElement('script'),
|
|
13609 |
head = document.head || document.getElementsByTagName('head')[0];
|
|
13610 |
if (browser.firefox) |
|
13611 |
code = '\n' + code; |
|
13612 |
script.appendChild(document.createTextNode( |
|
13613 |
'paper._execute = function(' + params + ') {' + code + '\n}'
|
|
13614 |
)); |
|
13615 |
head.appendChild(script); |
|
13616 |
func = paper._execute; |
|
13617 |
delete paper._execute; |
|
13618 |
head.removeChild(script); |
|
13619 |
} else {
|
|
13620 |
func = Function(params, code); |
|
13621 |
} |
|
13622 |
var res = func.apply(scope, args) || {};
|
|
13623 |
Base.each(toolHandlers, function(key) {
|
|
13624 |
var value = res[key]; |
|
13625 |
if (value) |
|
13626 |
tool[key] = value; |
|
13627 |
}); |
|
13628 |
if (view) {
|
|
13629 |
if (res.onResize) |
|
13630 |
view.setOnResize(res.onResize); |
|
13631 |
view.emit('resize', {
|
|
13632 |
size: view.size, |
|
13633 |
delta: new Point() |
|
13634 |
}); |
|
13635 |
if (res.onFrame) |
|
13636 |
view.setOnFrame(res.onFrame); |
|
13637 |
view.update(); |
|
13638 |
} |
|
13639 |
} |
|
13640 |
||
13641 |
function loadScript(script) {
|
|
13642 |
if (/^text\/(?:x-|)paperscript$/.test(script.type) |
|
13643 |
&& PaperScope.getAttribute(script, 'ignore') !== 'true') {
|
|
13644 |
var canvasId = PaperScope.getAttribute(script, 'canvas'), |
|
13645 |
canvas = document.getElementById(canvasId), |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13646 |
src = script.src || script.getAttribute('data-src'),
|
|
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13647 |
async = PaperScope.hasAttribute(script, 'async'), |
| 442 | 13648 |
scopeAttribute = 'data-paper-scope'; |
13649 |
if (!canvas) |
|
13650 |
throw new Error('Unable to find canvas with id "'
|
|
13651 |
+ canvasId + '"'); |
|
13652 |
var scope = PaperScope.get(canvas.getAttribute(scopeAttribute)) |
|
13653 |
|| new PaperScope().setup(canvas); |
|
13654 |
canvas.setAttribute(scopeAttribute, scope._id); |
|
13655 |
if (src) {
|
|
13656 |
Http.request('get', src, function(code) {
|
|
13657 |
execute(code, scope, src); |
|
|
495
444b80998255
update client version + small correction in dojoConfig to load ckeditor jquery adapter
ymh <ymh.work@gmail.com>
parents:
442
diff
changeset
|
13658 |
}, async); |
| 442 | 13659 |
} else {
|
13660 |
execute(script.innerHTML, scope, script.baseURI); |
|
13661 |
} |
|
13662 |
script.setAttribute('data-paper-ignore', 'true');
|
|
13663 |
return scope; |
|
13664 |
} |
|
13665 |
} |
|
13666 |
||
13667 |
function loadAll() {
|
|
13668 |
Base.each(document.getElementsByTagName('script'), loadScript);
|
|
13669 |
} |
|
13670 |
||
13671 |
function load(script) {
|
|
13672 |
return script ? loadScript(script) : loadAll(); |
|
13673 |
} |
|
13674 |
||
13675 |
if (document.readyState === 'complete') {
|
|
13676 |
setTimeout(loadAll); |
|
13677 |
} else {
|
|
13678 |
DomEvent.add(window, { load: loadAll });
|
|
13679 |
} |
|
13680 |
||
13681 |
return {
|
|
13682 |
compile: compile, |
|
13683 |
execute: execute, |
|
13684 |
load: load, |
|
13685 |
parse: parse |
|
13686 |
}; |
|
13687 |
||
13688 |
}).call(this); |
|
13689 |
||
13690 |
paper = new (PaperScope.inject(Base.exports, {
|
|
13691 |
enumerable: true, |
|
13692 |
Base: Base, |
|
13693 |
Numerical: Numerical, |
|
13694 |
Key: Key |
|
13695 |
}))(); |
|
13696 |
||
13697 |
if (typeof define === 'function' && define.amd) {
|
|
13698 |
define('paper', paper);
|
|
13699 |
} else if (typeof module === 'object' && module) {
|
|
13700 |
module.exports = paper; |
|
13701 |
} |
|
13702 |
||
13703 |
return paper; |
|
13704 |
}; |