Mercurial > MadButterfly
comparison tools/svg2code.py @ 260:29acbd8a0dd0
Integrate sh_image with svg2code.py.
diff -r e8a784a306d0 examples/svg2code_ex/dsc_3241.png
Binary file examples/svg2code_ex/dsc_3241.png has changed
diff -r e8a784a306d0 examples/svg2code_ex/dsc_3241.png
Binary file examples/svg2code_ex/dsc_3241.png has changed
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 23 Jan 2009 23:00:23 +0800 |
parents | 50d253d0fcba |
children | c96f38ad4bb6 |
comparison
equal
deleted
inserted
replaced
259:e8a784a306d0 | 260:29acbd8a0dd0 |
---|---|
369 pass | 369 pass |
370 pass | 370 pass |
371 | 371 |
372 @check_mbname | 372 @check_mbname |
373 def translate_text(text, coord_id, codefo, doc): | 373 def translate_text(text, coord_id, codefo, doc): |
374 coord_id = translate_shape_transform(text, coord_id, codefo) | |
375 | |
374 translate_font_style(text, codefo) | 376 translate_font_style(text, codefo) |
375 | 377 |
376 txt_strs = [] | 378 txt_strs = [] |
377 for node in text.childNodes: | 379 for node in text.childNodes: |
378 if node.localName == None: | 380 if node.localName == None: |
395 pass | 397 pass |
396 pass | 398 pass |
397 | 399 |
398 @check_mbname | 400 @check_mbname |
399 def translate_image(image, coord_id, codefo, doc): | 401 def translate_image(image, coord_id, codefo, doc): |
402 coord_id = translate_shape_transform(image, coord_id, codefo) | |
403 | |
400 image_id = _get_id(image) | 404 image_id = _get_id(image) |
401 if not image.hasAttribute('href'): | 405 if not image.hasAttributeNS(xlinkns, 'href'): |
402 raise ValueError, 'image %s must has a href attribute.' % (image_id) | 406 raise ValueError, 'image %s must has a href attribute.' % (image_id) |
403 href = image.getAttribute('href') | 407 href = image.getAttributeNS(xlinkns, 'href') |
404 if image.hasAttribute('x'): | 408 if image.hasAttribute('x'): |
405 x_str = image.getAttribute('x') | 409 x_str = image.getAttribute('x') |
406 x = int(x_str) | 410 x = float(x_str) |
407 else: | 411 else: |
408 x = 0 | 412 x = 0 |
409 pass | 413 pass |
410 if image.hasAttribute('y'): | 414 if image.hasAttribute('y'): |
411 y_str = image.getAttribute('y') | 415 y_str = image.getAttribute('y') |
412 y = int(y_str) | 416 y = float(y_str) |
413 else: | 417 else: |
414 y = 0 | 418 y = 0 |
415 pass | 419 pass |
416 if image.hasAttribute('width'): | 420 if image.hasAttribute('width'): |
417 width_str = image.getAttribute('width') | 421 width_str = image.getAttribute('width') |
418 width = int(width_str) | 422 width = float(width_str) |
419 else: | 423 else: |
420 width = -1 | 424 width = -1 |
421 pass | 425 pass |
422 if image.hasAttribute('height'): | 426 if image.hasAttribute('height'): |
423 height_str = image.getAttribute('height') | 427 height_str = image.getAttribute('height') |
424 height = int(height_str) | 428 height = float(height_str) |
425 else: | 429 else: |
426 height = -1 | 430 height = -1 |
427 pass | 431 pass |
428 print >> codefo, 'dnl' | 432 print >> codefo, 'dnl' |
429 print >> codefo, \ | 433 print >> codefo, \ |
430 'ADD_IMAGE([%s], [%s], %f, %f, %f, %f)dnl' % ( | 434 'ADD_IMAGE([%s], [%s], %f, %f, %f, %f, [%s])dnl' % ( |
431 image_id, href, x, y, width, height) | 435 image_id, href, x, y, width, height, coord_id) |
432 pass | 436 pass |
433 | 437 |
434 reo_func = re.compile('([a-zA-Z]+)\\([^\\)]*\\)') | 438 reo_func = re.compile('([a-zA-Z]+)\\([^\\)]*\\)') |
435 reo_translate = re.compile('translate\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)') | 439 reo_translate = re.compile('translate\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)') |
436 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]+)?)\\)') | 440 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]+)?)\\)') |