This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Fix shapeCSS function and update version
- Loading branch information
1 parent
805ac8c
commit 2525348
Showing
11 changed files
with
171 additions
and
19 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function CSSShape(style) { | ||
var self = this, | ||
style = config.virtualStyles[style]; | ||
|
||
if (!style) | ||
return self; | ||
|
||
// TODO: Draw in all canvas | ||
var data = '<svg xmlns="http://www.w3.org/2000/svg" width="' + | ||
self.paper.width + 'px" height="' + self.paper.height + 'px">' + | ||
'<foreignObject width="100%" height="100%">' + | ||
'<div xmlns="http://www.w3.org/1999/xhtml">' + | ||
'<div style="' + style.cssText + '"></div>' + | ||
'</div></foreignObject>' + | ||
'</svg>'; | ||
|
||
var DOMURL = window.URL || window.webkitURL || window, | ||
img = new Image(), | ||
svg = new Blob([data], { | ||
type: 'image/svg+xml;charset=utf-8' | ||
}); | ||
|
||
var url = DOMURL.createObjectURL(svg); | ||
img.src = url; | ||
|
||
img.addEventListener('load', function() { | ||
self.paper.ctx.beginPath(); | ||
self.paper.ctx.drawImage(img, 0, 0); | ||
DOMURL.revokeObjectURL(url); | ||
self.paper.ctx.closePath(); | ||
}); | ||
|
||
return self; | ||
} | ||
|
||
Screen.prototype.CSSShape = CSSShape; | ||
|
||
Origami.shape = function(style) { | ||
queue('CSSShape', style); | ||
return this; | ||
}; |
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,8 @@ | ||
.red-square { | ||
position: absolute; | ||
top: 50px; | ||
left: 50px; | ||
width: 100px; | ||
height: 100px; | ||
background: red; | ||
} |
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,55 @@ | ||
describe("Test CSSShape drawing - CSS to Canvas", function() { | ||
|
||
// Simple CSS "pacman" | ||
context('Simple Shapes', function() { | ||
beforeEach(function() { | ||
var canvas = document.createElement("canvas"); | ||
canvas.id = 'canvas1'; | ||
canvas.width = 500; | ||
canvas.height = 500; | ||
document.body.appendChild(canvas); | ||
|
||
var canvasMock = document.createElement("canvas"); | ||
canvasMock.id = 'canvas2'; | ||
canvasMock.width = 500; | ||
canvasMock.height = 500; | ||
document.body.appendChild(canvasMock); | ||
}); | ||
|
||
afterEach(function() { | ||
document.body.removeChild(document.querySelector('#canvas1')); | ||
document.body.removeChild(document.querySelector('#canvas2')); | ||
origami.cleanContexts(); | ||
}); | ||
|
||
context('using red square css class', function() { | ||
it("should create a red square in canvas", function(done) { | ||
var canvas1 = document.querySelector('#canvas1'), | ||
canvas2 = document.querySelector('#canvas2'); | ||
|
||
// Drawing | ||
this.timeout(5000); | ||
|
||
origami('#canvas1') | ||
.styles('.red-square') | ||
.shape('.red-square') | ||
.draw(); | ||
|
||
var ctx2 = canvas2.getContext('2d'); | ||
ctx2.beginPath(); | ||
ctx2.setLineDash([]); | ||
ctx2.fillStyle = 'red'; | ||
ctx2.fillRect(50, 50, 100, 100); | ||
ctx2.setLineDash([]); | ||
ctx2.closePath(); | ||
|
||
setTimeout(function() { | ||
var isEqual = imagediff.equal(canvas1, canvas2); | ||
expect(isEqual).to.eql(true); | ||
|
||
done(); | ||
}, 600); | ||
}); | ||
}); | ||
}); | ||
}); |
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