comparison mupdf-source/platform/java/jni/link.c @ 3:2c135c81b16c

MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:44:09 +0200
parents b50eed0cc0ef
children
comparison
equal deleted inserted replaced
0:6015a75abc2d 3:2c135c81b16c
1 // Copyright (C) 2004-2022 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
23 /* Link interface */
24
25 JNIEXPORT void JNICALL
26 FUN(Link_finalize)(JNIEnv *env, jobject self)
27 {
28 fz_context *ctx = get_context(env);
29 fz_link *link = from_Link_safe(env, self);
30 if (!ctx || !link) return;
31 (*env)->SetLongField(env, self, fid_Link_pointer, 0);
32 fz_drop_link(ctx, link);
33 }
34
35 JNIEXPORT jobject JNICALL
36 FUN(Link_getBounds)(JNIEnv *env, jobject self)
37 {
38 fz_context *ctx = get_context(env);
39 fz_link *link = from_Link(env, self);
40
41 if (!ctx || !link) return NULL;
42
43 return to_Rect_safe(ctx, env, link->rect);
44 }
45
46 JNIEXPORT void JNICALL
47 FUN(Link_setBounds)(JNIEnv *env, jobject self, jobject jbbox)
48 {
49 fz_context *ctx = get_context(env);
50 fz_link *link = from_Link(env, self);
51 fz_rect bbox = from_Rect(env, jbbox);
52
53 if (!ctx || !link) return;
54
55 fz_try(ctx)
56 fz_set_link_rect(ctx, link, bbox);
57 fz_catch(ctx)
58 jni_rethrow_void(env, ctx);
59 }
60
61 JNIEXPORT jstring JNICALL
62 FUN(Link_getURI)(JNIEnv *env, jobject self)
63 {
64 fz_context *ctx = get_context(env);
65 fz_link *link = from_Link(env, self);
66
67 if (!ctx || !link) return NULL;
68
69 return (*env)->NewStringUTF(env, link->uri);
70 }
71
72 JNIEXPORT void JNICALL
73 FUN(Link_setURI)(JNIEnv *env, jobject self, jstring juri)
74 {
75 fz_context *ctx = get_context(env);
76 fz_link *link = from_Link(env, self);
77 const char *uri = NULL;
78
79 if (!ctx || !link) return;
80
81 if (juri)
82 uri = (*env)->GetStringUTFChars(env, juri, NULL);
83
84 fz_try(ctx)
85 fz_set_link_uri(ctx, link, uri);
86 fz_always(ctx)
87 if (juri)
88 (*env)->ReleaseStringUTFChars(env, juri, uri);
89 fz_catch(ctx)
90 jni_rethrow_void(env, ctx);
91 }