pdfannotation.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289
  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. /* Annotation interface */
  23. JNIEXPORT void JNICALL
  24. FUN(PDFAnnotation_finalize)(JNIEnv *env, jobject self)
  25. {
  26. fz_context *ctx = get_context(env);
  27. pdf_annot *annot = from_PDFAnnotation_safe(env, self);
  28. if (!ctx || !annot) return;
  29. (*env)->SetLongField(env, self, fid_PDFAnnotation_pointer, 0);
  30. pdf_drop_annot(ctx, annot);
  31. }
  32. JNIEXPORT void JNICALL
  33. FUN(PDFAnnotation_run)(JNIEnv *env, jobject self, jobject jdev, jobject jctm, jobject jcookie)
  34. {
  35. fz_context *ctx = get_context(env);
  36. pdf_annot *annot = from_PDFAnnotation(env, self);
  37. fz_device *dev = from_Device(env, jdev);
  38. fz_matrix ctm = from_Matrix(env, jctm);
  39. fz_cookie *cookie= from_Cookie(env, jcookie);
  40. NativeDeviceInfo *info;
  41. int err;
  42. if (!ctx || !annot) return;
  43. if (!dev) jni_throw_arg_void(env, "device must not be null");
  44. info = lockNativeDevice(env, jdev, &err);
  45. if (err)
  46. return;
  47. fz_try(ctx)
  48. pdf_run_annot(ctx, annot, dev, ctm, cookie);
  49. fz_always(ctx)
  50. unlockNativeDevice(env, info);
  51. fz_catch(ctx)
  52. jni_rethrow_void(env, ctx);
  53. }
  54. JNIEXPORT jobject JNICALL
  55. FUN(PDFAnnotation_toPixmap)(JNIEnv *env, jobject self, jobject jctm, jobject jcs, jboolean alpha)
  56. {
  57. fz_context *ctx = get_context(env);
  58. pdf_annot *annot = from_PDFAnnotation(env, self);
  59. fz_matrix ctm = from_Matrix(env, jctm);
  60. fz_colorspace *cs = from_ColorSpace(env, jcs);
  61. fz_pixmap *pixmap = NULL;
  62. if (!ctx || !annot) return NULL;
  63. fz_try(ctx)
  64. pixmap = pdf_new_pixmap_from_annot(ctx, annot, ctm, cs, NULL, alpha);
  65. fz_catch(ctx)
  66. jni_rethrow(env, ctx);
  67. return to_Pixmap_safe_own(ctx, env, pixmap);
  68. }
  69. JNIEXPORT jobject JNICALL
  70. FUN(PDFAnnotation_getBounds)(JNIEnv *env, jobject self)
  71. {
  72. fz_context *ctx = get_context(env);
  73. pdf_annot *annot = from_PDFAnnotation(env, self);
  74. fz_rect rect;
  75. if (!ctx || !annot) return NULL;
  76. fz_try(ctx)
  77. rect = pdf_bound_annot(ctx, annot);
  78. fz_catch(ctx)
  79. jni_rethrow(env, ctx);
  80. return to_Rect_safe(ctx, env, rect);
  81. }
  82. JNIEXPORT jobject JNICALL
  83. FUN(PDFAnnotation_toDisplayList)(JNIEnv *env, jobject self)
  84. {
  85. fz_context *ctx = get_context(env);
  86. pdf_annot *annot = from_PDFAnnotation(env, self);
  87. fz_display_list *list = NULL;
  88. if (!ctx || !annot) return NULL;
  89. fz_try(ctx)
  90. list = pdf_new_display_list_from_annot(ctx, annot);
  91. fz_catch(ctx)
  92. jni_rethrow(env, ctx);
  93. return to_DisplayList_safe_own(ctx, env, list);
  94. }
  95. JNIEXPORT jint JNICALL
  96. FUN(PDFAnnotation_getType)(JNIEnv *env, jobject self)
  97. {
  98. fz_context *ctx = get_context(env);
  99. pdf_annot *annot = from_PDFAnnotation(env, self);
  100. jint type = 0;
  101. if (!ctx || !annot) return 0;
  102. fz_try(ctx)
  103. type = pdf_annot_type(ctx, annot);
  104. fz_catch(ctx)
  105. jni_rethrow(env, ctx);
  106. return type;
  107. }
  108. JNIEXPORT jint JNICALL
  109. FUN(PDFAnnotation_getFlags)(JNIEnv *env, jobject self)
  110. {
  111. fz_context *ctx = get_context(env);
  112. pdf_annot *annot = from_PDFAnnotation(env, self);
  113. jint flags = 0;
  114. if (!ctx || !annot) return 0;
  115. fz_try(ctx)
  116. flags = pdf_annot_flags(ctx, annot);
  117. fz_catch(ctx)
  118. jni_rethrow(env, ctx);
  119. return flags;
  120. }
  121. JNIEXPORT void JNICALL
  122. FUN(PDFAnnotation_setFlags)(JNIEnv *env, jobject self, jint flags)
  123. {
  124. fz_context *ctx = get_context(env);
  125. pdf_annot *annot = from_PDFAnnotation(env, self);
  126. if (!ctx || !annot) return;
  127. fz_try(ctx)
  128. pdf_set_annot_flags(ctx, annot, flags);
  129. fz_catch(ctx)
  130. jni_rethrow_void(env, ctx);
  131. }
  132. JNIEXPORT jstring JNICALL
  133. FUN(PDFAnnotation_getContents)(JNIEnv *env, jobject self)
  134. {
  135. fz_context *ctx = get_context(env);
  136. pdf_annot *annot = from_PDFAnnotation(env, self);
  137. const char *contents = NULL;
  138. if (!ctx || !annot) return NULL;
  139. fz_try(ctx)
  140. contents = pdf_annot_contents(ctx, annot);
  141. fz_catch(ctx)
  142. jni_rethrow(env, ctx);
  143. return (*env)->NewStringUTF(env, contents);
  144. }
  145. JNIEXPORT void JNICALL
  146. FUN(PDFAnnotation_setContents)(JNIEnv *env, jobject self, jstring jcontents)
  147. {
  148. fz_context *ctx = get_context(env);
  149. pdf_annot *annot = from_PDFAnnotation(env, self);
  150. const char *contents = "";
  151. if (!ctx || !annot) return;
  152. if (jcontents)
  153. {
  154. contents = (*env)->GetStringUTFChars(env, jcontents, NULL);
  155. if (!contents) return;
  156. }
  157. fz_try(ctx)
  158. pdf_set_annot_contents(ctx, annot, contents);
  159. fz_always(ctx)
  160. if (contents)
  161. (*env)->ReleaseStringUTFChars(env, jcontents, contents);
  162. fz_catch(ctx)
  163. jni_rethrow_void(env, ctx);
  164. }
  165. JNIEXPORT jstring JNICALL
  166. FUN(PDFAnnotation_getAuthor)(JNIEnv *env, jobject self)
  167. {
  168. fz_context *ctx = get_context(env);
  169. pdf_annot *annot = from_PDFAnnotation(env, self);
  170. const char *author = NULL;
  171. if (!ctx || !annot) return NULL;
  172. fz_try(ctx)
  173. author = pdf_annot_author(ctx, annot);
  174. fz_catch(ctx)
  175. jni_rethrow(env, ctx);
  176. return (*env)->NewStringUTF(env, author);
  177. }
  178. JNIEXPORT void JNICALL
  179. FUN(PDFAnnotation_setAuthor)(JNIEnv *env, jobject self, jstring jauthor)
  180. {
  181. fz_context *ctx = get_context(env);
  182. pdf_annot *annot = from_PDFAnnotation(env, self);
  183. const char *author = "";
  184. if (!ctx || !annot) return;
  185. if (jauthor)
  186. {
  187. author = (*env)->GetStringUTFChars(env, jauthor, NULL);
  188. if (!author) return;
  189. }
  190. fz_try(ctx)
  191. pdf_set_annot_author(ctx, annot, author);
  192. fz_always(ctx)
  193. if (author)
  194. (*env)->ReleaseStringUTFChars(env, jauthor, author);
  195. fz_catch(ctx)
  196. jni_rethrow_void(env, ctx);
  197. }
  198. JNIEXPORT jlong JNICALL
  199. FUN(PDFAnnotation_getModificationDateNative)(JNIEnv *env, jobject self)
  200. {
  201. fz_context *ctx = get_context(env);
  202. pdf_annot *annot = from_PDFAnnotation(env, self);
  203. jlong t;
  204. if (!ctx || !annot) return -1;
  205. fz_try(ctx)
  206. t = pdf_annot_modification_date(ctx, annot);
  207. fz_catch(ctx)
  208. jni_rethrow(env, ctx);
  209. return t * 1000;
  210. }
  211. JNIEXPORT void JNICALL
  212. FUN(PDFAnnotation_setModificationDate)(JNIEnv *env, jobject self, jlong time)
  213. {
  214. fz_context *ctx = get_context(env);
  215. pdf_annot *annot = from_PDFAnnotation(env, self);
  216. fz_try(ctx)
  217. pdf_set_annot_modification_date(ctx, annot, time / 1000);
  218. fz_catch(ctx)
  219. jni_rethrow_void(env, ctx);
  220. }
  221. JNIEXPORT jlong JNICALL
  222. FUN(PDFAnnotation_getCreationDateNative)(JNIEnv *env, jobject self)
  223. {
  224. fz_context *ctx = get_context(env);
  225. pdf_annot *annot = from_PDFAnnotation(env, self);
  226. jlong t;
  227. if (!ctx || !annot) return -1;
  228. fz_try(ctx)
  229. t = pdf_annot_creation_date(ctx, annot);
  230. fz_catch(ctx)
  231. jni_rethrow(env, ctx);
  232. return t * 1000;
  233. }
  234. JNIEXPORT void JNICALL
  235. FUN(PDFAnnotation_setCreationDate)(JNIEnv *env, jobject self, jlong time)
  236. {
  237. fz_context *ctx = get_context(env);
  238. pdf_annot *annot = from_PDFAnnotation(env, self);
  239. fz_try(ctx)
  240. pdf_set_annot_creation_date(ctx, annot, time / 1000);
  241. fz_catch(ctx)
  242. jni_rethrow_void(env, ctx);
  243. }
  244. JNIEXPORT jobject JNICALL
  245. FUN(PDFAnnotation_getRect)(JNIEnv *env, jobject self)
  246. {
  247. fz_context *ctx = get_context(env);
  248. pdf_annot *annot = from_PDFAnnotation(env, self);
  249. fz_rect rect;
  250. if (!ctx || !annot) return NULL;
  251. fz_try(ctx)
  252. rect = pdf_annot_rect(ctx, annot);
  253. fz_catch(ctx)
  254. jni_rethrow(env, ctx);
  255. return to_Rect_safe(ctx, env, rect);
  256. }
  257. JNIEXPORT void JNICALL
  258. FUN(PDFAnnotation_setRect)(JNIEnv *env, jobject self, jobject jrect)
  259. {
  260. fz_context *ctx = get_context(env);
  261. pdf_annot *annot = from_PDFAnnotation(env, self);
  262. fz_rect rect = from_Rect(env, jrect);
  263. if (!ctx || !annot) return;
  264. fz_try(ctx)
  265. pdf_set_annot_rect(ctx, annot, rect);
  266. fz_catch(ctx)
  267. jni_rethrow_void(env, ctx);
  268. }
  269. JNIEXPORT jobject JNICALL
  270. FUN(PDFAnnotation_getColor)(JNIEnv *env, jobject self)
  271. {
  272. fz_context *ctx = get_context(env);
  273. pdf_annot *annot = from_PDFAnnotation(env, self);
  274. int n;
  275. float color[4];
  276. jfloatArray arr;
  277. if (!ctx || !annot) return NULL;
  278. fz_try(ctx)
  279. pdf_annot_color(ctx, annot, &n, color);
  280. fz_catch(ctx)
  281. jni_rethrow(env, ctx);
  282. arr = (*env)->NewFloatArray(env, n);
  283. if (!arr || (*env)->ExceptionCheck(env)) return NULL;
  284. (*env)->SetFloatArrayRegion(env, arr, 0, n, &color[0]);
  285. if ((*env)->ExceptionCheck(env)) return NULL;
  286. return arr;
  287. }
  288. JNIEXPORT void JNICALL
  289. FUN(PDFAnnotation_setColor)(JNIEnv *env, jobject self, jobject jcolor)
  290. {
  291. fz_context *ctx = get_context(env);
  292. pdf_annot *annot = from_PDFAnnotation(env, self);
  293. float color[4];
  294. int n = 0;
  295. if (!ctx || !annot) return;
  296. if (!from_jfloatArray(env, color, nelem(color), jcolor)) return;
  297. if (jcolor)
  298. n = (*env)->GetArrayLength(env, jcolor);
  299. fz_try(ctx)
  300. pdf_set_annot_color(ctx, annot, n, color);
  301. fz_catch(ctx)
  302. jni_rethrow_void(env, ctx);
  303. }
  304. JNIEXPORT jobject JNICALL
  305. FUN(PDFAnnotation_getInteriorColor)(JNIEnv *env, jobject self)
  306. {
  307. fz_context *ctx = get_context(env);
  308. pdf_annot *annot = from_PDFAnnotation(env, self);
  309. int n;
  310. float color[4];
  311. jfloatArray arr;
  312. if (!ctx || !annot) return NULL;
  313. fz_try(ctx)
  314. pdf_annot_interior_color(ctx, annot, &n, color);
  315. fz_catch(ctx)
  316. jni_rethrow(env, ctx);
  317. arr = (*env)->NewFloatArray(env, n);
  318. if (!arr || (*env)->ExceptionCheck(env)) return NULL;
  319. (*env)->SetFloatArrayRegion(env, arr, 0, n, &color[0]);
  320. if ((*env)->ExceptionCheck(env)) return NULL;
  321. return arr;
  322. }
  323. JNIEXPORT void JNICALL
  324. FUN(PDFAnnotation_setInteriorColor)(JNIEnv *env, jobject self, jobject jcolor)
  325. {
  326. fz_context *ctx = get_context(env);
  327. pdf_annot *annot = from_PDFAnnotation(env, self);
  328. float color[4];
  329. int n = 0;
  330. if (!ctx || !annot) return;
  331. if (!from_jfloatArray(env, color, nelem(color), jcolor)) return;
  332. if (jcolor)
  333. n = (*env)->GetArrayLength(env, jcolor);
  334. fz_try(ctx)
  335. pdf_set_annot_interior_color(ctx, annot, n, color);
  336. fz_catch(ctx)
  337. jni_rethrow_void(env, ctx);
  338. }
  339. JNIEXPORT jfloat JNICALL
  340. FUN(PDFAnnotation_getOpacity)(JNIEnv *env, jobject self)
  341. {
  342. fz_context *ctx = get_context(env);
  343. pdf_annot *annot = from_PDFAnnotation(env, self);
  344. jfloat opacity;
  345. if (!ctx || !annot) return 0.0f;
  346. fz_try(ctx)
  347. opacity = pdf_annot_opacity(ctx, annot);
  348. fz_catch(ctx)
  349. jni_rethrow(env, ctx);
  350. return opacity;
  351. }
  352. JNIEXPORT void JNICALL
  353. FUN(PDFAnnotation_setOpacity)(JNIEnv *env, jobject self, jfloat opacity)
  354. {
  355. fz_context *ctx = get_context(env);
  356. pdf_annot *annot = from_PDFAnnotation(env, self);
  357. if (!ctx || !annot) return;
  358. fz_try(ctx)
  359. pdf_set_annot_opacity(ctx, annot, opacity);
  360. fz_catch(ctx)
  361. jni_rethrow_void(env, ctx);
  362. }
  363. JNIEXPORT jint JNICALL
  364. FUN(PDFAnnotation_getQuadPointCount)(JNIEnv *env, jobject self)
  365. {
  366. fz_context *ctx = get_context(env);
  367. pdf_annot *annot = from_PDFAnnotation(env, self);
  368. int n = 0;
  369. fz_try(ctx)
  370. n = pdf_annot_quad_point_count(ctx, annot);
  371. fz_catch(ctx)
  372. jni_rethrow(env, ctx);
  373. return n;
  374. }
  375. JNIEXPORT jobject JNICALL
  376. FUN(PDFAnnotation_getQuadPoint)(JNIEnv *env, jobject self, jint i)
  377. {
  378. fz_context *ctx = get_context(env);
  379. pdf_annot *annot = from_PDFAnnotation(env, self);
  380. fz_quad q;
  381. fz_try(ctx)
  382. q = pdf_annot_quad_point(ctx, annot, i);
  383. fz_catch(ctx)
  384. jni_rethrow(env, ctx);
  385. return to_Quad_safe(ctx, env, q);
  386. }
  387. JNIEXPORT void JNICALL
  388. FUN(PDFAnnotation_clearQuadPoints)(JNIEnv *env, jobject self)
  389. {
  390. fz_context *ctx = get_context(env);
  391. pdf_annot *annot = from_PDFAnnotation(env, self);
  392. fz_try(ctx)
  393. pdf_clear_annot_quad_points(ctx, annot);
  394. fz_catch(ctx)
  395. jni_rethrow_void(env, ctx);
  396. }
  397. JNIEXPORT void JNICALL
  398. FUN(PDFAnnotation_addQuadPoint)(JNIEnv *env, jobject self, jobject qobj)
  399. {
  400. fz_context *ctx = get_context(env);
  401. pdf_annot *annot = from_PDFAnnotation(env, self);
  402. fz_quad q = from_Quad(env, qobj);
  403. fz_try(ctx)
  404. pdf_add_annot_quad_point(ctx, annot, q);
  405. fz_catch(ctx)
  406. jni_rethrow_void(env, ctx);
  407. }
  408. JNIEXPORT jint JNICALL
  409. FUN(PDFAnnotation_getVertexCount)(JNIEnv *env, jobject self)
  410. {
  411. fz_context *ctx = get_context(env);
  412. pdf_annot *annot = from_PDFAnnotation(env, self);
  413. int n = 0;
  414. fz_try(ctx)
  415. n = pdf_annot_vertex_count(ctx, annot);
  416. fz_catch(ctx)
  417. jni_rethrow(env, ctx);
  418. return n;
  419. }
  420. JNIEXPORT jobject JNICALL
  421. FUN(PDFAnnotation_getVertex)(JNIEnv *env, jobject self, jint i)
  422. {
  423. fz_context *ctx = get_context(env);
  424. pdf_annot *annot = from_PDFAnnotation(env, self);
  425. fz_point v;
  426. fz_try(ctx)
  427. v = pdf_annot_vertex(ctx, annot, i);
  428. fz_catch(ctx)
  429. jni_rethrow(env, ctx);
  430. return to_Point_safe(ctx, env, v);
  431. }
  432. JNIEXPORT void JNICALL
  433. FUN(PDFAnnotation_clearVertices)(JNIEnv *env, jobject self)
  434. {
  435. fz_context *ctx = get_context(env);
  436. pdf_annot *annot = from_PDFAnnotation(env, self);
  437. fz_try(ctx)
  438. pdf_clear_annot_vertices(ctx, annot);
  439. fz_catch(ctx)
  440. jni_rethrow_void(env, ctx);
  441. }
  442. JNIEXPORT void JNICALL
  443. FUN(PDFAnnotation_addVertex)(JNIEnv *env, jobject self, float x, float y)
  444. {
  445. fz_context *ctx = get_context(env);
  446. pdf_annot *annot = from_PDFAnnotation(env, self);
  447. fz_try(ctx)
  448. pdf_add_annot_vertex(ctx, annot, fz_make_point(x, y));
  449. fz_catch(ctx)
  450. jni_rethrow_void(env, ctx);
  451. }
  452. JNIEXPORT jint JNICALL
  453. FUN(PDFAnnotation_getInkListCount)(JNIEnv *env, jobject self)
  454. {
  455. fz_context *ctx = get_context(env);
  456. pdf_annot *annot = from_PDFAnnotation(env, self);
  457. int n = 0;
  458. fz_try(ctx)
  459. n = pdf_annot_ink_list_count(ctx, annot);
  460. fz_catch(ctx)
  461. jni_rethrow(env, ctx);
  462. return n;
  463. }
  464. JNIEXPORT jint JNICALL
  465. FUN(PDFAnnotation_getInkListStrokeCount)(JNIEnv *env, jobject self, jint i)
  466. {
  467. fz_context *ctx = get_context(env);
  468. pdf_annot *annot = from_PDFAnnotation(env, self);
  469. int n = 0;
  470. fz_try(ctx)
  471. n = pdf_annot_ink_list_stroke_count(ctx, annot, i);
  472. fz_catch(ctx)
  473. jni_rethrow(env, ctx);
  474. return n;
  475. }
  476. JNIEXPORT jobject JNICALL
  477. FUN(PDFAnnotation_getInkListStrokeVertex)(JNIEnv *env, jobject self, jint i, jint k)
  478. {
  479. fz_context *ctx = get_context(env);
  480. pdf_annot *annot = from_PDFAnnotation(env, self);
  481. fz_point v;
  482. fz_try(ctx)
  483. v = pdf_annot_ink_list_stroke_vertex(ctx, annot, i, k);
  484. fz_catch(ctx)
  485. jni_rethrow(env, ctx);
  486. return to_Point_safe(ctx, env, v);
  487. }
  488. JNIEXPORT void JNICALL
  489. FUN(PDFAnnotation_clearInkList)(JNIEnv *env, jobject self)
  490. {
  491. fz_context *ctx = get_context(env);
  492. pdf_annot *annot = from_PDFAnnotation(env, self);
  493. fz_try(ctx)
  494. pdf_clear_annot_ink_list(ctx, annot);
  495. fz_catch(ctx)
  496. jni_rethrow_void(env, ctx);
  497. }
  498. JNIEXPORT void JNICALL
  499. FUN(PDFAnnotation_addInkListStroke)(JNIEnv *env, jobject self)
  500. {
  501. fz_context *ctx = get_context(env);
  502. pdf_annot *annot = from_PDFAnnotation(env, self);
  503. fz_try(ctx)
  504. pdf_add_annot_ink_list_stroke(ctx, annot);
  505. fz_catch(ctx)
  506. jni_rethrow_void(env, ctx);
  507. }
  508. JNIEXPORT void JNICALL
  509. FUN(PDFAnnotation_addInkListStrokeVertex)(JNIEnv *env, jobject self, float x, float y)
  510. {
  511. fz_context *ctx = get_context(env);
  512. pdf_annot *annot = from_PDFAnnotation(env, self);
  513. fz_try(ctx)
  514. pdf_add_annot_ink_list_stroke_vertex(ctx, annot, fz_make_point(x, y));
  515. fz_catch(ctx)
  516. jni_rethrow_void(env, ctx);
  517. }
  518. JNIEXPORT jboolean JNICALL
  519. FUN(PDFAnnotation_hasCallout)(JNIEnv *env, jobject self)
  520. {
  521. fz_context *ctx = get_context(env);
  522. pdf_annot *annot = from_PDFAnnotation(env, self);
  523. jboolean has = JNI_FALSE;
  524. fz_try(ctx)
  525. has = pdf_annot_has_callout(ctx, annot);
  526. fz_catch(ctx)
  527. jni_rethrow(env, ctx);
  528. return has;
  529. }
  530. JNIEXPORT jint JNICALL
  531. FUN(PDFAnnotation_getCalloutStyle)(JNIEnv *env, jobject self)
  532. {
  533. fz_context *ctx = get_context(env);
  534. pdf_annot *annot = from_PDFAnnotation(env, self);
  535. enum pdf_line_ending s = 0;
  536. fz_try(ctx)
  537. s = pdf_annot_callout_style(ctx, annot);
  538. fz_catch(ctx)
  539. jni_rethrow(env, ctx);
  540. return s;
  541. }
  542. JNIEXPORT void JNICALL
  543. FUN(PDFAnnotation_setCalloutStyle)(JNIEnv *env, jobject self, jint s)
  544. {
  545. fz_context *ctx = get_context(env);
  546. pdf_annot *annot = from_PDFAnnotation(env, self);
  547. fz_try(ctx)
  548. pdf_set_annot_callout_style(ctx, annot, s);
  549. fz_catch(ctx)
  550. jni_rethrow_void(env, ctx);
  551. }
  552. JNIEXPORT jobject JNICALL
  553. FUN(PDFAnnotation_getCalloutPoint)(JNIEnv *env, jobject self)
  554. {
  555. fz_context *ctx = get_context(env);
  556. pdf_annot *annot = from_PDFAnnotation(env, self);
  557. fz_point p;
  558. if (!ctx || !annot) return NULL;
  559. fz_try(ctx)
  560. p = pdf_annot_callout_point(ctx, annot);
  561. fz_catch(ctx)
  562. jni_rethrow(env, ctx);
  563. return (*env)->NewObject(env, cls_Point, mid_Point_init, p.x, p.y);
  564. }
  565. JNIEXPORT void JNICALL
  566. FUN(PDFAnnotation_setCalloutPoint)(JNIEnv *env, jobject self, jobject jp)
  567. {
  568. fz_context *ctx = get_context(env);
  569. pdf_annot *annot = from_PDFAnnotation(env, self);
  570. fz_point p;
  571. if (!ctx || !annot) return;
  572. if (!jp) jni_throw_arg_void(env, "point must not be null");
  573. p.x = (*env)->GetFloatField(env, jp, fid_Point_x);
  574. p.y = (*env)->GetFloatField(env, jp, fid_Point_y);
  575. fz_try(ctx)
  576. pdf_set_annot_callout_point(ctx, annot, p);
  577. fz_catch(ctx)
  578. jni_rethrow_void(env, ctx);
  579. }
  580. JNIEXPORT jobject JNICALL
  581. FUN(PDFAnnotation_getCalloutLine)(JNIEnv *env, jobject self)
  582. {
  583. fz_context *ctx = get_context(env);
  584. pdf_annot *annot = from_PDFAnnotation(env, self);
  585. fz_point points[3] = { 0 };
  586. jobject jline = NULL;
  587. jobject jpoint = NULL;
  588. int i, n;
  589. if (!ctx || !annot) return NULL;
  590. fz_try(ctx)
  591. pdf_annot_callout_line(ctx, annot, points, &n);
  592. fz_catch(ctx)
  593. jni_rethrow(env, ctx);
  594. if (n == 0)
  595. return NULL;
  596. jline = (*env)->NewObjectArray(env, n, cls_Point, NULL);
  597. if (!jline || (*env)->ExceptionCheck(env)) return NULL;
  598. for (i = 0; i < n; i++)
  599. {
  600. jpoint = (*env)->NewObject(env, cls_Point, mid_Point_init, points[i].x, points[i].y);
  601. if (!jpoint || (*env)->ExceptionCheck(env)) return NULL;
  602. (*env)->SetObjectArrayElement(env, jline, i, jpoint);
  603. if ((*env)->ExceptionCheck(env)) return NULL;
  604. (*env)->DeleteLocalRef(env, jpoint);
  605. }
  606. return jline;
  607. }
  608. JNIEXPORT void JNICALL
  609. FUN(PDFAnnotation_setCalloutLineNative)(JNIEnv *env, jobject self, jint n, jobject ja, jobject jb, jobject jc)
  610. {
  611. fz_context *ctx = get_context(env);
  612. pdf_annot *annot = from_PDFAnnotation(env, self);
  613. fz_point line[3];
  614. if (!ctx || !annot) return;
  615. if (n >= 2 && !ja) jni_throw_arg_void(env, "points must not be null");
  616. if (n >= 2 && !jb) jni_throw_arg_void(env, "points must not be null");
  617. if (n >= 3 && !jc) jni_throw_arg_void(env, "points must not be null");
  618. if (n >= 2) {
  619. line[0].x = (*env)->GetFloatField(env, ja, fid_Point_x);
  620. line[0].y = (*env)->GetFloatField(env, ja, fid_Point_y);
  621. line[1].x = (*env)->GetFloatField(env, jb, fid_Point_x);
  622. line[1].y = (*env)->GetFloatField(env, jb, fid_Point_y);
  623. }
  624. if (n >= 3) {
  625. line[2].x = (*env)->GetFloatField(env, jc, fid_Point_x);
  626. line[2].y = (*env)->GetFloatField(env, jc, fid_Point_y);
  627. }
  628. fz_try(ctx)
  629. {
  630. if (n == 0 || n == 2 || n == 3)
  631. pdf_set_annot_callout_line(ctx, annot, line, n);
  632. }
  633. fz_catch(ctx)
  634. jni_rethrow_void(env, ctx);
  635. }
  636. JNIEXPORT void JNICALL
  637. FUN(PDFAnnotation_eventEnter)(JNIEnv *env, jobject self)
  638. {
  639. fz_context *ctx = get_context(env);
  640. pdf_annot *annot = from_PDFAnnotation(env, self);
  641. if (!ctx || !annot) return;
  642. fz_try(ctx)
  643. {
  644. pdf_annot_event_enter(ctx, annot);
  645. pdf_set_annot_hot(ctx, annot, 1);
  646. }
  647. fz_catch(ctx)
  648. jni_rethrow_void(env, ctx);
  649. }
  650. JNIEXPORT void JNICALL
  651. FUN(PDFAnnotation_eventExit)(JNIEnv *env, jobject self)
  652. {
  653. fz_context *ctx = get_context(env);
  654. pdf_annot *annot = from_PDFAnnotation(env, self);
  655. if (!ctx || !annot) return;
  656. fz_try(ctx)
  657. {
  658. pdf_annot_event_exit(ctx, annot);
  659. pdf_set_annot_hot(ctx, annot, 0);
  660. }
  661. fz_catch(ctx)
  662. jni_rethrow_void(env, ctx);
  663. }
  664. JNIEXPORT void JNICALL
  665. FUN(PDFAnnotation_eventDown)(JNIEnv *env, jobject self)
  666. {
  667. fz_context *ctx = get_context(env);
  668. pdf_annot *annot = from_PDFAnnotation(env, self);
  669. if (!ctx || !annot) return;
  670. fz_try(ctx)
  671. {
  672. pdf_annot_event_down(ctx, annot);
  673. pdf_set_annot_active(ctx, annot, 1);
  674. }
  675. fz_catch(ctx)
  676. jni_rethrow_void(env, ctx);
  677. }
  678. JNIEXPORT void JNICALL
  679. FUN(PDFAnnotation_eventUp)(JNIEnv *env, jobject self)
  680. {
  681. fz_context *ctx = get_context(env);
  682. pdf_annot *annot = from_PDFAnnotation(env, self);
  683. if (!ctx || !annot) return;
  684. fz_try(ctx)
  685. {
  686. if (pdf_annot_hot(ctx, annot) && pdf_annot_active(ctx, annot))
  687. pdf_annot_event_up(ctx, annot);
  688. pdf_set_annot_active(ctx, annot, 0);
  689. }
  690. fz_catch(ctx)
  691. jni_rethrow_void(env, ctx);
  692. }
  693. JNIEXPORT void JNICALL
  694. FUN(PDFAnnotation_eventFocus)(JNIEnv *env, jobject self)
  695. {
  696. fz_context *ctx = get_context(env);
  697. pdf_annot *annot = from_PDFAnnotation(env, self);
  698. if (!ctx || !annot) return;
  699. fz_try(ctx)
  700. pdf_annot_event_focus(ctx, annot);
  701. fz_catch(ctx)
  702. jni_rethrow_void(env, ctx);
  703. }
  704. JNIEXPORT void JNICALL
  705. FUN(PDFAnnotation_eventBlur)(JNIEnv *env, jobject self)
  706. {
  707. fz_context *ctx = get_context(env);
  708. pdf_annot *annot = from_PDFAnnotation(env, self);
  709. if (!ctx || !annot) return;
  710. fz_try(ctx)
  711. pdf_annot_event_blur(ctx, annot);
  712. fz_catch(ctx)
  713. jni_rethrow_void(env, ctx);
  714. }
  715. JNIEXPORT jboolean JNICALL
  716. FUN(PDFAnnotation_update)(JNIEnv *env, jobject self)
  717. {
  718. fz_context *ctx = get_context(env);
  719. pdf_annot *annot = from_PDFAnnotation(env, self);
  720. jboolean changed = JNI_FALSE;
  721. if (!ctx || !annot) return JNI_FALSE;
  722. fz_try(ctx)
  723. changed = pdf_update_annot(ctx, annot);
  724. fz_catch(ctx)
  725. jni_rethrow(env, ctx);
  726. return changed;
  727. }
  728. JNIEXPORT jboolean JNICALL
  729. FUN(PDFAnnotation_getIsOpen)(JNIEnv *env, jobject self)
  730. {
  731. fz_context *ctx = get_context(env);
  732. pdf_annot *annot = from_PDFAnnotation(env, self);
  733. jboolean open = JNI_FALSE;
  734. if (!ctx || !annot) return JNI_FALSE;
  735. fz_try(ctx)
  736. open = pdf_annot_is_open(ctx, annot);
  737. fz_catch(ctx)
  738. jni_rethrow(env, ctx);
  739. return open;
  740. }
  741. JNIEXPORT void JNICALL
  742. FUN(PDFAnnotation_setIsOpen)(JNIEnv *env, jobject self, jboolean open)
  743. {
  744. fz_context *ctx = get_context(env);
  745. pdf_annot *annot = from_PDFAnnotation(env, self);
  746. if (!ctx || !annot) return;
  747. fz_try(ctx)
  748. pdf_set_annot_is_open(ctx, annot, open);
  749. fz_catch(ctx)
  750. jni_rethrow_void(env, ctx);
  751. }
  752. JNIEXPORT jstring JNICALL
  753. FUN(PDFAnnotation_getIcon)(JNIEnv *env, jobject self)
  754. {
  755. fz_context *ctx = get_context(env);
  756. pdf_annot *annot = from_PDFAnnotation(env, self);
  757. const char *name = NULL;
  758. if (!ctx || !annot) return NULL;
  759. fz_try(ctx)
  760. name = pdf_annot_icon_name(ctx, annot);
  761. fz_catch(ctx)
  762. jni_rethrow(env, ctx);
  763. return (*env)->NewStringUTF(env, name);
  764. }
  765. JNIEXPORT void JNICALL
  766. FUN(PDFAnnotation_setIcon)(JNIEnv *env, jobject self, jstring jname)
  767. {
  768. fz_context *ctx = get_context(env);
  769. pdf_annot *annot = from_PDFAnnotation(env, self);
  770. const char *name = NULL;
  771. if (!ctx || !annot) return;
  772. if (!jname) jni_throw_arg_void(env, "icon name must not be null");
  773. name = (*env)->GetStringUTFChars(env, jname, NULL);
  774. if (!name) return;
  775. fz_try(ctx)
  776. pdf_set_annot_icon_name(ctx, annot, name);
  777. fz_always(ctx)
  778. if (name)
  779. (*env)->ReleaseStringUTFChars(env, jname, name);
  780. fz_catch(ctx)
  781. jni_rethrow_void(env, ctx);
  782. }
  783. JNIEXPORT jintArray JNICALL
  784. FUN(PDFAnnotation_getLineEndingStyles)(JNIEnv *env, jobject self)
  785. {
  786. fz_context *ctx = get_context(env);
  787. pdf_annot *annot = from_PDFAnnotation(env, self);
  788. enum pdf_line_ending s = 0, e = 0;
  789. int line_endings[2];
  790. jintArray jline_endings = NULL;
  791. if (!ctx || !annot) return NULL;
  792. fz_try(ctx)
  793. pdf_annot_line_ending_styles(ctx, annot, &s, &e);
  794. fz_catch(ctx)
  795. jni_rethrow(env, ctx);
  796. line_endings[0] = s;
  797. line_endings[1] = e;
  798. jline_endings = (*env)->NewIntArray(env, 2);
  799. if (!jline_endings || (*env)->ExceptionCheck(env)) return NULL;
  800. (*env)->SetIntArrayRegion(env, jline_endings, 0, 2, &line_endings[0]);
  801. if ((*env)->ExceptionCheck(env)) return NULL;
  802. return jline_endings;
  803. }
  804. JNIEXPORT void JNICALL
  805. FUN(PDFAnnotation_setLineEndingStyles)(JNIEnv *env, jobject self, jint start_style, jint end_style)
  806. {
  807. fz_context *ctx = get_context(env);
  808. pdf_annot *annot = from_PDFAnnotation(env, self);
  809. if (!ctx || !annot) return;
  810. fz_try(ctx)
  811. pdf_set_annot_line_ending_styles(ctx, annot, start_style, end_style);
  812. fz_catch(ctx)
  813. jni_rethrow_void(env, ctx);
  814. }
  815. JNIEXPORT jobject JNICALL
  816. FUN(PDFAnnotation_getObject)(JNIEnv *env, jobject self)
  817. {
  818. fz_context *ctx = get_context(env);
  819. pdf_annot *annot = from_PDFAnnotation(env, self);
  820. if (!ctx || !annot) return NULL;
  821. return to_PDFObject_safe(ctx, env, pdf_annot_obj(ctx, annot));
  822. }
  823. JNIEXPORT jint JNICALL
  824. FUN(PDFAnnotation_getLanguage)(JNIEnv *env, jobject self)
  825. {
  826. fz_context *ctx = get_context(env);
  827. pdf_annot *annot = from_PDFAnnotation(env, self);
  828. int lang;
  829. if (!ctx || !annot) return FZ_LANG_UNSET;
  830. fz_try(ctx)
  831. lang = pdf_annot_language(ctx, annot);
  832. fz_catch(ctx)
  833. jni_rethrow(env, ctx);
  834. return lang;
  835. }
  836. JNIEXPORT void JNICALL
  837. FUN(PDFAnnotation_setLanguage)(JNIEnv *env, jobject self, jint lang)
  838. {
  839. fz_context *ctx = get_context(env);
  840. pdf_annot *annot = from_PDFAnnotation(env, self);
  841. if (!ctx || !annot) return;
  842. fz_try(ctx)
  843. pdf_set_annot_language(ctx, annot, lang);
  844. fz_catch(ctx)
  845. jni_rethrow_void(env, ctx);
  846. }
  847. JNIEXPORT jboolean JNICALL
  848. FUN(PDFAnnotation_hasQuadding)(JNIEnv *env, jobject self)
  849. {
  850. fz_context *ctx = get_context(env);
  851. pdf_annot *annot = from_PDFAnnotation(env, self);
  852. jboolean has = JNI_FALSE;
  853. fz_try(ctx)
  854. has = pdf_annot_has_quadding(ctx, annot);
  855. fz_catch(ctx)
  856. jni_rethrow(env, ctx);
  857. return has;
  858. }
  859. JNIEXPORT jint JNICALL
  860. FUN(PDFAnnotation_getQuadding)(JNIEnv *env, jobject self)
  861. {
  862. fz_context *ctx = get_context(env);
  863. pdf_annot *annot = from_PDFAnnotation(env, self);
  864. int quadding;
  865. if (!ctx || !annot) return 0;
  866. fz_try(ctx)
  867. quadding = pdf_annot_quadding(ctx, annot);
  868. fz_catch(ctx)
  869. jni_rethrow(env, ctx);
  870. return quadding;
  871. }
  872. JNIEXPORT void JNICALL
  873. FUN(PDFAnnotation_setQuadding)(JNIEnv *env, jobject self, jint quadding)
  874. {
  875. fz_context *ctx = get_context(env);
  876. pdf_annot *annot = from_PDFAnnotation(env, self);
  877. if (!ctx || !annot) return;
  878. fz_try(ctx)
  879. pdf_set_annot_quadding(ctx, annot, quadding);
  880. fz_catch(ctx)
  881. jni_rethrow_void(env, ctx);
  882. }
  883. JNIEXPORT jobject JNICALL
  884. FUN(PDFAnnotation_getLine)(JNIEnv *env, jobject self)
  885. {
  886. fz_context *ctx = get_context(env);
  887. pdf_annot *annot = from_PDFAnnotation(env, self);
  888. fz_point points[2] = { 0 };
  889. jobject jline = NULL;
  890. jobject jpoint = NULL;
  891. size_t i = 0;
  892. if (!ctx || !annot) return NULL;
  893. fz_try(ctx)
  894. pdf_annot_line(ctx, annot, &points[0], &points[1]);
  895. fz_catch(ctx)
  896. jni_rethrow(env, ctx);
  897. jline = (*env)->NewObjectArray(env, nelem(points), cls_Point, NULL);
  898. if (!jline || (*env)->ExceptionCheck(env)) return NULL;
  899. for (i = 0; i < nelem(points); i++)
  900. {
  901. jpoint = (*env)->NewObject(env, cls_Point, mid_Point_init, points[i].x, points[i].y);
  902. if (!jpoint || (*env)->ExceptionCheck(env)) return NULL;
  903. (*env)->SetObjectArrayElement(env, jline, i, jpoint);
  904. if ((*env)->ExceptionCheck(env)) return NULL;
  905. (*env)->DeleteLocalRef(env, jpoint);
  906. }
  907. return jline;
  908. }
  909. JNIEXPORT void JNICALL
  910. FUN(PDFAnnotation_setLine)(JNIEnv *env, jobject self, jobject ja, jobject jb)
  911. {
  912. fz_context *ctx = get_context(env);
  913. pdf_annot *annot = from_PDFAnnotation(env, self);
  914. fz_point a, b;
  915. if (!ctx || !annot) return;
  916. if (!ja || !jb) jni_throw_arg_void(env, "line points must not be null");
  917. a.x = (*env)->GetFloatField(env, ja, fid_Point_x);
  918. a.y = (*env)->GetFloatField(env, ja, fid_Point_y);
  919. b.x = (*env)->GetFloatField(env, jb, fid_Point_x);
  920. b.y = (*env)->GetFloatField(env, jb, fid_Point_y);
  921. fz_try(ctx)
  922. pdf_set_annot_line(ctx, annot, a, b);
  923. fz_catch(ctx)
  924. jni_rethrow_void(env, ctx);
  925. }
  926. JNIEXPORT jboolean JNICALL
  927. FUN(PDFAnnotation_hasDefaultAppearance)(JNIEnv *env, jobject self)
  928. {
  929. fz_context *ctx = get_context(env);
  930. pdf_annot *annot = from_PDFAnnotation(env, self);
  931. jboolean has = JNI_FALSE;
  932. fz_try(ctx)
  933. has = pdf_annot_has_default_appearance(ctx, annot);
  934. fz_catch(ctx)
  935. jni_rethrow(env, ctx);
  936. return has;
  937. }
  938. JNIEXPORT jobject JNICALL
  939. FUN(PDFAnnotation_getDefaultAppearance)(JNIEnv *env, jobject self)
  940. {
  941. fz_context *ctx = get_context(env);
  942. pdf_annot *annot = from_PDFAnnotation(env, self);
  943. jobject jda = NULL;
  944. jobject jfont = NULL;
  945. jobject jcolor = NULL;
  946. const char *font = NULL;
  947. float color[4] = { 0 };
  948. float size = 0;
  949. int n = 0;
  950. if (!ctx || !annot) return NULL;
  951. fz_try(ctx)
  952. pdf_annot_default_appearance(ctx, annot, &font, &size, &n, color);
  953. fz_catch(ctx)
  954. jni_rethrow(env, ctx);
  955. jfont = (*env)->NewStringUTF(env, font);
  956. if (!jfont || (*env)->ExceptionCheck(env)) return NULL;
  957. jcolor = (*env)->NewFloatArray(env, n);
  958. if (!jcolor || (*env)->ExceptionCheck(env)) return NULL;
  959. (*env)->SetFloatArrayRegion(env, jcolor, 0, n, color);
  960. if ((*env)->ExceptionCheck(env)) return NULL;
  961. jda = (*env)->NewObject(env, cls_DefaultAppearance, mid_DefaultAppearance_init);
  962. if (!jda) return NULL;
  963. (*env)->SetObjectField(env, jda, fid_DefaultAppearance_font, jfont);
  964. (*env)->SetFloatField(env, jda, fid_DefaultAppearance_size, size);
  965. (*env)->SetObjectField(env, jda, fid_DefaultAppearance_color, jcolor);
  966. return jda;
  967. }
  968. JNIEXPORT void JNICALL
  969. FUN(PDFAnnotation_setDefaultAppearance)(JNIEnv *env, jobject self, jstring jfont, jfloat size, jobject jcolor)
  970. {
  971. fz_context *ctx = get_context(env);
  972. pdf_annot *annot = from_PDFAnnotation(env, self);
  973. const char *font = NULL;
  974. float color[4] = { 0 };
  975. int n = 0;
  976. if (!ctx || !annot) return;
  977. if (!jfont) jni_throw_arg_void(env, "font must not be null");
  978. font = (*env)->GetStringUTFChars(env, jfont, NULL);
  979. if (!font) jni_throw_oom_void(env, "can not get characters in font name string");
  980. if (!from_jfloatArray(env, color, nelem(color), jcolor)) return;
  981. if (jcolor)
  982. n = (*env)->GetArrayLength(env, jcolor);
  983. fz_try(ctx)
  984. pdf_set_annot_default_appearance(ctx, annot, font, size, n, color);
  985. fz_always(ctx)
  986. (*env)->ReleaseStringUTFChars(env, jfont, font);
  987. fz_catch(ctx)
  988. jni_rethrow_void(env, ctx);
  989. }
  990. JNIEXPORT void JNICALL
  991. FUN(PDFAnnotation_setNativeAppearance)(JNIEnv *env, jobject self, jstring jappearance, jstring jstate, jobject jctm, jobject jbbox, jobject jres, jobject jcontents)
  992. {
  993. fz_context *ctx = get_context(env);
  994. pdf_annot *annot = from_PDFAnnotation(env, self);
  995. pdf_obj *res = from_PDFObject(env, jres);
  996. fz_matrix ctm = from_Matrix(env, jctm);
  997. fz_rect bbox = from_Rect(env, jbbox);
  998. fz_buffer *contents = from_Buffer(env, jcontents);
  999. const char *appearance = NULL;
  1000. const char *state = NULL;
  1001. if (!ctx || !annot) return;
  1002. if (jappearance)
  1003. {
  1004. appearance = (*env)->GetStringUTFChars(env, jappearance, NULL);
  1005. if (!appearance)
  1006. jni_throw_oom_void(env, "can not get characters in appearance string");
  1007. }
  1008. if (jstate)
  1009. {
  1010. state = (*env)->GetStringUTFChars(env, jstate, NULL);
  1011. if (!state)
  1012. {
  1013. (*env)->ReleaseStringUTFChars(env, jappearance, appearance);
  1014. jni_throw_oom_void(env, "can not get characters in state string");
  1015. }
  1016. }
  1017. fz_try(ctx)
  1018. pdf_set_annot_appearance(ctx, annot, appearance, state, ctm, bbox, res, contents);
  1019. fz_always(ctx)
  1020. {
  1021. if (jstate)
  1022. (*env)->ReleaseStringUTFChars(env, jstate, state);
  1023. if (jappearance)
  1024. (*env)->ReleaseStringUTFChars(env, jappearance, appearance);
  1025. }
  1026. fz_catch(ctx)
  1027. jni_rethrow_void(env, ctx);
  1028. }
  1029. JNIEXPORT void JNICALL
  1030. FUN(PDFAnnotation_setNativeAppearanceImage)(JNIEnv *env, jobject self, jobject jimage)
  1031. {
  1032. fz_context *ctx = get_context(env);
  1033. pdf_annot *annot = from_PDFAnnotation(env, self);
  1034. fz_image *image = from_Image(env, jimage);
  1035. if (!ctx || !annot || !image)
  1036. return;
  1037. fz_try(ctx)
  1038. pdf_set_annot_stamp_image(ctx, annot, image);
  1039. fz_catch(ctx)
  1040. jni_rethrow_void(env, ctx);
  1041. }
  1042. JNIEXPORT void JNICALL
  1043. FUN(PDFAnnotation_setNativeAppearanceDisplayList)(JNIEnv *env, jobject self, jstring jappearance, jstring jstate, jobject jctm, jobject jlist)
  1044. {
  1045. fz_context *ctx = get_context(env);
  1046. pdf_annot *annot = from_PDFAnnotation(env, self);
  1047. fz_matrix ctm = from_Matrix(env, jctm);
  1048. fz_display_list *list = from_DisplayList(env, jlist);
  1049. const char *appearance = NULL;
  1050. const char *state = NULL;
  1051. if (!ctx || !annot) return;
  1052. if (jappearance)
  1053. {
  1054. appearance = (*env)->GetStringUTFChars(env, jappearance, NULL);
  1055. if (!appearance)
  1056. jni_throw_oom_void(env, "can not get characters in appearance string");
  1057. }
  1058. if (jstate)
  1059. {
  1060. state = (*env)->GetStringUTFChars(env, jstate, NULL);
  1061. if (!state)
  1062. {
  1063. (*env)->ReleaseStringUTFChars(env, jappearance, appearance);
  1064. jni_throw_oom_void(env, "can not get characters in state string");
  1065. }
  1066. }
  1067. fz_try(ctx)
  1068. pdf_set_annot_appearance_from_display_list(ctx, annot, appearance, state, ctm, list);
  1069. fz_always(ctx)
  1070. {
  1071. if (jstate)
  1072. (*env)->ReleaseStringUTFChars(env, jstate, state);
  1073. if (jappearance)
  1074. (*env)->ReleaseStringUTFChars(env, jappearance, appearance);
  1075. }
  1076. fz_catch(ctx)
  1077. jni_rethrow_void(env, ctx);
  1078. }
  1079. JNIEXPORT jboolean JNICALL
  1080. FUN(PDFAnnotation_hasInteriorColor)(JNIEnv *env, jobject self)
  1081. {
  1082. fz_context *ctx = get_context(env);
  1083. pdf_annot *annot = from_PDFAnnotation(env, self);
  1084. jboolean has = JNI_FALSE;
  1085. fz_try(ctx)
  1086. has = pdf_annot_has_interior_color(ctx, annot);
  1087. fz_catch(ctx)
  1088. jni_rethrow(env, ctx);
  1089. return has;
  1090. }
  1091. JNIEXPORT jboolean JNICALL
  1092. FUN(PDFAnnotation_hasAuthor)(JNIEnv *env, jobject self)
  1093. {
  1094. fz_context *ctx = get_context(env);
  1095. pdf_annot *annot = from_PDFAnnotation(env, self);
  1096. jboolean has = JNI_FALSE;
  1097. fz_try(ctx)
  1098. has = pdf_annot_has_author(ctx, annot);
  1099. fz_catch(ctx)
  1100. jni_rethrow(env, ctx);
  1101. return has;
  1102. }
  1103. JNIEXPORT jboolean JNICALL
  1104. FUN(PDFAnnotation_hasLineEndingStyles)(JNIEnv *env, jobject self)
  1105. {
  1106. fz_context *ctx = get_context(env);
  1107. pdf_annot *annot = from_PDFAnnotation(env, self);
  1108. jboolean has = JNI_FALSE;
  1109. fz_try(ctx)
  1110. has = pdf_annot_has_line_ending_styles(ctx, annot);
  1111. fz_catch(ctx)
  1112. jni_rethrow(env, ctx);
  1113. return has;
  1114. }
  1115. JNIEXPORT jboolean JNICALL
  1116. FUN(PDFAnnotation_hasQuadPoints)(JNIEnv *env, jobject self)
  1117. {
  1118. fz_context *ctx = get_context(env);
  1119. pdf_annot *annot = from_PDFAnnotation(env, self);
  1120. jboolean has = JNI_FALSE;
  1121. fz_try(ctx)
  1122. has = pdf_annot_has_quad_points(ctx, annot);
  1123. fz_catch(ctx)
  1124. jni_rethrow(env, ctx);
  1125. return has;
  1126. }
  1127. JNIEXPORT jboolean JNICALL
  1128. FUN(PDFAnnotation_hasVertices)(JNIEnv *env, jobject self)
  1129. {
  1130. fz_context *ctx = get_context(env);
  1131. pdf_annot *annot = from_PDFAnnotation(env, self);
  1132. jboolean has = JNI_FALSE;
  1133. fz_try(ctx)
  1134. has = pdf_annot_has_vertices(ctx, annot);
  1135. fz_catch(ctx)
  1136. jni_rethrow(env, ctx);
  1137. return has;
  1138. }
  1139. JNIEXPORT jboolean JNICALL
  1140. FUN(PDFAnnotation_hasInkList)(JNIEnv *env, jobject self)
  1141. {
  1142. fz_context *ctx = get_context(env);
  1143. pdf_annot *annot = from_PDFAnnotation(env, self);
  1144. jboolean has = JNI_FALSE;
  1145. fz_try(ctx)
  1146. has = pdf_annot_has_ink_list(ctx, annot);
  1147. fz_catch(ctx)
  1148. jni_rethrow(env, ctx);
  1149. return has;
  1150. }
  1151. JNIEXPORT jboolean JNICALL
  1152. FUN(PDFAnnotation_hasIcon)(JNIEnv *env, jobject self)
  1153. {
  1154. fz_context *ctx = get_context(env);
  1155. pdf_annot *annot = from_PDFAnnotation(env, self);
  1156. jboolean has = JNI_FALSE;
  1157. fz_try(ctx)
  1158. has = pdf_annot_has_icon_name(ctx, annot);
  1159. fz_catch(ctx)
  1160. jni_rethrow(env, ctx);
  1161. return has;
  1162. }
  1163. JNIEXPORT jboolean JNICALL
  1164. FUN(PDFAnnotation_hasOpen)(JNIEnv *env, jobject self)
  1165. {
  1166. fz_context *ctx = get_context(env);
  1167. pdf_annot *annot = from_PDFAnnotation(env, self);
  1168. jboolean has = JNI_FALSE;
  1169. fz_try(ctx)
  1170. has = pdf_annot_has_open(ctx, annot);
  1171. fz_catch(ctx)
  1172. jni_rethrow(env, ctx);
  1173. return has;
  1174. }
  1175. JNIEXPORT jboolean JNICALL
  1176. FUN(PDFAnnotation_hasLine)(JNIEnv *env, jobject self)
  1177. {
  1178. fz_context *ctx = get_context(env);
  1179. pdf_annot *annot = from_PDFAnnotation(env, self);
  1180. jboolean has = JNI_FALSE;
  1181. fz_try(ctx)
  1182. has = pdf_annot_has_line(ctx, annot);
  1183. fz_catch(ctx)
  1184. jni_rethrow(env, ctx);
  1185. return has;
  1186. }
  1187. JNIEXPORT void JNICALL
  1188. FUN(PDFAnnotation_setFileSpec)(JNIEnv *env, jobject self, jobject jfs)
  1189. {
  1190. fz_context *ctx = get_context(env);
  1191. pdf_annot *annot = from_PDFAnnotation(env, self);
  1192. pdf_obj *fs = from_PDFObject(env, jfs);
  1193. fz_try(ctx)
  1194. pdf_set_annot_filespec(ctx, annot, fs);
  1195. fz_catch(ctx)
  1196. jni_rethrow_void(env, ctx);
  1197. }
  1198. JNIEXPORT jobject JNICALL
  1199. FUN(PDFAnnotation_getFileSpec)(JNIEnv *env, jobject self)
  1200. {
  1201. fz_context *ctx = get_context(env);
  1202. pdf_annot *annot = from_PDFAnnotation(env, self);
  1203. pdf_obj *fs = NULL;
  1204. fz_try(ctx)
  1205. fs = pdf_annot_filespec(ctx, annot);
  1206. fz_catch(ctx)
  1207. jni_rethrow(env, ctx);
  1208. return to_PDFObject_safe(ctx, env, fs);
  1209. }
  1210. JNIEXPORT jboolean JNICALL
  1211. FUN(PDFAnnotation_hasBorder)(JNIEnv *env, jobject self)
  1212. {
  1213. fz_context *ctx = get_context(env);
  1214. pdf_annot *annot = from_PDFAnnotation(env, self);
  1215. jboolean has = JNI_FALSE;
  1216. fz_try(ctx)
  1217. has = pdf_annot_has_border(ctx, annot);
  1218. fz_catch(ctx)
  1219. jni_rethrow(env, ctx);
  1220. return has;
  1221. }
  1222. JNIEXPORT jint JNICALL
  1223. FUN(PDFAnnotation_getBorderStyle)(JNIEnv *env, jobject self)
  1224. {
  1225. fz_context *ctx = get_context(env);
  1226. pdf_annot *annot = from_PDFAnnotation(env, self);
  1227. enum pdf_border_style style = PDF_BORDER_STYLE_SOLID;
  1228. if (!ctx || !annot) return 0;
  1229. fz_try(ctx)
  1230. style = pdf_annot_border_style(ctx, annot);
  1231. fz_catch(ctx)
  1232. jni_rethrow(env, ctx);
  1233. return style;
  1234. }
  1235. JNIEXPORT void JNICALL
  1236. FUN(PDFAnnotation_setBorderStyle)(JNIEnv *env, jobject self, jint style)
  1237. {
  1238. fz_context *ctx = get_context(env);
  1239. pdf_annot *annot = from_PDFAnnotation(env, self);
  1240. fz_try(ctx)
  1241. pdf_set_annot_border_style(ctx, annot, style);
  1242. fz_catch(ctx)
  1243. jni_rethrow_void(env, ctx);
  1244. }
  1245. JNIEXPORT jfloat JNICALL
  1246. FUN(PDFAnnotation_getBorderWidth)(JNIEnv *env, jobject self)
  1247. {
  1248. fz_context *ctx = get_context(env);
  1249. pdf_annot *annot = from_PDFAnnotation(env, self);
  1250. float width;
  1251. if (!ctx || !annot) return 0;
  1252. fz_try(ctx)
  1253. width = pdf_annot_border_width(ctx, annot);
  1254. fz_catch(ctx)
  1255. jni_rethrow(env, ctx);
  1256. return width;
  1257. }
  1258. JNIEXPORT void JNICALL
  1259. FUN(PDFAnnotation_setBorderWidth)(JNIEnv *env, jobject self, jfloat width)
  1260. {
  1261. fz_context *ctx = get_context(env);
  1262. pdf_annot *annot = from_PDFAnnotation(env, self);
  1263. fz_try(ctx)
  1264. pdf_set_annot_border_width(ctx, annot, width);
  1265. fz_catch(ctx)
  1266. jni_rethrow_void(env, ctx);
  1267. }
  1268. JNIEXPORT jint JNICALL
  1269. FUN(PDFAnnotation_getBorderDashCount)(JNIEnv *env, jobject self)
  1270. {
  1271. fz_context *ctx = get_context(env);
  1272. pdf_annot *annot = from_PDFAnnotation(env, self);
  1273. int count;
  1274. if (!ctx || !annot) return 0;
  1275. fz_try(ctx)
  1276. count = pdf_annot_border_dash_count(ctx, annot);
  1277. fz_catch(ctx)
  1278. jni_rethrow(env, ctx);
  1279. return count;
  1280. }
  1281. JNIEXPORT jfloat JNICALL
  1282. FUN(PDFAnnotation_getBorderDashItem)(JNIEnv *env, jobject self, jint i)
  1283. {
  1284. fz_context *ctx = get_context(env);
  1285. pdf_annot *annot = from_PDFAnnotation(env, self);
  1286. int length;
  1287. if (!ctx || !annot) return 0;
  1288. fz_try(ctx)
  1289. length = pdf_annot_border_dash_item(ctx, annot, i);
  1290. fz_catch(ctx)
  1291. jni_rethrow(env, ctx);
  1292. return length;
  1293. }
  1294. JNIEXPORT void JNICALL
  1295. FUN(PDFAnnotation_clearBorderDash)(JNIEnv *env, jobject self)
  1296. {
  1297. fz_context *ctx = get_context(env);
  1298. pdf_annot *annot = from_PDFAnnotation(env, self);
  1299. if (!ctx || !annot) return;
  1300. fz_try(ctx)
  1301. pdf_clear_annot_border_dash(ctx, annot);
  1302. fz_catch(ctx)
  1303. jni_rethrow_void(env, ctx);
  1304. }
  1305. JNIEXPORT void JNICALL
  1306. FUN(PDFAnnotation_addBorderDashItem)(JNIEnv *env, jobject self, jfloat length)
  1307. {
  1308. fz_context *ctx = get_context(env);
  1309. pdf_annot *annot = from_PDFAnnotation(env, self);
  1310. if (!ctx || !annot) return;
  1311. fz_try(ctx)
  1312. pdf_add_annot_border_dash_item(ctx, annot, length);
  1313. fz_catch(ctx)
  1314. jni_rethrow_void(env, ctx);
  1315. }
  1316. JNIEXPORT jboolean JNICALL
  1317. FUN(PDFAnnotation_hasBorderEffect)(JNIEnv *env, jobject self)
  1318. {
  1319. fz_context *ctx = get_context(env);
  1320. pdf_annot *annot = from_PDFAnnotation(env, self);
  1321. jboolean has = JNI_FALSE;
  1322. fz_try(ctx)
  1323. has = pdf_annot_has_border_effect(ctx, annot);
  1324. fz_catch(ctx)
  1325. jni_rethrow(env, ctx);
  1326. return has;
  1327. }
  1328. JNIEXPORT jint JNICALL
  1329. FUN(PDFAnnotation_getBorderEffect)(JNIEnv *env, jobject self)
  1330. {
  1331. fz_context *ctx = get_context(env);
  1332. pdf_annot *annot = from_PDFAnnotation(env, self);
  1333. jint effect = PDF_BORDER_EFFECT_NONE;
  1334. fz_try(ctx)
  1335. effect = pdf_annot_border_effect(ctx, annot);
  1336. fz_catch(ctx)
  1337. jni_rethrow(env, ctx);
  1338. return effect;
  1339. }
  1340. JNIEXPORT void JNICALL
  1341. FUN(PDFAnnotation_setBorderEffect)(JNIEnv *env, jobject self, jint effect)
  1342. {
  1343. fz_context *ctx = get_context(env);
  1344. pdf_annot *annot = from_PDFAnnotation(env, self);
  1345. fz_try(ctx)
  1346. pdf_set_annot_border_effect(ctx, annot, effect);
  1347. fz_catch(ctx)
  1348. jni_rethrow_void(env, ctx);
  1349. }
  1350. JNIEXPORT jfloat JNICALL
  1351. FUN(PDFAnnotation_getBorderEffectIntensity)(JNIEnv *env, jobject self)
  1352. {
  1353. fz_context *ctx = get_context(env);
  1354. pdf_annot *annot = from_PDFAnnotation(env, self);
  1355. jfloat intensity = PDF_BORDER_EFFECT_NONE;
  1356. fz_try(ctx)
  1357. intensity = pdf_annot_border_effect_intensity(ctx, annot);
  1358. fz_catch(ctx)
  1359. jni_rethrow(env, ctx);
  1360. return intensity;
  1361. }
  1362. JNIEXPORT void JNICALL
  1363. FUN(PDFAnnotation_setBorderEffectIntensity)(JNIEnv *env, jobject self, jfloat intensity)
  1364. {
  1365. fz_context *ctx = get_context(env);
  1366. pdf_annot *annot = from_PDFAnnotation(env, self);
  1367. fz_try(ctx)
  1368. pdf_set_annot_border_effect_intensity(ctx, annot, intensity);
  1369. fz_catch(ctx)
  1370. jni_rethrow_void(env, ctx);
  1371. }
  1372. JNIEXPORT jboolean JNICALL
  1373. FUN(PDFAnnotation_hasFileSpec)(JNIEnv *env, jobject self)
  1374. {
  1375. fz_context *ctx = get_context(env);
  1376. pdf_annot *annot = from_PDFAnnotation(env, self);
  1377. jboolean has = JNI_FALSE;
  1378. fz_try(ctx)
  1379. has = pdf_annot_has_filespec(ctx, annot);
  1380. fz_catch(ctx)
  1381. jni_rethrow(env, ctx);
  1382. return has;
  1383. }
  1384. JNIEXPORT void JNICALL
  1385. FUN(PDFAnnotation_setHiddenForEditing)(JNIEnv *env, jobject self, jboolean hidden)
  1386. {
  1387. fz_context *ctx = get_context(env);
  1388. pdf_annot *annot = from_PDFAnnotation_safe(env, self);
  1389. if (!ctx || !annot) return;
  1390. fz_try(ctx)
  1391. pdf_set_annot_hidden_for_editing(ctx, annot, hidden);
  1392. fz_catch(ctx)
  1393. jni_rethrow_void(env, ctx);
  1394. }
  1395. JNIEXPORT jboolean JNICALL
  1396. FUN(PDFAnnotation_getHiddenForEditing)(JNIEnv *env, jobject self)
  1397. {
  1398. fz_context *ctx = get_context(env);
  1399. pdf_annot *annot = from_PDFAnnotation_safe(env, self);
  1400. jboolean hidden = JNI_FALSE;
  1401. if (!ctx || !annot) return JNI_FALSE;
  1402. fz_try(ctx)
  1403. hidden = pdf_annot_hidden_for_editing(ctx, annot);
  1404. fz_catch(ctx)
  1405. jni_rethrow(env, ctx);
  1406. return hidden;
  1407. }
  1408. JNIEXPORT jboolean JNICALL
  1409. FUN(PDFAnnotation_applyRedaction)(JNIEnv *env, jobject self, jboolean blackBoxes, jint imageMethod, jint lineArt, jint text)
  1410. {
  1411. fz_context *ctx = get_context(env);
  1412. pdf_annot *annot = from_PDFAnnotation_safe(env, self);
  1413. pdf_redact_options opts = { blackBoxes, imageMethod, lineArt, text };
  1414. jboolean redacted = JNI_FALSE;
  1415. if (!ctx || !annot) return JNI_FALSE;
  1416. fz_try(ctx)
  1417. redacted = pdf_apply_redaction(ctx, annot, &opts);
  1418. fz_catch(ctx)
  1419. jni_rethrow(env, ctx);
  1420. return redacted;
  1421. }
  1422. JNIEXPORT jboolean JNICALL
  1423. FUN(PDFAnnotation_hasRect)(JNIEnv *env, jobject self)
  1424. {
  1425. fz_context *ctx = get_context(env);
  1426. pdf_annot *annot = from_PDFAnnotation(env, self);
  1427. jboolean has = JNI_FALSE;
  1428. fz_try(ctx)
  1429. has = pdf_annot_has_rect(ctx, annot);
  1430. fz_catch(ctx)
  1431. jni_rethrow(env, ctx);
  1432. return has;
  1433. }
  1434. JNIEXPORT jboolean JNICALL
  1435. FUN(PDFAnnotation_hasIntent)(JNIEnv *env, jobject self)
  1436. {
  1437. fz_context *ctx = get_context(env);
  1438. pdf_annot *annot = from_PDFAnnotation(env, self);
  1439. jboolean has = JNI_FALSE;
  1440. fz_try(ctx)
  1441. has = pdf_annot_has_intent(ctx, annot);
  1442. fz_catch(ctx)
  1443. jni_rethrow(env, ctx);
  1444. return has;
  1445. }
  1446. JNIEXPORT jint JNICALL
  1447. FUN(PDFAnnotation_getIntent)(JNIEnv *env, jobject self)
  1448. {
  1449. fz_context *ctx = get_context(env);
  1450. pdf_annot *annot = from_PDFAnnotation(env, self);
  1451. enum pdf_intent intent = PDF_ANNOT_IT_DEFAULT;
  1452. if (!ctx || !annot) return PDF_ANNOT_IT_DEFAULT;
  1453. fz_try(ctx)
  1454. intent = pdf_annot_intent(ctx, annot);
  1455. fz_catch(ctx)
  1456. jni_rethrow(env, ctx);
  1457. return intent;
  1458. }
  1459. JNIEXPORT void JNICALL
  1460. FUN(PDFAnnotation_setIntent)(JNIEnv *env, jobject self, jint intent)
  1461. {
  1462. fz_context *ctx = get_context(env);
  1463. pdf_annot *annot = from_PDFAnnotation(env, self);
  1464. if (!ctx || !annot) return;
  1465. fz_try(ctx)
  1466. pdf_set_annot_intent(ctx, annot, intent);
  1467. fz_catch(ctx)
  1468. jni_rethrow_void(env, ctx);
  1469. }
  1470. JNIEXPORT jboolean JNICALL
  1471. FUN(PDFAnnotation_hasPopup)(JNIEnv *env, jobject self)
  1472. {
  1473. fz_context *ctx = get_context(env);
  1474. pdf_annot *annot = from_PDFAnnotation(env, self);
  1475. jboolean has = JNI_FALSE;
  1476. fz_try(ctx)
  1477. has = pdf_annot_has_popup(ctx, annot);
  1478. fz_catch(ctx)
  1479. jni_rethrow(env, ctx);
  1480. return has;
  1481. }
  1482. JNIEXPORT jobject JNICALL
  1483. FUN(PDFAnnotation_getPopup)(JNIEnv *env, jobject self)
  1484. {
  1485. fz_context *ctx = get_context(env);
  1486. pdf_annot *annot = from_PDFAnnotation(env, self);
  1487. fz_rect rect;
  1488. if (!ctx || !annot) return JNI_FALSE;
  1489. fz_try(ctx)
  1490. rect = pdf_annot_popup(ctx, annot);
  1491. fz_catch(ctx)
  1492. jni_rethrow(env, ctx);
  1493. return to_Rect_safe(ctx, env, rect);
  1494. }
  1495. JNIEXPORT void JNICALL
  1496. FUN(PDFAnnotation_setPopup)(JNIEnv *env, jobject self, jobject jrect)
  1497. {
  1498. fz_context *ctx = get_context(env);
  1499. pdf_annot *annot = from_PDFAnnotation(env, self);
  1500. fz_rect rect = from_Rect(env, jrect);
  1501. if (!ctx || !annot) return;
  1502. fz_try(ctx)
  1503. pdf_set_annot_popup(ctx, annot, rect);
  1504. fz_catch(ctx)
  1505. jni_rethrow_void(env, ctx);
  1506. }
  1507. JNIEXPORT jfloat JNICALL
  1508. FUN(PDFAnnotation_getLineLeader)(JNIEnv *env, jobject self)
  1509. {
  1510. fz_context *ctx = get_context(env);
  1511. pdf_annot *annot = from_PDFAnnotation(env, self);
  1512. jfloat v;
  1513. if (!ctx || !annot) return 0;
  1514. fz_try(ctx)
  1515. v = pdf_annot_line_leader(ctx, annot);
  1516. fz_catch(ctx)
  1517. jni_rethrow(env, ctx);
  1518. return v;
  1519. }
  1520. JNIEXPORT void JNICALL
  1521. FUN(PDFAnnotation_setLineLeader)(JNIEnv *env, jobject self, jfloat length)
  1522. {
  1523. fz_context *ctx = get_context(env);
  1524. pdf_annot *annot = from_PDFAnnotation(env, self);
  1525. if (!ctx || !annot) return;
  1526. fz_try(ctx)
  1527. pdf_set_annot_line_leader(ctx, annot, length);
  1528. fz_catch(ctx)
  1529. jni_rethrow_void(env, ctx);
  1530. }
  1531. JNIEXPORT jfloat JNICALL
  1532. FUN(PDFAnnotation_getLineLeaderExtension)(JNIEnv *env, jobject self)
  1533. {
  1534. fz_context *ctx = get_context(env);
  1535. pdf_annot *annot = from_PDFAnnotation(env, self);
  1536. jfloat v;
  1537. if (!ctx || !annot) return 0;
  1538. fz_try(ctx)
  1539. v = pdf_annot_line_leader_extension(ctx, annot);
  1540. fz_catch(ctx)
  1541. jni_rethrow(env, ctx);
  1542. return v;
  1543. }
  1544. JNIEXPORT void JNICALL
  1545. FUN(PDFAnnotation_setLineLeaderExtension)(JNIEnv *env, jobject self, jfloat extension)
  1546. {
  1547. fz_context *ctx = get_context(env);
  1548. pdf_annot *annot = from_PDFAnnotation(env, self);
  1549. if (!ctx || !annot) return;
  1550. fz_try(ctx)
  1551. pdf_set_annot_line_leader_extension(ctx, annot, extension);
  1552. fz_catch(ctx)
  1553. jni_rethrow_void(env, ctx);
  1554. }
  1555. JNIEXPORT jfloat JNICALL
  1556. FUN(PDFAnnotation_getLineLeaderOffset)(JNIEnv *env, jobject self)
  1557. {
  1558. fz_context *ctx = get_context(env);
  1559. pdf_annot *annot = from_PDFAnnotation(env, self);
  1560. jfloat v;
  1561. if (!ctx || !annot) return 0;
  1562. fz_try(ctx)
  1563. v = pdf_annot_line_leader_offset(ctx, annot);
  1564. fz_catch(ctx)
  1565. jni_rethrow(env, ctx);
  1566. return v;
  1567. }
  1568. JNIEXPORT void JNICALL
  1569. FUN(PDFAnnotation_setLineLeaderOffset)(JNIEnv *env, jobject self, jfloat offset)
  1570. {
  1571. fz_context *ctx = get_context(env);
  1572. pdf_annot *annot = from_PDFAnnotation(env, self);
  1573. if (!ctx || !annot) return;
  1574. fz_try(ctx)
  1575. pdf_set_annot_line_leader_offset(ctx, annot, offset);
  1576. fz_catch(ctx)
  1577. jni_rethrow_void(env, ctx);
  1578. }
  1579. JNIEXPORT jboolean JNICALL
  1580. FUN(PDFAnnotation_getLineCaption)(JNIEnv *env, jobject self)
  1581. {
  1582. fz_context *ctx = get_context(env);
  1583. pdf_annot *annot = from_PDFAnnotation(env, self);
  1584. jboolean v;
  1585. if (!ctx || !annot) return JNI_FALSE;
  1586. fz_try(ctx)
  1587. v = pdf_annot_line_caption(ctx, annot);
  1588. fz_catch(ctx)
  1589. jni_rethrow(env, ctx);
  1590. return v;
  1591. }
  1592. JNIEXPORT void JNICALL
  1593. FUN(PDFAnnotation_setLineCaption)(JNIEnv *env, jobject self, jboolean caption)
  1594. {
  1595. fz_context *ctx = get_context(env);
  1596. pdf_annot *annot = from_PDFAnnotation(env, self);
  1597. if (!ctx || !annot) return;
  1598. fz_try(ctx)
  1599. pdf_set_annot_line_caption(ctx, annot, caption);
  1600. fz_catch(ctx)
  1601. jni_rethrow_void(env, ctx);
  1602. }
  1603. JNIEXPORT jobject JNICALL
  1604. FUN(PDFAnnotation_getLineCaptionOffset)(JNIEnv *env, jobject self)
  1605. {
  1606. fz_context *ctx = get_context(env);
  1607. pdf_annot *annot = from_PDFAnnotation(env, self);
  1608. fz_point offset;;
  1609. if (!ctx || !annot) return NULL;
  1610. fz_try(ctx)
  1611. offset = pdf_annot_line_caption_offset(ctx, annot);
  1612. fz_catch(ctx)
  1613. jni_rethrow(env, ctx);
  1614. return to_Point_safe(ctx, env, offset);
  1615. }
  1616. JNIEXPORT void JNICALL
  1617. FUN(PDFAnnotation_setLeaderLines)(JNIEnv *env, jobject self, jobject joffset)
  1618. {
  1619. fz_context *ctx = get_context(env);
  1620. pdf_annot *annot = from_PDFAnnotation(env, self);
  1621. fz_point offset = from_Point(env, joffset);
  1622. if (!ctx || !annot) return;
  1623. fz_try(ctx)
  1624. pdf_set_annot_line_caption_offset(ctx, annot, offset);
  1625. fz_catch(ctx)
  1626. jni_rethrow_void(env, ctx);
  1627. }
  1628. JNIEXPORT void JNICALL
  1629. FUN(PDFAnnotation_requestSynthesis)(JNIEnv *env, jobject self)
  1630. {
  1631. fz_context *ctx = get_context(env);
  1632. pdf_annot *annot = from_PDFAnnotation(env, self);
  1633. if (!ctx || !annot) return;
  1634. fz_try(ctx)
  1635. pdf_annot_request_synthesis(ctx, annot);
  1636. fz_catch(ctx)
  1637. jni_rethrow_void(env, ctx);
  1638. }
  1639. JNIEXPORT void JNICALL
  1640. FUN(PDFAnnotation_requestResynthesis)(JNIEnv *env, jobject self)
  1641. {
  1642. fz_context *ctx = get_context(env);
  1643. pdf_annot *annot = from_PDFAnnotation(env, self);
  1644. if (!ctx || !annot) return;
  1645. fz_try(ctx)
  1646. pdf_annot_request_resynthesis(ctx, annot);
  1647. fz_catch(ctx)
  1648. jni_rethrow_void(env, ctx);
  1649. }
  1650. JNIEXPORT jboolean JNICALL
  1651. FUN(PDFAnnotation_getHot)(JNIEnv *env, jobject self)
  1652. {
  1653. fz_context *ctx = get_context(env);
  1654. pdf_annot *annot = from_PDFAnnotation(env, self);
  1655. jboolean hot = JNI_FALSE;
  1656. if (!ctx || !annot) return JNI_FALSE;
  1657. fz_try(ctx)
  1658. hot = pdf_annot_hot(ctx, annot);
  1659. fz_catch(ctx)
  1660. jni_rethrow(env, ctx);
  1661. return hot;
  1662. }
  1663. JNIEXPORT void JNICALL
  1664. FUN(PDFAnnotation_setHot)(JNIEnv *env, jobject self, jboolean hot)
  1665. {
  1666. fz_context *ctx = get_context(env);
  1667. pdf_annot *annot = from_PDFAnnotation(env, self);
  1668. if (!ctx || !annot) return;
  1669. fz_try(ctx)
  1670. pdf_set_annot_hot(ctx, annot, hot);
  1671. fz_catch(ctx)
  1672. jni_rethrow_void(env, ctx);
  1673. }
  1674. JNIEXPORT void JNICALL
  1675. FUN(PDFAnnotation_process)(JNIEnv *env, jobject self, jobject jproc)
  1676. {
  1677. fz_context *ctx = get_context(env);
  1678. pdf_annot *annot = from_PDFAnnotation(env, self);
  1679. pdf_processor *proc = make_pdf_processor(env, ctx, jproc);
  1680. if (!ctx || !annot) return;
  1681. if (!proc) jni_throw_arg_void(env, "processor must not be null");
  1682. fz_try(ctx)
  1683. {
  1684. pdf_processor_push_resources(ctx, proc, pdf_page_resources(ctx, pdf_annot_page(ctx, annot)));
  1685. pdf_process_annot(ctx, proc, annot, NULL);
  1686. pdf_close_processor(ctx, proc);
  1687. }
  1688. fz_always(ctx)
  1689. {
  1690. pdf_processor_pop_resources(ctx, proc);
  1691. pdf_drop_processor(ctx, proc);
  1692. }
  1693. fz_catch(ctx)
  1694. jni_rethrow_void(env, ctx);
  1695. }
  1696. JNIEXPORT jboolean JNICALL
  1697. FUN(PDFAnnotation_hasRichContents)(JNIEnv *env, jobject self)
  1698. {
  1699. fz_context *ctx = get_context(env);
  1700. pdf_annot *annot = from_PDFAnnotation(env, self);
  1701. jboolean has = JNI_FALSE;
  1702. if (!ctx || !annot) return JNI_FALSE;
  1703. fz_try(ctx)
  1704. has = pdf_annot_has_rich_contents(ctx, annot);
  1705. fz_catch(ctx)
  1706. jni_rethrow(env, ctx);
  1707. return has;
  1708. }
  1709. JNIEXPORT jstring JNICALL
  1710. FUN(PDFAnnotation_getRichContents)(JNIEnv *env, jobject self)
  1711. {
  1712. fz_context *ctx = get_context(env);
  1713. pdf_annot *annot = from_PDFAnnotation(env, self);
  1714. const char *contents = NULL;
  1715. if (!ctx || !annot) return NULL;
  1716. fz_try(ctx)
  1717. contents = pdf_annot_rich_contents(ctx, annot);
  1718. fz_catch(ctx)
  1719. jni_rethrow(env, ctx);
  1720. return to_String_safe(ctx, env, contents);
  1721. }
  1722. JNIEXPORT void JNICALL
  1723. FUN(PDFAnnotation_setRichContents)(JNIEnv *env, jobject self, jstring jplaintext, jstring jrichtext)
  1724. {
  1725. fz_context *ctx = get_context(env);
  1726. pdf_annot *annot = from_PDFAnnotation(env, self);
  1727. const char *plaintext = NULL;
  1728. const char *richtext = NULL;
  1729. if (!ctx || !annot) return;
  1730. if (jplaintext)
  1731. {
  1732. plaintext = (*env)->GetStringUTFChars(env, jplaintext, NULL);
  1733. if (!plaintext) return;
  1734. }
  1735. if (jrichtext)
  1736. {
  1737. richtext = (*env)->GetStringUTFChars(env, jrichtext, NULL);
  1738. if (!richtext)
  1739. {
  1740. if (plaintext)
  1741. (*env)->ReleaseStringUTFChars(env, jplaintext, plaintext);
  1742. return;
  1743. }
  1744. }
  1745. fz_try(ctx)
  1746. pdf_set_annot_rich_contents(ctx, annot, plaintext, richtext);
  1747. fz_always(ctx)
  1748. {
  1749. if (richtext)
  1750. (*env)->ReleaseStringUTFChars(env, jrichtext, richtext);
  1751. if (plaintext)
  1752. (*env)->ReleaseStringUTFChars(env, jplaintext, plaintext);
  1753. }
  1754. fz_catch(ctx)
  1755. jni_rethrow_void(env, ctx);
  1756. }
  1757. JNIEXPORT jboolean JNICALL
  1758. FUN(PDFAnnotation_hasRichDefaults)(JNIEnv *env, jobject self)
  1759. {
  1760. fz_context *ctx = get_context(env);
  1761. pdf_annot *annot = from_PDFAnnotation(env, self);
  1762. jboolean has = JNI_FALSE;
  1763. if (!ctx || !annot) return JNI_FALSE;
  1764. fz_try(ctx)
  1765. has = pdf_annot_has_rich_defaults(ctx, annot);
  1766. fz_catch(ctx)
  1767. jni_rethrow(env, ctx);
  1768. return has;
  1769. }
  1770. JNIEXPORT jstring JNICALL
  1771. FUN(PDFAnnotation_getRichDefaults)(JNIEnv *env, jobject self)
  1772. {
  1773. fz_context *ctx = get_context(env);
  1774. pdf_annot *annot = from_PDFAnnotation(env, self);
  1775. const char *defaults = NULL;
  1776. if (!ctx || !annot) return NULL;
  1777. fz_try(ctx)
  1778. defaults = pdf_annot_rich_defaults(ctx, annot);
  1779. fz_catch(ctx)
  1780. jni_rethrow(env, ctx);
  1781. return to_String_safe(ctx, env, defaults);
  1782. }
  1783. JNIEXPORT void JNICALL
  1784. FUN(PDFAnnotation_setRichDefault)(JNIEnv *env, jobject self, jstring jstyle)
  1785. {
  1786. fz_context *ctx = get_context(env);
  1787. pdf_annot *annot = from_PDFAnnotation(env, self);
  1788. const char *style = NULL;
  1789. if (!ctx || !annot) return;
  1790. if (jstyle)
  1791. {
  1792. style = (*env)->GetStringUTFChars(env, jstyle, NULL);
  1793. if (!style) return;
  1794. }
  1795. fz_try(ctx)
  1796. pdf_set_annot_rich_defaults(ctx, annot, style);
  1797. fz_always(ctx)
  1798. if (style)
  1799. (*env)->ReleaseStringUTFChars(env, jstyle, style);
  1800. fz_catch(ctx)
  1801. jni_rethrow_void(env, ctx);
  1802. }
  1803. JNIEXPORT jobject JNICALL
  1804. FUN(PDFAnnotation_getStampImageObject)(JNIEnv *env, jobject self)
  1805. {
  1806. fz_context *ctx = get_context(env);
  1807. pdf_annot *annot = from_PDFAnnotation(env, self);
  1808. pdf_obj *obj = NULL;
  1809. if (!ctx || !annot) return NULL;
  1810. fz_try(ctx)
  1811. obj = pdf_annot_stamp_image_obj(ctx, annot);
  1812. fz_catch(ctx)
  1813. jni_rethrow(env, ctx);
  1814. return to_PDFObject_safe(ctx, env, obj);
  1815. }
  1816. JNIEXPORT void JNICALL
  1817. FUN(PDFAnnotation_setStampImageObject)(JNIEnv *env, jobject self, jobject jobj)
  1818. {
  1819. fz_context *ctx = get_context(env);
  1820. pdf_annot *annot = from_PDFAnnotation(env, self);
  1821. pdf_obj *obj = from_PDFObject(env, jobj);
  1822. if (!ctx || !annot) return;
  1823. fz_try(ctx)
  1824. pdf_set_annot_stamp_image_obj(ctx, annot, obj);
  1825. fz_catch(ctx)
  1826. jni_rethrow_void(env, ctx);
  1827. }
  1828. JNIEXPORT void JNICALL
  1829. FUN(PDFAnnotation_setStampImage)(JNIEnv *env, jobject self, jobject jimg)
  1830. {
  1831. fz_context *ctx = get_context(env);
  1832. pdf_annot *annot = from_PDFAnnotation(env, self);
  1833. fz_image *img = from_Image(env, jimg);
  1834. if (!ctx || !annot) return;
  1835. fz_try(ctx)
  1836. pdf_set_annot_stamp_image(ctx, annot, img);
  1837. fz_catch(ctx)
  1838. jni_rethrow_void(env, ctx);
  1839. }