Mercurial > MadButterfly
diff tools/svg2code.py @ 257:50d253d0fcba
Simple image loader and image shape.
- img_ldr.c is a simple image loader that rooted on a directory
specified when a loader instance been created.
- sh_image_t is corresponding shape of image tag in SVG.
- This changeset is still buggy. It need more testing.
- svg2code.py is not ready for image tag.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 15 Jan 2009 16:46:47 +0800 |
parents | 104d83378582 |
children | 29acbd8a0dd0 |
line wrap: on
line diff
--- a/tools/svg2code.py Thu Jan 15 02:15:35 2009 +0800 +++ b/tools/svg2code.py Thu Jan 15 16:46:47 2009 +0800 @@ -369,6 +369,7 @@ pass pass +@check_mbname def translate_text(text, coord_id, codefo, doc): translate_font_style(text, codefo) @@ -394,6 +395,42 @@ pass pass +@check_mbname +def translate_image(image, coord_id, codefo, doc): + image_id = _get_id(image) + if not image.hasAttribute('href'): + raise ValueError, 'image %s must has a href attribute.' % (image_id) + href = image.getAttribute('href') + if image.hasAttribute('x'): + x_str = image.getAttribute('x') + x = int(x_str) + else: + x = 0 + pass + if image.hasAttribute('y'): + y_str = image.getAttribute('y') + y = int(y_str) + else: + y = 0 + pass + if image.hasAttribute('width'): + width_str = image.getAttribute('width') + width = int(width_str) + else: + width = -1 + pass + if image.hasAttribute('height'): + height_str = image.getAttribute('height') + height = int(height_str) + else: + height = -1 + pass + print >> codefo, 'dnl' + print >> codefo, \ + 'ADD_IMAGE([%s], [%s], %f, %f, %f, %f)dnl' % ( + image_id, href, x, y, width, height) + 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]+)?)\\)') @@ -448,6 +485,8 @@ translate_rect(node, group_id, codefo, doc) elif node.localName == 'text': translate_text(node, group_id, codefo, doc) + elif node.localName == 'image': + translate_image(node, group_id, codefo, doc) pass pass pass