# HG changeset patch # User Thinker K.F. Li # Date 1218564460 -28800 # Node ID c668c5c3ceaea240962ecc9bb276777a60b58c83 # Parent f4b792afa74e7e29fa85b54fe8fafdf4291d25e3 M4 macro for C binding. diff -r f4b792afa74e -r c668c5c3ceae tools/mb_c_header.m4 --- a/tools/mb_c_header.m4 Tue Aug 12 14:21:09 2008 +0800 +++ b/tools/mb_c_header.m4 Wed Aug 13 02:07:40 2008 +0800 @@ -20,8 +20,12 @@ define([COLOR_STOP],[ ]) define([REF_STOPS],) -define([FILL_SHAPE],) -define([STROKE_SHAPE],) +define([FILL_SHAPE],[[ + paint_t *$1_fill; +]]) +define([STROKE_SHAPE],[[ + paint_t *$1_stroke; +]]) define([FILL_SHAPE_WITH_PAINT],) define([STROKE_SHAPE_WITH_PAINT],) @@ -32,6 +36,7 @@ [typedef struct $1 $1_t;] struct [$1] { + coord_t *root_coord; $2[]dnl }; diff -r f4b792afa74e -r c668c5c3ceae tools/mb_c_source.m4 --- a/tools/mb_c_source.m4 Tue Aug 12 14:21:09 2008 +0800 +++ b/tools/mb_c_source.m4 Wed Aug 13 02:07:40 2008 +0800 @@ -2,56 +2,117 @@ include([foreach.m4])dnl divert([-1]) -define([COUNT],[pushdef([COUNT_N])define([COUNT_N],0)dnl -foreach([x],[($1)],[define([COUNT_N],incr(COUNT_N))])COUNT_N[]dnl -popdef([COUNT_N])[]]) +define([UNQUOTE], [$*]) + +define([QUOTE], [[[$*]]]) -define([STOP_FIELDS],[dnl -ifelse(COUNT($2),0,,[dnl -[ int n_$1_stops; - grad_stop_t *$1_stop; -]])dnl -]) +define([COUNT],[ifelse([$*],[],0,[$#])]) -define([IMPORT],[define([$1],[$2$1(][$][@)])]) +define([IMPORT],[define([$1],[$2$1(]$[]@[)])]) -define([D_COLOR_STOP],[{$2,$3,$4,$5,$6},]) +define([D_COLOR_STOP],[ + {$6,$2,$3,$4,$5}]) define([D_ADD_LINEAR_PAINT],[dnl -ifelse(COUNT([$6]),0,,[dnl - static int n_$1_stops = COUNT([$6]); - static grad_stop_t $1_stops[[]] = {$6}; +ifelse(COUNT($6),0,,[dnl + static const int n_$1_stops = COUNT($6); + static const grad_stop_t $1_stops[[]] = {UNQUOTE($6)}; ])dnl ]) define([D_ADD_RADIAL_PAINT],[dnl -ifelse(COUNT([$5]),0,,[dnl - static int n_$1_stops = COUNT([$5]); +ifelse(COUNT($5),0,,[dnl + static const int n_$1_stops = COUNT($5); + static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)}; ])dnl ]) -define([D_REF_STOPS],[]); - define([DECLARE_VARS], [divert([-1]) -IMPORT([ADD_LINEAR_PAINT], [D_]) -IMPORT([ADD_RADIAL_PAINT],[D_]) -IMPORT([REF_STOPS],[D_]) -IMPORT([COLOR_STOP],[D_]) +define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])]) +DIMPORT([ADD_LINEAR_PAINT]) +DIMPORT([ADD_RADIAL_PAINT]) +DIMPORT([COLOR_STOP]) +define([REF_STOPS],) +define([ADD_PATH],) +define([ADD_RECT]) +define([ADD_COORD]) +define([FILL_SHAPE]) +define([STROKE_SHAPE]) +define([FILL_SHAPE_WITH_PAINT]) +define([STROKE_SHAPE_WITH_PAINT]) divert[]]) define([S_ADD_LINEAR_PAINT],[ obj->$1 = mb_linear_new(rdman, $2, $3, $4, $5); +ifelse(COUNT($6),0,,[dnl + stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); + memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); + paint_linear_stops(obj->$1, n_$1_stops, stops); +])dnl ]) + define([S_ADD_RADIAL_PAINT],[ obj->$1 = mb_radial_new(rdman, $2, $3, $4); -]) -define([S_REF_STOPS],[dnl +ifelse(COUNT($5),0,,[ + stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); + memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); + paint_radial_stops(obj->$1, n_$1_stops, stops); +])dnl ]) +define([S_COLOR_STOP],[]) +define([S_REF_STOPS],[dnl +[ stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$2_stops); + memcpy(stops, $2_stops, sizeof(grad_stop_t) * n_$2_stops); + paint_radial_stops(obj->$1, n_$2_stops, stops); +]]) + +define([S_ADD_RECT],[[ + obj->$1 = sh_rect_new($2, $3, $4, $5, 0, 0); + rdman_add_shape(rdman, obj->$1, obj->$6); +]]) + +define([S_ADD_PATH],[[ + obj->$1 = sh_path_new("$2"); + rdman_add_shape(rdman, obj->$1, obj->$3); +]]) + +define([S_ADD_COORD],[[ + obj->$1 = (coord_t *)malloc(sizeof(coord_t)); + coord_init(obj->$1, obj->$2); +]]) + +define([S_FILL_SHAPE_WITH_PAINT],[dnl +[ rdman_paint_fill(rdman, obj->$2, obj->$1); +]]) + +define([S_STROKE_SHAPE_WITH_PAINT],[dnl +[ rdman_paint_stroke(rdman, obj->$2, obj->$1); +]]) + +define([S_FILL_SHAPE],[dnl +[ obj->$1_fill = paint_color_new(rdman, $2, $3, $4, $5); + rdman_paint_fill(rdman, obj->$1_fill, obj->$1); +]]) + +define([S_STROKE_SHAPE],[dnl +[ obj->$1_stroke = paint_color_new(rdman, $2, $3, $4, $5); + rdman_paint_stroke(rdman, obj->$1_stroke, obj->$1); +]]) + define([SETUP_VARS],[divert([-1]) -IMPORT([ADD_LINEAR_PAINT],[S_]) -IMPORT([ADD_RADIAL_PAINT],[S_]) -IMPORT([REF_STOPS],[S_]) +define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) +SIMPORT([ADD_LINEAR_PAINT]) +SIMPORT([ADD_RADIAL_PAINT]) +SIMPORT([COLOR_STOP]) +SIMPORT([REF_STOPS]) +SIMPORT([ADD_PATH],) +SIMPORT([ADD_RECT]) +SIMPORT([ADD_COORD]) +SIMPORT([FILL_SHAPE]) +SIMPORT([STROKE_SHAPE]) +SIMPORT([FILL_SHAPE_WITH_PAINT]) +SIMPORT([STROKE_SHAPE_WITH_PAINT]) divert[]]) define([MADBUTTERFLY],[dnl @@ -63,12 +124,14 @@ #include "$1.h" $1_t *$1_new(redraw_mant_t *rdman) { - $1_t *obj;]DECLARE_VARS + $1_t *obj; + grad_stop_t *stops = NULL;]DECLARE_VARS $2[]dnl [ obj = ($1_t *)malloc(sizeof($1_t)); if(obj == NULL) return NULL; ]SETUP_VARS + obj->root_coord = rdman->root_coord; $2 [ return obj; }] diff -r f4b792afa74e -r c668c5c3ceae tools/svg2code.py --- a/tools/svg2code.py Tue Aug 12 14:21:09 2008 +0800 +++ b/tools/svg2code.py Wed Aug 13 02:07:40 2008 +0800 @@ -6,6 +6,7 @@ xlinkns='http://www.w3.org/1999/xlink' def translate_stops(parent, codefo, parent_id): + stops = [] for node in parent.childNodes: if node.localName == 'stop' and node.namespaceURI == svgns: style = node.getAttribute('style') @@ -26,10 +27,11 @@ opacity = style_map['stop-opacity'] offset = node.getAttribute('offset') - print >> codefo, '[COLOR_STOP([%s], %f, %f, %f, %f, %f)],' % ( - parent_id, r, g, b, float(opacity), float(offset)) + stops.append('[COLOR_STOP([%s], %f, %f, %f, %f, %f)]' % ( + parent_id, r, g, b, float(opacity), float(offset))) pass pass + print >> codefo, '%sdnl' % (', '.join(stops)) pass def translate_linearGradient(linear, codefo, doc):