Mercurial > MadButterfly
comparison tools/mb_c_source.m4 @ 431:bf1addb037b7
Add -s option to svg2code.py.
Option -s is for sh_stext type. With this option, svg2code.py will
generate code to using sh_stext type instead of sh_text for text nodes.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 29 Jul 2009 15:03:26 +0800 |
parents | 3e84458968ec |
children | bb4f651090bf |
comparison
equal
deleted
inserted
replaced
430:bec538d361e9 | 431:bf1addb037b7 |
---|---|
18 define([REF_STOPS_LINEAR]) | 18 define([REF_STOPS_LINEAR]) |
19 define([ADD_PATH]) | 19 define([ADD_PATH]) |
20 define([ADD_RECT]) | 20 define([ADD_RECT]) |
21 define([ADD_COORD]) | 21 define([ADD_COORD]) |
22 define([ADD_TEXT],) | 22 define([ADD_TEXT],) |
23 define([ADD_STEXT]) | |
23 define([ADD_IMAGE],) | 24 define([ADD_IMAGE],) |
24 define([PANGO_BEGIN_TEXT],) | 25 define([PANGO_BEGIN_TEXT],) |
25 define([PANGO_END_TEXT],) | 26 define([PANGO_END_TEXT],) |
26 define([PANGO_SIZE],) | 27 define([PANGO_SIZE],) |
27 define([PANGO_STYLE],) | 28 define([PANGO_STYLE],) |
37 define([PATH_HIDE],) | 38 define([PATH_HIDE],) |
38 define([COORD_TRANSLATE],) | 39 define([COORD_TRANSLATE],) |
39 define([COORD_MATRIX],) | 40 define([COORD_MATRIX],) |
40 define([SHAPE_TRANSLATE],) | 41 define([SHAPE_TRANSLATE],) |
41 define([SHAPE_MATRIX],) | 42 define([SHAPE_MATRIX],) |
43 define([STYLE_BLOCK]) | |
42 define([ADD_SYMBOL],) | 44 define([ADD_SYMBOL],) |
43 define([SCENE]) | 45 define([SCENE]) |
44 ]) | 46 ]) |
45 | 47 |
48 define([C_NL],[ | |
49 ]) | |
50 define([RM_C_NL], | |
51 [ifelse(index([$1],C_NL), -1, | |
52 [$1], | |
53 [substr([$1], 0, index([$1],C_NL))[\n]RM_C_NL(substr([$1], | |
54 eval(index([$1],C_NL) + 1)))])]) | |
55 define([TO_CSTR], ["[]RM_C_NL(patsubst(patsubst(patsubst([$1], | |
56 [\\], [[\\\\]]), | |
57 [ ],[[\\t]]), | |
58 ["], [[\\"]]))[]"]) | |
59 | |
60 dnl -------------------- Declare Local Variables -------------------- | |
46 define([D_COLOR_STOP],[ | 61 define([D_COLOR_STOP],[ |
47 {$6,$2,$3,$4,$5}]) | 62 {$6,$2,$3,$4,$5}]) |
48 | 63 |
49 define([D_ADD_LINEAR_PAINT],[dnl | 64 define([D_ADD_LINEAR_PAINT],[dnl |
50 ifelse(COUNT($6),0,,[dnl | 65 ifelse(COUNT($6),0,,[dnl |
56 define([D_ADD_RADIAL_PAINT],[dnl | 71 define([D_ADD_RADIAL_PAINT],[dnl |
57 ifelse(COUNT($5),0,,[dnl | 72 ifelse(COUNT($5),0,,[dnl |
58 static const int n_$1_stops = COUNT($5); | 73 static const int n_$1_stops = COUNT($5); |
59 static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)}; | 74 static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)}; |
60 ])dnl | 75 ])dnl |
76 ]) | |
77 | |
78 define([D_ADD_STEXT],[dnl | |
79 define([$1_CNT], 0)dnl | |
80 [ mb_style_blk_t *$1_blk; | |
81 ]]) | |
82 | |
83 define([D_STYLE_BLOCK],[dnl | |
84 define([$1_CNT], eval($1_CNT + 1))dnl | |
61 ]) | 85 ]) |
62 | 86 |
63 define([DECLARE_VARS], [divert([-1]) | 87 define([DECLARE_VARS], [divert([-1]) |
64 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])]) | 88 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])]) |
65 DECLARE_EMPTIES | 89 DECLARE_EMPTIES |
66 DIMPORT([ADD_LINEAR_PAINT]) | 90 DIMPORT([ADD_LINEAR_PAINT]) |
67 DIMPORT([ADD_RADIAL_PAINT]) | 91 DIMPORT([ADD_RADIAL_PAINT]) |
68 DIMPORT([COLOR_STOP]) | 92 DIMPORT([COLOR_STOP]) |
93 DIMPORT([ADD_STEXT]) | |
94 DIMPORT([STYLE_BLOCK]) | |
69 divert[]]) | 95 divert[]]) |
70 | 96 |
97 dnl -------------------- Setup Value for Member Variables -------------------- | |
71 define([S_ADD_LINEAR_PAINT],[ | 98 define([S_ADD_LINEAR_PAINT],[ |
72 obj->$1 = rdman_paint_linear_new(rdman, $2, $3, $4, $5); | 99 obj->$1 = rdman_paint_linear_new(rdman, $2, $3, $4, $5); |
73 ifelse(COUNT($6),0,,[dnl | 100 ifelse(COUNT($6),0,,[dnl |
74 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); | 101 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); |
75 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); | 102 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); |
239 obj->$1->matrix[4] = $5; | 266 obj->$1->matrix[4] = $5; |
240 obj->$1->matrix[2] = $6; | 267 obj->$1->matrix[2] = $6; |
241 obj->$1->matrix[5] = $7; | 268 obj->$1->matrix[5] = $7; |
242 rdman_coord_changed(rdman, obj->$1); | 269 rdman_coord_changed(rdman, obj->$1); |
243 ]]) | 270 ]]) |
271 | |
272 define([S_ADD_STEXT],[dnl | |
273 [ obj->$1 = rdman_shape_stext_new(rdman, ]TO_CSTR([$2])[, $3, $4); | |
274 rdman_add_shape(rdman, obj->$1, obj->$5); | |
275 obj->$1_style_blks_num = ]$1_CNT[; | |
276 obj->$1_style_blks = $1_blk = | |
277 (mb_style_blk_t *)malloc(sizeof(mb_style_blk_t) * ]$1_CNT[); | |
278 ]dnl | |
279 define($1_IDX,0)dnl | |
280 ]) | |
281 | |
282 define([S_STYLE_BLOCK],[dnl | |
283 [ $1_blk->n_chars = $2; | |
284 $1_blk->font_sz = $4; | |
285 $1_blk->face = mb_font_face_query(rdman, ]TO_CSTR([$3])[, $5, $6); | |
286 $1_blk++; | |
287 ]dnl | |
288 define([$1_IDX], eval($1_IDX + 1))dnl | |
289 ifelse($1_IDX, $1_CNT, | |
290 [ sh_stext_set_style(obj->$1, obj->$1_style_blks, ]$1_CNT[); | |
291 ])dnl | |
292 ]) | |
244 | 293 |
245 define([SETUP_VARS],[divert([-1]) | 294 define([SETUP_VARS],[divert([-1]) |
246 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) | 295 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) |
247 DECLARE_EMPTIES | 296 DECLARE_EMPTIES |
248 SIMPORT([ADD_LINEAR_PAINT]) | 297 SIMPORT([ADD_LINEAR_PAINT]) |
252 SIMPORT([REF_STOPS_LINEAR]) | 301 SIMPORT([REF_STOPS_LINEAR]) |
253 SIMPORT([ADD_PATH],) | 302 SIMPORT([ADD_PATH],) |
254 SIMPORT([ADD_RECT]) | 303 SIMPORT([ADD_RECT]) |
255 SIMPORT([ADD_COORD]) | 304 SIMPORT([ADD_COORD]) |
256 SIMPORT([ADD_TEXT]) | 305 SIMPORT([ADD_TEXT]) |
306 SIMPORT([ADD_STEXT]) | |
257 SIMPORT([ADD_IMAGE]) | 307 SIMPORT([ADD_IMAGE]) |
258 SIMPORT([PANGO_BEGIN_TEXT]) | 308 SIMPORT([PANGO_BEGIN_TEXT]) |
259 SIMPORT([PANGO_END_TEXT]) | 309 SIMPORT([PANGO_END_TEXT]) |
260 SIMPORT([PANGO_SIZE]) | 310 SIMPORT([PANGO_SIZE]) |
261 SIMPORT([PANGO_WEIGHT]) | 311 SIMPORT([PANGO_WEIGHT]) |
271 SIMPORT([PATH_HIDE]) | 321 SIMPORT([PATH_HIDE]) |
272 SIMPORT([COORD_TRANSLATE]) | 322 SIMPORT([COORD_TRANSLATE]) |
273 SIMPORT([COORD_MATRIX]) | 323 SIMPORT([COORD_MATRIX]) |
274 SIMPORT([SHAPE_TRANSLATE]) | 324 SIMPORT([SHAPE_TRANSLATE]) |
275 SIMPORT([SHAPE_MATRIX]) | 325 SIMPORT([SHAPE_MATRIX]) |
326 SIMPORT([STYLE_BLOCK]) | |
276 divert[]]) | 327 divert[]]) |
277 | 328 |
329 dnl -------------------- Clear Member Variables -------------------- | |
278 define([F_ADD_LINEAR_PAINT],[[ | 330 define([F_ADD_LINEAR_PAINT],[[ |
279 stops = paint_linear_stops(obj->$1, 0, NULL); | 331 stops = paint_linear_stops(obj->$1, 0, NULL); |
280 free(stops); | 332 free(stops); |
281 rdman_paint_free(rdman, obj->$1); | 333 rdman_paint_free(rdman, obj->$1); |
282 ]]) | 334 ]]) |
317 rdman_paint_free(rdman, obj->$1_fill); | 369 rdman_paint_free(rdman, obj->$1_fill); |
318 ]]) | 370 ]]) |
319 | 371 |
320 define([F_STROKE_SHAPE],[[ | 372 define([F_STROKE_SHAPE],[[ |
321 rdman_paint_free(rdman, obj->$1_stroke); | 373 rdman_paint_free(rdman, obj->$1_stroke); |
374 ]]) | |
375 | |
376 define([F_ADD_STEXT],[[ | |
377 rdman_shape_free(rdman, obj->$1); | |
322 ]]) | 378 ]]) |
323 | 379 |
324 define([CLEAR_VARS],[divert([-1]) | 380 define([CLEAR_VARS],[divert([-1]) |
325 define([FIMPORT],[IMPORT(]QUOTE($[]1)[,[F_])]) | 381 define([FIMPORT],[IMPORT(]QUOTE($[]1)[,[F_])]) |
326 DECLARE_EMPTIES | 382 DECLARE_EMPTIES |
333 FIMPORT([PANGO_BEGIN_TEXT]) | 389 FIMPORT([PANGO_BEGIN_TEXT]) |
334 FIMPORT([FILL_SHAPE]) | 390 FIMPORT([FILL_SHAPE]) |
335 FIMPORT([STROKE_SHAPE]) | 391 FIMPORT([STROKE_SHAPE]) |
336 divert[]]) | 392 divert[]]) |
337 | 393 |
394 dnl -------------------- Macro to Reverse Calling -------------------- | |
338 define([REVERSE_VARS],[divert([-1]) | 395 define([REVERSE_VARS],[divert([-1]) |
339 define([__REV_VAR],[]) | 396 define([__REV_VAR],[]) |
340 define([PUSH_REV], [ | 397 define([PUSH_REV], [ |
341 pushdef([__REV_VAR]) | 398 pushdef([__REV_VAR]) |
342 define([__REV_VAR], ]QUOTE(QUOTE($[]1))[)]) | 399 define([__REV_VAR], ]QUOTE(QUOTE($[]1))[)]) |
372 RIMPORT([SHAPE_TRANSLATE]) | 429 RIMPORT([SHAPE_TRANSLATE]) |
373 RIMPORT([SHAPE_MATRIX]) | 430 RIMPORT([SHAPE_MATRIX]) |
374 divert[]dnl | 431 divert[]dnl |
375 ]) | 432 ]) |
376 | 433 |
434 dnl -------------------- Define Symbol Table -------------------- | |
377 define([Y_ADD_SYMBOL],[[{"$2", MB_SPRITE_OFFSET($1)},]]) | 435 define([Y_ADD_SYMBOL],[[{"$2", MB_SPRITE_OFFSET($1)},]]) |
378 | 436 |
379 define([DECLARE_SYMS], [divert([-1]) | 437 define([DECLARE_SYMS], [divert([-1]) |
380 define([YIMPORT],[IMPORT(]QUOTE($[]1)[,[Y_])]) | 438 define([YIMPORT],[IMPORT(]QUOTE($[]1)[,[Y_])]) |
381 DECLARE_EMPTIES | 439 DECLARE_EMPTIES |
405 DECLARE_EMPTIES | 463 DECLARE_EMPTIES |
406 SCAIMPORT([SCENE]) | 464 SCAIMPORT([SCENE]) |
407 divert[]dnl | 465 divert[]dnl |
408 ]) | 466 ]) |
409 | 467 |
468 dnl -------------------- C Template -------------------- | |
410 define([MADBUTTERFLY],[dnl | 469 define([MADBUTTERFLY],[dnl |
411 [#include <stdio.h> | 470 [#include <stdio.h> |
412 #include <stdlib.h> | 471 #include <stdlib.h> |
413 #include <string.h> | 472 #include <string.h> |
414 #include <mb_types.h> | 473 #include <mb_types.h> |