changeset 310:25a68d15e92f

Merge the image loader back
author wycc
date Sun, 22 Feb 2009 14:20:17 +0800
parents 4dfb850dee92
children 9fa4459c08a9
files tools/svg2code.py
diffstat 1 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/svg2code.py	Sun Feb 22 13:45:28 2009 +0800
+++ b/tools/svg2code.py	Sun Feb 22 14:20:17 2009 +0800
@@ -585,6 +585,45 @@
         pass
     pass
 
+@check_mbname
+def translate_image(image, coord_id, codefo, doc):
+    coord_id = translate_shape_transform(image, coord_id, codefo)
+    
+    image_id = _get_id(image)
+    if not image.hasAttributeNS(xlinkns, 'href'):
+	raise ValueError, 'image %s must has a href attribute.' % (image_id)
+    href = image.getAttributeNS(xlinkns, 'href')
+    if image.hasAttribute('x'):
+	x_str = image.getAttribute('x')
+        x = float(x_str)
+    else:
+	x = 0
+        pass
+    if image.hasAttribute('y'):
+	y_str = image.getAttribute('y')
+        y = float(y_str)
+    else:
+	y = 0
+        pass
+    if image.hasAttribute('width'):
+	width_str = image.getAttribute('width')
+        width = float(width_str)
+    else:
+	width = -1
+        pass
+    if image.hasAttribute('height'):
+	height_str = image.getAttribute('height')
+        height = float(height_str)
+    else:
+	height = -1
+        pass
+    print >> codefo, 'dnl'
+    print >> codefo, \
+		'ADD_IMAGE([%s], [%s], %f, %f, %f, %f, [%s])dnl' % (
+		        image_id, href, x, y, width, height, coord_id)
+    pass
+ 
+
 reo_func = re.compile('([a-zA-Z]+)\\([^\\)]*\\)')
 reo_translate = re.compile('translate\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)')
 reo_matrix = re.compile('matrix\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)')
@@ -639,7 +678,8 @@
             translate_rect(node, group_id, codefo, doc)
         elif node.localName == 'text':
             translate_text(node, group_id, codefo, doc)
-            pass
+        elif node.localName == 'image':
+            translate_image(node, group_id, codefo, doc)
         elif node.localName == 'textarea':
             translate_textarea(node, group_id, codefo, doc)
             pass