wrap.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. // Copyright (C) 2004-2025 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. /* Conversion functions: C to Java. These all throw fitz exceptions. */
  23. static inline jobject to_ColorSpace(fz_context *ctx, JNIEnv *env, fz_colorspace *cs)
  24. {
  25. jobject jcs;
  26. if (!ctx || !cs) return NULL;
  27. fz_keep_colorspace(ctx, cs);
  28. jcs = (*env)->CallStaticObjectMethod(env, cls_ColorSpace, mid_ColorSpace_fromPointer, jlong_cast(cs));
  29. if (!jcs)
  30. fz_drop_colorspace(ctx, cs);
  31. if ((*env)->ExceptionCheck(env))
  32. fz_throw_java(ctx, env);
  33. return jcs;
  34. }
  35. static inline jobject to_DefaultColorSpaces(fz_context *ctx, JNIEnv *env, fz_default_colorspaces *dcs)
  36. {
  37. jobject jdcs;
  38. if (!ctx || !dcs) return NULL;
  39. fz_keep_default_colorspaces(ctx, dcs);
  40. jdcs = (*env)->NewObject(env, cls_DefaultColorSpaces, mid_DefaultColorSpaces_init, jlong_cast(dcs));
  41. if (!jdcs)
  42. fz_drop_default_colorspaces(ctx, dcs);
  43. if ((*env)->ExceptionCheck(env))
  44. fz_throw_java(ctx, env);
  45. return jdcs;
  46. }
  47. static inline jobject to_FitzInputStream(fz_context *ctx, JNIEnv *env, fz_stream *stm)
  48. {
  49. jobject jstm;
  50. if (!ctx || !stm) return NULL;
  51. fz_keep_stream(ctx, stm);
  52. jstm = (*env)->NewObject(env, cls_FitzInputStream, mid_FitzInputStream_init, jlong_cast(stm));
  53. if (!jstm)
  54. fz_drop_stream(ctx, stm);
  55. if ((*env)->ExceptionCheck(env))
  56. fz_throw_java(ctx, env);
  57. return jstm;
  58. }
  59. static inline jobject to_Image(fz_context *ctx, JNIEnv *env, fz_image *img)
  60. {
  61. jobject jimg;
  62. if (!ctx || !img) return NULL;
  63. fz_keep_image(ctx, img);
  64. jimg = (*env)->NewObject(env, cls_Image, mid_Image_init, jlong_cast(img));
  65. if (!jimg)
  66. fz_drop_image(ctx, img);
  67. if ((*env)->ExceptionCheck(env))
  68. fz_throw_java(ctx, env);
  69. return jimg;
  70. }
  71. static inline jobject to_Matrix(fz_context *ctx, JNIEnv *env, fz_matrix mat)
  72. {
  73. jobject jctm;
  74. if (!ctx) return NULL;
  75. jctm = (*env)->NewObject(env, cls_Matrix, mid_Matrix_init, mat.a, mat.b, mat.c, mat.d, mat.e, mat.f);
  76. if ((*env)->ExceptionCheck(env))
  77. fz_throw_java(ctx, env);
  78. return jctm;
  79. }
  80. static inline jobject to_Path(fz_context *ctx, JNIEnv *env, const fz_path *path)
  81. {
  82. jobject jpath;
  83. if (!ctx || !path) return NULL;
  84. fz_keep_path(ctx, path);
  85. jpath = (*env)->NewObject(env, cls_Path, mid_Path_init, jlong_cast(path));
  86. if (!jpath)
  87. fz_drop_path(ctx, path);
  88. if ((*env)->ExceptionCheck(env))
  89. fz_throw_java(ctx, env);
  90. return jpath;
  91. }
  92. static inline jobject to_Rect(fz_context *ctx, JNIEnv *env, fz_rect rect)
  93. {
  94. jobject jrect;
  95. if (!ctx) return NULL;
  96. jrect = (*env)->NewObject(env, cls_Rect, mid_Rect_init, rect.x0, rect.y0, rect.x1, rect.y1);
  97. if ((*env)->ExceptionCheck(env))
  98. fz_throw_java(ctx, env);
  99. return jrect;
  100. }
  101. static inline jobject to_Shade(fz_context *ctx, JNIEnv *env, fz_shade *shd)
  102. {
  103. jobject jshd;
  104. if (!ctx || !shd) return NULL;
  105. fz_keep_shade(ctx, shd);
  106. jshd = (*env)->NewObject(env, cls_Shade, mid_Shade_init, jlong_cast(shd));
  107. if (!jshd)
  108. fz_drop_shade(ctx, shd);
  109. if ((*env)->ExceptionCheck(env))
  110. fz_throw_java(ctx, env);
  111. return jshd;
  112. }
  113. static inline jobject to_StrokeState(fz_context *ctx, JNIEnv *env, const fz_stroke_state *state)
  114. {
  115. jobject jstate;
  116. if (!ctx || !state) return NULL;
  117. fz_keep_stroke_state(ctx, state);
  118. jstate = (*env)->NewObject(env, cls_StrokeState, mid_StrokeState_init, jlong_cast(state));
  119. if (!jstate)
  120. fz_drop_stroke_state(ctx, state);
  121. if ((*env)->ExceptionCheck(env))
  122. fz_throw_java(ctx, env);
  123. return jstate;
  124. }
  125. static inline jobject to_Text(fz_context *ctx, JNIEnv *env, const fz_text *text)
  126. {
  127. jobject jtext;
  128. if (!ctx) return NULL;
  129. fz_keep_text(ctx, text);
  130. jtext = (*env)->NewObject(env, cls_Text, mid_Text_init, jlong_cast(text));
  131. if (!jtext)
  132. fz_drop_text(ctx, text);
  133. if ((*env)->ExceptionCheck(env))
  134. fz_throw_java(ctx, env);
  135. return jtext;
  136. }
  137. static inline jbyteArray to_byteArray(fz_context *ctx, JNIEnv *env, const unsigned char *arr, jint n)
  138. {
  139. jbyteArray jarr;
  140. if (!ctx) return NULL;
  141. jarr = (*env)->NewByteArray(env, n);
  142. if ((*env)->ExceptionCheck(env))
  143. fz_throw_java(ctx, env);
  144. if (!jarr)
  145. fz_throw(ctx, FZ_ERROR_GENERIC, "cannot allocate byte array");
  146. (*env)->SetByteArrayRegion(env, jarr, 0, n, (jbyte *) arr);
  147. if ((*env)->ExceptionCheck(env))
  148. fz_throw_java(ctx, env);
  149. return jarr;
  150. }
  151. static inline jfloatArray to_floatArray(fz_context *ctx, JNIEnv *env, const float *arr, jint n)
  152. {
  153. jfloatArray jarr;
  154. if (!ctx) return NULL;
  155. jarr = (*env)->NewFloatArray(env, n);
  156. if ((*env)->ExceptionCheck(env))
  157. fz_throw_java(ctx, env);
  158. if (!jarr)
  159. fz_throw(ctx, FZ_ERROR_GENERIC, "cannot allocate float array");
  160. (*env)->SetFloatArrayRegion(env, jarr, 0, n, arr);
  161. if ((*env)->ExceptionCheck(env))
  162. fz_throw_java(ctx, env);
  163. return jarr;
  164. }
  165. static inline jintArray to_intArray(fz_context *ctx, JNIEnv *env, const int *arr, jint n)
  166. {
  167. jintArray jarr;
  168. if (!ctx) return NULL;
  169. jarr = (*env)->NewIntArray(env, n);
  170. if ((*env)->ExceptionCheck(env))
  171. fz_throw_java(ctx, env);
  172. if (!jarr)
  173. fz_throw(ctx, FZ_ERROR_GENERIC, "cannot allocate int array");
  174. (*env)->SetIntArrayRegion(env, jarr, 0, n, (jint *) arr);
  175. if ((*env)->ExceptionCheck(env))
  176. fz_throw_java(ctx, env);
  177. return jarr;
  178. }
  179. /* Conversion functions: C to Java. None of these throw fitz exceptions. */
  180. static inline jobject to_Buffer_safe(fz_context *ctx, JNIEnv *env, fz_buffer *buf)
  181. {
  182. jobject jbuf;
  183. if (!ctx || !buf) return NULL;
  184. fz_keep_buffer(ctx, buf);
  185. jbuf = (*env)->NewObject(env, cls_Buffer, mid_Buffer_init, jlong_cast(buf));
  186. if (!jbuf)
  187. fz_drop_buffer(ctx, buf);
  188. return jbuf;
  189. }
  190. static inline jint to_ColorParams_safe(fz_context *ctx, JNIEnv *env, fz_color_params cp)
  191. {
  192. if (!ctx) return 0;
  193. return (((int) (!!cp.bp)<<5) | ((int) (!!cp.op)<<6) | ((int) (!!cp.opm)<<7) | (cp.ri & 31));
  194. }
  195. static inline jobject to_ColorSpace_safe(fz_context *ctx, JNIEnv *env, fz_colorspace *cs)
  196. {
  197. jobject jcs;
  198. if (!ctx || !cs) return NULL;
  199. fz_keep_colorspace(ctx, cs);
  200. jcs = (*env)->CallStaticObjectMethod(env, cls_ColorSpace, mid_ColorSpace_fromPointer, jlong_cast(cs));
  201. if (!jcs) fz_drop_colorspace(ctx, cs);
  202. if ((*env)->ExceptionCheck(env)) return NULL;
  203. return jcs;
  204. }
  205. static inline jobject to_Font_safe(fz_context *ctx, JNIEnv *env, fz_font *font)
  206. {
  207. jobject jfont;
  208. if (!ctx || !font) return NULL;
  209. fz_keep_font(ctx, font);
  210. jfont = (*env)->NewObject(env, cls_Font, mid_Font_init, jlong_cast(font));
  211. if (!jfont)
  212. fz_drop_font(ctx, font);
  213. return jfont;
  214. }
  215. static inline jobject to_Image_safe(fz_context *ctx, JNIEnv *env, fz_image *img)
  216. {
  217. jobject jimg;
  218. if (!ctx || !img) return NULL;
  219. fz_keep_image(ctx, img);
  220. jimg = (*env)->NewObject(env, cls_Image, mid_Image_init, jlong_cast(img));
  221. if (!jimg)
  222. fz_drop_image(ctx, img);
  223. return jimg;
  224. }
  225. static inline jobject to_Link_safe(fz_context *ctx, JNIEnv *env, fz_link *link)
  226. {
  227. jobject jlink;
  228. if (!ctx || !link) return NULL;
  229. fz_keep_link(ctx, link);
  230. jlink = (*env)->NewObject(env, cls_Link, mid_Link_init, jlong_cast(link));
  231. if (!jlink)
  232. fz_drop_link(ctx, link);
  233. return jlink;
  234. }
  235. static inline jobject to_Matrix_safe(fz_context *ctx, JNIEnv *env, fz_matrix mat)
  236. {
  237. if (!ctx) return NULL;
  238. return (*env)->NewObject(env, cls_Matrix, mid_Matrix_init, mat.a, mat.b, mat.c, mat.d, mat.e, mat.f);
  239. }
  240. static inline jobject to_Outline_safe(fz_context *ctx, JNIEnv *env, fz_document *doc, fz_outline *outline)
  241. {
  242. jobject joutline = NULL;
  243. jobject jarr = NULL;
  244. jsize jindex = 0;
  245. jsize count = 0;
  246. fz_outline *counter = outline;
  247. if (!ctx || !outline) return NULL;
  248. while (counter)
  249. {
  250. count++;
  251. counter = counter->next;
  252. }
  253. jarr = (*env)->NewObjectArray(env, count, cls_Outline, NULL);
  254. if (!jarr || (*env)->ExceptionCheck(env)) return NULL;
  255. while (outline)
  256. {
  257. jstring jtitle = NULL;
  258. jstring juri = NULL;
  259. jobject jdown = NULL;
  260. if (outline->title)
  261. {
  262. jtitle = (*env)->NewStringUTF(env, outline->title);
  263. if (!jtitle || (*env)->ExceptionCheck(env)) return NULL;
  264. }
  265. if (outline->uri)
  266. {
  267. juri = (*env)->NewStringUTF(env, outline->uri);
  268. if (!juri || (*env)->ExceptionCheck(env)) return NULL;
  269. }
  270. if (outline->down)
  271. {
  272. jdown = to_Outline_safe(ctx, env, doc, outline->down);
  273. if (!jdown) return NULL;
  274. }
  275. joutline = (*env)->NewObject(env, cls_Outline, mid_Outline_init, jtitle, juri, jdown);
  276. if (!joutline) return NULL;
  277. if (jdown)
  278. (*env)->DeleteLocalRef(env, jdown);
  279. if (juri)
  280. (*env)->DeleteLocalRef(env, juri);
  281. if (jtitle)
  282. (*env)->DeleteLocalRef(env, jtitle);
  283. (*env)->SetObjectArrayElement(env, jarr, jindex++, joutline);
  284. if ((*env)->ExceptionCheck(env)) return NULL;
  285. (*env)->DeleteLocalRef(env, joutline);
  286. outline = outline->next;
  287. }
  288. return jarr;
  289. }
  290. static inline jobject to_OutlineIterator_safe(fz_context *ctx, JNIEnv *env, fz_outline_iterator *iterator)
  291. {
  292. jobject jiterator = NULL;
  293. if (!ctx || !iterator) return NULL;
  294. jiterator = (*env)->NewObject(env, cls_OutlineIterator, mid_OutlineIterator_init, (jlong)iterator);
  295. if (!jiterator || (*env)->ExceptionCheck(env)) return NULL;
  296. return jiterator;
  297. }
  298. static inline jobject to_PDFAnnotation_safe(fz_context *ctx, JNIEnv *env, pdf_annot *annot)
  299. {
  300. jobject jannot;
  301. if (!ctx || !annot) return NULL;
  302. pdf_keep_annot(ctx, annot);
  303. jannot = (*env)->NewObject(env, cls_PDFAnnotation, mid_PDFAnnotation_init, jlong_cast(annot));
  304. if (!jannot)
  305. pdf_drop_annot(ctx, annot);
  306. return jannot;
  307. }
  308. static inline jobject to_PDFDocument_safe(fz_context *ctx, JNIEnv *env, pdf_document *pdf)
  309. {
  310. jobject jpdf;
  311. if (!ctx || !pdf) return NULL;
  312. pdf_keep_document(ctx, pdf);
  313. jpdf = (*env)->NewObject(env, cls_PDFDocument, mid_PDFDocument_init, jlong_cast(pdf));
  314. if (!jpdf)
  315. pdf_drop_document(ctx, pdf);
  316. return jpdf;
  317. }
  318. static inline jobject to_PDFObject_safe(fz_context *ctx, JNIEnv *env, pdf_obj *obj)
  319. {
  320. jobject jobj;
  321. if (!ctx) return NULL;
  322. if (obj == NULL)
  323. return (*env)->GetStaticObjectField(env, cls_PDFObject, fid_PDFObject_Null);
  324. pdf_keep_obj(ctx, obj);
  325. jobj = (*env)->NewObject(env, cls_PDFObject, mid_PDFObject_init, jlong_cast(obj));
  326. if (!jobj)
  327. pdf_drop_obj(ctx, obj);
  328. return jobj;
  329. }
  330. static inline jobject to_Point_safe(fz_context *ctx, JNIEnv *env, fz_point point)
  331. {
  332. if (!ctx) return NULL;
  333. return (*env)->NewObject(env, cls_Point, mid_Point_init, point.x, point.y);
  334. }
  335. static inline jobject to_Quad_safe(fz_context *ctx, JNIEnv *env, fz_quad quad)
  336. {
  337. if (!ctx) return NULL;
  338. return (*env)->NewObject(env, cls_Quad, mid_Quad_init,
  339. quad.ul.x, quad.ul.y,
  340. quad.ur.x, quad.ur.y,
  341. quad.ll.x, quad.ll.y,
  342. quad.lr.x, quad.lr.y);
  343. }
  344. static inline jobjectArray to_QuadArray_safe(fz_context *ctx, JNIEnv *env, const fz_quad *quads, jint n)
  345. {
  346. jobjectArray arr;
  347. int i;
  348. if (!ctx || !quads) return NULL;
  349. arr = (*env)->NewObjectArray(env, n, cls_Quad, NULL);
  350. if (!arr || (*env)->ExceptionCheck(env)) return NULL;
  351. for (i = 0; i < n; i++)
  352. {
  353. jobject jquad = to_Quad_safe(ctx, env, quads[i]);
  354. if (!jquad) return NULL;
  355. (*env)->SetObjectArrayElement(env, arr, i, jquad);
  356. if ((*env)->ExceptionCheck(env)) return NULL;
  357. (*env)->DeleteLocalRef(env, jquad);
  358. }
  359. return arr;
  360. }
  361. static inline jobject to_DOM_safe(fz_context *ctx, JNIEnv *env, fz_xml *xml)
  362. {
  363. jobject jxml;
  364. if (!ctx || !xml) return NULL;
  365. fz_keep_xml(ctx, xml);
  366. jxml = (*env)->NewObject(env, cls_DOM, mid_DOM_init, jlong_cast(xml));
  367. if (!jxml) fz_drop_xml(ctx, xml);
  368. if ((*env)->ExceptionCheck(env)) return NULL;
  369. return jxml;
  370. }
  371. static inline jobject to_Shade_safe(fz_context *ctx, JNIEnv *env, fz_shade *sh)
  372. {
  373. jobject jsh;
  374. if (!ctx || !sh) return NULL;
  375. fz_keep_shade(ctx, sh);
  376. jsh = (*env)->NewObject(env, cls_Shade, mid_Shade_init, jlong_cast(sh));
  377. if (!jsh) fz_drop_shade(ctx, sh);
  378. if ((*env)->ExceptionCheck(env)) return NULL;
  379. return jsh;
  380. }
  381. static inline jobject to_String_safe(fz_context *ctx, JNIEnv *env, const char *val)
  382. {
  383. jstring jval;
  384. if (!ctx) return NULL;
  385. jval = (*env)->NewStringUTF(env, val);
  386. if (!jval || (*env)->ExceptionCheck(env))
  387. fz_throw_java(ctx, env);
  388. return jval;
  389. }
  390. static inline jobject to_Rect_safe(fz_context *ctx, JNIEnv *env, fz_rect rect)
  391. {
  392. if (!ctx) return NULL;
  393. return (*env)->NewObject(env, cls_Rect, mid_Rect_init, rect.x0, rect.y0, rect.x1, rect.y1);
  394. }
  395. static inline jobjectArray to_StringArray_safe(fz_context *ctx, JNIEnv *env, const char **strings, int n)
  396. {
  397. jobjectArray arr;
  398. int i;
  399. if (!ctx || !strings) return NULL;
  400. arr = (*env)->NewObjectArray(env, n, cls_String, NULL);
  401. if (!arr || (*env)->ExceptionCheck(env)) return NULL;
  402. for (i = 0; i < n; i++)
  403. {
  404. jstring jstring;
  405. jstring = (*env)->NewStringUTF(env, strings[i]);
  406. if (!jstring || (*env)->ExceptionCheck(env)) return NULL;
  407. (*env)->SetObjectArrayElement(env, arr, i, jstring);
  408. if ((*env)->ExceptionCheck(env)) return NULL;
  409. (*env)->DeleteLocalRef(env, jstring);
  410. }
  411. return arr;
  412. }
  413. static inline jobject to_PDFWidget_safe(fz_context *ctx, JNIEnv *env, pdf_annot *widget)
  414. {
  415. jobject jwidget;
  416. int nopts;
  417. char **opts = NULL;
  418. jobjectArray jopts = NULL;
  419. fz_var(opts);
  420. pdf_keep_annot(ctx, widget);
  421. jwidget = (*env)->NewObject(env, cls_PDFWidget, mid_PDFWidget_init, jlong_cast(widget));
  422. if (!jwidget || (*env)->ExceptionCheck(env))
  423. {
  424. pdf_drop_annot(ctx, widget);
  425. jni_throw_null(env, "cannot wrap PDF widget in java object");
  426. }
  427. fz_try(ctx)
  428. {
  429. int fieldType = pdf_widget_type(ctx, widget);
  430. int fieldFlags = pdf_field_flags(ctx, pdf_annot_obj(ctx, widget));
  431. (*env)->SetIntField(env, jwidget, fid_PDFWidget_fieldType, fieldType);
  432. (*env)->SetIntField(env, jwidget, fid_PDFWidget_fieldFlags, fieldFlags);
  433. if (fieldType == PDF_WIDGET_TYPE_TEXT)
  434. {
  435. (*env)->SetIntField(env, jwidget, fid_PDFWidget_maxLen, pdf_text_widget_max_len(ctx, widget));
  436. (*env)->SetIntField(env, jwidget, fid_PDFWidget_textFormat, pdf_text_widget_format(ctx, widget));
  437. }
  438. if (fieldType == PDF_WIDGET_TYPE_COMBOBOX || fieldType == PDF_WIDGET_TYPE_LISTBOX)
  439. {
  440. nopts = pdf_choice_widget_options(ctx, widget, 0, NULL);
  441. if (nopts > 0)
  442. {
  443. opts = Memento_label(fz_malloc(ctx, nopts * sizeof(*opts)), "to_PDFWidget");
  444. pdf_choice_widget_options(ctx, widget, 0, (const char **)opts);
  445. jopts = to_StringArray_safe(ctx, env, (const char **)opts, nopts);
  446. if (!jopts || (*env)->ExceptionCheck(env))
  447. fz_throw_java(ctx, env);
  448. }
  449. }
  450. }
  451. fz_always(ctx)
  452. {
  453. fz_free(ctx, opts);
  454. }
  455. fz_catch(ctx)
  456. {
  457. jni_rethrow(env, ctx);
  458. }
  459. (*env)->SetObjectField(env, jwidget, fid_PDFWidget_options, jopts);
  460. return jwidget;
  461. }
  462. static inline jobject to_VectorInfo_safe(fz_context *ctx, JNIEnv *env, int flags)
  463. {
  464. jobject jvecinfo;
  465. if (!ctx) return NULL;
  466. jvecinfo = (*env)->NewObject(env, cls_StructuredTextWalker_VectorInfo, mid_StructuredTextWalker_VectorInfo_init);
  467. (*env)->SetBooleanField(env, jvecinfo, fid_StructuredTextWalker_VectorInfo_isStroked, flags & FZ_STEXT_VECTOR_IS_STROKED);
  468. (*env)->SetBooleanField(env, jvecinfo, fid_StructuredTextWalker_VectorInfo_isRectangle, flags & FZ_STEXT_VECTOR_IS_RECTANGLE);
  469. return jvecinfo;
  470. }
  471. /* Conversion functions: C to Java. Take ownership of fitz object. None of these throw fitz exceptions. */
  472. static inline jobject to_Buffer_safe_own(fz_context *ctx, JNIEnv *env, fz_buffer *buf)
  473. {
  474. jobject jobj;
  475. if (!ctx || !buf) return NULL;
  476. jobj = (*env)->NewObject(env, cls_Buffer, mid_Buffer_init, jlong_cast(buf));
  477. if (!jobj)
  478. fz_drop_buffer(ctx, buf);
  479. return jobj;
  480. }
  481. static inline jobject to_ColorSpace_safe_own(fz_context *ctx, JNIEnv *env, fz_colorspace *cs)
  482. {
  483. jobject jobj;
  484. if (!ctx || !cs) return NULL;
  485. jobj = (*env)->NewObject(env, cls_ColorSpace, mid_ColorSpace_init, jlong_cast(cs));
  486. if (!jobj)
  487. fz_drop_colorspace(ctx, cs);
  488. return jobj;
  489. }
  490. static inline jobject to_Document_safe_own(fz_context *ctx, JNIEnv *env, fz_document *doc)
  491. {
  492. jobject obj;
  493. pdf_document *pdf;
  494. if (!ctx || !doc) return NULL;
  495. pdf = pdf_document_from_fz_document(ctx, doc);
  496. if (pdf)
  497. /* This relies on the fact that pdf == doc! */
  498. obj = (*env)->NewObject(env, cls_PDFDocument, mid_PDFDocument_init, jlong_cast(pdf));
  499. else
  500. obj = (*env)->NewObject(env, cls_Document, mid_Document_init, jlong_cast(doc));
  501. if (!obj)
  502. fz_drop_document(ctx, doc);
  503. return obj;
  504. }
  505. static inline jobject to_DisplayList_safe_own(fz_context *ctx, JNIEnv *env, fz_display_list *list)
  506. {
  507. jobject jlist;
  508. if (!ctx || !list) return NULL;
  509. jlist = (*env)->NewObject(env, cls_DisplayList, mid_DisplayList_init, jlong_cast(list));
  510. if (!jlist)
  511. fz_drop_display_list(ctx, list);
  512. return jlist;
  513. }
  514. static inline jobject to_Image_safe_own(fz_context *ctx, JNIEnv *env, fz_image *img)
  515. {
  516. jobject jimg;
  517. if (!ctx || !img) return NULL;
  518. jimg = (*env)->NewObject(env, cls_Image, mid_Image_init, jlong_cast(img));
  519. if (!jimg)
  520. fz_drop_image(ctx, img);
  521. return jimg;
  522. }
  523. static inline jobject to_NativeDevice_safe_own(fz_context *ctx, JNIEnv *env, fz_device *device)
  524. {
  525. jobject jdev;
  526. if (!ctx || !device) return NULL;
  527. jdev = (*env)->NewObject(env, cls_NativeDevice, mid_NativeDevice_init, jlong_cast(device));
  528. if (!jdev)
  529. fz_drop_device(ctx, device);
  530. return jdev;
  531. }
  532. static inline jobject to_Page_safe_own(fz_context *ctx, JNIEnv *env, fz_page *page)
  533. {
  534. jobject jobj;
  535. pdf_page *ppage;
  536. if (!ctx || !page) return NULL;
  537. ppage = pdf_page_from_fz_page(ctx, page);
  538. if (ppage)
  539. jobj = (*env)->NewObject(env, cls_PDFPage, mid_PDFPage_init, jlong_cast(page));
  540. else
  541. jobj = (*env)->NewObject(env, cls_Page, mid_Page_init, jlong_cast(page));
  542. if (!jobj)
  543. fz_drop_page(ctx, page);
  544. return jobj;
  545. }
  546. static inline jobject to_PDFDocument_safe_own(fz_context *ctx, JNIEnv *env, pdf_document *pdf)
  547. {
  548. jobject obj;
  549. if (!ctx || !pdf) return NULL;
  550. obj = (*env)->NewObject(env, cls_PDFDocument, mid_PDFDocument_init, jlong_cast(pdf));
  551. if (!obj)
  552. fz_drop_document(ctx, &pdf->super);
  553. return obj;
  554. }
  555. static inline jobject to_Link_safe_own(fz_context *ctx, JNIEnv *env, fz_link *link)
  556. {
  557. jobject jobj;
  558. if (!ctx || !link) return NULL;
  559. jobj = (*env)->NewObject(env, cls_Link, mid_Link_init, jlong_cast(link));
  560. if (!jobj)
  561. fz_drop_link(ctx, link);
  562. return jobj;
  563. }
  564. static inline jobject to_PDFAnnotation_safe_own(fz_context *ctx, JNIEnv *env, pdf_annot *annot)
  565. {
  566. jobject jannot;
  567. if (!ctx || !annot) return NULL;
  568. jannot = (*env)->NewObject(env, cls_PDFAnnotation, mid_PDFAnnotation_init, jlong_cast(annot));
  569. if (!jannot)
  570. pdf_drop_annot(ctx, annot);
  571. return jannot;
  572. }
  573. static inline jobject to_PDFWidget_safe_own(fz_context *ctx, JNIEnv *env, pdf_annot *widget)
  574. {
  575. jobject jwidget;
  576. if (!ctx || !widget) return NULL;
  577. jwidget = (*env)->NewObject(env, cls_PDFWidget, mid_PDFWidget_init, jlong_cast(widget));
  578. if (!jwidget)
  579. pdf_drop_annot(ctx, widget);
  580. return jwidget;
  581. }
  582. static inline jobject to_PDFGraftMap_safe_own(fz_context *ctx, JNIEnv *env, jobject pdf, pdf_graft_map *map)
  583. {
  584. jobject jmap;
  585. if (!ctx || !map || !pdf) return NULL;
  586. jmap = (*env)->NewObject(env, cls_PDFGraftMap, mid_PDFGraftMap_init, jlong_cast(map), pdf);
  587. if (!jmap)
  588. pdf_drop_graft_map(ctx, map);
  589. return jmap;
  590. }
  591. static inline jobject to_PDFObject_safe_own(fz_context *ctx, JNIEnv *env, pdf_obj *obj)
  592. {
  593. jobject jobj;
  594. if (!ctx || !obj) return NULL;
  595. jobj = (*env)->NewObject(env, cls_PDFObject, mid_PDFObject_init, jlong_cast(obj));
  596. if (!jobj)
  597. pdf_drop_obj(ctx, obj);
  598. return jobj;
  599. }
  600. static inline jobject to_Pixmap_safe_own(fz_context *ctx, JNIEnv *env, fz_pixmap *pixmap)
  601. {
  602. jobject jobj;
  603. if (!ctx || !pixmap) return NULL;
  604. jobj = (*env)->NewObject(env, cls_Pixmap, mid_Pixmap_init, jlong_cast(pixmap));
  605. if (!jobj)
  606. fz_drop_pixmap(ctx, pixmap);
  607. return jobj;
  608. }
  609. static inline jobject to_String_safe_own(fz_context *ctx, JNIEnv *env, char *val)
  610. {
  611. jstring jval;
  612. if (!ctx) return NULL;
  613. jval = (*env)->NewStringUTF(env, val);
  614. fz_free(ctx, val);
  615. return jval;
  616. }
  617. static inline jobject to_StructuredText_safe_own(fz_context *ctx, JNIEnv *env, fz_stext_page *text)
  618. {
  619. jobject jtext;
  620. if (!ctx || !text) return NULL;
  621. jtext = (*env)->NewObject(env, cls_StructuredText, mid_StructuredText_init, jlong_cast(text));
  622. if (!jtext)
  623. fz_drop_stext_page(ctx, text);
  624. return jtext;
  625. }
  626. /* Conversion functions: Java to C. These all throw java exceptions. */
  627. static inline fz_archive *from_Archive(JNIEnv *env, jobject jobj)
  628. {
  629. fz_archive *arch;
  630. if (!jobj) return NULL;
  631. arch = CAST(fz_archive *, (*env)->GetLongField(env, jobj, fid_Archive_pointer));
  632. if (!arch) jni_throw_null(env, "cannot use already destroyed Archive");
  633. return arch;
  634. }
  635. static inline fz_buffer *from_Buffer(JNIEnv *env, jobject jobj)
  636. {
  637. fz_buffer *buffer;
  638. if (!jobj) return NULL;
  639. buffer = CAST(fz_buffer *, (*env)->GetLongField(env, jobj, fid_Buffer_pointer));
  640. if (!buffer) jni_throw_null(env, "cannot use already destroyed Buffer");
  641. return buffer;
  642. }
  643. static inline fz_colorspace *from_ColorSpace(JNIEnv *env, jobject jobj)
  644. {
  645. fz_colorspace *cs;
  646. if (!jobj) return NULL;
  647. cs = CAST(fz_colorspace *, (*env)->GetLongField(env, jobj, fid_ColorSpace_pointer));
  648. if (!cs) jni_throw_null(env, "cannot use already destroyed ColorSpace");
  649. return cs;
  650. }
  651. static inline fz_cookie *from_Cookie(JNIEnv *env, jobject jobj)
  652. {
  653. fz_cookie *cookie;
  654. if (!jobj) return NULL;
  655. cookie = CAST(fz_cookie *, (*env)->GetLongField(env, jobj, fid_Cookie_pointer));
  656. if (!cookie) jni_throw_null(env, "cannot use already destroyed Cookie");
  657. return cookie;
  658. }
  659. static inline fz_default_colorspaces *from_DefaultColorSpaces(JNIEnv *env, jobject jobj)
  660. {
  661. fz_default_colorspaces *dcs;
  662. if (!jobj) return NULL;
  663. dcs = CAST(fz_default_colorspaces *, (*env)->GetLongField(env, jobj, fid_DefaultColorSpaces_pointer));
  664. if (!dcs) jni_throw_null(env, "cannot use already destroyed DefaultColorSpaces");
  665. return dcs;
  666. }
  667. static fz_device *from_Device(JNIEnv *env, jobject jobj)
  668. {
  669. fz_device *dev;
  670. if (!jobj) return NULL;
  671. dev = CAST(fz_device *, (*env)->GetLongField(env, jobj, fid_Device_pointer));
  672. if (!dev) jni_throw_null(env, "cannot use already destroyed Device");
  673. return dev;
  674. }
  675. static inline fz_display_list *from_DisplayList(JNIEnv *env, jobject jobj)
  676. {
  677. fz_display_list *list;
  678. if (!jobj) return NULL;
  679. list = CAST(fz_display_list *, (*env)->GetLongField(env, jobj, fid_DisplayList_pointer));
  680. if (!list) jni_throw_null(env, "cannot use already destroyed DisplayList");
  681. return list;
  682. }
  683. static inline fz_document *from_Document(JNIEnv *env, jobject jobj)
  684. {
  685. fz_document *doc;
  686. if (!jobj) return NULL;
  687. doc = CAST(fz_document *, (*env)->GetLongField(env, jobj, fid_Document_pointer));
  688. if (!doc) jni_throw_null(env, "cannot use already destroyed Document");
  689. return doc;
  690. }
  691. static inline fz_document_writer *from_DocumentWriter(JNIEnv *env, jobject jobj)
  692. {
  693. fz_document_writer *wri;
  694. if (!jobj) return NULL;
  695. wri = CAST(fz_document_writer *, (*env)->GetLongField(env, jobj, fid_DocumentWriter_pointer));
  696. if (!wri) jni_throw_null(env, "cannot use already destroyed DocumentWriter");
  697. return wri;
  698. }
  699. static inline fz_font *from_Font(JNIEnv *env, jobject jobj)
  700. {
  701. fz_font *font;
  702. if (!jobj) return NULL;
  703. font = CAST(fz_font *, (*env)->GetLongField(env, jobj, fid_Font_pointer));
  704. if (!font) jni_throw_null(env, "cannot use already destroyed Font");
  705. return font;
  706. }
  707. static inline fz_image *from_Image(JNIEnv *env, jobject jobj)
  708. {
  709. fz_image *image;
  710. if (!jobj) return NULL;
  711. image = CAST(fz_image *, (*env)->GetLongField(env, jobj, fid_Image_pointer));
  712. if (!image) jni_throw_null(env, "cannot use already destroyed Image");
  713. return image;
  714. }
  715. static inline fz_link *from_Link(JNIEnv *env, jobject jobj)
  716. {
  717. fz_link *link;
  718. if (!jobj) return NULL;
  719. link = CAST(fz_link *, (*env)->GetLongField(env, jobj, fid_Link_pointer));
  720. if (!link) jni_throw_null(env, "cannot use already destroyed Link");
  721. return link;
  722. }
  723. static inline fz_outline_iterator *from_OutlineIterator(JNIEnv *env, jobject jobj)
  724. {
  725. fz_outline_iterator *iterator;
  726. if (!jobj) return NULL;
  727. iterator = CAST(fz_outline_iterator *, (*env)->GetLongField(env, jobj, fid_OutlineIterator_pointer));
  728. if (!iterator) jni_throw_null(env, "cannot use already destroyed OutlineIterator");
  729. return iterator;
  730. }
  731. static inline fz_page *from_Page(JNIEnv *env, jobject jobj)
  732. {
  733. fz_page *page;
  734. if (!jobj) return NULL;
  735. page = CAST(fz_page *, (*env)->GetLongField(env, jobj, fid_Page_pointer));
  736. if (!page) jni_throw_null(env, "cannot use already destroyed Page");
  737. return page;
  738. }
  739. static inline fz_path *from_Path(JNIEnv *env, jobject jobj)
  740. {
  741. fz_path *path;
  742. if (!jobj) return NULL;
  743. path = CAST(fz_path *, (*env)->GetLongField(env, jobj, fid_Path_pointer));
  744. if (!path) jni_throw_null(env, "cannot use already destroyed Path");
  745. return path;
  746. }
  747. static inline pdf_annot *from_PDFAnnotation(JNIEnv *env, jobject jobj)
  748. {
  749. pdf_annot *annot;
  750. if (!jobj) return NULL;
  751. annot = CAST(pdf_annot *, (*env)->GetLongField(env, jobj, fid_PDFAnnotation_pointer));
  752. if (!annot) jni_throw_null(env, "cannot use already destroyed PDFAnnotation");
  753. return annot;
  754. }
  755. static inline pdf_document *from_PDFDocument(JNIEnv *env, jobject jobj)
  756. {
  757. pdf_document *pdf;
  758. if (!jobj) return NULL;
  759. pdf = CAST(pdf_document *, (*env)->GetLongField(env, jobj, fid_PDFDocument_pointer));
  760. if (!pdf) jni_throw_null(env, "cannot use already destroyed PDFDocument");
  761. return pdf;
  762. }
  763. static inline pdf_graft_map *from_PDFGraftMap(JNIEnv *env, jobject jobj)
  764. {
  765. pdf_graft_map *map;
  766. if (!jobj) return NULL;
  767. map = CAST(pdf_graft_map *, (*env)->GetLongField(env, jobj, fid_PDFGraftMap_pointer));
  768. if (!map) jni_throw_null(env, "cannot use already destroyed PDFGraftMap");
  769. return map;
  770. }
  771. static inline pdf_obj *from_PDFObject(JNIEnv *env, jobject jobj)
  772. {
  773. pdf_obj *obj;
  774. if (!jobj) return NULL;
  775. obj = CAST(pdf_obj *, (*env)->GetLongField(env, jobj, fid_PDFObject_pointer));
  776. return obj;
  777. }
  778. static inline pdf_page *from_PDFPage(JNIEnv *env, jobject jobj)
  779. {
  780. pdf_page *page;
  781. if (!jobj) return NULL;
  782. page = CAST(pdf_page *, (*env)->GetLongField(env, jobj, fid_PDFPage_pointer));
  783. if (!page) jni_throw_null(env, "cannot use already destroyed PDFPage");
  784. return page;
  785. }
  786. static inline fz_pixmap *from_Pixmap(JNIEnv *env, jobject jobj)
  787. {
  788. fz_pixmap *pixmap;
  789. if (!jobj) return NULL;
  790. pixmap = CAST(fz_pixmap *, (*env)->GetLongField(env, jobj, fid_Pixmap_pointer));
  791. if (!pixmap) jni_throw_null(env, "cannot use already destroyed Pixmap");
  792. return pixmap;
  793. }
  794. static inline fz_shade *from_Shade(JNIEnv *env, jobject jobj)
  795. {
  796. fz_shade *shd;
  797. if (!jobj) return NULL;
  798. shd = CAST(fz_shade *, (*env)->GetLongField(env, jobj, fid_Shade_pointer));
  799. if (!shd) jni_throw_null(env, "cannot use already destroyed Shade");
  800. return shd;
  801. }
  802. static inline fz_stroke_state *from_StrokeState(JNIEnv *env, jobject jobj)
  803. {
  804. fz_stroke_state *stroke;
  805. if (!jobj) return NULL;
  806. stroke = CAST(fz_stroke_state *, (*env)->GetLongField(env, jobj, fid_StrokeState_pointer));
  807. if (!stroke) jni_throw_null(env, "cannot use already destroyed StrokeState");
  808. return stroke;
  809. }
  810. static inline fz_stext_page *from_StructuredText(JNIEnv *env, jobject jobj)
  811. {
  812. fz_stext_page *stext;
  813. if (!jobj) return NULL;
  814. stext = CAST(fz_stext_page *, (*env)->GetLongField(env, jobj, fid_StructuredText_pointer));
  815. if (!stext) jni_throw_null(env, "cannot use already destroyed StructuredText");
  816. return stext;
  817. }
  818. static inline fz_text *from_Text(JNIEnv *env, jobject jobj)
  819. {
  820. fz_text *text;
  821. if (!jobj) return NULL;
  822. text = CAST(fz_text *, (*env)->GetLongField(env, jobj, fid_Text_pointer));
  823. if (!text) jni_throw_null(env, "cannot use already destroyed Text");
  824. return text;
  825. }
  826. static inline int from_jfloatArray(JNIEnv *env, float *color, jint n, jfloatArray jcolor)
  827. {
  828. jsize len;
  829. if (!jcolor)
  830. len = 0;
  831. else
  832. {
  833. len = (*env)->GetArrayLength(env, jcolor);
  834. if (len > n)
  835. len = n;
  836. (*env)->GetFloatArrayRegion(env, jcolor, 0, len, color);
  837. if ((*env)->ExceptionCheck(env)) return 0;
  838. }
  839. if (len < n)
  840. memset(color+len, 0, (n - len) * sizeof(float));
  841. return 1;
  842. }
  843. static inline fz_matrix from_Matrix(JNIEnv *env, jobject jmat)
  844. {
  845. fz_matrix mat;
  846. if (!jmat)
  847. return fz_identity;
  848. mat.a = (*env)->GetFloatField(env, jmat, fid_Matrix_a);
  849. mat.b = (*env)->GetFloatField(env, jmat, fid_Matrix_b);
  850. mat.c = (*env)->GetFloatField(env, jmat, fid_Matrix_c);
  851. mat.d = (*env)->GetFloatField(env, jmat, fid_Matrix_d);
  852. mat.e = (*env)->GetFloatField(env, jmat, fid_Matrix_e);
  853. mat.f = (*env)->GetFloatField(env, jmat, fid_Matrix_f);
  854. return mat;
  855. }
  856. static inline fz_point from_Point(JNIEnv *env, jobject jpt)
  857. {
  858. fz_point pt;
  859. if (!jpt)
  860. {
  861. pt.x = pt.y = 0;
  862. return pt;
  863. }
  864. pt.x = (*env)->GetFloatField(env, jpt, fid_Point_x);
  865. pt.y = (*env)->GetFloatField(env, jpt, fid_Point_y);
  866. return pt;
  867. }
  868. static inline fz_rect from_Rect(JNIEnv *env, jobject jrect)
  869. {
  870. fz_rect rect;
  871. if (!jrect)
  872. return fz_empty_rect;
  873. rect.x0 = (*env)->GetFloatField(env, jrect, fid_Rect_x0);
  874. rect.x1 = (*env)->GetFloatField(env, jrect, fid_Rect_x1);
  875. rect.y0 = (*env)->GetFloatField(env, jrect, fid_Rect_y0);
  876. rect.y1 = (*env)->GetFloatField(env, jrect, fid_Rect_y1);
  877. return rect;
  878. }
  879. static inline fz_quad from_Quad(JNIEnv *env, jobject jquad)
  880. {
  881. fz_quad quad;
  882. if (!jquad)
  883. return fz_make_quad(0, 0, 0, 0, 0, 0, 0, 0);
  884. quad.ul.x = (*env)->GetFloatField(env, jquad, fid_Quad_ul_x);
  885. quad.ul.y = (*env)->GetFloatField(env, jquad, fid_Quad_ul_y);
  886. quad.ur.x = (*env)->GetFloatField(env, jquad, fid_Quad_ur_x);
  887. quad.ur.y = (*env)->GetFloatField(env, jquad, fid_Quad_ur_y);
  888. quad.ll.x = (*env)->GetFloatField(env, jquad, fid_Quad_ll_x);
  889. quad.ll.y = (*env)->GetFloatField(env, jquad, fid_Quad_ll_y);
  890. quad.lr.x = (*env)->GetFloatField(env, jquad, fid_Quad_lr_x);
  891. quad.lr.y = (*env)->GetFloatField(env, jquad, fid_Quad_lr_y);
  892. return quad;
  893. }
  894. static fz_link_dest from_LinkDestination(JNIEnv *env, jobject jdest)
  895. {
  896. fz_link_dest dest;
  897. if (!jdest)
  898. return fz_make_link_dest_none();
  899. dest.loc.chapter = (*env)->GetIntField(env, jdest, fid_LinkDestination_chapter);
  900. dest.loc.page = (*env)->GetIntField(env, jdest, fid_LinkDestination_page);
  901. dest.type = (*env)->GetIntField(env, jdest, fid_LinkDestination_type);
  902. dest.x = (*env)->GetFloatField(env, jdest, fid_LinkDestination_x);
  903. dest.y = (*env)->GetFloatField(env, jdest, fid_LinkDestination_y);
  904. dest.w = (*env)->GetFloatField(env, jdest, fid_LinkDestination_width);
  905. dest.h = (*env)->GetFloatField(env, jdest, fid_LinkDestination_height);
  906. dest.zoom = (*env)->GetFloatField(env, jdest, fid_LinkDestination_zoom);
  907. return dest;
  908. }
  909. /* Conversion functions: Java to C. None of these throw java exceptions. */
  910. static inline fz_archive *from_Archive_safe(JNIEnv *env, jobject jobj)
  911. {
  912. if (!jobj) return NULL;
  913. return CAST(fz_archive *, (*env)->GetLongField(env, jobj, fid_Archive_pointer));
  914. }
  915. static inline fz_buffer *from_Buffer_safe(JNIEnv *env, jobject jobj)
  916. {
  917. if (!jobj) return NULL;
  918. return CAST(fz_buffer *, (*env)->GetLongField(env, jobj, fid_Buffer_pointer));
  919. }
  920. static inline fz_color_params from_ColorParams_safe(JNIEnv *env, jint params)
  921. {
  922. fz_color_params p;
  923. p.bp = (params>>5) & 1;
  924. p.op = (params>>6) & 1;
  925. p.opm = (params>>7) & 1;
  926. p.ri = (params & 31);
  927. return p;
  928. }
  929. static inline fz_colorspace *from_ColorSpace_safe(JNIEnv *env, jobject jobj)
  930. {
  931. if (!jobj) return NULL;
  932. return CAST(fz_colorspace *, (*env)->GetLongField(env, jobj, fid_ColorSpace_pointer));
  933. }
  934. static inline fz_cookie *from_Cookie_safe(JNIEnv *env, jobject jobj)
  935. {
  936. if (!jobj) return NULL;
  937. return CAST(fz_cookie *, (*env)->GetLongField(env, jobj, fid_Cookie_pointer));
  938. }
  939. static inline fz_default_colorspaces *from_DefaultColorSpaces_safe(JNIEnv *env, jobject jobj)
  940. {
  941. if (!jobj) return NULL;
  942. return CAST(fz_default_colorspaces *, (*env)->GetLongField(env, jobj, fid_DefaultColorSpaces_pointer));
  943. }
  944. static fz_device *from_Device_safe(JNIEnv *env, jobject jobj)
  945. {
  946. if (!jobj) return NULL;
  947. return CAST(fz_device *, (*env)->GetLongField(env, jobj, fid_Device_pointer));
  948. }
  949. static inline fz_display_list *from_DisplayList_safe(JNIEnv *env, jobject jobj)
  950. {
  951. if (!jobj) return NULL;
  952. return CAST(fz_display_list *, (*env)->GetLongField(env, jobj, fid_DisplayList_pointer));
  953. }
  954. static inline fz_document *from_Document_safe(JNIEnv *env, jobject jobj)
  955. {
  956. if (!jobj) return NULL;
  957. return CAST(fz_document *, (*env)->GetLongField(env, jobj, fid_Document_pointer));
  958. }
  959. static inline fz_document_writer *from_DocumentWriter_safe(JNIEnv *env, jobject jobj)
  960. {
  961. if (!jobj) return NULL;
  962. return CAST(fz_document_writer *, (*env)->GetLongField(env, jobj, fid_DocumentWriter_pointer));
  963. }
  964. static inline fz_font *from_Font_safe(JNIEnv *env, jobject jobj)
  965. {
  966. if (!jobj) return NULL;
  967. return CAST(fz_font *, (*env)->GetLongField(env, jobj, fid_Font_pointer));
  968. }
  969. static inline fz_story *from_Story_safe(JNIEnv *env, jobject jobj)
  970. {
  971. if (!jobj) return NULL;
  972. return CAST(fz_story *, (*env)->GetLongField(env, jobj, fid_Story_pointer));
  973. }
  974. static inline fz_image *from_Image_safe(JNIEnv *env, jobject jobj)
  975. {
  976. if (!jobj) return NULL;
  977. return CAST(fz_image *, (*env)->GetLongField(env, jobj, fid_Image_pointer));
  978. }
  979. static inline fz_link *from_Link_safe(JNIEnv *env, jobject jobj)
  980. {
  981. if (!jobj) return NULL;
  982. return CAST(fz_link *, (*env)->GetLongField(env, jobj, fid_Link_pointer));
  983. }
  984. static inline fz_page *from_Page_safe(JNIEnv *env, jobject jobj)
  985. {
  986. if (!jobj) return NULL;
  987. return CAST(fz_page *, (*env)->GetLongField(env, jobj, fid_Page_pointer));
  988. }
  989. static inline fz_path *from_Path_safe(JNIEnv *env, jobject jobj)
  990. {
  991. if (!jobj) return NULL;
  992. return CAST(fz_path *, (*env)->GetLongField(env, jobj, fid_Path_pointer));
  993. }
  994. static inline pdf_annot *from_PDFAnnotation_safe(JNIEnv *env, jobject jobj)
  995. {
  996. if (!jobj) return NULL;
  997. return CAST(pdf_annot *, (*env)->GetLongField(env, jobj, fid_PDFAnnotation_pointer));
  998. }
  999. static inline pdf_document *from_PDFDocument_safe(JNIEnv *env, jobject jobj)
  1000. {
  1001. if (!jobj) return NULL;
  1002. return CAST(pdf_document *, (*env)->GetLongField(env, jobj, fid_PDFDocument_pointer));
  1003. }
  1004. static inline pdf_graft_map *from_PDFGraftMap_safe(JNIEnv *env, jobject jobj)
  1005. {
  1006. if (!jobj) return NULL;
  1007. return CAST(pdf_graft_map *, (*env)->GetLongField(env, jobj, fid_PDFGraftMap_pointer));
  1008. }
  1009. static inline pdf_obj *from_PDFObject_safe(JNIEnv *env, jobject jobj)
  1010. {
  1011. if (!jobj) return NULL;
  1012. return CAST(pdf_obj *, (*env)->GetLongField(env, jobj, fid_PDFObject_pointer));
  1013. }
  1014. static inline pdf_annot *from_PDFWidget_safe(JNIEnv *env, jobject jobj)
  1015. {
  1016. if (!jobj) return NULL;
  1017. return CAST(pdf_annot *, (*env)->GetLongField(env, jobj, fid_PDFWidget_pointer));
  1018. }
  1019. static inline pdf_pkcs7_signer *from_PKCS7Signer_safe(JNIEnv *env, jobject jobj)
  1020. {
  1021. if (!jobj) return NULL;
  1022. return CAST(pdf_pkcs7_signer *, (*env)->GetLongField(env, jobj, fid_PKCS7Signer_pointer));
  1023. }
  1024. static inline java_pkcs7_verifier *from_PKCS7Verifier_safe(JNIEnv *env, jobject jobj)
  1025. {
  1026. if (!jobj) return NULL;
  1027. return CAST(java_pkcs7_verifier *, (*env)->GetLongField(env, jobj, fid_PKCS7Verifier_pointer));
  1028. }
  1029. static inline fz_stream *from_FitzInputStream_safe(JNIEnv *env, jobject jobj)
  1030. {
  1031. if (!jobj) return NULL;
  1032. return CAST(fz_stream *, (*env)->GetLongField(env, jobj, fid_FitzInputStream_pointer));
  1033. }
  1034. static inline fz_pixmap *from_Pixmap_safe(JNIEnv *env, jobject jobj)
  1035. {
  1036. if (!jobj) return NULL;
  1037. return CAST(fz_pixmap *, (*env)->GetLongField(env, jobj, fid_Pixmap_pointer));
  1038. }
  1039. static inline fz_shade *from_Shade_safe(JNIEnv *env, jobject jobj)
  1040. {
  1041. if (!jobj) return NULL;
  1042. return CAST(fz_shade *, (*env)->GetLongField(env, jobj, fid_Shade_pointer));
  1043. }
  1044. static inline fz_stroke_state *from_StrokeState_safe(JNIEnv *env, jobject jobj)
  1045. {
  1046. if (!jobj) return NULL;
  1047. return CAST(fz_stroke_state *, (*env)->GetLongField(env, jobj, fid_StrokeState_pointer));
  1048. }
  1049. static inline fz_stext_page *from_StructuredText_safe(JNIEnv *env, jobject jobj)
  1050. {
  1051. if (!jobj) return NULL;
  1052. return CAST(fz_stext_page *, (*env)->GetLongField(env, jobj, fid_StructuredText_pointer));
  1053. }
  1054. static inline fz_text *from_Text_safe(JNIEnv *env, jobject jobj)
  1055. {
  1056. if (!jobj) return NULL;
  1057. return CAST(fz_text *, (*env)->GetLongField(env, jobj, fid_Text_pointer));
  1058. }
  1059. static inline fz_xml *from_DOM_safe(JNIEnv *env, jobject jobj)
  1060. {
  1061. if (!jobj) return NULL;
  1062. return CAST(fz_xml *, (*env)->GetLongField(env, jobj, fid_DOM_pointer));
  1063. }