Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--taconstants.py2
-rw-r--r--talogo.py8
-rwxr-xr-xtasprite_factory.py30
-rw-r--r--tautils.py4
-rw-r--r--tawindow.py29
5 files changed, 56 insertions, 17 deletions
diff --git a/taconstants.py b/taconstants.py
index 0e283bf..cf7cec0 100644
--- a/taconstants.py
+++ b/taconstants.py
@@ -134,7 +134,7 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right',
['kbinput', 'push', 'printheap', 'keyboard', 'pop', 'clearheap',
'myfunc1arg', 'userdefined', 'addturtle', 'comment', 'print',
'cartesian', 'width', 'height', 'polar', 'sandwichtop',
- 'sandwichbottom'],
+ 'sandwichbottom', 'savesvg'],
['journal', 'audio', 'description', 'savepix', 'hideblocks',
'showblocks', 'fullscreen', 'picturelist', 'picture1x1a',
'picture1x1', 'picture2x2', 'picture2x1', 'picture1x2'],
diff --git a/talogo.py b/talogo.py
index c1d1290..4e0bfa5 100644
--- a/talogo.py
+++ b/talogo.py
@@ -339,6 +339,7 @@ class LogoCode:
'rightx':[0, lambda self: self.tw.rightx],
'rpos':[0, lambda self: self.tw.canvas.width/(self.tw.coord_scale*2)],
'savepix':[1, lambda self, x: self.save_picture(x)],
+ 'savesvg':[1, lambda self, x: self.save_svg(x)],
'scale':[0, lambda self: self.scale],
'setcolor':[1, lambda self, x: self.tw.canvas.setcolor(x)],
'seth':[1, lambda self, x: self.tw.canvas.seth(x)],
@@ -445,6 +446,7 @@ class LogoCode:
self.stacks[k] = None
self.stacks['stack1'] = None
self.stacks['stack2'] = None
+ self.tw.saving_svg = False
for b in blocks:
b.unhighlight()
@@ -480,6 +482,8 @@ class LogoCode:
dock = blk.docks[0]
if len(dock)>4: # There could be a '(', ')', '[' or ']'.
code.append(dock[4])
+ if blk.name == 'savesvg':
+ self.tw.saving_svg = True
if blk.primitive is not None: # make a tuple (prim, blk)
code.append((blk.primitive, self.tw.block_list.list.index(blk)))
elif len(blk.values)>0: # Extract the value from content blocks.
@@ -1002,6 +1006,10 @@ class LogoCode:
def save_picture(self, name):
self.tw.save_as_image(name)
+ def save_svg(self, name):
+ self.tw.canvas.svg_close()
+ self.tw.save_as_image(name, True)
+
def show_list(self, sarray):
x = self.tw.canvas.xcor/self.tw.coord_scale
y = self.tw.canvas.ycor/self.tw.coord_scale
diff --git a/tasprite_factory.py b/tasprite_factory.py
index e7a0e44..be2b676 100755
--- a/tasprite_factory.py
+++ b/tasprite_factory.py
@@ -30,10 +30,10 @@ class SVG:
def __init__(self):
self._x = 0
self._y = 0
- self._min_x = 0
- self._min_y = 0
- self._max_x = 0
- self._max_y = 0
+ self._min_x = 10000
+ self._min_y = 10000
+ self._max_x = -10000
+ self._max_y = -10000
self._width = 0
self._height = 0
self.docks = []
@@ -545,6 +545,12 @@ class SVG:
def set_no_arm(self, flag=True):
self._no_arm = flag
+ def reset_min_max(self):
+ self._min_x = 10000
+ self._min_y = 10000
+ self._max_x = -10000
+ self._max_y = -10000
+
#
# Exotic methods
#
@@ -574,7 +580,7 @@ class SVG:
# SVG helper methods
#
- def _header(self):
+ def _header(self, center=False):
return "%s%s%s%s%s%s%s%s%.1f%s%s%.1f%s%s%s" % (
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!-- Created with Python -->\n",
@@ -586,7 +592,7 @@ class SVG:
" width=\"", self._width, "\"\n",
" height=\"", self._height, "\">\n",
self._defs(),
- self._transform())
+ self._transform(center))
def _defs(self):
if self._gradiant is True:
@@ -608,14 +614,18 @@ class SVG:
else:
return ""
- def _transform(self):
+ def _transform(self, center):
if self._orientation != 0:
orientation = "<g\ntransform = \"rotate(%.1f %.1f %.1f)\">\n" % (
self._orientation, self._width/2.0, self._height/2.0)
else:
orientation = ""
- return "<g\ntransform=\"scale(%.1f, %.1f)\">\n%s" % (
- self._scale, self._scale, orientation )
+ if center:
+ return "<g\ntransform=\"translate(%.1f, %.1f)\">\n" % (
+ -self._min_x, -self._min_y)
+ else:
+ return "<g\ntransform=\"scale(%.1f, %.1f)\">\n%s" % (
+ self._scale, self._scale, orientation )
def _footer(self):
if self._orientation != 0:
@@ -735,10 +745,12 @@ class SVG:
return svg_str
def new_path(self, x, y):
+ """
self._min_x = x
self._min_y = y
self._max_x = x
self._max_y = y
+ """
self._x = x
self._y = y
return " <path d=\"m%.1f %.1f " % (x, y)
diff --git a/tautils.py b/tautils.py
index a889095..48ac5ce 100644
--- a/tautils.py
+++ b/tautils.py
@@ -143,6 +143,10 @@ def save_picture(canvas, fname):
0, 0, 0, 0, canvas.width, canvas.height)
pixbuf.save(fname, 'png')
+def save_svg(string, fname):
+ f = file(fname, "w")
+ f.write(string)
+ f.close()
def get_pixbuf_from_journal(dsobject, w, h):
try:
diff --git a/tawindow.py b/tawindow.py
index 59ab210..eb42aad 100644
--- a/tawindow.py
+++ b/tawindow.py
@@ -55,7 +55,7 @@ from taturtle import Turtles, Turtle
from tautils import magnitude, get_load_name, get_save_name, data_from_file,\
data_to_file, round_int, get_id, get_pixbuf_from_journal,\
movie_media_type, audio_media_type, image_media_type,\
- save_picture, calc_image_size
+ save_picture, save_svg, calc_image_size
from tasprite_factory import SVG, svg_str_to_pixbuf, svg_from_file
from sprites import Sprites, Sprite
@@ -176,6 +176,8 @@ class TurtleArtWindow():
else:
Turtle(self.turtles, 1, mycolors.split(','))
self.active_turtle = self.turtles.get_turtle(1)
+ self.saving_svg = False
+ self.svg_string = ''
self.selected_turtle = None
self.canvas = TurtleGraphics(self, self.width, self.height)
self.titlex = -(self.canvas.width*TITLEXY[0])/(self.coord_scale*2)
@@ -2600,11 +2602,17 @@ class TurtleArtWindow():
"""
Grab the current canvas and save it.
"""
- def save_as_image(self, name=""):
- if len(name) == 0:
- filename = "ta.png"
+ def save_as_image(self, name="", svg=False):
+ if svg:
+ if len(name) == 0:
+ filename = "ta.svg"
+ else:
+ filename = name+".svg"
else:
- filename = name+".png"
+ if len(name) == 0:
+ filename = "ta.png"
+ else:
+ filename = name+".png"
if self.running_sugar:
datapath = os.path.join(self.activity.get_activity_root(),
@@ -2612,7 +2620,11 @@ class TurtleArtWindow():
else:
datapath = os.getcwd()
file_path = os.path.join(datapath, filename)
- save_picture(self.canvas, file_path)
+ if svg:
+ save_svg(self.svg_string, file_path)
+ self.svg_string = ''
+ else:
+ save_picture(self.canvas, file_path)
if self.running_sugar:
dsobject = datastore.create()
@@ -2622,7 +2634,10 @@ class TurtleArtWindow():
else:
dsobject.metadata['title'] = name
dsobject.metadata['icon-color'] = profile.get_color().to_string()
- dsobject.metadata['mime_type'] = 'image/png'
+ if svg:
+ dsobject.metadata['mime_type'] = 'image/svg'
+ else:
+ dsobject.metadata['mime_type'] = 'image/png'
dsobject.set_file_path(file_path)
datastore.write(dsobject)
dsobject.destroy()