link.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /* Link interface */
  23. JNIEXPORT void JNICALL
  24. FUN(Link_finalize)(JNIEnv *env, jobject self)
  25. {
  26. fz_context *ctx = get_context(env);
  27. fz_link *link = from_Link_safe(env, self);
  28. if (!ctx || !link) return;
  29. (*env)->SetLongField(env, self, fid_Link_pointer, 0);
  30. fz_drop_link(ctx, link);
  31. }
  32. JNIEXPORT jobject JNICALL
  33. FUN(Link_getBounds)(JNIEnv *env, jobject self)
  34. {
  35. fz_context *ctx = get_context(env);
  36. fz_link *link = from_Link(env, self);
  37. if (!ctx || !link) return NULL;
  38. return to_Rect_safe(ctx, env, link->rect);
  39. }
  40. JNIEXPORT void JNICALL
  41. FUN(Link_setBounds)(JNIEnv *env, jobject self, jobject jbbox)
  42. {
  43. fz_context *ctx = get_context(env);
  44. fz_link *link = from_Link(env, self);
  45. fz_rect bbox = from_Rect(env, jbbox);
  46. if (!ctx || !link) return;
  47. fz_try(ctx)
  48. fz_set_link_rect(ctx, link, bbox);
  49. fz_catch(ctx)
  50. jni_rethrow_void(env, ctx);
  51. }
  52. JNIEXPORT jstring JNICALL
  53. FUN(Link_getURI)(JNIEnv *env, jobject self)
  54. {
  55. fz_context *ctx = get_context(env);
  56. fz_link *link = from_Link(env, self);
  57. if (!ctx || !link) return NULL;
  58. return (*env)->NewStringUTF(env, link->uri);
  59. }
  60. JNIEXPORT void JNICALL
  61. FUN(Link_setURI)(JNIEnv *env, jobject self, jstring juri)
  62. {
  63. fz_context *ctx = get_context(env);
  64. fz_link *link = from_Link(env, self);
  65. const char *uri = NULL;
  66. if (!ctx || !link) return;
  67. if (juri)
  68. uri = (*env)->GetStringUTFChars(env, juri, NULL);
  69. fz_try(ctx)
  70. fz_set_link_uri(ctx, link, uri);
  71. fz_always(ctx)
  72. if (juri)
  73. (*env)->ReleaseStringUTFChars(env, juri, uri);
  74. fz_catch(ctx)
  75. jni_rethrow_void(env, ctx);
  76. }