Mercurial > MadButterfly
comparison tools/svg2code.py @ 210:3fadd2f2742e
M4 macros to generate code for dynamic loading.
- Introduce sprite.
- Add mb_sprite_t and mb_sprite_lsym_t
- mb_sprite_lsym_t is sprite with symbol that searched with linear search.
- Add mb_sprite_lsym_t as first member variable of sprite.
- Add symbol table to generated C code.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 12 Dec 2008 00:33:54 +0800 |
parents | bcad1ccdf45c |
children | 104d83378582 |
comparison
equal
deleted
inserted
replaced
209:6f63aa67ed83 | 210:3fadd2f2742e |
---|---|
50 pass | 50 pass |
51 print >> codefo, '%sdnl' % (', '.join(stops)) | 51 print >> codefo, '%sdnl' % (', '.join(stops)) |
52 pass | 52 pass |
53 | 53 |
54 def translate_linearGradient(linear, codefo, doc): | 54 def translate_linearGradient(linear, codefo, doc): |
55 linear_id = linear.getAttribute('id') | 55 linear_id = _get_id(linear) |
56 if linear.hasAttribute('x1'): | 56 if linear.hasAttribute('x1'): |
57 x1 = float(linear.getAttribute('x1')) | 57 x1 = float(linear.getAttribute('x1')) |
58 y1 = float(linear.getAttribute('y1')) | 58 y1 = float(linear.getAttribute('y1')) |
59 x2 = float(linear.getAttribute('x2')) | 59 x2 = float(linear.getAttribute('x2')) |
60 y2 = float(linear.getAttribute('y2')) | 60 y2 = float(linear.getAttribute('y2')) |
72 linear_id, href[1:]) | 72 linear_id, href[1:]) |
73 pass | 73 pass |
74 pass | 74 pass |
75 | 75 |
76 def translate_radialGradient(radial, codefo, doc): | 76 def translate_radialGradient(radial, codefo, doc): |
77 radial_id = radial.getAttribute('id') | 77 radial_id = _get_id(radial) |
78 try: | 78 try: |
79 cx = float(radial.getAttribute('cx')) | 79 cx = float(radial.getAttribute('cx')) |
80 cy = float(radial.getAttribute('cy')) | 80 cy = float(radial.getAttribute('cy')) |
81 except: | 81 except: |
82 cx = cy = 0 | 82 cx = cy = 0 |
268 cmd = f | 268 cmd = f |
269 narg=0 | 269 narg=0 |
270 pass | 270 pass |
271 return [commands,args,fix_args] | 271 return [commands,args,fix_args] |
272 | 272 |
273 _id_sn = 0 | |
274 | |
275 def _get_id(obj): | |
276 global _id_sn | |
277 | |
278 if obj.hasAttribute('id'): | |
279 oid = obj.getAttribute('id') | |
280 else: | |
281 oid = '_MB_RAND_%s_' % (_id_sn) | |
282 obj.setAttribute('id', oid) | |
283 _id_sn = _id_sn + 1 | |
284 pass | |
285 return oid | |
286 | |
287 ## | |
288 # Decorator that check if objects have attribute 'mbname'. | |
289 # | |
290 def check_mbname(func): | |
291 def deco(obj, coord_id, codefo, doc): | |
292 if obj.hasAttribute('mbname'): | |
293 ## \note mbname declare that this node should be in the | |
294 # symbol table. | |
295 mbname = obj.getAttribute('mbname') | |
296 print >> codefo, 'ADD_SYMBOL([%s])dnl' % (mbname) | |
297 pass | |
298 func(obj, coord_id, codefo, doc) | |
299 pass | |
300 return deco | |
301 | |
302 @check_mbname | |
273 def translate_path(path, coord_id, codefo, doc): | 303 def translate_path(path, coord_id, codefo, doc): |
274 coord_id = translate_shape_transform(path, coord_id, codefo) | 304 coord_id = translate_shape_transform(path, coord_id, codefo) |
275 | 305 |
276 path_id = path.getAttribute('id') | 306 path_id = path.getAttribute('id') |
277 d = path.getAttribute('d') | 307 d = path.getAttribute('d') |
288 print >> codefo, 'ADD_PATH([%s], [%s],[%s],[%s],[%d],[%s],[%d])dnl' % (path_id, coord_id,commands,sarg,len(args),s_fix_arg,len(fix_args)) | 318 print >> codefo, 'ADD_PATH([%s], [%s],[%s],[%s],[%d],[%s],[%d])dnl' % (path_id, coord_id,commands,sarg,len(args),s_fix_arg,len(fix_args)) |
289 | 319 |
290 translate_style(path, coord_id, codefo, doc, 'PATH_') | 320 translate_style(path, coord_id, codefo, doc, 'PATH_') |
291 pass | 321 pass |
292 | 322 |
323 @check_mbname | |
293 def translate_rect(rect, coord_id, codefo, doc): | 324 def translate_rect(rect, coord_id, codefo, doc): |
294 coord_id = translate_shape_transform(rect, coord_id, codefo) | 325 coord_id = translate_shape_transform(rect, coord_id, codefo) |
295 | 326 |
296 rect_id = rect.getAttribute('id') | 327 rect_id = _get_id(rect) |
297 x = float(rect.getAttribute('x')) | 328 x = float(rect.getAttribute('x')) |
298 y = float(rect.getAttribute('y')) | 329 y = float(rect.getAttribute('y')) |
299 rx = 0.0 | 330 rx = 0.0 |
300 if rect.hasAttribute('rx'): | 331 if rect.hasAttribute('rx'): |
301 rx = float(rect.getAttribute('rx')) | 332 rx = float(rect.getAttribute('rx')) |
311 rect_id, x, y, width, height, rx, ry, coord_id) | 342 rect_id, x, y, width, height, rx, ry, coord_id) |
312 translate_style(rect, coord_id, codefo, doc, 'RECT_') | 343 translate_style(rect, coord_id, codefo, doc, 'RECT_') |
313 pass | 344 pass |
314 | 345 |
315 def translate_font_style(text, codefo): | 346 def translate_font_style(text, codefo): |
316 text_id = text.getAttribute('id') | 347 text_id = _get_id(text) |
317 style_str = text.getAttribute('style') | 348 style_str = text.getAttribute('style') |
318 style_map = get_style_map(style_str) | 349 style_map = get_style_map(style_str) |
319 | 350 |
320 font_sz = 10.0 | 351 font_sz = 10.0 |
321 if style_map.has_key('font-size'): | 352 if style_map.has_key('font-size'): |
347 node.setAttribute('style', text.getAttribute('style')) | 378 node.setAttribute('style', text.getAttribute('style')) |
348 translate_text(node, coord_id, codefo, doc) | 379 translate_text(node, coord_id, codefo, doc) |
349 pass | 380 pass |
350 pass | 381 pass |
351 if txt_strs: | 382 if txt_strs: |
352 text_id = text.getAttribute('id') | 383 text_id = _get_id(text) |
353 x = float(text.getAttribute('x')) | 384 x = float(text.getAttribute('x')) |
354 y = float(text.getAttribute('y')) | 385 y = float(text.getAttribute('y')) |
355 print >> codefo, 'dnl' | 386 print >> codefo, 'dnl' |
356 print >> codefo, \ | 387 print >> codefo, \ |
357 'ADD_TEXT([%s], [%s], %f, %f, MB_FONT_SZ, [%s])dnl' % ( | 388 'ADD_TEXT([%s], [%s], %f, %f, MB_FONT_SZ, [%s])dnl' % ( |
390 prefix, coord_id, r10, r11, r12, r20, r21, r22) | 421 prefix, coord_id, r10, r11, r12, r20, r21, r22) |
391 pass | 422 pass |
392 pass | 423 pass |
393 pass | 424 pass |
394 | 425 |
426 @check_mbname | |
395 def translate_group(group, parent_id, codefo, doc): | 427 def translate_group(group, parent_id, codefo, doc): |
396 group_id = group.getAttribute('id') | 428 group_id = _get_id(group) |
397 print >> codefo, 'dnl' | 429 print >> codefo, 'dnl' |
398 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) | 430 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) |
399 | 431 |
400 if group.hasAttribute('transform'): | 432 if group.hasAttribute('transform'): |
401 transform = group.getAttribute('transform') | 433 transform = group.getAttribute('transform') |