diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-12-10 12:26:09 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-12-12 12:00:42 +0000 |
commit | 5dfaa22a578ff6561e8d15a8c08546c840476313 (patch) | |
tree | 94fb602a9d1ab8a6305c4ad3e48650fbaa2a32ed /util | |
parent | 738cb327450821db2d3689e514376c0d9bc55e87 (diff) |
[script] Add repeat operator.
Simple operator to repeat procedure n times.
Diffstat (limited to 'util')
-rw-r--r-- | util/cairo-script/cairo-script-operators.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/util/cairo-script/cairo-script-operators.c b/util/cairo-script/cairo-script-operators.c index e5b6b2d3..822f0581 100644 --- a/util/cairo-script/cairo-script-operators.c +++ b/util/cairo-script/cairo-script-operators.c @@ -3421,6 +3421,41 @@ _rel_move_to (csi_t *ctx) } static csi_status_t +_repeat (csi_t *ctx) +{ + csi_array_t *proc; + csi_integer_t count; + csi_status_t status; + + check (2); + + status = _csi_ostack_get_procedure (ctx, 0, &proc); + if (_csi_unlikely (status)) + return status; + + status = _csi_ostack_get_integer (ctx, 1, &count); + if (_csi_unlikely (status)) + return status; + + if (_csi_unlikely (count < 0)) + return _csi_error (CSI_STATUS_INVALID_SCRIPT); + + proc->base.ref++; + pop (2); + + while (count--) { + status = _csi_array_execute (ctx, proc); + if (_csi_unlikely (status)) + break; + } + + if (--proc->base.ref == 0) + csi_array_free (ctx, proc); + + return status; +} + +static csi_status_t _reset_clip (csi_t *ctx) { return _do_cairo_op (ctx, cairo_reset_clip); @@ -5489,7 +5524,7 @@ _defs[] = { { "radial", _radial }, { "rand", NULL }, { "rectangle", _rectangle }, - { "repeat", NULL }, + { "repeat", _repeat }, { "restore", _restore }, { "rel_curve_to", _rel_curve_to }, { "rel_line_to", _rel_line_to }, |