1 /* Annotation interface */
2
3 JNIEXPORT void JNICALL
FUN(PDFAnnotation_finalize)4 FUN(PDFAnnotation_finalize)(JNIEnv *env, jobject self)
5 {
6 fz_context *ctx = get_context(env);
7 pdf_annot *annot = from_PDFAnnotation_safe(env, self);
8 if (!ctx || !annot) return;
9 (*env)->SetLongField(env, self, fid_PDFAnnotation_pointer, 0);
10 pdf_drop_annot(ctx, annot);
11 }
12
13 JNIEXPORT void JNICALL
FUN(PDFAnnotation_run)14 FUN(PDFAnnotation_run)(JNIEnv *env, jobject self, jobject jdev, jobject jctm, jobject jcookie)
15 {
16 fz_context *ctx = get_context(env);
17 pdf_annot *annot = from_PDFAnnotation(env, self);
18 fz_device *dev = from_Device(env, jdev);
19 fz_matrix ctm = from_Matrix(env, jctm);
20 fz_cookie *cookie= from_Cookie(env, jcookie);
21 NativeDeviceInfo *info;
22 int err;
23
24 if (!ctx || !annot) return;
25 if (!dev) jni_throw_arg_void(env, "device must not be null");
26
27 info = lockNativeDevice(env, jdev, &err);
28 if (err)
29 return;
30 fz_try(ctx)
31 pdf_run_annot(ctx, annot, dev, ctm, cookie);
32 fz_always(ctx)
33 unlockNativeDevice(env, info);
34 fz_catch(ctx)
35 jni_rethrow_void(env, ctx);
36 }
37
38 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_toPixmap)39 FUN(PDFAnnotation_toPixmap)(JNIEnv *env, jobject self, jobject jctm, jobject jcs, jboolean alpha)
40 {
41 fz_context *ctx = get_context(env);
42 pdf_annot *annot = from_PDFAnnotation(env, self);
43 fz_matrix ctm = from_Matrix(env, jctm);
44 fz_colorspace *cs = from_ColorSpace(env, jcs);
45 fz_pixmap *pixmap = NULL;
46
47 if (!ctx || !annot) return NULL;
48
49 fz_try(ctx)
50 pixmap = pdf_new_pixmap_from_annot(ctx, annot, ctm, cs, NULL, alpha);
51 fz_catch(ctx)
52 jni_rethrow(env, ctx);
53
54 return to_Pixmap_safe_own(ctx, env, pixmap);
55 }
56
57 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getBounds)58 FUN(PDFAnnotation_getBounds)(JNIEnv *env, jobject self)
59 {
60 fz_context *ctx = get_context(env);
61 pdf_annot *annot = from_PDFAnnotation(env, self);
62 fz_rect rect;
63
64 if (!ctx || !annot) return NULL;
65
66 fz_try(ctx)
67 rect = pdf_bound_annot(ctx, annot);
68 fz_catch(ctx)
69 jni_rethrow(env, ctx);
70
71 return to_Rect_safe(ctx, env, rect);
72 }
73
74 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_toDisplayList)75 FUN(PDFAnnotation_toDisplayList)(JNIEnv *env, jobject self)
76 {
77 fz_context *ctx = get_context(env);
78 pdf_annot *annot = from_PDFAnnotation(env, self);
79 fz_display_list *list = NULL;
80
81 if (!ctx || !annot) return NULL;
82
83 fz_try(ctx)
84 list = pdf_new_display_list_from_annot(ctx, annot);
85 fz_catch(ctx)
86 jni_rethrow(env, ctx);
87
88 return to_DisplayList_safe_own(ctx, env, list);
89 }
90
91 JNIEXPORT jint JNICALL
FUN(PDFAnnotation_getType)92 FUN(PDFAnnotation_getType)(JNIEnv *env, jobject self)
93 {
94 fz_context *ctx = get_context(env);
95 pdf_annot *annot = from_PDFAnnotation(env, self);
96 jint subtype = 0;
97
98 if (!ctx || !annot) return 0;
99
100 fz_try(ctx)
101 subtype = pdf_annot_type(ctx, annot);
102 fz_catch(ctx)
103 jni_rethrow(env, ctx);
104
105 return subtype;
106 }
107
108 JNIEXPORT jint JNICALL
FUN(PDFAnnotation_getFlags)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
115 if (!ctx || !annot) return 0;
116
117 fz_try(ctx)
118 flags = pdf_annot_flags(ctx, annot);
119 fz_catch(ctx)
120 jni_rethrow(env, ctx);
121
122 return flags;
123 }
124
125 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setFlags)126 FUN(PDFAnnotation_setFlags)(JNIEnv *env, jobject self, jint flags)
127 {
128 fz_context *ctx = get_context(env);
129 pdf_annot *annot = from_PDFAnnotation(env, self);
130
131 if (!ctx || !annot) return;
132
133 fz_try(ctx)
134 pdf_set_annot_flags(ctx, annot, flags);
135 fz_catch(ctx)
136 jni_rethrow_void(env, ctx);
137 }
138
139 JNIEXPORT jstring JNICALL
FUN(PDFAnnotation_getContents)140 FUN(PDFAnnotation_getContents)(JNIEnv *env, jobject self)
141 {
142 fz_context *ctx = get_context(env);
143 pdf_annot *annot = from_PDFAnnotation(env, self);
144 const char *contents = NULL;
145
146 if (!ctx || !annot) return NULL;
147
148 fz_try(ctx)
149 contents = pdf_annot_contents(ctx, annot);
150 fz_catch(ctx)
151 jni_rethrow(env, ctx);
152
153 return (*env)->NewStringUTF(env, contents);
154 }
155
156 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setContents)157 FUN(PDFAnnotation_setContents)(JNIEnv *env, jobject self, jstring jcontents)
158 {
159 fz_context *ctx = get_context(env);
160 pdf_annot *annot = from_PDFAnnotation(env, self);
161 const char *contents = "";
162
163 if (!ctx || !annot) return;
164 if (jcontents)
165 {
166 contents = (*env)->GetStringUTFChars(env, jcontents, NULL);
167 if (!contents) return;
168 }
169
170 fz_try(ctx)
171 pdf_set_annot_contents(ctx, annot, contents);
172 fz_always(ctx)
173 if (contents)
174 (*env)->ReleaseStringUTFChars(env, jcontents, contents);
175 fz_catch(ctx)
176 jni_rethrow_void(env, ctx);
177 }
178
179 JNIEXPORT jstring JNICALL
FUN(PDFAnnotation_getAuthor)180 FUN(PDFAnnotation_getAuthor)(JNIEnv *env, jobject self)
181 {
182 fz_context *ctx = get_context(env);
183 pdf_annot *annot = from_PDFAnnotation(env, self);
184 const char *author = NULL;
185
186 if (!ctx || !annot) return NULL;
187
188 fz_try(ctx)
189 author = pdf_annot_author(ctx, annot);
190 fz_catch(ctx)
191 jni_rethrow(env, ctx);
192
193 return (*env)->NewStringUTF(env, author);
194 }
195
196 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setAuthor)197 FUN(PDFAnnotation_setAuthor)(JNIEnv *env, jobject self, jstring jauthor)
198 {
199 fz_context *ctx = get_context(env);
200 pdf_annot *annot = from_PDFAnnotation(env, self);
201 const char *author = "";
202
203 if (!ctx || !annot) return;
204 if (jauthor)
205 {
206 author = (*env)->GetStringUTFChars(env, jauthor, NULL);
207 if (!author) return;
208 }
209
210 fz_try(ctx)
211 pdf_set_annot_author(ctx, annot, author);
212 fz_always(ctx)
213 if (author)
214 (*env)->ReleaseStringUTFChars(env, jauthor, author);
215 fz_catch(ctx)
216 jni_rethrow_void(env, ctx);
217 }
218
219 JNIEXPORT jlong JNICALL
FUN(PDFAnnotation_getModificationDateNative)220 FUN(PDFAnnotation_getModificationDateNative)(JNIEnv *env, jobject self)
221 {
222 fz_context *ctx = get_context(env);
223 pdf_annot *annot = from_PDFAnnotation(env, self);
224 jlong t;
225
226 if (!ctx || !annot) return -1;
227
228 fz_try(ctx)
229 t = pdf_annot_modification_date(ctx, annot);
230 fz_catch(ctx)
231 jni_rethrow(env, ctx);
232
233 return t * 1000;
234 }
235
236 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setModificationDate)237 FUN(PDFAnnotation_setModificationDate)(JNIEnv *env, jobject self, jlong time)
238 {
239 fz_context *ctx = get_context(env);
240 pdf_annot *annot = from_PDFAnnotation(env, self);
241
242 fz_try(ctx)
243 pdf_set_annot_modification_date(ctx, annot, time / 1000);
244 fz_catch(ctx)
245 jni_rethrow_void(env, ctx);
246 }
247
248 JNIEXPORT jlong JNICALL
FUN(PDFAnnotation_getCreationDateNative)249 FUN(PDFAnnotation_getCreationDateNative)(JNIEnv *env, jobject self)
250 {
251 fz_context *ctx = get_context(env);
252 pdf_annot *annot = from_PDFAnnotation(env, self);
253 jlong t;
254
255 if (!ctx || !annot) return -1;
256
257 fz_try(ctx)
258 t = pdf_annot_creation_date(ctx, annot);
259 fz_catch(ctx)
260 jni_rethrow(env, ctx);
261
262 return t * 1000;
263 }
264
265 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setCreationDate)266 FUN(PDFAnnotation_setCreationDate)(JNIEnv *env, jobject self, jlong time)
267 {
268 fz_context *ctx = get_context(env);
269 pdf_annot *annot = from_PDFAnnotation(env, self);
270
271 fz_try(ctx)
272 pdf_set_annot_creation_date(ctx, annot, time / 1000);
273 fz_catch(ctx)
274 jni_rethrow_void(env, ctx);
275 }
276
277 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getRect)278 FUN(PDFAnnotation_getRect)(JNIEnv *env, jobject self)
279 {
280 fz_context *ctx = get_context(env);
281 pdf_annot *annot = from_PDFAnnotation(env, self);
282 fz_rect rect;
283
284 if (!ctx || !annot) return NULL;
285
286 fz_try(ctx)
287 rect = pdf_annot_rect(ctx, annot);
288 fz_catch(ctx)
289 jni_rethrow(env, ctx);
290
291 return to_Rect_safe(ctx, env, rect);
292 }
293
294 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setRect)295 FUN(PDFAnnotation_setRect)(JNIEnv *env, jobject self, jobject jrect)
296 {
297 fz_context *ctx = get_context(env);
298 pdf_annot *annot = from_PDFAnnotation(env, self);
299 fz_rect rect = from_Rect(env, jrect);
300
301 if (!ctx || !annot) return;
302
303 fz_try(ctx)
304 pdf_set_annot_rect(ctx, annot, rect);
305 fz_catch(ctx)
306 jni_rethrow_void(env, ctx);
307 }
308
309 JNIEXPORT jfloat JNICALL
FUN(PDFAnnotation_getBorder)310 FUN(PDFAnnotation_getBorder)(JNIEnv *env, jobject self)
311 {
312 fz_context *ctx = get_context(env);
313 pdf_annot *annot = from_PDFAnnotation(env, self);
314 jfloat border;
315
316 if (!ctx || !annot) return 0;
317
318 fz_try(ctx)
319 border = pdf_annot_border(ctx, annot);
320 fz_catch(ctx)
321 jni_rethrow(env, ctx);
322
323 return border;
324 }
325
326 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setBorder)327 FUN(PDFAnnotation_setBorder)(JNIEnv *env, jobject self, jfloat border)
328 {
329 fz_context *ctx = get_context(env);
330 pdf_annot *annot = from_PDFAnnotation(env, self);
331
332 if (!ctx || !annot) return;
333
334 fz_try(ctx)
335 pdf_set_annot_border(ctx, annot, border);
336 fz_catch(ctx)
337 jni_rethrow_void(env, ctx);
338 }
339
340 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getColor)341 FUN(PDFAnnotation_getColor)(JNIEnv *env, jobject self)
342 {
343 fz_context *ctx = get_context(env);
344 pdf_annot *annot = from_PDFAnnotation(env, self);
345 int n;
346 float color[4];
347 jfloatArray arr;
348
349 if (!ctx || !annot) return NULL;
350
351 fz_try(ctx)
352 pdf_annot_color(ctx, annot, &n, color);
353 fz_catch(ctx)
354 jni_rethrow(env, ctx);
355
356 arr = (*env)->NewFloatArray(env, n);
357 if (!arr || (*env)->ExceptionCheck(env)) return NULL;
358
359 (*env)->SetFloatArrayRegion(env, arr, 0, n, &color[0]);
360 if ((*env)->ExceptionCheck(env)) return NULL;
361
362 return arr;
363 }
364
365 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setColor)366 FUN(PDFAnnotation_setColor)(JNIEnv *env, jobject self, jobject jcolor)
367 {
368 fz_context *ctx = get_context(env);
369 pdf_annot *annot = from_PDFAnnotation(env, self);
370 float color[4];
371 int n = 0;
372
373 if (!ctx || !annot) return;
374 if (!from_jfloatArray(env, color, nelem(color), jcolor)) return;
375 if (jcolor)
376 n = (*env)->GetArrayLength(env, jcolor);
377
378 fz_try(ctx)
379 pdf_set_annot_color(ctx, annot, n, color);
380 fz_catch(ctx)
381 jni_rethrow_void(env, ctx);
382 }
383
384 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getInteriorColor)385 FUN(PDFAnnotation_getInteriorColor)(JNIEnv *env, jobject self)
386 {
387 fz_context *ctx = get_context(env);
388 pdf_annot *annot = from_PDFAnnotation(env, self);
389 int n;
390 float color[4];
391 jfloatArray arr;
392
393 if (!ctx || !annot) return NULL;
394
395 fz_try(ctx)
396 pdf_annot_interior_color(ctx, annot, &n, color);
397 fz_catch(ctx)
398 jni_rethrow(env, ctx);
399
400 arr = (*env)->NewFloatArray(env, n);
401 if (!arr || (*env)->ExceptionCheck(env)) return NULL;
402
403 (*env)->SetFloatArrayRegion(env, arr, 0, n, &color[0]);
404 if ((*env)->ExceptionCheck(env)) return NULL;
405
406 return arr;
407 }
408
409 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setInteriorColor)410 FUN(PDFAnnotation_setInteriorColor)(JNIEnv *env, jobject self, jobject jcolor)
411 {
412 fz_context *ctx = get_context(env);
413 pdf_annot *annot = from_PDFAnnotation(env, self);
414 float color[4];
415 int n = 0;
416
417 if (!ctx || !annot) return;
418 if (!from_jfloatArray(env, color, nelem(color), jcolor)) return;
419 if (jcolor)
420 n = (*env)->GetArrayLength(env, jcolor);
421
422 fz_try(ctx)
423 pdf_set_annot_interior_color(ctx, annot, n, color);
424 fz_catch(ctx)
425 jni_rethrow_void(env, ctx);
426 }
427
428 JNIEXPORT jint JNICALL
FUN(PDFAnnotation_getQuadPointCount)429 FUN(PDFAnnotation_getQuadPointCount)(JNIEnv *env, jobject self)
430 {
431 fz_context *ctx = get_context(env);
432 pdf_annot *annot = from_PDFAnnotation(env, self);
433 int n = 0;
434
435 fz_try(ctx)
436 n = pdf_annot_quad_point_count(ctx, annot);
437 fz_catch(ctx)
438 jni_rethrow(env, ctx);
439
440 return n;
441 }
442
443 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getQuadPoint)444 FUN(PDFAnnotation_getQuadPoint)(JNIEnv *env, jobject self, jint i)
445 {
446 fz_context *ctx = get_context(env);
447 pdf_annot *annot = from_PDFAnnotation(env, self);
448 fz_quad q;
449
450 fz_try(ctx)
451 q = pdf_annot_quad_point(ctx, annot, i);
452 fz_catch(ctx)
453 jni_rethrow(env, ctx);
454
455 return to_Quad_safe(ctx, env, q);
456 }
457
458 JNIEXPORT void JNICALL
FUN(PDFAnnotation_clearQuadPoints)459 FUN(PDFAnnotation_clearQuadPoints)(JNIEnv *env, jobject self)
460 {
461 fz_context *ctx = get_context(env);
462 pdf_annot *annot = from_PDFAnnotation(env, self);
463
464 fz_try(ctx)
465 pdf_clear_annot_quad_points(ctx, annot);
466 fz_catch(ctx)
467 jni_rethrow_void(env, ctx);
468 }
469
470 JNIEXPORT void JNICALL
FUN(PDFAnnotation_addQuadPoint)471 FUN(PDFAnnotation_addQuadPoint)(JNIEnv *env, jobject self, jobject qobj)
472 {
473 fz_context *ctx = get_context(env);
474 pdf_annot *annot = from_PDFAnnotation(env, self);
475 fz_quad q = from_Quad(env, qobj);
476
477 fz_try(ctx)
478 pdf_add_annot_quad_point(ctx, annot, q);
479 fz_catch(ctx)
480 jni_rethrow_void(env, ctx);
481 }
482
483 JNIEXPORT jint JNICALL
FUN(PDFAnnotation_getVertexCount)484 FUN(PDFAnnotation_getVertexCount)(JNIEnv *env, jobject self)
485 {
486 fz_context *ctx = get_context(env);
487 pdf_annot *annot = from_PDFAnnotation(env, self);
488 int n = 0;
489
490 fz_try(ctx)
491 n = pdf_annot_vertex_count(ctx, annot);
492 fz_catch(ctx)
493 jni_rethrow(env, ctx);
494
495 return n;
496 }
497
498 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getVertex)499 FUN(PDFAnnotation_getVertex)(JNIEnv *env, jobject self, jint i)
500 {
501 fz_context *ctx = get_context(env);
502 pdf_annot *annot = from_PDFAnnotation(env, self);
503 fz_point v;
504
505 fz_try(ctx)
506 v = pdf_annot_vertex(ctx, annot, i);
507 fz_catch(ctx)
508 jni_rethrow(env, ctx);
509
510 return to_Point_safe(ctx, env, v);
511 }
512
513 JNIEXPORT void JNICALL
FUN(PDFAnnotation_clearVertices)514 FUN(PDFAnnotation_clearVertices)(JNIEnv *env, jobject self)
515 {
516 fz_context *ctx = get_context(env);
517 pdf_annot *annot = from_PDFAnnotation(env, self);
518
519 fz_try(ctx)
520 pdf_clear_annot_vertices(ctx, annot);
521 fz_catch(ctx)
522 jni_rethrow_void(env, ctx);
523 }
524
525 JNIEXPORT void JNICALL
FUN(PDFAnnotation_addVertex)526 FUN(PDFAnnotation_addVertex)(JNIEnv *env, jobject self, float x, float y)
527 {
528 fz_context *ctx = get_context(env);
529 pdf_annot *annot = from_PDFAnnotation(env, self);
530
531 fz_try(ctx)
532 pdf_add_annot_vertex(ctx, annot, fz_make_point(x, y));
533 fz_catch(ctx)
534 jni_rethrow_void(env, ctx);
535 }
536
537 JNIEXPORT jint JNICALL
FUN(PDFAnnotation_getInkListCount)538 FUN(PDFAnnotation_getInkListCount)(JNIEnv *env, jobject self)
539 {
540 fz_context *ctx = get_context(env);
541 pdf_annot *annot = from_PDFAnnotation(env, self);
542 int n = 0;
543
544 fz_try(ctx)
545 n = pdf_annot_ink_list_count(ctx, annot);
546 fz_catch(ctx)
547 jni_rethrow(env, ctx);
548
549 return n;
550 }
551
552 JNIEXPORT jint JNICALL
FUN(PDFAnnotation_getInkListStrokeCount)553 FUN(PDFAnnotation_getInkListStrokeCount)(JNIEnv *env, jobject self, jint i)
554 {
555 fz_context *ctx = get_context(env);
556 pdf_annot *annot = from_PDFAnnotation(env, self);
557 int n = 0;
558
559 fz_try(ctx)
560 n = pdf_annot_ink_list_stroke_count(ctx, annot, i);
561 fz_catch(ctx)
562 jni_rethrow(env, ctx);
563
564 return n;
565 }
566
567 JNIEXPORT jobject JNICALL
FUN(PDFAnnotation_getInkListStrokeVertex)568 FUN(PDFAnnotation_getInkListStrokeVertex)(JNIEnv *env, jobject self, jint i, jint k)
569 {
570 fz_context *ctx = get_context(env);
571 pdf_annot *annot = from_PDFAnnotation(env, self);
572 fz_point v;
573
574 fz_try(ctx)
575 v = pdf_annot_ink_list_stroke_vertex(ctx, annot, i, k);
576 fz_catch(ctx)
577 jni_rethrow(env, ctx);
578
579 return to_Point_safe(ctx, env, v);
580 }
581
582 JNIEXPORT void JNICALL
FUN(PDFAnnotation_clearInkList)583 FUN(PDFAnnotation_clearInkList)(JNIEnv *env, jobject self)
584 {
585 fz_context *ctx = get_context(env);
586 pdf_annot *annot = from_PDFAnnotation(env, self);
587
588 fz_try(ctx)
589 pdf_clear_annot_ink_list(ctx, annot);
590 fz_catch(ctx)
591 jni_rethrow_void(env, ctx);
592 }
593
594 JNIEXPORT void JNICALL
FUN(PDFAnnotation_addInkListStroke)595 FUN(PDFAnnotation_addInkListStroke)(JNIEnv *env, jobject self)
596 {
597 fz_context *ctx = get_context(env);
598 pdf_annot *annot = from_PDFAnnotation(env, self);
599
600 fz_try(ctx)
601 pdf_add_annot_ink_list_stroke(ctx, annot);
602 fz_catch(ctx)
603 jni_rethrow_void(env, ctx);
604 }
605
606 JNIEXPORT void JNICALL
FUN(PDFAnnotation_addInkListStrokeVertex)607 FUN(PDFAnnotation_addInkListStrokeVertex)(JNIEnv *env, jobject self, float x, float y)
608 {
609 fz_context *ctx = get_context(env);
610 pdf_annot *annot = from_PDFAnnotation(env, self);
611
612 fz_try(ctx)
613 pdf_add_annot_ink_list_stroke_vertex(ctx, annot, fz_make_point(x, y));
614 fz_catch(ctx)
615 jni_rethrow_void(env, ctx);
616 }
617
618 JNIEXPORT void JNICALL
FUN(PDFAnnotation_eventEnter)619 FUN(PDFAnnotation_eventEnter)(JNIEnv *env, jobject self)
620 {
621 fz_context *ctx = get_context(env);
622 pdf_annot *annot = from_PDFAnnotation(env, self);
623
624 if (!ctx || !annot) return;
625
626 fz_try(ctx)
627 {
628 pdf_annot_event_enter(ctx, annot);
629 annot->is_hot = 1;
630 }
631 fz_catch(ctx)
632 jni_rethrow_void(env, ctx);
633 }
634
635 JNIEXPORT void JNICALL
FUN(PDFAnnotation_eventExit)636 FUN(PDFAnnotation_eventExit)(JNIEnv *env, jobject self)
637 {
638 fz_context *ctx = get_context(env);
639 pdf_annot *annot = from_PDFAnnotation(env, self);
640
641 if (!ctx || !annot) return;
642
643 fz_try(ctx)
644 {
645 pdf_annot_event_exit(ctx, annot);
646 annot->is_hot = 0;
647 }
648 fz_catch(ctx)
649 jni_rethrow_void(env, ctx);
650 }
651
652 JNIEXPORT void JNICALL
FUN(PDFAnnotation_eventDown)653 FUN(PDFAnnotation_eventDown)(JNIEnv *env, jobject self)
654 {
655 fz_context *ctx = get_context(env);
656 pdf_annot *annot = from_PDFAnnotation(env, self);
657
658 if (!ctx || !annot) return;
659
660 fz_try(ctx)
661 {
662 pdf_annot_event_down(ctx, annot);
663 annot->is_active = 1;
664 }
665 fz_catch(ctx)
666 jni_rethrow_void(env, ctx);
667 }
668
669 JNIEXPORT void JNICALL
FUN(PDFAnnotation_eventUp)670 FUN(PDFAnnotation_eventUp)(JNIEnv *env, jobject self)
671 {
672 fz_context *ctx = get_context(env);
673 pdf_annot *annot = from_PDFAnnotation(env, self);
674
675 if (!ctx || !annot) return;
676
677 fz_try(ctx)
678 {
679 if (annot->is_hot && annot->is_active)
680 pdf_annot_event_up(ctx, annot);
681 annot->is_active = 0;
682 }
683 fz_catch(ctx)
684 jni_rethrow_void(env, ctx);
685 }
686
687 JNIEXPORT void JNICALL
FUN(PDFAnnotation_eventFocus)688 FUN(PDFAnnotation_eventFocus)(JNIEnv *env, jobject self)
689 {
690 fz_context *ctx = get_context(env);
691 pdf_annot *annot = from_PDFAnnotation(env, self);
692
693 if (!ctx || !annot) return;
694
695 fz_try(ctx)
696 pdf_annot_event_focus(ctx, annot);
697 fz_catch(ctx)
698 jni_rethrow_void(env, ctx);
699 }
700
701 JNIEXPORT void JNICALL
FUN(PDFAnnotation_eventBlur)702 FUN(PDFAnnotation_eventBlur)(JNIEnv *env, jobject self)
703 {
704 fz_context *ctx = get_context(env);
705 pdf_annot *annot = from_PDFAnnotation(env, self);
706
707 if (!ctx || !annot) return;
708
709 fz_try(ctx)
710 pdf_annot_event_blur(ctx, annot);
711 fz_catch(ctx)
712 jni_rethrow_void(env, ctx);
713 }
714
715 JNIEXPORT jboolean JNICALL
FUN(PDFAnnotation_update)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
722 if (!ctx || !annot) return JNI_FALSE;
723
724 fz_try(ctx)
725 changed = pdf_update_annot(ctx, annot);
726 fz_catch(ctx)
727 jni_rethrow(env, ctx);
728
729 return changed;
730 }
731
732 JNIEXPORT jboolean JNICALL
FUN(PDFAnnotation_isOpen)733 FUN(PDFAnnotation_isOpen)(JNIEnv *env, jobject self)
734 {
735 fz_context *ctx = get_context(env);
736 pdf_annot *annot = from_PDFAnnotation(env, self);
737 jboolean open = JNI_FALSE;
738
739 if (!ctx || !annot) return JNI_FALSE;
740
741 fz_try(ctx)
742 open = pdf_annot_is_open(ctx, annot);
743 fz_catch(ctx)
744 jni_rethrow(env, ctx);
745
746 return open;
747 }
748
749 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setIsOpen)750 FUN(PDFAnnotation_setIsOpen)(JNIEnv *env, jobject self, jboolean open)
751 {
752 fz_context *ctx = get_context(env);
753 pdf_annot *annot = from_PDFAnnotation(env, self);
754
755 if (!ctx || !annot) return;
756
757 fz_try(ctx)
758 pdf_set_annot_is_open(ctx, annot, open);
759 fz_catch(ctx)
760 jni_rethrow_void(env, ctx);
761 }
762
763 JNIEXPORT jstring JNICALL
FUN(PDFAnnotation_getIcon)764 FUN(PDFAnnotation_getIcon)(JNIEnv *env, jobject self)
765 {
766 fz_context *ctx = get_context(env);
767 pdf_annot *annot = from_PDFAnnotation(env, self);
768 const char *name = NULL;
769
770 if (!ctx || !annot) return NULL;
771
772 fz_try(ctx)
773 name = pdf_annot_icon_name(ctx, annot);
774 fz_catch(ctx)
775 jni_rethrow(env, ctx);
776
777 return (*env)->NewStringUTF(env, name);
778 }
779
780 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setIcon)781 FUN(PDFAnnotation_setIcon)(JNIEnv *env, jobject self, jstring jname)
782 {
783 fz_context *ctx = get_context(env);
784 pdf_annot *annot = from_PDFAnnotation(env, self);
785 const char *name = NULL;
786
787 if (!ctx || !annot) return;
788 if (!jname) jni_throw_arg_void(env, "icon name must not be null");
789
790 name = (*env)->GetStringUTFChars(env, jname, NULL);
791 if (!name) return;
792
793 fz_try(ctx)
794 pdf_set_annot_icon_name(ctx, annot, name);
795 fz_always(ctx)
796 if (name)
797 (*env)->ReleaseStringUTFChars(env, jname, name);
798 fz_catch(ctx)
799 jni_rethrow_void(env, ctx);
800 }
801
802 JNIEXPORT jintArray JNICALL
FUN(PDFAnnotation_getLineEndingStyles)803 FUN(PDFAnnotation_getLineEndingStyles)(JNIEnv *env, jobject self)
804 {
805 fz_context *ctx = get_context(env);
806 pdf_annot *annot = from_PDFAnnotation(env, self);
807 enum pdf_line_ending s = 0, e = 0;
808 int line_endings[2];
809 jintArray jline_endings = NULL;
810
811 if (!ctx || !annot) return NULL;
812
813 fz_try(ctx)
814 pdf_annot_line_ending_styles(ctx, annot, &s, &e);
815 fz_catch(ctx)
816 jni_rethrow(env, ctx);
817
818 line_endings[0] = s;
819 line_endings[1] = e;
820
821 jline_endings = (*env)->NewIntArray(env, 2);
822 if (!jline_endings || (*env)->ExceptionCheck(env)) return NULL;
823
824 (*env)->SetIntArrayRegion(env, jline_endings, 0, 2, &line_endings[0]);
825 if ((*env)->ExceptionCheck(env)) return NULL;
826
827 return jline_endings;
828 }
829
830 JNIEXPORT void JNICALL
FUN(PDFAnnotation_setLineEndingStyles)831 FUN(PDFAnnotation_setLineEndingStyles)(JNIEnv *env, jobject self, jint start_style, jint end_style)
832 {
833 fz_context *ctx = get_context(env);
834 pdf_annot *annot = from_PDFAnnotation(env, self);
835
836 if (!ctx || !annot) return;
837
838 fz_try(ctx)
839 pdf_set_annot_line_ending_styles(ctx, annot, start_style, end_style);
840 fz_catch(ctx)
841 jni_rethrow_void(env, ctx);
842 }
843