Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/tassotirap/ink2canvas

Conflicts:
	.gitignore
  • Loading branch information...
commit 39c3a27fa2248c814780964d3ed370c9caf7779e 2 parents 387adfd + 18a2865
@tassotirap tassotirap authored
View
5 .gitignore
@@ -1,4 +1,9 @@
+.gitignore
*.swp
*.swo
*.pyc
mockito/*
+.project
+.pydevproject
+.settings/org.eclipse.core.resources.prefs
+*~
View
1  .settings/org.eclipse.core.resources.prefs
@@ -1,5 +1,4 @@
eclipse.preferences.version=1
encoding//ink2canvas/canvas.py=utf-8
encoding//ink2canvas/main.py=utf-8
-encoding//ink2canvas/svg.py=utf-8
encoding/standalone.py=utf-8
View
2  ink2canvas/canvas.py
@@ -41,7 +41,7 @@ def output(self):
<!DOCTYPE html>
<html>
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Inkscape Output</title>
</head>
<body>
View
169 test/canvas_unit_test.py
@@ -151,7 +151,172 @@ def testArc(self):
def testArcWithNewCtx(self):
self.canvasWithContext.arc(1, 2, 3, 4, 5, 1)
self.assertEqual(self.canvasWithContext.code, ["\tfoo.arc(%f, %f, %f, %f, %.8f, %d);\n" % (1, 2, 3, 4, 5, 1)])
-
+
+ def testWriteCorrectInsertion(self):
+ text = "ctx.Texto"
+ self.canvas.write(text)
+ self.assertEqual(self.canvas.code[0], "\t" + text + "\n")
+
+ def testWriteCorrectInsertionWithNewCtx(self):
+ text = "ctx.Texto"
+ self.canvasWithContext.write(text)
+ self.assertEqual(self.canvasWithContext.code[0], "\t" + text.replace("ctx", self.canvasWithContext.obj) + "\n")
+
+ def testOutput(self):
+ from textwrap import dedent
+ output = self.canvas.output()
+ expected_output = """
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <title>Inkscape Output</title>
+ </head>
+ <body>
+ <canvas id='canvas' width='%d' height='%d'></canvas>
+ <script>
+ var %s = document.getElementById("canvas").getContext("2d");
+ %s
+ </script>
+ </body>
+ </html>
+ """
+ expected_output = dedent(expected_output) % (self.canvas.width, self.canvas.height, self.canvas.obj, "".join(self.canvas.code))
+ self.assertEqual(output, expected_output)
+
+ def testCreateLinearGradient(self):
+ href = "str"
+ x1, y1, x2, y2 = 0.0 , 2.0 , 3.0, 4.0
+ data = (href, x1, y1, x2, y2)
+ expectedList = ["\tvar %s = \
+ ctx.createLinearGradient(%f,%f,%f,%f);\n" % data]
+ self.canvas.createLinearGradient(href,x1, y1, x2, y2)
+ self.assertEqual(self.canvas.code, expectedList)
+
+ def testCreateRadialGradient(self):
+ href = "str"
+ cx1, cy1, rx, cx2, cy2, ry = 0.0 , 2.0, 3.0, 4.0, 5.0, 6.0
+ data = (href, cx1, cy1, rx, cx2, cy2, ry)
+ expectedList = ["\tvar %s = ctx.createRadialGradient\
+ (%f,%f,%f,%f,%f,%f);\n" % data]
+ self.canvas.createRadialGradient(href, cx1, cy1, rx, cx2, cy2, ry)
+ self.assertEqual(self.canvas.code, expectedList)
+
+ def testAddColorStop(self):
+ href, pos, color = "href" , 2.0, "color"
+ data = (href, pos, color)
+ expectedList = ["\t%s.addColorStop(%f, %s);\n" % data]
+ self.canvas.addColorStop(href, pos, color)
+ self.assertEqual(self.canvas.code, expectedList)
+
+ def testSetOpacity(self):
+ #Float Test
+ value = 2.5
+ expectedReturn = "\tctx.globalAlpha = %.1f;\n" % float(value)
+ self.canvas.setOpacity(value)
+ self.assertEqual(self.canvas.code[0], expectedReturn)
+
+ #Integer Test
+ value = 2
+ expectedReturn = "\tctx.globalAlpha = %.1f;\n" % float(value)
+ self.canvas.setOpacity(value)
+ self.assertEqual(self.canvas.code[1], expectedReturn)
+
+ def testSetFillNoOpacity(self):
+ value = "url()"
+ self.canvas.setFill(value)
+ self.assertEqual(self.canvas.code, [])
+
+ value = "0 0 255"
+ fill = self.canvas.getColor(value, 1)
+ self.canvas.setFill(value)
+ self.assertEqual(self.canvas.code[0], "\tctx.fillStyle = %s;\n" % fill)
+
+ value = "0 0 254"
+ fill = self.canvas.getColor(value, 1)
+ self.assertNotEqual(self.canvas.code[0], "\tctx.fillStyle = %s;\n" % fill)
+
+ def testSetFillWithOpacity(self):
+ self.canvas.style["fill-opacity"] = 0.5
+
+ value = "url()"
+ self.canvas.setFill(value)
+ self.assertEqual(self.canvas.code, [])
+
+ value = "0 0 255"
+ fill = self.canvas.getColor(value, 0.5)
+ self.canvas.setFill(value)
+ self.assertEqual(self.canvas.code[0], "\tctx.fillStyle = %s;\n" % fill)
+
+ value = "0 0 254"
+ fill = self.canvas.getColor(value, 0.5)
+ self.assertNotEqual(self.canvas.code[0], "\tctx.fillStyle = %s;\n" % fill)
+
+ def testSetStroke(self):
+ value = "0 0 255"
+ self.canvas.setStroke(value)
+ self.assertEqual(self.canvas.code[0], "\tctx.strokeStyle = %s;\n" % self.canvas.getColor(value, 1))
+
+ value = "0 0 254"
+ self.assertNotEqual(self.canvas.code[0], "\tctx.strokeStyle = %s;\n" % self.canvas.getColor(value, 1))
+
+ self.canvas.style["stroke-opacity"] = 0.5
+
+ value = "0 0 255"
+ self.canvas.setStroke(value)
+ self.assertEqual(self.canvas.code[1], "\tctx.strokeStyle = %s;\n" % self.canvas.getColor(value, 0.5))
+
+ value = "0 0 254"
+ self.assertNotEqual(self.canvas.code[0], "\tctx.strokeStyle = %s;\n" % self.canvas.getColor(value, 0.5))
+
+ def testSetFont(self):
+ value = "Fonte"
+ self.canvas.setFont(value)
+ self.assertEqual(self.canvas.code[0],"\tctx.font = \"%s\";\n" % value)
+
+ def testTranslate(self):
+ cx = cy = 1.0
+ self.canvas.write("ctx.translate(%f, %f);" % (cx, cy))
+ self.assertEqual(self.canvas.code[0],"\tctx.translate(%f, %f);\n" % (cx, cy))
+
+ def testRotate(self):
+ angle = 1.0
+ self.canvas.write("ctx.rotate(%f);" % angle)
+ self.assertEqual(self.canvas.code[0],"\tctx.rotate(%f);\n" % angle)
+
+ def testsScale(self):
+ rx, ry = 1.0, 2.0
+ self.canvas.write("ctx.scale(%f, %f);" % (rx, ry))
+ self.assertEqual(self.canvas.code[0],"\tctx.scale(%f, %f);\n" % (rx, ry))
+
+ def testsTransform(self):
+ m11, m12, m21, m22, dx, dy = 1.0, 2.0, 3.0, 4.0, 5.0, 6.0
+ self.canvas.write("ctx.transform(%f, %f, %f, %f, %f, %f);" % (m11, m12, m21, m22, dx, dy))
+ self.assertEqual(self.canvas.code[0],"\tctx.transform(%f, %f, %f, %f, %f, %f);\n" % (m11, m12, m21, m22, dx, dy))
+
+ def testRestore(self):
+ text = "ctx.restore();"
+ self.canvas.write(text)
+ self.assertEqual(self.canvas.code[0],"\t"+text+"\n")
+
+ def testClosePath(self):
+ text1, text2, text3 = "ctx.closePath();","ctx.fill();","ctx.stroke();"
+ self.canvas.closePath(False)
+ self.assertEquals(self.canvas.code, [])
+
+ self.canvas.style["fill"] = "none"
+ self.canvas.style["stroke"] = "none"
+ self.canvas.closePath(True)
+ self.assertEqual(self.canvas.code[0],"\t"+text1+"\n")
+
+ self.canvas.style["fill"] = "fill"
+ self.canvas.style["stroke"] = "stroke"
+ self.canvas.closePath(True)
+ self.assertEqual(self.canvas.code[1],"\t"+text1+"\n")
+ self.assertEqual(self.canvas.code[2],"\t"+text2+"\n")
+ self.assertEqual(self.canvas.code[3],"\t"+text3+"\n")
+
+
if __name__ == '__main__':
unittest.main()
-
+
Please sign in to comment.
Something went wrong with that request. Please try again.