# HG changeset patch # User Thinker K.F. Li # Date 1219391223 -28800 # Node ID 9b4a02bcaeb1d44a1abfda13991e5aab4383411e # Parent 42698de1f653b4c1b2c90f47ed7b33ffc8a5b13f matrix() function in transform attribute of group and shapes diff -r 42698de1f653 -r 9b4a02bcaeb1 examples/svg2code_ex/svg2code_ex.svg --- a/examples/svg2code_ex/svg2code_ex.svg Fri Aug 22 12:52:48 2008 +0800 +++ b/examples/svg2code_ex/svg2code_ex.svg Fri Aug 22 15:47:03 2008 +0800 @@ -22,6 +22,29 @@ id="defs4"> + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 42698de1f653 -r 9b4a02bcaeb1 src/redraw_man.c --- a/src/redraw_man.c Fri Aug 22 12:52:48 2008 +0800 +++ b/src/redraw_man.c Fri Aug 22 15:47:03 2008 +0800 @@ -362,6 +362,21 @@ return OK; } +static void make_sure_dirty_coords(redraw_man_t *rdman) { + int max_dirty_coords; + int r; + + if(rdman->n_dirty_coords >= rdman->max_dirty_coords) { + /* Max of dirty_coords is not big enough. */ + max_dirty_coords = rdman->max_dirty_coords + 16; + + r = extend_memblk((void **)&rdman->dirty_coords, + sizeof(coord_t *) * rdman->n_dirty_coords, + sizeof(coord_t *) * max_dirty_coords); + rdman->max_dirty_coords = max_dirty_coords; + } +} + /*! \brief Mark a coord is changed. * * A changed coord_t object is marked as dirty and put @@ -369,28 +384,18 @@ */ int rdman_coord_changed(redraw_man_t *rdman, coord_t *coord) { coord_t *child; - int max_dirty_coords; - int r; if(coord->flags & COF_DIRTY) return OK; - if(rdman->n_dirty_coords >= rdman->max_dirty_coords) { - /* Max of dirty_coords is not big enough. */ - max_dirty_coords = rdman->max_dirty_coords + 16; - - r = extend_memblk((void **)&rdman->dirty_coords, - sizeof(coord_t *) * rdman->n_dirty_coords, - sizeof(coord_t *) * max_dirty_coords); - rdman->max_dirty_coords = max_dirty_coords; - } - /* Make the coord and child coords dirty. */ for(child = coord; child != NULL; child = preorder_coord_subtree(coord, child)) { - rdman->dirty_coords[rdman->n_dirty_coords++] = coord; - coord->flags |= COF_DIRTY; + make_sure_dirty_coords(rdman); + + rdman->dirty_coords[rdman->n_dirty_coords++] = child; + child->flags |= COF_DIRTY; } return OK; diff -r 42698de1f653 -r 9b4a02bcaeb1 tools/mb_c_header.m4 --- a/tools/mb_c_header.m4 Fri Aug 22 12:52:48 2008 +0800 +++ b/tools/mb_c_header.m4 Fri Aug 22 15:47:03 2008 +0800 @@ -37,6 +37,8 @@ define([PATH_HIDE],) define([RECT_HIDE],) define([COORD_TRANSLATE],) +define([COORD_MATRIX],) +define([SHAPE_MATRIX],) define([MADBUTTERFLY],[dnl [#ifndef __$1_H_ diff -r 42698de1f653 -r 9b4a02bcaeb1 tools/mb_c_source.m4 --- a/tools/mb_c_source.m4 Fri Aug 22 12:52:48 2008 +0800 +++ b/tools/mb_c_source.m4 Fri Aug 22 15:47:03 2008 +0800 @@ -47,6 +47,8 @@ define([RECT_HIDE],) define([PATH_HIDE],) define([COORD_TRANSLATE],) +define([COORD_MATRIX],) +define([SHAPE_MATRIX],) divert[]]) define([S_ADD_LINEAR_PAINT],[ @@ -143,6 +145,26 @@ rdman_coord_changed(rdman, obj->$1); ]]) +define([S_COORD_MATRIX],[dnl +[ obj->$1->matrix[0] = $2; + obj->$1->matrix[3] = $3; + obj->$1->matrix[1] = $4; + obj->$1->matrix[4] = $5; + obj->$1->matrix[2] = $6; + obj->$1->matrix[5] = $7; + rdman_coord_changed(rdman, obj->$1); +]]) + +define([S_SHAPE_MATRIX],[dnl +[ obj->$1->matrix[0] = $2; + obj->$1->matrix[3] = $3; + obj->$1->matrix[1] = $4; + obj->$1->matrix[4] = $5; + obj->$1->matrix[2] = $6; + obj->$1->matrix[5] = $7; + rdman_coord_changed(rdman, obj->$1); +]]) + define([SETUP_VARS],[divert([-1]) define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) SIMPORT([ADD_LINEAR_PAINT]) @@ -163,6 +185,8 @@ SIMPORT([RECT_HIDE]) SIMPORT([PATH_HIDE]) SIMPORT([COORD_TRANSLATE]) +SIMPORT([COORD_MATRIX]) +SIMPORT([SHAPE_MATRIX]) divert[]]) define([F_ADD_LINEAR_PAINT],[[ @@ -217,6 +241,8 @@ define([RECT_HIDE],) define([PATH_HIDE],) define([COORD_TRANSLATE],) +define([COORD_MATRIX],) +define([SHAPE_MATRIX],) divert[]]) define([MADBUTTERFLY],[dnl diff -r 42698de1f653 -r 9b4a02bcaeb1 tools/svg2code.py --- a/tools/svg2code.py Fri Aug 22 12:52:48 2008 +0800 +++ b/tools/svg2code.py Fri Aug 22 15:47:03 2008 +0800 @@ -6,6 +6,7 @@ svgns='http://www.w3.org/2000/svg' xlinkns='http://www.w3.org/1999/xlink' +re_rgb = re.compile('rgb\\( *([0-9]+(\\.[0-9]+)?) *, *([0-9]+(\\.[0-9]+)?) *, *([0-9]+(\\.[0-9]+)?) *\\)') def translate_stops(parent, codefo, parent_id): stops = [] for node in parent.childNodes: @@ -24,7 +25,14 @@ g = float(int(color[3:5], 16)) / 255.0 b = float(int(color[5:7], 16)) / 255.0 else: - raise ValueError, '\'%s\' is invalid color value.' % (color) + mo = re_rgb.match(color) + if mo: + r = float(mo.group(1)) + g = float(mo.group(3)) + b = float(mo.group(5)) + else: + raise ValueError, '\'%s\' is invalid color value.' % (color) + pass opacity = style_map['stop-opacity'] offset = node.getAttribute('offset') @@ -173,15 +181,34 @@ pass pass +def translate_shape_transform(shape, coord_id, codefo): + shape_id = shape.getAttribute('id') + + if shape.hasAttribute('transform'): + shape_coord_id = shape_id + '_coord' + print >> codefo, 'dnl' + print >> codefo, 'ADD_COORD([%s], [%s])dnl' % ( + shape_coord_id, coord_id) + transform = shape.getAttribute('transform') + translate_transform(shape_coord_id, transform, codefo, 'SHAPE_') + coord_id = shape_coord_id + pass + return coord_id + def translate_path(path, coord_id, codefo, doc): + coord_id = translate_shape_transform(path, coord_id, codefo) + path_id = path.getAttribute('id') d = path.getAttribute('d') print >> codefo, 'dnl' print >> codefo, 'ADD_PATH([%s], [%s], [%s])dnl' % (path_id, d, coord_id) + translate_style(path, coord_id, codefo, doc, 'PATH_') pass def translate_rect(rect, coord_id, codefo, doc): + coord_id = translate_shape_transform(rect, coord_id, codefo) + rect_id = rect.getAttribute('id') x = float(rect.getAttribute('x')) y = float(rect.getAttribute('y')) @@ -250,15 +277,35 @@ pass pass -reo_translate = re.compile('translate\\(([0-9]+),([0-9]+)\\)') -def translate_transform(coord_id, transform, codefo): +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]+)?)\\)') +def translate_transform(coord_id, transform, codefo, prefix): transform = transform.strip() - mo = reo_translate.match(transform) - if mo: - x = float(mo.group(1)) - y = float(mo.group(2)) - print >> codefo, 'COORD_TRANSLATE([%s], %f, %f)dnl' % ( - coord_id, x, y) + mo = reo_func.match(transform) + if not mo: + return + name = mo.group(1) + print name + if name == 'translate': + mo = reo_translate.match(transform) + if mo: + x = float(mo.group(1)) + y = float(mo.group(3)) + print >> codefo, '%sTRANSLATE([%s], %f, %f)dnl' % ( + prefix, coord_id, x, y) + pass + elif name == 'matrix': + mo = reo_matrix.match(transform) + if mo: + r10, r11, r12 = \ + float(mo.group(1)), float(mo.group(3)), float(mo.group(5)) + r20, r21, r22 = \ + float(mo.group(7)), float(mo.group(9)), float(mo.group(11)) + print >> codefo, \ + '%sMATRIX([%s], %f, %f, %f, %f, %f, %f)dnl' % ( + prefix, coord_id, r10, r11, r12, r20, r21, r22) + pass pass pass @@ -269,7 +316,7 @@ if group.hasAttribute('transform'): transform = group.getAttribute('transform') - translate_transform(group_id, transform, codefo) + translate_transform(group_id, transform, codefo, 'COORD_') pass translate_style(group, group_id, codefo, doc, 'GROUP_')