forked from fabricjs/fabric.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shadow option to toDataURL and cloneAsImage (fabricjs#5308)
* first test * less accuracy
- Loading branch information
Showing
7 changed files
with
140 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
(function() { | ||
if ((fabric.isLikelyNode && process.env.launcher === 'Firefox') || navigator.userAgent.indexOf('Firefox') !== -1) { | ||
fabric.browserShadowBlurConstant = 0.9; | ||
} | ||
if ((fabric.isLikelyNode && process.env.launcher === 'Node')) { | ||
fabric.browserShadowBlurConstant = 1; | ||
} | ||
if ((fabric.isLikelyNode && process.env.launcher === 'Chrome') || navigator.userAgent.indexOf('Chrome') !== -1) { | ||
fabric.browserShadowBlurConstant = 1.5; | ||
} | ||
if ((fabric.isLikelyNode && process.env.launcher === 'Edge') || navigator.userAgent.indexOf('Edge') !== -1) { | ||
fabric.browserShadowBlurConstant = 1.75; | ||
} | ||
fabric.enableGLFiltering = false; | ||
fabric.isWebglSupported = false; | ||
fabric.Object.prototype.objectCaching = true; | ||
var visualTestLoop; | ||
if (fabric.isLikelyNode) { | ||
visualTestLoop = global.visualTestLoop; | ||
} | ||
else { | ||
visualTestLoop = window.visualTestLoop; | ||
} | ||
var fabricCanvas = this.canvas = new fabric.Canvas(null, { | ||
enableRetinaScaling: false, renderOnAddRemove: false, width: 200, height: 200, | ||
}); | ||
|
||
var tests = []; | ||
|
||
function toDataURL1(canvas, callback) { | ||
var text = new fabric.Text('Hi i m an image', | ||
{ strokeWidth: 2, stroke: 'red', fontSize: 60, objectCaching: false } | ||
); | ||
callback(text.toDataURL()); | ||
} | ||
|
||
tests.push({ | ||
test: 'Text to DataURL', | ||
code: toDataURL1, | ||
golden: 'dataurl1.png', | ||
newModule: 'DataURL exports', | ||
percentage: 0.09, | ||
}); | ||
|
||
function toDataURL2(canvas, callback) { | ||
var text = new fabric.Text('Hi i m an image', | ||
{ strokeWidth: 0, fontSize: 60, objectCaching: false } | ||
); | ||
var shadow = new fabric.Shadow({ | ||
color: 'purple', | ||
offsetX: 0, | ||
offsetY: 0, | ||
blur: 6, | ||
}); | ||
text.shadow = shadow; | ||
callback(text.toDataURL()); | ||
} | ||
|
||
tests.push({ | ||
test: 'Text to DataURL with shadow no offset', | ||
code: toDataURL2, | ||
golden: 'dataurl2.png', | ||
percentage: 0.09, | ||
}); | ||
|
||
function toDataURL3(canvas, callback) { | ||
var text = new fabric.Text('Hi i m an image', | ||
{ strokeWidth: 0, fontSize: 60, objectCaching: false } | ||
); | ||
var shadow = new fabric.Shadow({ | ||
color: 'purple', | ||
offsetX: -30, | ||
offsetY: +40, | ||
blur: 10, | ||
}); | ||
text.shadow = shadow; | ||
callback(text.toDataURL()); | ||
} | ||
|
||
tests.push({ | ||
test: 'Text to DataURL with shadow large offset', | ||
code: toDataURL3, | ||
golden: 'dataurl3.png', | ||
percentage: 0.09, | ||
}); | ||
|
||
function testWrapper(test) { | ||
var actualTest = test.code; | ||
test.code = function(canvas, callback) { | ||
actualTest(canvas, function(dataURL) { | ||
var img = fabric.document.createElement('img'); | ||
var canvas = fabric.document.createElement('canvas'); | ||
img.onload = function() { | ||
canvas.width = img.width; | ||
canvas.height = img.height; | ||
canvas.getContext('2d').drawImage(img, 0, 0); | ||
callback(canvas); | ||
}; | ||
img.src = dataURL; | ||
}); | ||
}; | ||
visualTestLoop(fabricCanvas, QUnit)(test); | ||
} | ||
|
||
tests.forEach(testWrapper); | ||
})(); |