comparison 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
comparison
equal deleted inserted replaced
256:cac9ad3df633 257:50d253d0fcba
367 if style_map.has_key('font-family'): 367 if style_map.has_key('font-family'):
368 font_family = style_map['font-family'].lower() 368 font_family = style_map['font-family'].lower()
369 pass 369 pass
370 pass 370 pass
371 371
372 @check_mbname
372 def translate_text(text, coord_id, codefo, doc): 373 def translate_text(text, coord_id, codefo, doc):
373 translate_font_style(text, codefo) 374 translate_font_style(text, codefo)
374 375
375 txt_strs = [] 376 txt_strs = []
376 for node in text.childNodes: 377 for node in text.childNodes:
390 'ADD_TEXT([%s], [%s], %f, %f, MB_FONT_SZ, [%s])dnl' % ( 391 'ADD_TEXT([%s], [%s], %f, %f, MB_FONT_SZ, [%s])dnl' % (
391 text_id.encode('utf8'), u''.join(txt_strs).encode('utf8'), 392 text_id.encode('utf8'), u''.join(txt_strs).encode('utf8'),
392 x, y, coord_id.encode('utf8')) 393 x, y, coord_id.encode('utf8'))
393 translate_style(text, coord_id, codefo, doc, 'TEXT_') 394 translate_style(text, coord_id, codefo, doc, 'TEXT_')
394 pass 395 pass
396 pass
397
398 @check_mbname
399 def translate_image(image, coord_id, codefo, doc):
400 image_id = _get_id(image)
401 if not image.hasAttribute('href'):
402 raise ValueError, 'image %s must has a href attribute.' % (image_id)
403 href = image.getAttribute('href')
404 if image.hasAttribute('x'):
405 x_str = image.getAttribute('x')
406 x = int(x_str)
407 else:
408 x = 0
409 pass
410 if image.hasAttribute('y'):
411 y_str = image.getAttribute('y')
412 y = int(y_str)
413 else:
414 y = 0
415 pass
416 if image.hasAttribute('width'):
417 width_str = image.getAttribute('width')
418 width = int(width_str)
419 else:
420 width = -1
421 pass
422 if image.hasAttribute('height'):
423 height_str = image.getAttribute('height')
424 height = int(height_str)
425 else:
426 height = -1
427 pass
428 print >> codefo, 'dnl'
429 print >> codefo, \
430 'ADD_IMAGE([%s], [%s], %f, %f, %f, %f)dnl' % (
431 image_id, href, x, y, width, height)
395 pass 432 pass
396 433
397 reo_func = re.compile('([a-zA-Z]+)\\([^\\)]*\\)') 434 reo_func = re.compile('([a-zA-Z]+)\\([^\\)]*\\)')
398 reo_translate = re.compile('translate\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)') 435 reo_translate = re.compile('translate\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)')
399 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]+)?)\\)') 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]+)?)\\)')
446 translate_path(node, group_id, codefo, doc) 483 translate_path(node, group_id, codefo, doc)
447 elif node.localName == 'rect': 484 elif node.localName == 'rect':
448 translate_rect(node, group_id, codefo, doc) 485 translate_rect(node, group_id, codefo, doc)
449 elif node.localName == 'text': 486 elif node.localName == 'text':
450 translate_text(node, group_id, codefo, doc) 487 translate_text(node, group_id, codefo, doc)
488 elif node.localName == 'image':
489 translate_image(node, group_id, codefo, doc)
451 pass 490 pass
452 pass 491 pass
453 pass 492 pass
454 493
455 ## \brief Translate "scenes" tag in "metadata" tag. 494 ## \brief Translate "scenes" tag in "metadata" tag.