summaryrefslogtreecommitdiff
path: root/source/tools/murun.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-05-09 14:22:51 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-05-16 12:48:07 +0200
commit756835b8388c93b30831c84b7208a47d6849920d (patch)
tree2b621371626f3281cf8fdabe4d87eda2eebb492d /source/tools/murun.c
parentf4cb197ad36f5ea3ab834abb41d2641daf152622 (diff)
downloadmupdf-756835b8388c93b30831c84b7208a47d6849920d.tar.xz
js: Add Shade.bound function and bbox device example.
Diffstat (limited to 'source/tools/murun.c')
-rw-r--r--source/tools/murun.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 6b2df126..3ed840fb 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -437,14 +437,18 @@ struct color {
static fz_matrix ffi_tomatrix(js_State *J, int idx)
{
- fz_matrix matrix;
- js_getindex(J, idx, 0); matrix.a = js_tonumber(J, -1); js_pop(J, 1);
- js_getindex(J, idx, 1); matrix.b = js_tonumber(J, -1); js_pop(J, 1);
- js_getindex(J, idx, 2); matrix.c = js_tonumber(J, -1); js_pop(J, 1);
- js_getindex(J, idx, 3); matrix.d = js_tonumber(J, -1); js_pop(J, 1);
- js_getindex(J, idx, 4); matrix.e = js_tonumber(J, -1); js_pop(J, 1);
- js_getindex(J, idx, 5); matrix.f = js_tonumber(J, -1); js_pop(J, 1);
- return matrix;
+ if (js_iscoercible(J, idx))
+ {
+ fz_matrix matrix;
+ js_getindex(J, idx, 0); matrix.a = js_tonumber(J, -1); js_pop(J, 1);
+ js_getindex(J, idx, 1); matrix.b = js_tonumber(J, -1); js_pop(J, 1);
+ js_getindex(J, idx, 2); matrix.c = js_tonumber(J, -1); js_pop(J, 1);
+ js_getindex(J, idx, 3); matrix.d = js_tonumber(J, -1); js_pop(J, 1);
+ js_getindex(J, idx, 4); matrix.e = js_tonumber(J, -1); js_pop(J, 1);
+ js_getindex(J, idx, 5); matrix.f = js_tonumber(J, -1); js_pop(J, 1);
+ return matrix;
+ }
+ return fz_identity;
}
static void ffi_pushmatrix(js_State *J, fz_matrix matrix)
@@ -2314,6 +2318,21 @@ static void ffi_Image_toPixmap(js_State *J)
js_newuserdata(J, "fz_pixmap", pixmap, ffi_gc_fz_pixmap);
}
+static void ffi_Shade_bound(js_State *J)
+{
+ fz_context *ctx = js_getcontext(J);
+ fz_shade *shade = js_touserdata(J, 0, "fz_shade");
+ fz_matrix ctm = ffi_tomatrix(J, 1);
+ fz_rect bounds;
+
+ fz_try(ctx)
+ fz_bound_shade(ctx, shade, &ctm, &bounds);
+ fz_catch(ctx)
+ rethrow(J);
+
+ ffi_pushrect(J, bounds);
+}
+
static void ffi_new_Font(js_State *J)
{
fz_context *ctx = js_getcontext(J);
@@ -4575,6 +4594,7 @@ int murun_main(int argc, char **argv)
js_newobject(J);
{
+ jsB_propfun(J, "Shade.bound", ffi_Shade_bound, 1);
}
js_setregistry(J, "fz_shade");