Comparing version 1.6.3 to 1.6.4
@@ -238,2 +238,3 @@ var fs = require('fs'), | ||
ifSpecifiedInclude('image_filters', 'src/filters/resize_filter.class.js'), | ||
ifSpecifiedInclude('image_filters', 'src/filters/colormatrix_filter.class.js'), | ||
@@ -240,0 +241,0 @@ ifSpecifiedInclude('text', 'src/shapes/text.class.js'), |
@@ -0,1 +1,26 @@ | ||
**Version 1.6.4** | ||
- Improvement: Ignore svg: namespace during svg import. [#3081](https://github.com/kangax/fabric.js/pull/3081) | ||
- Improvement: Better fix for lineHeight of iText/Text [#3094](https://github.com/kangax/fabric.js/pull/3094) | ||
- Improvement: Support for gradient with 'Infinity' coordinates [#3082](https://github.com/kangax/fabric.js/pull/3082) | ||
- Improvement: Generally "improved" logic of targeting [#3111](https://github.com/kangax/fabric.js/pull/3111) | ||
- Fix: Selection of active group with transparency and preserveObjectStacking true or false [#3109](https://github.com/kangax/fabric.js/pull/3109) | ||
- Fix: pattern brush now create the same pattern seen while drawing [#3112](https://github.com/kangax/fabric.js/pull/3112) | ||
- Fix: Allow css merge during svg import [#3114](https://github.com/kangax/fabric.js/pull/3114) | ||
- Improvement: added numeric origins handling fomr 0 to 1. [#3121](https://github.com/kangax/fabric.js/pull/3121) | ||
- Fix: Fix a defect with shadow of objects in a scaled group. [#3134](https://github.com/kangax/fabric.js/pull/3134) | ||
- Improvement: Do not fire unecessary selection:changed events. [#3119](https://github.com/kangax/fabric.js/pull/3119) | ||
- Fix: Attached hiddenTextarea to body fixes IE, thanks to @plainview. [#3137](https://github.com/kangax/fabric.js/pull/3137) | ||
- Fix: Shift unselect activegroup on transformed canvas. [#3144](https://github.com/kangax/fabric.js/pull/3144) | ||
- Added: ColorMatrix filter [#3139](https://github.com/kangax/fabric.js/pull/3139) | ||
- Fix: Fix condition in wich restoring from Object could cause object overwriting [#3146](https://github.com/kangax/fabric.js/pull/3146) | ||
- Change: cloneAsImage for Object and toDataUrl for object are not retina enabled by default. Added option to enable. [#3147](https://github.com/kangax/fabric.js/pull/3147) | ||
- Improvement: Added textSpacing support for text/itext/textbox [#3097](https://github.com/kangax/fabric.js/pull/3097) | ||
- Fix: Quote font family when setting the context fontstyle [#3191](https://github.com/kangax/fabric.js/pull/3191) | ||
- Fix: use getSrc during image export, make subclassing easier, return eventually the .src property if nothing else is available [#3189](https://github.com/kangax/fabric.js/pull/3189) | ||
- Fix: Inverted the meaning of border scale factor [#3154](https://github.com/kangax/fabric.js/pull/3154) | ||
- Improvement: Added support for RGBA in HEX notation. [#3202](https://github.com/kangax/fabric.js/pull/3202) | ||
- Improvement: Added object deselected event. [#3195](https://github.com/kangax/fabric.js/pull/3195) | ||
- Fix: loadFromJson callback now gets fired after filter are applied [#3210](https://github.com/kangax/fabric.js/pull/3210) | ||
**Version 1.6.3** | ||
@@ -2,0 +27,0 @@ |
@@ -5,4 +5,10 @@ { | ||
"homepage": "http://fabricjs.com/", | ||
"version": "1.6.3", | ||
"version": "1.6.4", | ||
"author": "Juriy Zaytsev <kangax@gmail.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Andrea Bogazzi", | ||
"email": "andreabogazzi79@gmail.com" | ||
} | ||
], | ||
"keywords": [ | ||
@@ -48,3 +54,3 @@ "canvas", | ||
"devDependencies": { | ||
"uglify-js": "2.6.x", | ||
"uglify-js": "2.7.x", | ||
"jscs": "2.x.x", | ||
@@ -51,0 +57,0 @@ "jshint": "2.9.x", |
@@ -39,3 +39,7 @@ var testrunner = require('qunit'); | ||
'./test/unit/object_origin.js', | ||
'./test/unit/itext.js' | ||
'./test/unit/itext.js', | ||
'./test/unit/itext_key_behaviour.js', | ||
'./test/unit/collection.js', | ||
'./test/unit/point.js', | ||
'./test/unit/intersection.js', | ||
] | ||
@@ -42,0 +46,0 @@ }, function(err, report) { |
@@ -78,3 +78,3 @@ (function() { | ||
'opacity': 1, | ||
'src': fabric.isLikelyNode ? undefined : IMG_SRC, | ||
'src': IMG_SRC, | ||
'shadow': null, | ||
@@ -85,3 +85,3 @@ 'visible': true, | ||
'filters': [], | ||
'resizeFilters': [], | ||
'resizeFilters': [], | ||
'fillRule': 'nonzero', | ||
@@ -120,2 +120,3 @@ 'globalCompositeOperation': 'source-over', | ||
img.src = imgData; | ||
img._src = src; | ||
callback && callback(); | ||
@@ -164,5 +165,3 @@ }); | ||
canvas.overlayColor = fabric.StaticCanvas.prototype.overlayColor; | ||
canvas.controlsAboveOverlay = fabric.StaticCanvas.prototype.controlsAboveOverlay; | ||
canvas.preserveObjectStacking = fabric.StaticCanvas.prototype.preserveObjectStacking; | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
canvas.viewportTransform = [1, 0, 0, 1, 0, 0]; | ||
canvas.calcOffset(); | ||
@@ -441,12 +440,2 @@ } | ||
test('preserveObjectStacking', function() { | ||
ok(typeof canvas.preserveObjectStacking == 'boolean'); | ||
ok(!canvas.preserveObjectStacking); | ||
}); | ||
test('renderTop', function() { | ||
ok(typeof canvas.renderTop == 'function'); | ||
equal(canvas, canvas.renderTop()); | ||
}); | ||
test('toDataURL', function() { | ||
@@ -494,3 +483,3 @@ ok(typeof canvas.toDataURL == 'function'); | ||
equal(rect.getCenterPoint().x, canvas.height / 2, 'object\'s "center.x" property should correspond to canvas element\'s center when canvas is transformed'); | ||
canvas.setZoom(1); | ||
}); | ||
@@ -520,2 +509,3 @@ | ||
equal(rect.getCenterPoint().x, canvas.height / 2, 'object\'s "center.x" property should correspond to canvas element\'s center when canvas is transformed'); | ||
canvas.setZoom(1); | ||
}); | ||
@@ -934,38 +924,2 @@ | ||
test('loadFromJSON with custom properties on Canvas with no async object', function() { | ||
var serialized = JSON.parse(PATH_JSON); | ||
serialized.controlsAboveOverlay = true; | ||
serialized.preserveObjectStacking = true; | ||
equal(canvas.controlsAboveOverlay, fabric.Canvas.prototype.controlsAboveOverlay); | ||
equal(canvas.preserveObjectStacking, fabric.Canvas.prototype.preserveObjectStacking); | ||
canvas.loadFromJSON(serialized, function() { | ||
ok(!canvas.isEmpty(), 'canvas is not empty'); | ||
equal(canvas.controlsAboveOverlay, true); | ||
equal(canvas.preserveObjectStacking, true); | ||
}); | ||
// if no async object the callback is called syncronously | ||
equal(canvas.controlsAboveOverlay, true); | ||
equal(canvas.preserveObjectStacking, true); | ||
}); | ||
asyncTest('loadFromJSON with custom properties on Canvas with image', function() { | ||
var JSON_STRING = '{"objects":[{"type":"image","originX":"left","originY":"top","left":13.6,"top":-1.4,"width":3000,"height":3351,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.05,"scaleY":0.05,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"src":"' + IMG_SRC + '","filters":[],"crossOrigin":"","alignX":"none","alignY":"none","meetOrSlice":"meet"}],' | ||
+ '"background":"green"}'; | ||
var serialized = JSON.parse(JSON_STRING); | ||
serialized.controlsAboveOverlay = true; | ||
serialized.preserveObjectStacking = true; | ||
equal(canvas.controlsAboveOverlay, fabric.Canvas.prototype.controlsAboveOverlay); | ||
equal(canvas.preserveObjectStacking, fabric.Canvas.prototype.preserveObjectStacking); | ||
canvas.loadFromJSON(serialized, function() { | ||
ok(!canvas.isEmpty(), 'canvas is not empty'); | ||
equal(canvas.controlsAboveOverlay, true); | ||
equal(canvas.preserveObjectStacking, true); | ||
start(); | ||
}); | ||
// before callback the properties are still false. | ||
equal(canvas.controlsAboveOverlay, false); | ||
equal(canvas.preserveObjectStacking, false); | ||
}); | ||
asyncTest('loadFromJSON with image background and color', function() { | ||
@@ -1335,2 +1289,83 @@ var serialized = JSON.parse(PATH_JSON); | ||
test('setViewportTransform', function() { | ||
ok(typeof canvas.setViewportTransform == 'function'); | ||
var vpt = [2, 0, 0, 2, 50, 50]; | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, 0, 0], 'initial viewport is identity matrix'); | ||
canvas.setViewportTransform(vpt); | ||
deepEqual(canvas.viewportTransform, vpt, 'viewport now is the set one'); | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
}); | ||
test('getZoom', function() { | ||
ok(typeof canvas.getZoom == 'function'); | ||
var vpt = [2, 0, 0, 2, 50, 50]; | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
deepEqual(canvas.getZoom(), 1, 'initial zoom is 1'); | ||
canvas.setViewportTransform(vpt); | ||
deepEqual(canvas.getZoom(), 2, 'zoom is set to 2'); | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
}); | ||
test('setZoom', function() { | ||
ok(typeof canvas.setZoom == 'function'); | ||
deepEqual(canvas.getZoom(), 1, 'initial zoom is 1'); | ||
canvas.setZoom(2); | ||
deepEqual(canvas.getZoom(), 2, 'zoom is set to 2'); | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
}); | ||
test('zoomToPoint', function() { | ||
ok(typeof canvas.zoomToPoint == 'function'); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, 0, 0], 'initial viewport is identity matrix'); | ||
var point = new fabric.Point(50, 50); | ||
canvas.zoomToPoint(point, 1); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, 0, 0], 'viewport has no changes if not moving with zoom level'); | ||
canvas.zoomToPoint(point, 2); | ||
deepEqual(canvas.viewportTransform, [2, 0, 0, 2, -50, -50], 'viewport has a translation effect and zoom'); | ||
canvas.zoomToPoint(point, 3); | ||
deepEqual(canvas.viewportTransform, [3, 0, 0, 3, -100, -100], 'viewport has a translation effect and zoom'); | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
}); | ||
test('absolutePan', function() { | ||
ok(typeof canvas.absolutePan == 'function'); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, 0, 0], 'initial viewport is identity matrix'); | ||
var point = new fabric.Point(50, 50); | ||
canvas.absolutePan(point); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, -point.x, -point.y], 'viewport has translation effect applied'); | ||
canvas.absolutePan(point); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, -point.x, -point.y], 'viewport has same translation effect applied'); | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
}); | ||
test('relativePan', function() { | ||
ok(typeof canvas.relativePan == 'function'); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, 0, 0], 'initial viewport is identity matrix'); | ||
var point = new fabric.Point(-50, -50); | ||
canvas.relativePan(point); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, -50, -50], 'viewport has translation effect applied'); | ||
canvas.relativePan(point); | ||
deepEqual(canvas.viewportTransform, [1, 0, 0, 1, -100, -100], 'viewport has translation effect applied on top of old one'); | ||
canvas.viewportTransform = fabric.StaticCanvas.prototype.viewportTransform; | ||
}); | ||
test('getActiveObject', function() { | ||
ok(typeof canvas.getActiveObject == 'function'); | ||
var activeObject = canvas.getActiveObject(); | ||
equal(activeObject, null, 'should return null'); | ||
}); | ||
test('getActiveGroup', function() { | ||
ok(typeof canvas.getActiveGroup == 'function'); | ||
var activeGroup = canvas.getActiveGroup(); | ||
equal(activeGroup, null, 'should return null'); | ||
}); | ||
test('getContext', function() { | ||
ok(typeof canvas.getContext == 'function'); | ||
var context = canvas.getContext(); | ||
equal(context, canvas.contextContainer, 'should return the context container'); | ||
}); | ||
//how to test with an exception? | ||
@@ -1337,0 +1372,0 @@ /*asyncTest('options in setBackgroundImage from invalid URL', function() { |
@@ -51,2 +51,18 @@ (function() { | ||
function _createImageElement() { | ||
return fabric.isLikelyNode ? new (require('canvas').Image)() : fabric.document.createElement('img'); | ||
} | ||
function getAbsolutePath(path) { | ||
var isAbsolute = /^https?:/.test(path); | ||
if (isAbsolute) return path; | ||
var imgEl = _createImageElement(); | ||
imgEl.src = path; | ||
var src = imgEl.src; | ||
imgEl = null; | ||
return src; | ||
} | ||
var IMG_SRC = fabric.isLikelyNode ? (__dirname + '/../fixtures/test_image.gif') : getAbsolutePath('../fixtures/test_image.gif'); | ||
var el = fabric.document.createElement('canvas'); | ||
@@ -65,3 +81,3 @@ el.width = 600; el.height = 600; | ||
function makeTriangle(options) { | ||
var defaultOptions = { width: 10, height: 10 }; | ||
var defaultOptions = { width: 30, height: 30 }; | ||
return new fabric.Triangle(fabric.util.object.extend(defaultOptions, options || { })); | ||
@@ -73,2 +89,4 @@ } | ||
upperCanvasEl.style.display = ''; | ||
canvas.controlsAboveOverlay = fabric.Canvas.prototype.controlsAboveOverlay; | ||
canvas.preserveObjectStacking = fabric.Canvas.prototype.preserveObjectStacking; | ||
}, | ||
@@ -109,2 +127,79 @@ teardown: function() { | ||
test('preserveObjectStacking', function() { | ||
ok(typeof canvas.preserveObjectStacking == 'boolean'); | ||
ok(!canvas.preserveObjectStacking, 'default is false'); | ||
}); | ||
test('uniScaleTransform', function() { | ||
ok(typeof canvas.uniScaleTransform == 'boolean'); | ||
ok(!canvas.uniScaleTransform, 'default is false'); | ||
}); | ||
test('uniScaleKey', function() { | ||
ok(typeof canvas.uniScaleKey == 'string'); | ||
equal(canvas.uniScaleKey, 'shiftKey', 'default is shift'); | ||
}); | ||
test('centeredScaling', function() { | ||
ok(typeof canvas.centeredScaling == 'boolean'); | ||
ok(!canvas.centeredScaling, 'default is false'); | ||
}); | ||
test('centeredRotation', function() { | ||
ok(typeof canvas.centeredRotation == 'boolean'); | ||
ok(!canvas.centeredRotation, 'default is false'); | ||
}); | ||
test('centeredKey', function() { | ||
ok(typeof canvas.centeredKey == 'string'); | ||
equal(canvas.centeredKey, 'altKey', 'default is alt'); | ||
}); | ||
test('altActionKey', function() { | ||
ok(typeof canvas.altActionKey == 'string'); | ||
equal(canvas.altActionKey, 'shiftKey', 'default is shift'); | ||
}); | ||
test('interactive', function() { | ||
ok(typeof canvas.interactive == 'boolean'); | ||
ok(canvas.interactive, 'default is true'); | ||
}); | ||
test('selection', function() { | ||
ok(typeof canvas.selection == 'boolean'); | ||
ok(canvas.selection, 'default is true'); | ||
}); | ||
test('_initInteractive', function() { | ||
ok(typeof canvas._initInteractive == 'function'); | ||
}); | ||
test('renderTop', function() { | ||
ok(typeof canvas.renderTop == 'function'); | ||
equal(canvas, canvas.renderTop()); | ||
}); | ||
test('_chooseObjectsToRender', function() { | ||
ok(typeof canvas._chooseObjectsToRender == 'function'); | ||
var rect = makeRect(), rect2 = makeRect(), rect3 = makeRect(); | ||
canvas.add(rect); | ||
canvas.add(rect2); | ||
canvas.add(rect3); | ||
var objs = canvas._chooseObjectsToRender(); | ||
equal(objs[0], rect); | ||
equal(objs[1], rect2); | ||
equal(objs[2], rect3); | ||
canvas.setActiveObject(rect); | ||
objs = canvas._chooseObjectsToRender(); | ||
equal(objs[0], rect2); | ||
equal(objs[1], rect3); | ||
equal(objs[2], rect); | ||
canvas.setActiveObject(rect2); | ||
canvas.preserveObjectStacking = true; | ||
objs = canvas._chooseObjectsToRender(); | ||
equal(objs[0], rect); | ||
equal(objs[1], rect2); | ||
equal(objs[2], rect3); | ||
}); | ||
test('calcOffset', function() { | ||
@@ -221,5 +316,4 @@ ok(typeof canvas.calcOffset == 'function', 'should respond to `calcOffset`'); | ||
test('renderTop', function() { | ||
ok(typeof canvas.renderTop == 'function'); | ||
equal(canvas, canvas.renderTop()); | ||
test('_drawSelection', function() { | ||
ok(typeof canvas._drawSelection == 'function'); | ||
}); | ||
@@ -233,7 +327,7 @@ | ||
clientX: 5, clientY: 5 | ||
}, true); | ||
}); | ||
equal(target, rect, 'Should return the rect'); | ||
target = canvas.findTarget({ | ||
clientX: 30, clientY: 30 | ||
}, true); | ||
}); | ||
equal(target, null, 'Should not find target'); | ||
@@ -243,23 +337,36 @@ canvas.remove(rect); | ||
test('findTarget last rendered', function() { | ||
test('findTarget preserveObjectStacking false', function() { | ||
ok(typeof canvas.findTarget == 'function'); | ||
var rect = makeRect({ left: 0, top: 0 }), target; | ||
canvas.preserveObjectStacking = false; | ||
var rect = makeRect({ left: 0, top: 0 }), | ||
rectOver = makeRect({ left: 0, top: 0 }), | ||
target, | ||
pointer = { clientX: 5, clientY: 5 }; | ||
canvas.add(rect); | ||
target = canvas.findTarget({ | ||
clientX: 5, clientY: 5 | ||
}, true); | ||
canvas.setActiveObject(target); | ||
canvas.add(rectOver); | ||
canvas.setActiveObject(rect); | ||
canvas.renderAll(); | ||
target = canvas.findTarget(pointer); | ||
equal(target, rect, 'Should return the rect'); | ||
canvas.renderAll(); | ||
equal(canvas.lastRenderedWithControls, rect); | ||
canvas.remove(rect); | ||
target = canvas.findTarget({ | ||
clientX: 5, clientY: 5 | ||
}, true); | ||
equal(target, null, 'Should not find target'); | ||
equal(canvas.lastRenderedWithControls, undefined, 'lastRendereWithControls reference should disappear'); | ||
}); | ||
test('findTarget preserveObjectStacking true', function() { | ||
ok(typeof canvas.findTarget == 'function'); | ||
canvas.preserveObjectStacking = true; | ||
var rect = makeRect({ left: 0, top: 0 }), | ||
rectOver = makeRect({ left: 0, top: 0 }), | ||
target, | ||
pointer = { clientX: 5, clientY: 5 }; | ||
canvas.add(rect); | ||
canvas.add(rectOver); | ||
target = canvas.findTarget(pointer); | ||
equal(target, rectOver, 'Should return the rectOver, rect is not considered'); | ||
canvas.setActiveObject(rect); | ||
target = canvas.findTarget(pointer); | ||
equal(target, rect, 'Should return the rect, because it is active'); | ||
canvas.preserveObjectStacking = false; | ||
}); | ||
test('findTarget with subTargetCheck', function() { | ||
var rect = makeRect({ left: 0, top: 0 }), | ||
var rect = makeRect({ left: 0, top: 0 }), | ||
rect2 = makeRect({ left: 30, top: 30}), target, | ||
@@ -276,3 +383,3 @@ group = new fabric.Group([rect, rect2]); | ||
clientX: 30, clientY: 30 | ||
}, true); | ||
}); | ||
equal(target, group, 'Should return the group'); | ||
@@ -282,3 +389,3 @@ group.subTargetCheck = true; | ||
clientX: 5, clientY: 5 | ||
}, true); | ||
}); | ||
equal(target, group, 'Should return the group'); | ||
@@ -288,3 +395,3 @@ equal(canvas.targets[0], rect, 'should return the rect'); | ||
clientX: 15, clientY: 15 | ||
}, true); | ||
}); | ||
equal(target, group, 'Should return the group'); | ||
@@ -294,3 +401,3 @@ equal(canvas.targets[0], undefined, 'no subtarget should return'); | ||
clientX: 32, clientY: 32 | ||
}, true); | ||
}); | ||
equal(target, group, 'Should return the group'); | ||
@@ -306,14 +413,14 @@ equal(canvas.targets[0], rect2, 'should return the rect2'); | ||
target = canvas.findTarget({ | ||
clientX: 2, clientY: 1 | ||
}, true); | ||
clientX: 5, clientY: 5 | ||
}); | ||
equal(target, triangle, 'Should return the triangle by bounding box'); | ||
//TODO find out why this stops the tests | ||
//canvas.perPixelTargetFind = true; | ||
//target = canvas.findTarget({ | ||
// clientX: 2, clientY: 1 | ||
//}, true); | ||
//equal(target, null, 'Should return null because of transparency checks'); | ||
canvas.perPixelTargetFind = true; | ||
target = canvas.findTarget({ | ||
clientX: 5, clientY: 5 | ||
}, true); | ||
}); | ||
equal(target, null, 'Should return null because of transparency checks'); | ||
target = canvas.findTarget({ | ||
clientX: 15, clientY: 15 | ||
}); | ||
equal(target, triangle, 'Should return the triangle now'); | ||
@@ -326,15 +433,53 @@ canvas.perPixelTargetFind = false; | ||
var rect1 = makeRect({ left: 0, top: 0 }), target; | ||
var rect2 = makeRect({ left: 20, top: 0 }); | ||
var rect2 = makeRect({ left: 20, top: 20 }); | ||
var rect3 = makeRect({ left: 20, top: 0 }); | ||
canvas.add(rect1); | ||
canvas.add(rect2); | ||
canvas.add(rect3); | ||
var group = new fabric.Group([ rect1, rect2 ]); | ||
canvas.add(group); | ||
canvas.setActiveGroup(group); | ||
target = canvas.findTarget({ | ||
clientX: 5, clientY: 5 | ||
}); | ||
equal(target, group, 'Should return the activegroup'); | ||
target = canvas.findTarget({ | ||
clientX: 40, clientY: 15 | ||
}); | ||
equal(target, null, 'Should miss the activegroup'); | ||
target = canvas.findTarget({ | ||
clientX: 5, clientY: 5 | ||
}, true); | ||
equal(target, rect1, 'Should return the rect inside activegroup'); | ||
target = canvas.findTarget({ | ||
clientX: 25, clientY: 5 | ||
}); | ||
equal(target, group, 'Should return the activegroup'); | ||
//TODO: make it work with perPixelTargetFind | ||
target = canvas.findTarget({ | ||
clientX: 25, clientY: 5 | ||
}, true); | ||
equal(target, rect3, 'Should return the rect behind activegroup'); | ||
}); | ||
test('findTarget on activegroup with perPixelTargetFind', function() { | ||
var rect1 = makeRect({ left: 0, top: 0 }), target; | ||
var rect2 = makeRect({ left: 20, top: 20 }); | ||
canvas.perPixelTargetFind = true; | ||
canvas.preserveObjectStacking = true; | ||
canvas.add(rect1); | ||
canvas.add(rect2); | ||
var group = new fabric.Group([ rect1, rect2 ]); | ||
canvas.setActiveGroup(group); | ||
target = canvas.findTarget({ | ||
clientX: 8, clientY: 8 | ||
}); | ||
equal(target, group, 'Should return the activegroup'); | ||
target = canvas.findTarget({ | ||
clientX: 15, clientY: 15 | ||
}); | ||
equal(target, null, 'Should miss the activegroup'); | ||
canvas.perPixelTargetFind = false; | ||
canvas.preserveObjectStacking = false; | ||
}); | ||
test('activeGroup sendToBack', function() { | ||
@@ -359,3 +504,3 @@ | ||
}); | ||
test('activeGroup bringToFront', function() { | ||
@@ -673,3 +818,3 @@ | ||
equal(c2.overlayColor, 'yellow', 'Color should be set properly'); | ||
}); | ||
@@ -693,3 +838,3 @@ }); | ||
equal(c2.overlayColor, 'yellow', 'Color should be set properly'); | ||
}); | ||
@@ -761,2 +906,74 @@ }); | ||
test('loadFromJSON with custom properties on Canvas with no async object', function() { | ||
var serialized = JSON.parse(PATH_JSON); | ||
serialized.controlsAboveOverlay = true; | ||
serialized.preserveObjectStacking = true; | ||
equal(canvas.controlsAboveOverlay, fabric.Canvas.prototype.controlsAboveOverlay); | ||
equal(canvas.preserveObjectStacking, fabric.Canvas.prototype.preserveObjectStacking); | ||
canvas.loadFromJSON(serialized, function() { | ||
ok(!canvas.isEmpty(), 'canvas is not empty'); | ||
equal(canvas.controlsAboveOverlay, true); | ||
equal(canvas.preserveObjectStacking, true); | ||
}); | ||
// if no async object the callback is called syncronously | ||
equal(canvas.controlsAboveOverlay, true); | ||
equal(canvas.preserveObjectStacking, true); | ||
}); | ||
asyncTest('loadFromJSON with custom properties on Canvas with image', function() { | ||
var JSON_STRING = '{"objects":[{"type":"image","originX":"left","originY":"top","left":13.6,"top":-1.4,"width":3000,"height":3351,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":0,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.05,"scaleY":0.05,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"src":"' + IMG_SRC + '","filters":[],"crossOrigin":"","alignX":"none","alignY":"none","meetOrSlice":"meet"}],' | ||
+ '"background":"green"}'; | ||
var serialized = JSON.parse(JSON_STRING); | ||
serialized.controlsAboveOverlay = true; | ||
serialized.preserveObjectStacking = true; | ||
equal(canvas.controlsAboveOverlay, fabric.Canvas.prototype.controlsAboveOverlay); | ||
equal(canvas.preserveObjectStacking, fabric.Canvas.prototype.preserveObjectStacking); | ||
canvas.loadFromJSON(serialized, function() { | ||
ok(!canvas.isEmpty(), 'canvas is not empty'); | ||
equal(canvas.controlsAboveOverlay, true); | ||
equal(canvas.preserveObjectStacking, true); | ||
start(); | ||
}); | ||
// before callback the properties are still false. | ||
equal(canvas.controlsAboveOverlay, false); | ||
equal(canvas.preserveObjectStacking, false); | ||
}); | ||
test('normalize pointer', function(){ | ||
ok(typeof canvas._normalizePointer == 'function'); | ||
var pointer = { x: 10, y: 20 }, | ||
object = makeRect({ top: 10, left: 10, width: 50, height: 50, strokeWidth: 0}), | ||
normalizedPointer = canvas._normalizePointer(object, pointer); | ||
equal(normalizedPointer.x, -25, 'should be in top left corner of rect'); | ||
equal(normalizedPointer.y, -15, 'should be in top left corner of rect'); | ||
object.angle = 90; | ||
normalizedPointer = canvas._normalizePointer(object, pointer); | ||
equal(normalizedPointer.x, -15, 'should consider angle'); | ||
equal(normalizedPointer.y, -25, 'should consider angle'); | ||
object.angle = 0; | ||
object.scaleX = 2; | ||
object.scaleY = 2; | ||
normalizedPointer = canvas._normalizePointer(object, pointer); | ||
equal(normalizedPointer.x, -25, 'should consider scale'); | ||
equal(normalizedPointer.y, -20, 'should consider scale'); | ||
object.skewX = 60; | ||
normalizedPointer = canvas._normalizePointer(object, pointer); | ||
equal(normalizedPointer.x.toFixed(2), -33.66, 'should consider skewX'); | ||
equal(normalizedPointer.y, -20, 'should not change'); | ||
}); | ||
test('restorePointerVpt', function(){ | ||
ok(typeof canvas.restorePointerVpt == 'function'); | ||
var pointer = { x: 10, y: 20 }, | ||
restoredPointer = canvas.restorePointerVpt(pointer); | ||
equal(restoredPointer.x, pointer.x, 'no changes if not vpt is set'); | ||
equal(restoredPointer.y, pointer.y, 'no changes if not vpt is set'); | ||
canvas.viewportTransform = [2, 0, 0, 2, 50, -60]; | ||
restoredPointer = canvas.restorePointerVpt(pointer); | ||
equal(restoredPointer.x, -20, 'vpt changes restored'); | ||
equal(restoredPointer.y, 40, 'vpt changes restored'); | ||
canvas.viewportTransform = [1, 0, 0, 1, 0, 0]; | ||
}); | ||
// asyncTest('loadFromJSON with backgroundImage', function() { | ||
@@ -1077,3 +1294,3 @@ // canvas.setBackgroundImage('../../assets/pug.jpg'); | ||
}); | ||
test('dispose', function() { | ||
@@ -1121,3 +1338,3 @@ //made local vars to do not dispose the external canvas | ||
}); | ||
// test('dispose', function() { | ||
@@ -1286,2 +1503,100 @@ // function invokeEventsOnCanvas() { | ||
test('setupCurrentTransform', function() { | ||
ok(typeof canvas._setupCurrentTransform == 'function'); | ||
var rect = new fabric.Rect({ left: 75, top: 75, width: 50, height: 50 }); | ||
canvas.add(rect); | ||
var canvasEl = canvas.getElement(), | ||
canvasOffset = fabric.util.getElementOffset(canvasEl); | ||
var eventStub = { | ||
clientX: canvasOffset.left + 100, | ||
clientY: canvasOffset.top + 100, | ||
target: rect | ||
}; | ||
rect.active = true; | ||
canvas._setupCurrentTransform(eventStub, rect); | ||
var t = canvas._currentTransform; | ||
equal(t.target, rect, 'should have rect as a target'); | ||
equal(t.action, 'drag', 'should target inside rect and setup drag'); | ||
equal(t.corner, 0, 'no corner selected'); | ||
equal(t.originX, rect.originX, 'no origin change for drag'); | ||
equal(t.originY, rect.originY, 'no origin change for drag'); | ||
eventStub = { | ||
clientX: canvasOffset.left + rect.oCoords.tl.corner.tl.x + 1, | ||
clientY: canvasOffset.top + rect.oCoords.tl.corner.tl.y + 1, | ||
target: rect | ||
}; | ||
canvas._setupCurrentTransform(eventStub, rect); | ||
t = canvas._currentTransform; | ||
equal(t.target, rect, 'should have rect as a target'); | ||
equal(t.action, 'scale', 'should target a corner and setup scale'); | ||
equal(t.corner, 'tl', 'tl selected'); | ||
equal(t.originX, 'right', 'origin in opposite direction'); | ||
equal(t.originY, 'bottom', 'origin in opposite direction'); | ||
equal(t.shiftKey, undefined, 'shift was not pressed'); | ||
eventStub = { | ||
clientX: canvasOffset.left + rect.left - 2, | ||
clientY: canvasOffset.top + rect.top + rect.height/2, | ||
target: rect, | ||
shiftKey: true | ||
}; | ||
canvas._setupCurrentTransform(eventStub, rect); | ||
t = canvas._currentTransform; | ||
equal(t.target, rect, 'should have rect as a target'); | ||
equal(t.action, 'skewY', 'should target a corner and setup skew'); | ||
equal(t.shiftKey, true, 'shift was pressed'); | ||
equal(t.corner, 'ml', 'ml selected'); | ||
equal(t.originX, 'right', 'origin in opposite direction'); | ||
eventStub = { | ||
clientX: canvasOffset.left + rect.oCoords.mtr.x, | ||
clientY: canvasOffset.top + rect.oCoords.mtr.y, | ||
target: rect, | ||
}; | ||
canvas._setupCurrentTransform(eventStub, rect); | ||
t = canvas._currentTransform; | ||
equal(t.target, rect, 'should have rect as a target'); | ||
equal(t.action, 'rotate', 'should target a corner and setup rotate'); | ||
equal(t.corner, 'mtr', 'mtr selected'); | ||
canvas._currentTransform = false; | ||
}); | ||
test('_scaleObject', function() { | ||
ok(typeof canvas._scaleObject == 'function'); | ||
var rect = new fabric.Rect({ left: 75, top: 75, width: 50, height: 50 }); | ||
canvas.add(rect); | ||
var canvasEl = canvas.getElement(), | ||
canvasOffset = fabric.util.getElementOffset(canvasEl); | ||
var eventStub = { | ||
clientX: canvasOffset.left + rect.oCoords.tl.corner.tl.x + 1, | ||
clientY: canvasOffset.top + rect.oCoords.tl.corner.tl.y + 1, | ||
target: rect | ||
}; | ||
canvas._setupCurrentTransform(eventStub, rect); | ||
var scaled = canvas._scaleObject(30, 30, 'equally'); | ||
equal(scaled, true, 'return true if scaling happened'); | ||
scaled = canvas._scaleObject(30, 30, 'equally'); | ||
equal(scaled, false, 'return false if no movement happen'); | ||
}); | ||
test('containsPoint in viewport transform', function() { | ||
canvas.viewportTransform = [2, 0, 0, 2, 50, 50]; | ||
var rect = new fabric.Rect({ left: 75, top: 75, width: 50, height: 50 }); | ||
canvas.add(rect); | ||
var canvasEl = canvas.getElement(), | ||
canvasOffset = fabric.util.getElementOffset(canvasEl); | ||
var eventStub = { | ||
clientX: canvasOffset.left + 250, | ||
clientY: canvasOffset.top + 250, | ||
target: rect | ||
}; | ||
ok(canvas.containsPoint(eventStub, rect), 'point at (250, 250) should be within area (75, 75, 125, 125)'); | ||
canvas.viewportTransform = [1, 0, 0, 1, 0, 0]; | ||
}); | ||
asyncTest('fxRemove', function() { | ||
@@ -1288,0 +1603,0 @@ ok(typeof canvas.fxRemove == 'function'); |
@@ -286,11 +286,39 @@ (function(){ | ||
// uppercase | ||
deepEqual(fabric.Color.sourceFromHex('#FFFFFF00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFFFFFCC'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFFFFFFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFFFFF00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFFFFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFFC'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFF0'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('FFFFFF00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('FFFFFFCC'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('FFFFFFFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('FFFFFF00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('FFFFFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('FFFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('FFFC'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('FFF0'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('FFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFFFFF'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#FFF'), [255,255,255,1]); | ||
// lowercase | ||
deepEqual(fabric.Color.sourceFromHex('#ffffff00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('#ffffffcc'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('#ffffffff'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#ffffff00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('#ffffff'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#ffff'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('#fffc'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('#fff0'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('#fff'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('ffffff00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('ffffffcc'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('ffffffff'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('ffffff00'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('ffffff'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('ffff'), [255,255,255,1]); | ||
deepEqual(fabric.Color.sourceFromHex('fffc'), [255,255,255,0.8]); | ||
deepEqual(fabric.Color.sourceFromHex('fff0'), [255,255,255,0]); | ||
deepEqual(fabric.Color.sourceFromHex('fff'), [255,255,255,1]); | ||
@@ -297,0 +325,0 @@ }); |
@@ -163,10 +163,47 @@ (function() { | ||
// TODO: need to double check these values | ||
equal(gradient.coords.x1, 0); | ||
equal(gradient.coords.y1, 0); | ||
equal(gradient.coords.x2, 100); | ||
equal(gradient.coords.y2, 0); | ||
equal(gradient.coords.x1, 50); | ||
equal(gradient.coords.y1, 50); | ||
equal(gradient.colorStops[0].offset, 1); | ||
equal(gradient.colorStops[1].offset, 0); | ||
//equal(gradient.coords.x2, 100); | ||
//equal(gradient.coords.y2, 100); | ||
equal(gradient.colorStops[0].color, 'rgb(0,0,0)'); | ||
equal(gradient.colorStops[1].color, 'rgb(255,255,255)'); | ||
equal(gradient.colorStops[0].opacity, 0); | ||
}); | ||
test('fromElement linearGradient with Infinity', function() { | ||
ok(typeof fabric.Gradient.fromElement == 'function'); | ||
var element = fabric.document.createElement('linearGradient'); | ||
var stop1 = fabric.document.createElement('stop'); | ||
var stop2 = fabric.document.createElement('stop'); | ||
stop1.setAttribute('offset', '0%'); | ||
stop1.setAttribute('stop-color', 'white'); | ||
stop2.setAttribute('offset', '100%'); | ||
stop2.setAttribute('stop-color', 'black'); | ||
stop2.setAttribute('stop-opacity', '0'); | ||
element.setAttribute('x1', '-Infinity'); | ||
element.setAttribute('x2', 'Infinity'); | ||
element.setAttribute('y1', 'Infinity'); | ||
element.setAttribute('y2', '-Infinity'); | ||
element.appendChild(stop1); | ||
element.appendChild(stop2); | ||
var object = new fabric.Object({ width: 100, height: 100, top: 0, left: 0 }); | ||
var gradient = fabric.Gradient.fromElement(element, object); | ||
ok(gradient instanceof fabric.Gradient); | ||
equal(gradient.coords.x1, 0); | ||
equal(gradient.coords.y1, 100); | ||
equal(gradient.coords.x2, 100); | ||
equal(gradient.coords.y2, 0); | ||
equal(gradient.colorStops[0].offset, 1); | ||
@@ -206,2 +243,113 @@ equal(gradient.colorStops[1].offset, 0); | ||
test('fromElement with x1,x2,y1,2 linear', function() { | ||
ok(typeof fabric.Gradient.fromElement == 'function'); | ||
var element = fabric.document.createElement('linearGradient'); | ||
element.setAttribute('x1', '30%'); | ||
element.setAttribute('x2', '20%'); | ||
element.setAttribute('y1', '0.1'); | ||
element.setAttribute('y2', 'Infinity'); | ||
var object = new fabric.Object({ width: 200, height: 200 }); | ||
var gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 60); | ||
equal(gradient.coords.y1, 20); | ||
equal(gradient.coords.x2, 40); | ||
equal(gradient.coords.y2, 200); | ||
object = new fabric.Object({ width: 200, height: 200, top: 50, left: 10 }); | ||
gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 70); | ||
equal(gradient.coords.y1, 70); | ||
equal(gradient.coords.x2, 50); | ||
equal(gradient.coords.y2, 250); | ||
}); | ||
test('fromElement with x1,x2,y1,2 radial', function() { | ||
ok(typeof fabric.Gradient.fromElement == 'function'); | ||
var element = fabric.document.createElement('radialGradient'); | ||
element.setAttribute('fx', '30%'); | ||
element.setAttribute('fy', '20%'); | ||
element.setAttribute('cx', '0.1'); | ||
element.setAttribute('cy', '1'); | ||
element.setAttribute('r', '100%'); | ||
var object = new fabric.Object({ width: 200, height: 200 }); | ||
var gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 60, 'should change with width height'); | ||
equal(gradient.coords.y1, 40, 'should change with width height'); | ||
equal(gradient.coords.x2, 20, 'should change with width height'); | ||
equal(gradient.coords.y2, 200, 'should change with width height'); | ||
equal(gradient.coords.r1, 0, 'should change with width height'); | ||
equal(gradient.coords.r2, 200, 'should change with width height'); | ||
object = new fabric.Object({ width: 200, height: 200, top: 10, left: 10 }); | ||
gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 70, 'should change with top left'); | ||
equal(gradient.coords.y1, 50, 'should change with top left'); | ||
equal(gradient.coords.x2, 30, 'should change with top left'); | ||
equal(gradient.coords.y2, 210, 'should change with top left'); | ||
equal(gradient.coords.r1, 10, 'should change with top left'); | ||
equal(gradient.coords.r2, 210, 'should change with top left'); | ||
}); | ||
test('fromElement with x1,x2,y1,2 radial userSpaceOnUse', function() { | ||
ok(typeof fabric.Gradient.fromElement == 'function'); | ||
var element = fabric.document.createElement('radialGradient'); | ||
element.setAttribute('fx', '30'); | ||
element.setAttribute('fy', '20'); | ||
element.setAttribute('cx', '15'); | ||
element.setAttribute('cy', '18'); | ||
element.setAttribute('r', '100'); | ||
element.setAttribute('gradientUnits', 'userSpaceOnUse'); | ||
var object = new fabric.Object({ width: 200, height: 200 }); | ||
var gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 30, 'should not change with width height'); | ||
equal(gradient.coords.y1, 20, 'should not change with width height'); | ||
equal(gradient.coords.x2, 15, 'should not change with width height'); | ||
equal(gradient.coords.y2, 18, 'should not change with width height'); | ||
equal(gradient.coords.r1, 0, 'should not change with width height'); | ||
equal(gradient.coords.r2, 100, 'should not change with width height'); | ||
object = new fabric.Object({ width: 200, height: 200, top: 50, left: 60 }); | ||
gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 30, 'should not change with top left'); | ||
equal(gradient.coords.y1, 20, 'should not change with top left'); | ||
equal(gradient.coords.x2, 15, 'should not change with top left'); | ||
equal(gradient.coords.y2, 18, 'should not change with top left'); | ||
equal(gradient.coords.r1, 0, 'should not change with top left'); | ||
equal(gradient.coords.r2, 100, 'should not change with top left'); | ||
}); | ||
test('fromElement with x1,x2,y1,2 linear userSpaceOnUse', function() { | ||
ok(typeof fabric.Gradient.fromElement == 'function'); | ||
var element = fabric.document.createElement('linearGradient'); | ||
element.setAttribute('x1', '30'); | ||
element.setAttribute('y1', '20'); | ||
element.setAttribute('x2', '15'); | ||
element.setAttribute('y2', '18'); | ||
element.setAttribute('gradientUnits', 'userSpaceOnUse'); | ||
var object = new fabric.Object({ width: 200, height: 200 }); | ||
var gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 30, 'should not change with width height'); | ||
equal(gradient.coords.y1, 20, 'should not change with width height'); | ||
equal(gradient.coords.x2, 15, 'should not change with width height'); | ||
equal(gradient.coords.y2, 18, 'should not change with width height'); | ||
object = new fabric.Object({ width: 200, height: 200, top: 40, left: 40 }); | ||
gradient = fabric.Gradient.fromElement(element, object); | ||
equal(gradient.coords.x1, 30, 'should not change with top left'); | ||
equal(gradient.coords.y1, 20, 'should not change with top left'); | ||
equal(gradient.coords.x2, 15, 'should not change with top left'); | ||
equal(gradient.coords.y2, 18, 'should not change with top left'); | ||
}); | ||
test('fromElement radialGradient', function() { | ||
@@ -228,10 +376,7 @@ ok(typeof fabric.Gradient.fromElement == 'function'); | ||
// TODO: need to double check these values | ||
equal(gradient.coords.x1, 50); | ||
equal(gradient.coords.y1, 50); | ||
equal(gradient.coords.x2, 50); | ||
equal(gradient.coords.y2, 50); | ||
//equal(gradient.coords.x2, 100); | ||
//equal(gradient.coords.y2, 100); | ||
equal(gradient.colorStops[0].offset, 1); | ||
@@ -265,10 +410,7 @@ equal(gradient.colorStops[1].offset, 0); | ||
// TODO: need to double check these values | ||
equal(gradient.coords.x1, 50); | ||
equal(gradient.coords.y1, 50); | ||
equal(gradient.coords.x2, 50); | ||
equal(gradient.coords.y2, 50); | ||
//equal(gradient.coords.x2, 100); | ||
//equal(gradient.coords.y2, 100); | ||
equal(gradient.colorStops[0].offset, 1); | ||
@@ -318,10 +460,7 @@ equal(gradient.colorStops[1].offset, 0); | ||
// TODO: need to double check these values | ||
equal(gradient.coords.x1, 0); | ||
equal(gradient.coords.y1, 0); | ||
equal(gradient.coords.x2, 100); | ||
equal(gradient.coords.y2, 0); | ||
equal(gradient.coords.x1, 50); | ||
equal(gradient.coords.y1, 50); | ||
//equal(gradient.coords.x2, 100); | ||
//equal(gradient.coords.y2, 100); | ||
equal(gradient.colorStops[0].offset, 1); | ||
@@ -379,10 +518,7 @@ equal(gradient.colorStops[1].offset, 0.75); | ||
// TODO: need to double check these values | ||
equal(gradient.coords.x1, 50); | ||
equal(gradient.coords.y1, 50); | ||
equal(gradient.coords.x2, 50); | ||
equal(gradient.coords.y2, 50); | ||
//equal(gradient.coords.x2, 100); | ||
//equal(gradient.coords.y2, 100); | ||
equal(gradient.colorStops[0].offset, 1); | ||
@@ -404,3 +540,3 @@ equal(gradient.colorStops[1].offset, 0.75); | ||
test('forObject linearCradient', function() { | ||
test('forObject linearGradient', function() { | ||
ok(typeof fabric.Gradient.forObject == 'function'); | ||
@@ -407,0 +543,0 @@ |
@@ -6,3 +6,3 @@ (function() { | ||
var canvas = this.canvas = fabric.isLikelyNode ? fabric.createCanvasForNode(600, 600, {enableRetinaScaling: false}) : new fabric.Canvas(el); | ||
var canvas = this.canvas = fabric.isLikelyNode ? fabric.createCanvasForNode(600, 600, {enableRetinaScaling: false}) : new fabric.Canvas(el, {enableRetinaScaling: false}); | ||
@@ -372,4 +372,4 @@ // function _createImageElement() { | ||
equal(iteratedObjects[1], group.getObjects()[0]); | ||
equal(iteratedObjects[0], group.getObjects()[1]); | ||
equal(iteratedObjects[0], group.getObjects()[0], 'iteration give back objects in same order'); | ||
equal(iteratedObjects[1], group.getObjects()[1], 'iteration give back objects in same order'); | ||
}); | ||
@@ -526,15 +526,15 @@ | ||
canvas.add(group); | ||
equal(canvas.enableRetinaScaling, false); | ||
equal(isTransparent(ctx, 0, 0, 0), true); | ||
equal(isTransparent(ctx, 1, 1, 0), false); | ||
equal(isTransparent(ctx, 2, 2, 0), false); | ||
equal(isTransparent(ctx, 3, 3, 0), true); | ||
equal(isTransparent(ctx, 4, 4, 0), false); | ||
equal(canvas.enableRetinaScaling, false, 'enable retina scaling is off'); | ||
equal(isTransparent(ctx, 0, 0, 0), true, '0,0 is transparent'); | ||
equal(isTransparent(ctx, 1, 1, 0), false, '1,1 is opaque'); | ||
equal(isTransparent(ctx, 2, 2, 0), false, '2,2 is opaque'); | ||
equal(isTransparent(ctx, 3, 3, 0), true, '3,3 is transparent'); | ||
equal(isTransparent(ctx, 4, 4, 0), false, '4,4 is opaque'); | ||
group.transformMatrix = [2, 0, 0, 2, 1, 1]; | ||
canvas.renderAll(); | ||
equal(isTransparent(ctx, 0, 0, 0), true); | ||
equal(isTransparent(ctx, 1, 1, 0), true); | ||
equal(isTransparent(ctx, 2, 2, 0), true); | ||
equal(isTransparent(ctx, 3, 3, 0), false); | ||
equal(isTransparent(ctx, 4, 4, 0), false); | ||
equal(isTransparent(ctx, 0, 0, 0), true, '0,0 is transparent'); | ||
equal(isTransparent(ctx, 1, 1, 0), true, '1,1 is transparent'); | ||
equal(isTransparent(ctx, 2, 2, 0), true, '2,2 is transparent'); | ||
equal(isTransparent(ctx, 3, 3, 0), false, '3,3 is opaque'); | ||
equal(isTransparent(ctx, 4, 4, 0), false, '4,4 is opaque'); | ||
}); | ||
@@ -541,0 +541,0 @@ // asyncTest('cloning group with image', function() { |
@@ -38,3 +38,3 @@ (function() { | ||
'opacity': 1, | ||
'src': fabric.isLikelyNode ? undefined : IMG_SRC, | ||
'src': IMG_SRC, | ||
'shadow': null, | ||
@@ -45,3 +45,3 @@ 'visible': true, | ||
'filters': [], | ||
'resizeFilters': [], | ||
'resizeFilters': [], | ||
'fillRule': 'nonzero', | ||
@@ -62,18 +62,32 @@ 'globalCompositeOperation': 'source-over', | ||
function _createImageObject(width, height, callback) { | ||
function _createImageObject(width, height, callback, options) { | ||
var elImage = _createImageElement(); | ||
elImage.width = width; | ||
elImage.height = height; | ||
setSrc(elImage, IMG_SRC, function() { | ||
callback(new fabric.Image(elImage)); | ||
if (width != elImage.width || height != elImage.height) { | ||
if (fabric.isLikelyNode) { | ||
var Canvas = require('canvas'); | ||
var canvas = new Canvas(width, height); | ||
canvas.getContext('2d').drawImage(elImage, 0, 0, width, height); | ||
elImage._src = canvas.toDataURL(); | ||
elImage.src = elImage._src; | ||
} | ||
else { | ||
elImage.width = width; | ||
elImage.height = height; | ||
} | ||
return new fabric.Image(elImage, options, callback); | ||
} | ||
else { | ||
return new fabric.Image(elImage, options, callback); | ||
} | ||
}); | ||
} | ||
function createImageObject(callback) { | ||
return _createImageObject(IMG_WIDTH, IMG_HEIGHT, callback); | ||
function createImageObject(callback, options) { | ||
return _createImageObject(IMG_WIDTH, IMG_HEIGHT, callback, options); | ||
} | ||
// function createSmallImageObject(callback) { | ||
// return _createImageObject(IMG_WIDTH / 2, IMG_HEIGHT / 2, callback); | ||
// } | ||
function createSmallImageObject(callback, options) { | ||
return _createImageObject(IMG_WIDTH / 2, IMG_HEIGHT / 2, callback, options); | ||
} | ||
@@ -85,2 +99,3 @@ function setSrc(img, src, callback) { | ||
img.src = imgData; | ||
img._src = src; | ||
callback && callback(); | ||
@@ -90,4 +105,6 @@ }); | ||
else { | ||
img.onload = function() { | ||
callback && callback(); | ||
}; | ||
img.src = src; | ||
callback && callback(); | ||
} | ||
@@ -129,3 +146,2 @@ } | ||
createImageObject(function(image) { | ||
image._originalElement = null; | ||
ok(typeof image.toObject == 'function'); | ||
@@ -140,3 +156,3 @@ var toObject = image.toObject(); | ||
} | ||
deepEqual(toObject, fabric.util.object.extend(REFERENCE_IMG_OBJECT, {src: ''})); | ||
deepEqual(toObject, REFERENCE_IMG_OBJECT); | ||
start(); | ||
@@ -162,4 +178,4 @@ }); | ||
equal(filterFromObj.resizeType, 'bilinear'); | ||
start(); | ||
}); | ||
start(); | ||
}); | ||
@@ -171,3 +187,3 @@ }); | ||
ok(typeof image.toObject == 'function'); | ||
var filter = new fabric.Image.filters.Resize({resizeType: 'bilinear', scaleX: 0.5, scaleY: 0.5}); | ||
var filter = new fabric.Image.filters.Resize({resizeType: 'bilinear', scaleX: 0.2, scaleY: 0.2}); | ||
image.filters.push(filter); | ||
@@ -177,4 +193,4 @@ var width = image.width, height = image.height; | ||
image.applyFilters(function() { | ||
equal(image.width, width / 2, 'width should be halved now'); | ||
equal(image.height, height / 2, 'height should be halved now'); | ||
equal(image.width, width / 5, 'width should be a fifth'); | ||
equal(image.height, height / 5, 'height should a fifth'); | ||
var toObject = image.toObject(); | ||
@@ -184,9 +200,9 @@ deepEqual(toObject.filters[0], filter.toObject()); | ||
equal(toObject.height, height, 'height is stored as before filters'); | ||
fabric.Image.fromObject(toObject, function(imageFromObject) { | ||
var filterFromObj = imageFromObject.filters[0]; | ||
fabric.Image.fromObject(toObject, function(_imageFromObject) { | ||
var filterFromObj = _imageFromObject.filters[0]; | ||
ok(filterFromObj instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize'); | ||
equal(filterFromObj.scaleY, 0.5); | ||
equal(filterFromObj.scaleX, 0.5); | ||
//equal(imageFromObject.width, width, 'on image reload width is halved again'); | ||
//equal(imageFromObject.height, height, 'on image reload width is halved again'); | ||
equal(filterFromObj.scaleY, 0.2); | ||
equal(filterFromObj.scaleX, 0.2); | ||
equal(_imageFromObject.width, width / 5, 'on image reload width is halved again'); | ||
equal(_imageFromObject.height, height / 5, 'on image reload width is halved again'); | ||
start(); | ||
@@ -198,31 +214,6 @@ }); | ||
// asyncTest('toObject without default values', function() { | ||
// createImageObject(function(image) { | ||
// image.includeDefaultValues = false; | ||
// var object = image.toObject(); | ||
// // workaround for node-canvas sometimes producing images with width/height and sometimes not | ||
// if (object.width === 0) { | ||
// object.width = IMG_WIDTH; | ||
// } | ||
// if (object.height === 0) { | ||
// object.height = IMG_HEIGHT; | ||
// } | ||
// deepEqual(object, { | ||
// type: 'image', | ||
// // why the hell deepEqual fail [] == [] check?! | ||
// filters: [], | ||
// crossOrigin: '' | ||
// }); | ||
// start(); | ||
// }); | ||
// }); | ||
asyncTest('toString', function() { | ||
createImageObject(function(image) { | ||
ok(typeof image.toString == 'function'); | ||
equal(image.toString(), '#<fabric.Image: { src: "' + (fabric.isLikelyNode ? undefined : IMG_SRC) + '" }>'); | ||
equal(image.toString(), '#<fabric.Image: { src: "' + IMG_SRC + '" }>'); | ||
start(); | ||
@@ -235,3 +226,3 @@ }); | ||
ok(typeof image.getSrc == 'function'); | ||
equal(image.getSrc(), fabric.isLikelyNode ? undefined : IMG_SRC); | ||
equal(image.getSrc(), IMG_SRC); | ||
start(); | ||
@@ -291,126 +282,104 @@ }); | ||
// asyncTest('clone', function() { | ||
// createImageObject(function(image) { | ||
// ok(typeof image.clone == 'function'); | ||
asyncTest('clone', function() { | ||
createImageObject(function(image) { | ||
ok(typeof image.clone == 'function'); | ||
// var imageClone = null; | ||
// image.clone(function(clone) { | ||
// imageClone = clone; | ||
// }); | ||
image.clone(function(clone) { | ||
ok(clone instanceof fabric.Image); | ||
deepEqual(clone.toObject(), image.toObject()); | ||
start(); | ||
}); | ||
}); | ||
}); | ||
// setTimeout(function() { | ||
// ok(imageClone instanceof fabric.Image); | ||
// deepEqual(imageClone.toObject(), image.toObject()); | ||
// start(); | ||
// }, 1000); | ||
// }); | ||
// }); | ||
asyncTest('cloneWidthHeight', function() { | ||
createSmallImageObject(function(image) { | ||
image.clone(function(clone) { | ||
equal(clone.width, IMG_WIDTH / 2, | ||
'clone\'s element should have width identical to that of original image'); | ||
equal(clone.height, IMG_HEIGHT / 2, | ||
'clone\'s element should have height identical to that of original image'); | ||
start(); | ||
}); | ||
}); | ||
}); | ||
// asyncTest('cloneWidthHeight', function() { | ||
// var image = createSmallImageObject(); | ||
asyncTest('fromObject', function() { | ||
ok(typeof fabric.Image.fromObject == 'function'); | ||
// var imageClone = null; | ||
// image.clone(function(clone) { | ||
// imageClone = clone; | ||
// }); | ||
// should not throw error when no callback is given | ||
var obj = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_IMG_OBJECT), { | ||
src: IMG_SRC | ||
}); | ||
fabric.Image.fromObject(obj, function(instance){ | ||
ok(instance instanceof fabric.Image); | ||
start(); | ||
}); | ||
}); | ||
// setTimeout(function() { | ||
// equal(imageClone.getElement().width, IMG_WIDTH / 2, | ||
// 'clone\'s element should have width identical to that of original image'); | ||
// equal(imageClone.getElement().height, IMG_HEIGHT / 2, | ||
// 'clone\'s element should have height identical to that of original image'); | ||
// start(); | ||
// }, 1000); | ||
// }); | ||
asyncTest('fromURL', function() { | ||
ok(typeof fabric.Image.fromURL == 'function'); | ||
fabric.Image.fromURL(IMG_SRC, function(instance) { | ||
ok(instance instanceof fabric.Image); | ||
deepEqual(REFERENCE_IMG_OBJECT, instance.toObject()); | ||
start(); | ||
}); | ||
}); | ||
// asyncTest('fromObject', function() { | ||
// ok(typeof fabric.Image.fromObject == 'function'); | ||
asyncTest('fromElement', function() { | ||
// // should not throw error when no callback is given | ||
// var obj = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_IMG_OBJECT), { | ||
// src: IMG_SRC | ||
// }); | ||
// fabric.Image.fromObject(obj); | ||
function makeImageElement(attributes) { | ||
var element = _createImageElement(); | ||
if (fabric.isLikelyNode) { | ||
element.getAttribute = function(x) { | ||
return element[x]; | ||
}; | ||
element.setAttribute = function(x, value) { | ||
element[x] = value; | ||
}; | ||
} | ||
for (var prop in attributes) { | ||
element.setAttribute(prop, attributes[prop]); | ||
} | ||
return element; | ||
} | ||
// var image; | ||
// fabric.Image.fromObject(obj, function(instance){ | ||
// image = instance; | ||
// }); | ||
var IMAGE_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAARCAYAAADtyJ2fAAAACXBIWXMAAAsSAAALEgHS3X78AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAVBJREFUeNqMU7tOBDEMtENuy614/QE/gZBOuvJK+Et6CiQ6JP6ExxWI7bhL1vgVExYKLPmsTTIzjieHd+MZZSBIAJwEyJU0EWaum+lNljRux3O6nl70Gx/GUwUeyYcDJWZNhMK1aEXYe95Mz4iP44kDTRUZSWSq1YEHri0/HZxXfGSFBN+qDEJTrNI+QXRBviZ7eWCQgjsg+IHiHYB30MhqUxwcmH1Arc2kFDwkBldeFGJLPqs/AbbF2dWgUym6Z2Tb6RVzYxG1wUnmaNcOonZiU0++l6C7FzoQY42g3+8jz+GZ+dWMr1rRH0OjAFhPO+VJFx/vWDqPmk8H97CGBUYUiqAGW0PVe1+aX8j2Ll0tgHtvLx6AK9Tu1ZTFTQ0ojChqGD4qkOzeAuzVfgzsaTym1ClS+IdwtQCFooQMBTumNun1H6Bfcc9/MUn4R3wJMAAZH6MmA4ht4gAAAABJRU5ErkJggg=="; | ||
// setTimeout(function() { | ||
// ok(image instanceof fabric.Image); | ||
// start(); | ||
// }, 1000); | ||
// }); | ||
ok(typeof fabric.Image.fromElement == 'function', 'fromElement should exist'); | ||
// asyncTest('fromURL', function() { | ||
// ok(typeof fabric.Image.fromURL == 'function'); | ||
var imageEl = makeImageElement({ | ||
width: "14", | ||
height: "17", | ||
"xlink:href": IMAGE_DATA_URL | ||
}); | ||
// // should not throw error when no callback is given | ||
// // can't use `assertNothingRaised` due to asynchronous callback | ||
// fabric.Image.fromURL(IMG_SRC); | ||
fabric.Image.fromElement(imageEl, function(imgObject) { | ||
ok(imgObject instanceof fabric.Image); | ||
deepEqual(imgObject.get('width'), 14, 'width of an object'); | ||
deepEqual(imgObject.get('height'), 17, 'height of an object'); | ||
deepEqual(imgObject.getSrc(), IMAGE_DATA_URL, 'src of an object'); | ||
start(); | ||
}); | ||
}); | ||
// var image; | ||
// fabric.Image.fromURL(IMG_SRC, function(instance) { | ||
// image = instance; | ||
// asyncTest('minimumScale', function() { | ||
// createImageObject(function(image) { | ||
// ok(typeof image.toObject == 'function'); | ||
// var filter = new fabric.Image.filters.Resize({resizeType: 'sliceHack', scaleX: 0.2, scaleY: 0.2}); | ||
// image.resizeFilters.push(filter); | ||
// var width = image.width, height = image.height; | ||
// ok(image.resizeFilters[0] instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize'); | ||
// var toObject = image.toObject(); | ||
// fabric.Image.fromObject(toObject, function(_imageFromObject) { | ||
// var filterFromObj = _imageFromObject.resizeFilters[0]; | ||
// ok(filterFromObj instanceof fabric.Image.filters.Resize, 'should inherit from fabric.Image.filters.Resize'); | ||
// equal(filterFromObj.scaleY, 0.2); | ||
// equal(filterFromObj.scaleX, 0.2); | ||
// var canvasEl = _imageFromObject.applyFilters(null, _imageFromObject.resizeFilters, _imageFromObject._originalElement, true); | ||
// start(); | ||
// }); | ||
// }); | ||
// setTimeout(function() { | ||
// ok(image instanceof fabric.Image); | ||
// deepEqual(REFERENCE_IMG_OBJECT, image.toObject()); | ||
// start(); | ||
// }, 1000); | ||
// }); | ||
// test('toGrayscale', function() { | ||
// var image = createImageObject(), | ||
// imageEl = _createImageElement(); | ||
// imageEl.src = IMG_SRC; | ||
// image.setElement(imageEl); | ||
// ok(typeof image.toGrayscale == 'function'); | ||
// if (!fabric.Canvas.supports('toDataURL')) { | ||
// alert('toDataURL is not supported. Some tests can not be run.'); | ||
// } | ||
// else { | ||
// equal(image.toGrayscale(), image, 'chainable'); | ||
// } | ||
// }); | ||
// asyncTest('fromElement', function() { | ||
// function makeImageElement(attributes) { | ||
// var element = _createImageElement(); | ||
// for (var prop in attributes) { | ||
// element.setAttribute(prop, attributes[prop]); | ||
// } | ||
// return element; | ||
// } | ||
// var IMAGE_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAARCAYAAADtyJ2fAAAACXBIWXMAAAsSAAALEgHS3X78AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAVBJREFUeNqMU7tOBDEMtENuy614/QE/gZBOuvJK+Et6CiQ6JP6ExxWI7bhL1vgVExYKLPmsTTIzjieHd+MZZSBIAJwEyJU0EWaum+lNljRux3O6nl70Gx/GUwUeyYcDJWZNhMK1aEXYe95Mz4iP44kDTRUZSWSq1YEHri0/HZxXfGSFBN+qDEJTrNI+QXRBviZ7eWCQgjsg+IHiHYB30MhqUxwcmH1Arc2kFDwkBldeFGJLPqs/AbbF2dWgUym6Z2Tb6RVzYxG1wUnmaNcOonZiU0++l6C7FzoQY42g3+8jz+GZ+dWMr1rRH0OjAFhPO+VJFx/vWDqPmk8H97CGBUYUiqAGW0PVe1+aX8j2Ll0tgHtvLx6AK9Tu1ZTFTQ0ojChqGD4qkOzeAuzVfgzsaTym1ClS+IdwtQCFooQMBTumNun1H6Bfcc9/MUn4R3wJMAAZH6MmA4ht4gAAAABJRU5ErkJggg=="; | ||
// ok(typeof fabric.Image.fromElement == 'function', 'fromElement should exist'); | ||
// var imageEl = makeImageElement({ | ||
// width: "14", | ||
// height: "17", | ||
// "xlink:href": IMAGE_DATA_URL | ||
// }); | ||
// var imgObject; | ||
// fabric.Image.fromElement(imageEl, function(obj) { | ||
// imgObject = obj; | ||
// }); | ||
// setTimeout(function() { | ||
// ok(imgObject instanceof fabric.Image); | ||
// deepEqual(imgObject.get('width'), 14, 'width of an object'); | ||
// deepEqual(imgObject.get('height'), 17, 'height of an object'); | ||
// deepEqual(imgObject.getSrc(), IMAGE_DATA_URL, 'src of an object'); | ||
// start(); | ||
// }, 500); | ||
// }); | ||
})(); |
@@ -49,2 +49,3 @@ (function() { | ||
'transformMatrix': null, | ||
'charSpacing': 0, | ||
styles: { } | ||
@@ -716,3 +717,3 @@ }; | ||
test('toSVG', function() { | ||
var iText = new fabric.IText('test foo bar-baz\nqux', { | ||
var iText = new fabric.IText('test', { | ||
styles: { | ||
@@ -725,10 +726,6 @@ 0: { | ||
}); | ||
equal(typeof iText.toSVG, 'function'); | ||
// because translate values differ | ||
if (!fabric.isLikelyNode) { | ||
equal(iText.toSVG(), '\t<g transform=\"translate(124.88 52.93)\">\n\t\t<text font-family=\"Times New Roman\" font-size=\"40\" font-weight=\"normal\" style=\"stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;\" ><tspan x=\"-124.384765625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: #112233; fill-rule: ; opacity: 1;\">t</tspan><tspan x=\"-113.271484375\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">e</tspan><tspan x=\"-95.517578125\" y=\"-17.232\" style=\"stroke: #223344; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">s</tspan><tspan x=\"-79.951171875\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">t</tspan><tspan x=\"-68.837890625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\"> </tspan><tspan x=\"-58.837890625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">f</tspan><tspan x=\"-45.517578125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">o</tspan><tspan x=\"-25.517578125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">o</tspan><tspan x=\"-5.517578125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\"> </tspan><tspan x=\"4.482421875\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">b</tspan><tspan x=\"24.482421875\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">a</tspan><tspan x=\"42.236328125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">r</tspan><tspan x=\"55.556640625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">-</tspan><tspan x=\"68.876953125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">b</tspan><tspan x=\"88.876953125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">a</tspan><tspan x=\"106.630859375\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">z</tspan><tspan x=\"-124.38\" y=\"35.2\" fill=\"rgb(0,0,0)\">qux</tspan></text>\n\t</g>\n'); | ||
equal(iText.toSVG(), '\t<g transform=\"translate(27.77 22.6)\">\n\t\t<text font-family=\"Times New Roman\" font-size=\"40\" font-weight=\"normal\" style=\"stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;\" >\n\t\t\t<tspan x=\"-27.77\" y=\"12.6\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(17,34,51); fill-rule: ; opacity: 1;\">t</tspan>\n\t\t\t<tspan x=\"-16.66\" y=\"12.6\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">e</tspan>\n\t\t\t<tspan x=\"1.09\" y=\"12.6\" style=\"stroke: rgb(34,51,68); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">s</tspan>\n\t\t\t<tspan x=\"16.66\" y=\"12.6\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">t</tspan>\n\t\t</text>\n\t</g>\n'); | ||
} | ||
// TODO: more SVG tests here? | ||
@@ -754,9 +751,15 @@ }); | ||
equal(typeof iText.toSVG, 'function'); | ||
// because translate values differ | ||
if (!fabric.isLikelyNode) { | ||
equal(canvas.toSVG(), '\t<g transform=\"translate(124.88 52.93)\">\n\t\t<text font-family=\"Times New Roman\" font-size=\"40\" font-weight=\"normal\" style=\"stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;\" ><tspan x=\"-124.384765625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: #112233; fill-rule: ; opacity: 1;\">t</tspan><tspan x=\"-113.271484375\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">e</tspan><tspan x=\"-95.517578125\" y=\"-17.232\" style=\"stroke: #223344; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">s</tspan><tspan x=\"-79.951171875\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">t</tspan><tspan x=\"-68.837890625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\"> </tspan><tspan x=\"-58.837890625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">f</tspan><tspan x=\"-45.517578125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">o</tspan><tspan x=\"-25.517578125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">o</tspan><tspan x=\"-5.517578125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\"> </tspan><tspan x=\"4.482421875\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">b</tspan><tspan x=\"24.482421875\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">a</tspan><tspan x=\"42.236328125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">r</tspan><tspan x=\"55.556640625\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">-</tspan><tspan x=\"68.876953125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">b</tspan><tspan x=\"88.876953125\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">a</tspan><tspan x=\"106.630859375\" y=\"-17.232\" style=\"stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: ; opacity: 1;\">z</tspan><tspan x=\"-124.38\" y=\"35.2\" fill=\"rgb(0,0,0)\">qux</tspan></text>\n\t</g>\n'); | ||
var parser; | ||
if (fabric.isLikelyNode) { | ||
var XmlDomParser = require('xmldom').DOMParser; | ||
parser = new XmlDomParser(); | ||
} | ||
else { | ||
parser = new DOMParser(); | ||
} | ||
var svgString = canvas.toSVG(), | ||
doc = parser.parseFromString(svgString, "image/svg+xml"), | ||
style = doc.getElementsByTagName('style')[0].firstChild.data; | ||
equal(style, '\n\t\t@font-face {\n\t\t\tfont-family: \'Plaster\';\n\t\t\tsrc: url(\'path-to-plaster-font-file\');\n\t\t}\n\t\t@font-face {\n\t\t\tfont-family: \'Engagement\';\n\t\t\tsrc: url(\'path-to-engagement-font-file\');\n\t\t}\n'); | ||
}); | ||
})(); |
(function() { | ||
var rectOptions = { | ||
@@ -16,3 +16,3 @@ 'originX': 'left', | ||
}; | ||
QUnit.module('fabric.ObjectOrigins'); | ||
@@ -34,2 +34,5 @@ | ||
p = rect.translateToCenterPoint(point, 'center', 'center'); | ||
deepEqual(p, new fabric.Point(15, 20)); | ||
p = rect.translateToCenterPoint(point, 'center', 'top'); | ||
@@ -74,12 +77,12 @@ deepEqual(p, new fabric.Point(15, 62)); | ||
deepEqual(p, new fabric.Point(39.090210326743936, -14.404385860137658)); | ||
p = rect.translateToCenterPoint(point, 'left', 'center'); | ||
deepEqual(p, new fabric.Point(33.02134497435782, 32.61868159972301)); | ||
p = rect.translateToCenterPoint(point, 'left', 'top'); | ||
deepEqual(p, new fabric.Point(8.931134647613884, 67.02306745986067)); | ||
p = rect.translateToCenterPoint(point, 'left', 'bottom'); | ||
deepEqual(p, new fabric.Point(57.11155530110176, -1.7857042604146471)); | ||
p = rect.translateToCenterPoint(point, 'right', 'center'); | ||
@@ -299,3 +302,3 @@ deepEqual(p, new fabric.Point(-3.0213449743578202, 7.381318400276987)); | ||
p; | ||
rect.angle = 35; | ||
@@ -355,2 +358,331 @@ rect.strokeWidth = 0; | ||
test('translateToCenterPoint with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p, | ||
point = new fabric.Point(15, 20); | ||
p = rect.translateToCenterPoint(point, 0.5, 0.5); | ||
deepEqual(p, new fabric.Point(15, 20)); | ||
p = rect.translateToCenterPoint(point, 0.5, 0.5); | ||
deepEqual(p, new fabric.Point(15, 20)); | ||
p = rect.translateToCenterPoint(point, 0.5, 0); | ||
deepEqual(p, new fabric.Point(15, 62)); | ||
p = rect.translateToCenterPoint(point, 0.5, 1); | ||
deepEqual(p, new fabric.Point(15, -22)); | ||
p = rect.translateToCenterPoint(point, 0, 0.5); | ||
deepEqual(p, new fabric.Point(37, 20)); | ||
p = rect.translateToCenterPoint(point, 0, 0); | ||
deepEqual(p, new fabric.Point(37, 62)); | ||
p = rect.translateToCenterPoint(point, 0, 1); | ||
deepEqual(p, new fabric.Point(37, -22)); | ||
p = rect.translateToCenterPoint(point, 1, 0.5); | ||
deepEqual(p, new fabric.Point(-7, 20)); | ||
p = rect.translateToCenterPoint(point, 1, 0); | ||
deepEqual(p, new fabric.Point(-7, 62)); | ||
p = rect.translateToCenterPoint(point, 1, 1); | ||
deepEqual(p, new fabric.Point(-7, -22)); | ||
}); | ||
test('translateToCenterPointRotated with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p, | ||
point = new fabric.Point(15, 20); | ||
rect.angle = 35; | ||
p = rect.translateToCenterPoint(point, 0.5, 0.5); | ||
deepEqual(p, new fabric.Point(15, 20)); | ||
p = rect.translateToCenterPoint(point, 0.5, 0); | ||
deepEqual(p, new fabric.Point(-9.090210326743936, 54.40438586013766)); | ||
p = rect.translateToCenterPoint(point, 0.5, 1); | ||
deepEqual(p, new fabric.Point(39.090210326743936, -14.404385860137658)); | ||
p = rect.translateToCenterPoint(point, 0, 0.5); | ||
deepEqual(p, new fabric.Point(33.02134497435782, 32.61868159972301)); | ||
p = rect.translateToCenterPoint(point, 0, 0); | ||
deepEqual(p, new fabric.Point(8.931134647613884, 67.02306745986067)); | ||
p = rect.translateToCenterPoint(point, 0, 1); | ||
deepEqual(p, new fabric.Point(57.11155530110176, -1.7857042604146471)); | ||
p = rect.translateToCenterPoint(point, 1, 0.5); | ||
deepEqual(p, new fabric.Point(-3.0213449743578202, 7.381318400276987)); | ||
p = rect.translateToCenterPoint(point, 1, 0); | ||
deepEqual(p, new fabric.Point(-27.11155530110176, 41.78570426041465)); | ||
p = rect.translateToCenterPoint(point, 1, 1); | ||
deepEqual(p, new fabric.Point(21.068865352386116, -27.02306745986067)); | ||
}); | ||
test('translateToOriginPoint with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p, | ||
point = new fabric.Point(15, 20); | ||
p = rect.translateToOriginPoint(point, 0.5, 0.5); | ||
deepEqual(p, new fabric.Point(15, 20)); | ||
p = rect.translateToOriginPoint(point, 0.5, 0); | ||
deepEqual(p, new fabric.Point(15, -22)); | ||
p = rect.translateToOriginPoint(point, 0.5, 1); | ||
deepEqual(p, new fabric.Point(15, 62)); | ||
p = rect.translateToOriginPoint(point, 0, 0.5); | ||
deepEqual(p, new fabric.Point(-7, 20)); | ||
p = rect.translateToOriginPoint(point, 0, 0); | ||
deepEqual(p, new fabric.Point(-7, -22)); | ||
p = rect.translateToOriginPoint(point, 0, 1); | ||
deepEqual(p, new fabric.Point(-7, 62)); | ||
p = rect.translateToOriginPoint(point, 1, 0.5); | ||
deepEqual(p, new fabric.Point(37, 20)); | ||
p = rect.translateToOriginPoint(point, 1, 0); | ||
deepEqual(p, new fabric.Point(37, -22)); | ||
p = rect.translateToOriginPoint(point, 1, 1); | ||
deepEqual(p, new fabric.Point(37, 62)); | ||
}); | ||
test('translateToOriginPointRotated with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p, | ||
point = new fabric.Point(15, 20); | ||
rect.angle = 35; | ||
p = rect.translateToOriginPoint(point, 0.5, 0.5); | ||
deepEqual(p, new fabric.Point(15, 20)); | ||
p = rect.translateToOriginPoint(point, 0.5, 0); | ||
deepEqual(p, new fabric.Point(39.090210326743936, -14.404385860137658)); | ||
p = rect.translateToOriginPoint(point, 0.5, 1); | ||
deepEqual(p, new fabric.Point(-9.090210326743936, 54.40438586013766)); | ||
p = rect.translateToOriginPoint(point, 0, 0.5); | ||
deepEqual(p, new fabric.Point(-3.0213449743578202, 7.381318400276987)); | ||
p = rect.translateToOriginPoint(point, 0, 0); | ||
deepEqual(p, new fabric.Point(21.068865352386116, -27.02306745986067)); | ||
p = rect.translateToOriginPoint(point, 0, 1); | ||
deepEqual(p, new fabric.Point(-27.11155530110176, 41.78570426041465)); | ||
p = rect.translateToOriginPoint(point, 1, 0.5); | ||
deepEqual(p, new fabric.Point(33.02134497435782, 32.61868159972301)); | ||
p = rect.translateToOriginPoint(point, 1, 0); | ||
deepEqual(p, new fabric.Point(57.11155530110176, -1.7857042604146471)); | ||
p = rect.translateToOriginPoint(point, 1, 1); | ||
deepEqual(p, new fabric.Point(8.931134647613884, 67.02306745986067)); | ||
}); | ||
test('toLocalPoint with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p, | ||
point = new fabric.Point(15, 20); | ||
p = rect.toLocalPoint(point, 0.5, 0.5); | ||
deepEqual(p, new fabric.Point(-42, -67)); | ||
p = rect.toLocalPoint(point, 0.5, 0); | ||
deepEqual(p, new fabric.Point(-42, -25)); | ||
p = rect.toLocalPoint(point, 0.5, 1); | ||
deepEqual(p, new fabric.Point(-42, -109)); | ||
p = rect.toLocalPoint(point, 0, 0.5); | ||
deepEqual(p, new fabric.Point(-20, -67)); | ||
p = rect.toLocalPoint(point, 0, 0); | ||
deepEqual(p, new fabric.Point(-20, -25)); | ||
p = rect.toLocalPoint(point, 0, 1); | ||
deepEqual(p, new fabric.Point(-20, -109)); | ||
p = rect.toLocalPoint(point, 1, 0.5); | ||
deepEqual(p, new fabric.Point(-64, -67)); | ||
p = rect.toLocalPoint(point, 1, 0); | ||
deepEqual(p, new fabric.Point(-64, -25)); | ||
p = rect.toLocalPoint(point, 1, 1); | ||
deepEqual(p, new fabric.Point(-64, -109)); | ||
p = rect.toLocalPoint(point); | ||
deepEqual(p, new fabric.Point(-20, -25)); | ||
}); | ||
test('toLocalPointRotated with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p, | ||
point = new fabric.Point(15, 20); | ||
rect.angle = 35; | ||
p = rect.toLocalPoint(point, 0.5, 0.5); | ||
deepEqual(p, new fabric.Point(-52.72245179455599, -51.00727238020387)); | ||
p = rect.toLocalPoint(point, 0.5, 0); | ||
deepEqual(p, new fabric.Point(-52.72245179455599, -9.007272380203872)); | ||
p = rect.toLocalPoint(point, 0.5, 1); | ||
deepEqual(p, new fabric.Point(-52.72245179455599, -93.00727238020387)); | ||
p = rect.toLocalPoint(point, 0, 0.5); | ||
deepEqual(p, new fabric.Point(-30.722451794555987, -51.00727238020387)); | ||
p = rect.toLocalPoint(point, 0, 0); | ||
deepEqual(p, new fabric.Point(-30.722451794555987, -9.007272380203872)); | ||
p = rect.toLocalPoint(point, 0, 1); | ||
deepEqual(p, new fabric.Point(-30.722451794555987, -93.00727238020387)); | ||
p = rect.toLocalPoint(point, 1, 0.5); | ||
deepEqual(p, new fabric.Point(-74.722451794556, -51.00727238020387)); | ||
p = rect.toLocalPoint(point, 1, 0); | ||
deepEqual(p, new fabric.Point(-74.722451794556, -9.007272380203872)); | ||
p = rect.toLocalPoint(point, 1, 1); | ||
deepEqual(p, new fabric.Point(-74.722451794556, -93.00727238020387)); | ||
p = rect.toLocalPoint(point); | ||
deepEqual(p, new fabric.Point(-58.791317146942106, -3.9842049203432026)); | ||
}); | ||
test('adjustPosition with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p; | ||
rect.strokeWidth = 0; | ||
rect.originX = 'left'; | ||
rect.originY = 'top'; | ||
p = rect.adjustPosition(0); | ||
deepEqual(rect.left, 35); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 0); | ||
p = rect.adjustPosition(0.5); | ||
deepEqual(rect.left, 55); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 0.5); | ||
p = rect.adjustPosition(1); | ||
deepEqual(rect.left, 75); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 1); | ||
rect.originX = 0.5; | ||
rect.originY = 0.5; | ||
p = rect.adjustPosition(0); | ||
deepEqual(rect.left, 55); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 0); | ||
p = rect.adjustPosition(0.5); | ||
deepEqual(rect.left, 75); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 0.5); | ||
p = rect.adjustPosition(1); | ||
deepEqual(rect.left, 95); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 1); | ||
rect.originX = 1; | ||
rect.originY = 1; | ||
p = rect.adjustPosition(0); | ||
deepEqual(rect.left, 55); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 0); | ||
p = rect.adjustPosition(0.5); | ||
deepEqual(rect.left, 75); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 0.5); | ||
p = rect.adjustPosition(1); | ||
deepEqual(rect.left, 95); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 1); | ||
}); | ||
test('adjustPositionRotated with numeric origins', function(){ | ||
var rect = new fabric.Rect(rectOptions), | ||
p; | ||
rect.angle = 35; | ||
rect.strokeWidth = 0; | ||
rect.originX = 0; | ||
rect.originY = 0; | ||
p = rect.adjustPosition(0); | ||
deepEqual(rect.left, 35); | ||
deepEqual(rect.top, 45); | ||
equal(rect.originX, 0); | ||
p = rect.adjustPosition(0.5); | ||
deepEqual(rect.left, 51.383040885779835); | ||
deepEqual(rect.top, 56.471528727020925); | ||
equal(rect.originX, 0.5); | ||
p = rect.adjustPosition(1); | ||
deepEqual(rect.left, 67.76608177155967); | ||
deepEqual(rect.top, 67.94305745404185); | ||
equal(rect.originX, 1); | ||
rect.originX = 0.5; | ||
rect.originY = 0.5; | ||
p = rect.adjustPosition(0); | ||
deepEqual(rect.left, 51.383040885779835); | ||
deepEqual(rect.top, 56.471528727020925); | ||
equal(rect.originX, 0); | ||
p = rect.adjustPosition(0.5); | ||
deepEqual(rect.left, 67.76608177155967); | ||
deepEqual(rect.top, 67.94305745404185); | ||
equal(rect.originX, 0.5); | ||
p = rect.adjustPosition(1); | ||
deepEqual(rect.left, 84.1491226573395); | ||
deepEqual(rect.top, 79.41458618106277); | ||
equal(rect.originX, 1); | ||
rect.originX = 1; | ||
rect.originY = 1; | ||
p = rect.adjustPosition(0); | ||
deepEqual(rect.left, 51.383040885779835); | ||
deepEqual(rect.top, 56.47152872702093); | ||
equal(rect.originX, 0); | ||
p = rect.adjustPosition(0.5); | ||
deepEqual(rect.left, 67.76608177155967); | ||
deepEqual(rect.top, 67.94305745404185); | ||
equal(rect.originX, 0.5); | ||
p = rect.adjustPosition(1); | ||
deepEqual(rect.left, 84.1491226573395); | ||
deepEqual(rect.top, 79.41458618106277); | ||
equal(rect.originX, 1); | ||
}); | ||
})(); |
@@ -569,3 +569,3 @@ (function(){ | ||
asyncTest('cloneAsImage', function() { | ||
var cObj = new fabric.Rect({ width: 100, height: 100, fill: 'red' }); | ||
var cObj = new fabric.Rect({ width: 100, height: 100, fill: 'red', strokeWidth: 0 }); | ||
@@ -584,2 +584,3 @@ ok(typeof cObj.cloneAsImage == 'function'); | ||
ok(image instanceof fabric.Image); | ||
equal(image.width, 100, 'the image has same dimension of object'); | ||
start(); | ||
@@ -594,2 +595,26 @@ }, 500); | ||
asyncTest('cloneAsImage with retina scaling enabled', function() { | ||
var cObj = new fabric.Rect({ width: 100, height: 100, fill: 'red', strokeWidth: 0 }); | ||
fabric.devicePixelRatio = 2; | ||
if (!fabric.Canvas.supports('toDataURL')) { | ||
fabric.log('`toDataURL` is not supported by this environment; skipping `cloneAsImage` test (as it relies on `toDataURL`)'); | ||
start(); | ||
} | ||
else { | ||
var image; | ||
setTimeout(function() { | ||
ok(image); | ||
ok(image instanceof fabric.Image); | ||
equal(image.width, 200, 'the image has been scaled by retina'); | ||
fabric.devicePixelRatio = 1; | ||
start(); | ||
}, 500); | ||
cObj.cloneAsImage(function(i) { | ||
image = i; | ||
}, { enableRetinaScaling: true }); | ||
} | ||
}); | ||
test('toDataURL', function() { | ||
@@ -607,3 +632,3 @@ // var data = | ||
var cObj = new fabric.Rect({ | ||
width: 100, height: 100, fill: 'red' | ||
width: 100, height: 100, fill: 'red', strokeWidth: 0 | ||
}); | ||
@@ -1434,2 +1459,52 @@ | ||
test('getObjectScale', function() { | ||
var object = new fabric.Object({ scaleX: 3, scaleY : 2}); | ||
var objectScale = object.getObjectScaling(); | ||
deepEqual(objectScale, {scaleX: object.scaleX, scaleY: object.scaleY}); | ||
}); | ||
test('getObjectScale in group', function() { | ||
var object = new fabric.Object({ scaleX: 3, scaleY : 2}); | ||
var group = new fabric.Group(); | ||
group.scaleX = 2; | ||
group.scaleY = 2; | ||
object.group = group; | ||
var objectScale = object.getObjectScaling(); | ||
deepEqual(objectScale, { | ||
scaleX: object.scaleX * group.scaleX, | ||
scaleY: object.scaleY * group.scaleY | ||
}); | ||
}); | ||
test('_setShadow', function(){ | ||
var el = fabric.document.createElement('canvas'); | ||
el.width = 600; el.height = 600; | ||
var canvas = fabric.isLikelyNode ? fabric.createCanvasForNode() : new fabric.StaticCanvas(el); | ||
var context = canvas.contextContainer; | ||
var object = new fabric.Object({ scaleX: 1, scaleY : 1}); | ||
var group = new fabric.Group(); | ||
group.scaleX = 2; | ||
group.scaleY = 2; | ||
object.setShadow({ | ||
color: 'red', | ||
blur: 10, | ||
offsetX: 5, | ||
offsetY: 15 | ||
}); | ||
object._setShadow(context); | ||
equal(context.shadowOffsetX, object.shadow.offsetX); | ||
equal(context.shadowOffsetY, object.shadow.offsetY); | ||
equal(context.shadowBlur, object.shadow.blur); | ||
object.scaleX = 2; | ||
object.scaleY = 3; | ||
object._setShadow(context); | ||
equal(context.shadowOffsetX, object.shadow.offsetX * object.scaleX); | ||
equal(context.shadowOffsetY, object.shadow.offsetY * object.scaleY); | ||
equal(context.shadowBlur, object.shadow.blur * (object.scaleX + object.scaleY) / 2); | ||
object.group = group; | ||
object._setShadow(context); | ||
equal(context.shadowOffsetX, object.shadow.offsetX * object.scaleX * group.scaleX); | ||
equal(context.shadowOffsetY, object.shadow.offsetY * object.scaleY * group.scaleY); | ||
equal(context.shadowBlur, object.shadow.blur * (object.scaleX * group.scaleX + object.scaleY * group.scaleY) / 2); | ||
}); | ||
})(); |
@@ -346,8 +346,21 @@ (function(){ | ||
rect = objects[0]; | ||
ok(rect instanceof fabric.Rect); | ||
start(); | ||
}); | ||
setTimeout(function() { | ||
}); | ||
asyncTest('parseSVGFromString with svg:namespace', function() { | ||
var string = '<?xml version="1.0" standalone="no"?><svg width="100%" height="100%" version="1.1" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' + | ||
'<svg:defs><svg:rect id="myrect" width="300" height="100" style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/></svg:defs>' + | ||
'<svg:use xlink:href="#myrect" x="50" y="50" ></svg:use>' + | ||
'</svg>', | ||
rect; | ||
ok(fabric.loadSVGFromString); | ||
fabric.loadSVGFromString(string, function(objects) { | ||
rect = objects[0]; | ||
ok(rect instanceof fabric.Rect); | ||
start(); | ||
}, 1000); | ||
}); | ||
}); | ||
@@ -550,2 +563,32 @@ | ||
test('getCssRule with same selectors', function() { | ||
ok(fabric.getCSSRules); | ||
var doc = fabric.document, | ||
svgUid = 'uniqueId', | ||
styleElement = doc.createElement('style'); | ||
styleElement.textContent = '.cls1,.cls2 { fill: #FF0000;} .cls1 { stroke: #00FF00;} .cls3,.cls1 { stroke-width: 3;}'; | ||
doc.body.appendChild(styleElement); | ||
var expectedObject = { | ||
'.cls1': { | ||
'fill': '#FF0000', | ||
'stroke': '#00FF00', | ||
'strokeWidth': 3 | ||
}, | ||
'.cls2': { | ||
'fill': '#FF0000' | ||
}, | ||
'.cls3': { | ||
'strokeWidth': 3 | ||
} | ||
}; | ||
fabric.cssRules[svgUid] = fabric.getCSSRules(doc); | ||
deepEqual(fabric.cssRules[svgUid], expectedObject); | ||
}); | ||
})(); |
@@ -49,3 +49,4 @@ (function() { | ||
'skewY': 0, | ||
'transformMatrix': null | ||
'transformMatrix': null, | ||
'charSpacing': 0 | ||
}; | ||
@@ -74,2 +75,16 @@ | ||
test('_getFontDeclaration', function() { | ||
var text = createTextObject(); | ||
ok(typeof text._getFontDeclaration == 'function', 'has a private method _getFontDeclaration'); | ||
var fontDecl = text._getFontDeclaration(); | ||
ok(typeof fontDecl == 'string', 'it returns a string'); | ||
if (fabric.isLikelyNode) { | ||
equal(fontDecl, 'normal 40px "Times New Roman"'); | ||
} | ||
else { | ||
equal(fontDecl, ' normal 40px "Times New Roman"'); | ||
} | ||
}); | ||
test('toObject', function() { | ||
@@ -76,0 +91,0 @@ var text = createTextObject(); |
@@ -844,2 +844,117 @@ (function() { | ||
test('clearFabricFontCache', function() { | ||
ok(typeof fabric.util.clearFabricFontCache == 'function'); | ||
fabric.charWidthsCache = { arial : { some: 'cache'}, helvetica : { some: 'cache'} }; | ||
fabric.util.clearFabricFontCache('arial'); | ||
equal(fabric.charWidthsCache.arial, undefined, 'arial cache is deleted'); | ||
equal(fabric.charWidthsCache.helvetica.some, 'cache', 'helvetica cache is still available'); | ||
fabric.util.clearFabricFontCache(); | ||
deepEqual(fabric.charWidthsCache, { }, 'all cache is deleted'); | ||
}); | ||
test('parsePreserveAspectRatioAttribute', function() { | ||
ok(typeof fabric.util.parsePreserveAspectRatioAttribute == 'function'); | ||
var parsed; | ||
parsed = fabric.util.parsePreserveAspectRatioAttribute("none"); | ||
equal(parsed.meetOrSlice, 'meet'); | ||
equal(parsed.alignX, 'none'); | ||
equal(parsed.alignY, 'none'); | ||
parsed = fabric.util.parsePreserveAspectRatioAttribute("none slice"); | ||
equal(parsed.meetOrSlice, 'slice'); | ||
equal(parsed.alignX, 'none'); | ||
equal(parsed.alignY, 'none'); | ||
parsed = fabric.util.parsePreserveAspectRatioAttribute("XmidYmax meet"); | ||
equal(parsed.meetOrSlice, 'meet'); | ||
equal(parsed.alignX, 'mid'); | ||
equal(parsed.alignY, 'max'); | ||
}); | ||
test('multiplyTransformMatrices', function() { | ||
ok(typeof fabric.util.multiplyTransformMatrices == 'function'); | ||
var m1 = [1, 1, 1, 1, 1, 1], m2 = [1, 1, 1, 1, 1, 1], m3; | ||
m3 = fabric.util.multiplyTransformMatrices(m1, m2); | ||
deepEqual(m3, [2, 2, 2, 2, 3, 3]); | ||
m3 = fabric.util.multiplyTransformMatrices(m1, m2, true); | ||
deepEqual(m3, [2, 2, 2, 2, 0, 0]); | ||
}); | ||
test('customTransformMatrix', function() { | ||
ok(typeof fabric.util.customTransformMatrix == 'function'); | ||
var m1 = fabric.util.customTransformMatrix(5, 4, 45); | ||
deepEqual(m1, [5, 0, 4.999999999999999, 4, 0, 0]); | ||
}); | ||
test('resetObjectTransform', function() { | ||
ok(typeof fabric.util.resetObjectTransform == 'function'); | ||
var rect = new fabric.Rect({ | ||
top:1, | ||
width: 100, | ||
height: 100, | ||
angle: 30, | ||
scaleX: 2, | ||
scaleY: 1, | ||
flipX: true, | ||
flipY : true, | ||
skewX: 30, | ||
skewY: 30 | ||
}); | ||
equal(rect.skewX, 30); | ||
equal(rect.skewY, 30); | ||
equal(rect.scaleX, 2); | ||
equal(rect.scaleY, 1); | ||
equal(rect.flipX, true); | ||
equal(rect.flipY, true); | ||
equal(rect.angle, 30); | ||
fabric.util.resetObjectTransform(rect); | ||
equal(rect.skewX, 0); | ||
equal(rect.skewY, 0); | ||
equal(rect.scaleX, 1); | ||
equal(rect.scaleY, 1); | ||
equal(rect.flipX, false); | ||
equal(rect.flipY, false); | ||
equal(rect.angle, 0); | ||
}); | ||
test('invertTransform', function() { | ||
ok(typeof fabric.util.invertTransform == 'function'); | ||
var m1 = [1, 2, 3, 4, 5, 6], m3; | ||
m3 = fabric.util.invertTransform(m1); | ||
deepEqual(m3, [-2, 1, 1.5, -0.5, 1, -2]); | ||
}); | ||
test('rotateVector', function() { | ||
ok(typeof fabric.util.rotateVector == 'function'); | ||
}); | ||
test('rotatePoint', function() { | ||
ok(typeof fabric.util.rotatePoint == 'function'); | ||
}); | ||
test('transformPoint', function() { | ||
ok(typeof fabric.util.transformPoint == 'function'); | ||
}); | ||
test('makeBoundingBoxFromPoints', function() { | ||
ok(typeof fabric.util.makeBoundingBoxFromPoints == 'function'); | ||
}); | ||
test('parseUnit', function() { | ||
ok(typeof fabric.util.parseUnit == 'function'); | ||
}); | ||
test('createCanvasElement', function() { | ||
ok(typeof fabric.util.createCanvasElement == 'function'); | ||
}); | ||
test('createImage', function() { | ||
ok(typeof fabric.util.createImage == 'function'); | ||
}); | ||
test('createAccessors', function() { | ||
ok(typeof fabric.util.createAccessors == 'function'); | ||
}); | ||
test('qrDecompose', function() { | ||
ok(typeof fabric.util.qrDecompose == 'function'); | ||
}); | ||
})(); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11051856
70
53984
10