diff --git a/jp_doodle/svg_translation.py b/jp_doodle/svg_translation.py index a9b8e53..237c53e 100644 --- a/jp_doodle/svg_translation.py +++ b/jp_doodle/svg_translation.py @@ -127,6 +127,12 @@ def line(self, x1, y1, x2, y2, color, lineWidth, **other_arguments_ignored): ) def rect(self, x, y, w, h, color, degrees = None, lineWidth=1, fill=True, **other_arguments_ignored): + if w < 0: + x = x + w + w = abs(w) + if h < 0: + y = y + h + h = abs(h) (x, y) = self.canvas_to_svg_axis(x, y) atts = {} if fill: @@ -138,9 +144,8 @@ def rect(self, x, y, w, h, color, degrees = None, lineWidth=1, fill=True, **othe # svg rect element does not support negative coordinates if degrees: atts['transform'] = "rotate(%s, %s, %s)" %(-degrees, x, y) - else: - atts['x'] = x - atts['y'] = y-h + atts['x'] = x + atts['y'] = y-h style = "" if lineWidth: style += "stroke-width:" + str(lineWidth) @@ -174,11 +179,11 @@ def polygon(self, points, color, fill=True, close = True, lineWidth=1, **other_a ) def image(self, x, y, w, h, image_name, **other_arguments_ignored): - # href is hard coded + # href is hard coded: image_name must be the file path (x, y) = self.canvas_to_svg_axis(x, y) self.add_draw_tag( tag_name="image", - href = image_name+".png", + href = image_name, x = x, y = y-h, height = h, diff --git a/notebooks/misc/svg_tests/image test.ipynb b/notebooks/misc/svg_tests/image test.ipynb index a16ecd5..e9b5039 100644 --- a/notebooks/misc/svg_tests/image test.ipynb +++ b/notebooks/misc/svg_tests/image test.ipynb @@ -12,13 +12,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "73e866324ddd4a5f904b52540e559d82", + "model_id": "6be65d542e574c5f80d5e2c1bc9073c4", "version_major": 2, "version_minor": 0 }, @@ -39,15 +39,15 @@ "# Scaled the image to byte values.\n", "inverted = (1 - img) * 255\n", "# Load the image to the canvas and name it.\n", - "demo.name_image_array(\"mandrill\", inverted)\n", + "demo.name_image_array(\"mandrill.png\", inverted)\n", "# Draw the image by name.\n", - "demo.named_image(\"mandrill\", 50, 50, 210, 130)\n", + "demo.named_image(\"mandrill.png\", 50, 50, 210, 130)\n", "demo.fit()" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -72,7 +72,7 @@ " 'y': 50,\n", " 'w': 210,\n", " 'h': 130,\n", - " 'image_name': 'mandrill',\n", + " 'image_name': 'mandrill.png',\n", " 'degrees': 0,\n", " 'draw_on_canvas': {},\n", " 'object_index': 0,\n", @@ -82,7 +82,7 @@ " 'sample_pixel': {'x': 160, 'y': 110}}]" ] }, - "execution_count": 6, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -93,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { diff --git a/notebooks/misc/svg_tests/rect test.ipynb b/notebooks/misc/svg_tests/rect test.ipynb index adc9d1e..1fe1e0c 100644 --- a/notebooks/misc/svg_tests/rect test.ipynb +++ b/notebooks/misc/svg_tests/rect test.ipynb @@ -19,7 +19,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2969f09be85a422cb7a2f307374d236d", + "model_id": "e1b19d8358734e25a87b19aba5fc2896", "version_major": 2, "version_minor": 0 }, @@ -69,9 +69,9 @@ "\n", " \n", "\t\n", - "\t\n", + "\t\n", "\t\n", - "\t\n", + "\t\n", "\t\n", "\n" ],