Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/platform/java/jni/displaylist.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 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 | |
| 23 /* DisplayList interface */ | |
| 24 | |
| 25 JNIEXPORT jlong JNICALL | |
| 26 FUN(DisplayList_newNative)(JNIEnv *env, jobject self, jobject jmediabox) | |
| 27 { | |
| 28 fz_context *ctx = get_context(env); | |
| 29 fz_rect mediabox = from_Rect(env, jmediabox); | |
| 30 | |
| 31 fz_display_list *list = NULL; | |
| 32 | |
| 33 if (!ctx) return 0; | |
| 34 | |
| 35 fz_try(ctx) | |
| 36 list = fz_new_display_list(ctx, mediabox); | |
| 37 fz_catch(ctx) | |
| 38 jni_rethrow(env, ctx); | |
| 39 | |
| 40 return jlong_cast(list); | |
| 41 } | |
| 42 | |
| 43 JNIEXPORT void JNICALL | |
| 44 FUN(DisplayList_run)(JNIEnv *env, jobject self, jobject jdev, jobject jctm, jobject jrect, jobject jcookie) | |
| 45 { | |
| 46 fz_context *ctx = get_context(env); | |
| 47 fz_display_list *list = from_DisplayList(env, self); | |
| 48 fz_device *dev = from_Device(env, jdev); | |
| 49 fz_matrix ctm = from_Matrix(env, jctm); | |
| 50 fz_cookie *cookie = from_Cookie(env, jcookie); | |
| 51 NativeDeviceInfo *info; | |
| 52 fz_rect rect; | |
| 53 int err; | |
| 54 | |
| 55 if (!ctx || !list) return; | |
| 56 if (!dev) jni_throw_arg_void(env, "device must not be null"); | |
| 57 | |
| 58 /* Use a scissor rectangle if one is supplied */ | |
| 59 if (jrect) | |
| 60 rect = from_Rect(env, jrect); | |
| 61 else | |
| 62 rect = fz_infinite_rect; | |
| 63 | |
| 64 info = lockNativeDevice(env, jdev, &err); | |
| 65 if (err) | |
| 66 return; | |
| 67 fz_try(ctx) | |
| 68 fz_run_display_list(ctx, list, dev, ctm, rect, cookie); | |
| 69 fz_always(ctx) | |
| 70 unlockNativeDevice(env, info); | |
| 71 fz_catch(ctx) | |
| 72 jni_rethrow_void(env, ctx); | |
| 73 } | |
| 74 | |
| 75 JNIEXPORT void JNICALL | |
| 76 FUN(DisplayList_finalize)(JNIEnv *env, jobject self) | |
| 77 { | |
| 78 fz_context *ctx = get_context(env); | |
| 79 fz_display_list *list = from_DisplayList_safe(env, self); | |
| 80 if (!ctx || !list) return; | |
| 81 (*env)->SetLongField(env, self, fid_DisplayList_pointer, 0); | |
| 82 fz_drop_display_list(ctx, list); | |
| 83 } | |
| 84 | |
| 85 JNIEXPORT jobject JNICALL | |
| 86 FUN(DisplayList_toPixmap)(JNIEnv *env, jobject self, jobject jctm, jobject jcs, jboolean alpha) | |
| 87 { | |
| 88 fz_context *ctx = get_context(env); | |
| 89 fz_display_list *list = from_DisplayList(env, self); | |
| 90 fz_matrix ctm = from_Matrix(env, jctm); | |
| 91 fz_colorspace *cs = from_ColorSpace(env, jcs); | |
| 92 fz_pixmap *pixmap = NULL; | |
| 93 | |
| 94 if (!ctx || !list) return NULL; | |
| 95 | |
| 96 fz_try(ctx) | |
| 97 pixmap = fz_new_pixmap_from_display_list(ctx, list, ctm, cs, alpha); | |
| 98 fz_catch(ctx) | |
| 99 jni_rethrow(env, ctx); | |
| 100 | |
| 101 return to_Pixmap_safe_own(ctx, env, pixmap); | |
| 102 } | |
| 103 | |
| 104 JNIEXPORT jobject JNICALL | |
| 105 FUN(DisplayList_toStructuredText)(JNIEnv *env, jobject self, jstring joptions) | |
| 106 { | |
| 107 fz_context *ctx = get_context(env); | |
| 108 fz_display_list *list = from_DisplayList(env, self); | |
| 109 fz_stext_page *text = NULL; | |
| 110 const char *options= NULL; | |
| 111 fz_stext_options opts; | |
| 112 | |
| 113 if (!ctx || !list) return NULL; | |
| 114 | |
| 115 if (joptions) | |
| 116 { | |
| 117 options = (*env)->GetStringUTFChars(env, joptions, NULL); | |
| 118 if (!options) return NULL; | |
| 119 } | |
| 120 | |
| 121 fz_try(ctx) | |
| 122 { | |
| 123 fz_parse_stext_options(ctx, &opts, options); | |
| 124 text = fz_new_stext_page_from_display_list(ctx, list, &opts); | |
| 125 } | |
| 126 fz_always(ctx) | |
| 127 { | |
| 128 if (options) | |
| 129 (*env)->ReleaseStringUTFChars(env, joptions, options); | |
| 130 } | |
| 131 fz_catch(ctx) | |
| 132 jni_rethrow(env, ctx); | |
| 133 | |
| 134 return to_StructuredText_safe_own(ctx, env, text); | |
| 135 } | |
| 136 | |
| 137 JNIEXPORT jobjectArray JNICALL | |
| 138 FUN(DisplayList_search)(JNIEnv *env, jobject self, jstring jneedle) | |
| 139 { | |
| 140 fz_context *ctx = get_context(env); | |
| 141 fz_display_list *list = from_DisplayList(env, self); | |
| 142 const char *needle = NULL; | |
| 143 search_state state = { env, NULL, 0 }; | |
| 144 jobject jsample = NULL; | |
| 145 | |
| 146 if (!ctx || !list) return NULL; | |
| 147 if (!jneedle) jni_throw_arg(env, "needle must not be null"); | |
| 148 | |
| 149 needle = (*env)->GetStringUTFChars(env, jneedle, NULL); | |
| 150 if (!needle) return NULL; | |
| 151 | |
| 152 state.hits = (*env)->NewObject(env, cls_ArrayList, mid_ArrayList_init); | |
| 153 if (!state.hits || (*env)->ExceptionCheck(env)) return NULL; | |
| 154 | |
| 155 fz_try(ctx) | |
| 156 fz_search_display_list_cb(ctx, list, needle, hit_callback, &state); | |
| 157 fz_always(ctx) | |
| 158 { | |
| 159 (*env)->ReleaseStringUTFChars(env, jneedle, needle); | |
| 160 } | |
| 161 fz_catch(ctx) | |
| 162 jni_rethrow(env, ctx); | |
| 163 | |
| 164 if (state.error) | |
| 165 return NULL; | |
| 166 | |
| 167 jsample = (*env)->NewObjectArray(env, 0, cls_ArrayOfQuad, NULL); | |
| 168 return (*env)->CallObjectMethod(env, state.hits, mid_ArrayList_toArray, jsample); | |
| 169 } | |
| 170 | |
| 171 JNIEXPORT jobject JNICALL | |
| 172 FUN(DisplayList_getBounds)(JNIEnv *env, jobject self) | |
| 173 { | |
| 174 fz_context *ctx = get_context(env); | |
| 175 fz_display_list *list = from_DisplayList(env, self); | |
| 176 fz_rect bounds; | |
| 177 | |
| 178 if (!ctx || !list) return NULL; | |
| 179 | |
| 180 fz_try(ctx) | |
| 181 bounds = fz_bound_display_list(ctx, list); | |
| 182 fz_catch(ctx) | |
| 183 jni_rethrow(env, ctx); | |
| 184 | |
| 185 return to_Rect(ctx, env, bounds); | |
| 186 } | |
| 187 | |
| 188 JNIEXPORT jobject JNICALL | |
| 189 FUN(DisplayList_decodeBarcode)(JNIEnv *env, jobject self, jobject jsubarea, jfloat rotate) | |
| 190 { | |
| 191 fz_context *ctx = get_context(env); | |
| 192 fz_display_list *list = from_DisplayList(env, self); | |
| 193 fz_rect subarea = from_Rect(env, jsubarea); | |
| 194 fz_barcode_type type = FZ_BARCODE_NONE; | |
| 195 char *contents = NULL; | |
| 196 jobject jcontents; | |
| 197 jobject jbarcodeinfo; | |
| 198 | |
| 199 if (!ctx || !list) | |
| 200 return NULL; | |
| 201 | |
| 202 fz_try(ctx) | |
| 203 contents = fz_decode_barcode_from_display_list(ctx, &type, list, subarea, rotate); | |
| 204 fz_catch(ctx) | |
| 205 jni_rethrow(env, ctx); | |
| 206 | |
| 207 jcontents = (*env)->NewStringUTF(env, contents); | |
| 208 fz_free(ctx, contents); | |
| 209 if (!jcontents || (*env)->ExceptionCheck(env)) | |
| 210 return NULL; | |
| 211 | |
| 212 jbarcodeinfo = (*env)->NewObject(env, cls_BarcodeInfo, mid_BarcodeInfo_init, type, jcontents); | |
| 213 if (!jbarcodeinfo || (*env)->ExceptionCheck(env)) | |
| 214 return NULL; | |
| 215 | |
| 216 return jbarcodeinfo; | |
| 217 } |
