# HG changeset patch # User Thinker K.F. Li # Date 1218522069 -28800 # Node ID f4b792afa74e7e29fa85b54fe8fafdf4291d25e3 # Parent 7d976d925431497d8bfb4c5c277039155a2bff84 m4 translator diff -r 7d976d925431 -r f4b792afa74e tools/foreach.m4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/foreach.m4 Tue Aug 12 14:21:09 2008 +0800 @@ -0,0 +1,10 @@ +divert([-1]) + +define([_arg1], [$1]) + +define([_foreach], [ifelse([$2], [()], [], +[define([$1], _arg1$2)$3[]_foreach([$1], (shift$2), [$3])])]) + +define([foreach], [pushdef([$1])_foreach($@)popdef([$1])]) + +divert[]dnl diff -r 7d976d925431 -r f4b792afa74e tools/mb_c_header.m4 --- a/tools/mb_c_header.m4 Tue Aug 12 08:48:16 2008 +0800 +++ b/tools/mb_c_header.m4 Tue Aug 12 14:21:09 2008 +0800 @@ -1,22 +1,30 @@ changequote(`[', `]')dnl -define([ADD_LINEAR_PAINT],[[ paint_t *$1; -]])dnl -define([ADD_RADIAL_PAINT],[[ paint_t *$1; -]])dnl -define([ADD_PATH],[[ shape_t *$1; -]])dnl -define([ADD_RECT],[[ shape_t *$1; -]])dnl -define([ADD_COORD],[[ coord_t *$1; -]])dnl -dnl -define([REF_STOPS],)dnl -define([ADD_STOP],)dnl -define([FILL_SHAPE],)dnl -define([STROKE_SHAPE],)dnl -define([FILL_SHAPE_WITH_PAINT],)dnl -define([STROKE_SHAPE_WITH_PAINT],)dnl -dnl +divert([-1]) + +define([ADD_LINEAR_PAINT],[[ + paint_t *$1; +]]) + +define([ADD_RADIAL_PAINT],[[ + paint_t *$1; +]]) +define([ADD_PATH],[ +[ shape_t *$1; +]]) +define([ADD_RECT],[ +[ shape_t *$1; +]]) +define([ADD_COORD],[ +[ coord_t *$1; +]]) +define([COLOR_STOP],[ ]) + +define([REF_STOPS],) +define([FILL_SHAPE],) +define([STROKE_SHAPE],) +define([FILL_SHAPE_WITH_PAINT],) +define([STROKE_SHAPE_WITH_PAINT],) + define([MADBUTTERFLY],[dnl [#ifndef __$1_H_ #define __$1_H_] @@ -24,9 +32,9 @@ [typedef struct $1 $1_t;] struct [$1] { -$2dnl +$2[]dnl }; [#endif /* __$1_H_ */] -])dnl -dnl \ No newline at end of file +]) +divert[]dnl diff -r 7d976d925431 -r f4b792afa74e tools/mb_c_source.m4 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/mb_c_source.m4 Tue Aug 12 14:21:09 2008 +0800 @@ -0,0 +1,76 @@ +changequote(`[', `]')dnl +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([STOP_FIELDS],[dnl +ifelse(COUNT($2),0,,[dnl +[ int n_$1_stops; + grad_stop_t *$1_stop; +]])dnl +]) + +define([IMPORT],[define([$1],[$2$1(][$][@)])]) + +define([D_COLOR_STOP],[{$2,$3,$4,$5,$6},]) + +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}; +])dnl +]) + +define([D_ADD_RADIAL_PAINT],[dnl +ifelse(COUNT([$5]),0,,[dnl + static int n_$1_stops = COUNT([$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_]) +divert[]]) + +define([S_ADD_LINEAR_PAINT],[ + obj->$1 = mb_linear_new(rdman, $2, $3, $4, $5); +]) +define([S_ADD_RADIAL_PAINT],[ + obj->$1 = mb_radial_new(rdman, $2, $3, $4); +]) +define([S_REF_STOPS],[dnl +]) + +define([SETUP_VARS],[divert([-1]) +IMPORT([ADD_LINEAR_PAINT],[S_]) +IMPORT([ADD_RADIAL_PAINT],[S_]) +IMPORT([REF_STOPS],[S_]) +divert[]]) + +define([MADBUTTERFLY],[dnl +[#include +#include "mb_types.h" +#include "redraw_man.h" +#include "shapes.h" +#include "paint.h" +#include "$1.h" + +$1_t *$1_new(redraw_mant_t *rdman) { + $1_t *obj;]DECLARE_VARS +$2[]dnl +[ + obj = ($1_t *)malloc(sizeof($1_t)); + if(obj == NULL) return NULL; +]SETUP_VARS +$2 +[ return obj; +}] +]) +divert[]dnl diff -r 7d976d925431 -r f4b792afa74e tools/svg2code.py --- a/tools/svg2code.py Tue Aug 12 08:48:16 2008 +0800 +++ b/tools/svg2code.py Tue Aug 12 14:21:09 2008 +0800 @@ -26,7 +26,7 @@ opacity = style_map['stop-opacity'] offset = node.getAttribute('offset') - print >> codefo, 'ADD_STOP([%s], [%f, %f, %f, %f], [%f])dnl' % ( + print >> codefo, '[COLOR_STOP([%s], %f, %f, %f, %f, %f)],' % ( parent_id, r, g, b, float(opacity), float(offset)) pass pass @@ -42,9 +42,10 @@ else: x1 = y1 = x2 = y2 = 0 pass - print >> codefo, 'ADD_LINEAR_PAINT([%s], [%f, %f, %f, %f])dnl' % ( + print >> codefo, 'ADD_LINEAR_PAINT([%s], %f, %f, %f, %f, [' % ( linear_id, x1, y1, x2, y2) translate_stops(linear, codefo, linear_id) + print >> codefo, '])dnl' href = linear.getAttributeNS(xlinkns, 'href').strip() if href and href[0] == '#': @@ -65,9 +66,10 @@ except: r = 0.5 pass - print >> codefo, 'ADD_RADIAL_PAINT([%s], [%f, %f], %f)dnl' % ( + print >> codefo, 'ADD_RADIAL_PAINT([%s], %f, %f, %f, [' % ( radial_id, cx, cy, r) translate_stops(radial, codefo, radial_id) + print >>codefo, '])dnl' href = radial.getAttributeNS(xlinkns, 'href').strip() if href[0] == '#':