Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/platform/java/jni/story.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-2024 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 /* Story interface */ | |
| 24 | |
| 25 JNIEXPORT void JNICALL | |
| 26 FUN(Story_finalize)(JNIEnv *env, jobject self) | |
| 27 { | |
| 28 fz_context *ctx = get_context(env); | |
| 29 fz_story *story = from_Story_safe(env, self); | |
| 30 if (!ctx || !story) return; | |
| 31 (*env)->SetLongField(env, self, fid_Story_pointer, 0); | |
| 32 fz_drop_story(ctx, story); | |
| 33 } | |
| 34 | |
| 35 JNIEXPORT jlong JNICALL | |
| 36 FUN(Story_newStory)(JNIEnv *env, jclass cls, jbyteArray content, jbyteArray css, float em, jobject jarch) | |
| 37 { | |
| 38 fz_context *ctx = get_context(env); | |
| 39 int content_len, css_len; | |
| 40 jbyte *content_bytes = NULL; | |
| 41 jbyte *css_bytes = NULL; | |
| 42 fz_story *story = NULL; | |
| 43 fz_buffer *content_buf = NULL; | |
| 44 fz_buffer *css_buf = NULL; | |
| 45 fz_archive *arch = from_Archive(env, jarch); | |
| 46 | |
| 47 if (!ctx) return 0; | |
| 48 | |
| 49 if (content) | |
| 50 { | |
| 51 content_len = (*env)->GetArrayLength(env, content); | |
| 52 content_bytes = (*env)->GetByteArrayElements(env, content, NULL); | |
| 53 } | |
| 54 else | |
| 55 { | |
| 56 content_len = 0; | |
| 57 content_bytes = NULL; | |
| 58 } | |
| 59 if (css) | |
| 60 { | |
| 61 css_len = (*env)->GetArrayLength(env, css); | |
| 62 css_bytes = (*env)->GetByteArrayElements(env, css, NULL); | |
| 63 } | |
| 64 else | |
| 65 { | |
| 66 css_len = 0; | |
| 67 css_bytes = NULL; | |
| 68 } | |
| 69 | |
| 70 fz_var(content_buf); | |
| 71 fz_var(css_buf); | |
| 72 fz_var(story); | |
| 73 | |
| 74 fz_try(ctx) | |
| 75 { | |
| 76 content_buf = fz_new_buffer_from_copied_data(ctx, (const unsigned char *)content_bytes, content_len); | |
| 77 css_buf = fz_new_buffer_from_copied_data(ctx, (const unsigned char *)css_bytes, css_len); | |
| 78 fz_terminate_buffer(ctx, css_buf); | |
| 79 | |
| 80 story = fz_new_story(ctx, content_buf, (const char *)css_buf->data, em, arch); | |
| 81 } | |
| 82 fz_always(ctx) | |
| 83 { | |
| 84 fz_drop_buffer(ctx, content_buf); | |
| 85 } | |
| 86 fz_catch(ctx) | |
| 87 { | |
| 88 jni_rethrow(env, ctx); | |
| 89 } | |
| 90 | |
| 91 return jlong_cast(story); | |
| 92 } | |
| 93 | |
| 94 JNIEXPORT jint JNICALL | |
| 95 FUN(Story_place)(JNIEnv *env, jobject self, jobject jrect, jobject jfilled, jint flags) | |
| 96 { | |
| 97 fz_context *ctx = get_context(env); | |
| 98 fz_story *story = from_Story_safe(env, self); | |
| 99 fz_rect rect = from_Rect(env, jrect); | |
| 100 fz_rect filled = fz_empty_rect; | |
| 101 int more; | |
| 102 | |
| 103 fz_try(ctx) | |
| 104 { | |
| 105 more = fz_place_story_flags(ctx, story, rect, &filled, flags); | |
| 106 | |
| 107 (*env)->SetFloatField(env, jfilled, fid_Rect_x0, filled.x0); | |
| 108 (*env)->SetFloatField(env, jfilled, fid_Rect_x1, filled.x1); | |
| 109 (*env)->SetFloatField(env, jfilled, fid_Rect_y0, filled.y0); | |
| 110 (*env)->SetFloatField(env, jfilled, fid_Rect_y1, filled.y1); | |
| 111 } | |
| 112 fz_catch(ctx) | |
| 113 jni_rethrow(env, ctx); | |
| 114 | |
| 115 return more; | |
| 116 } | |
| 117 | |
| 118 JNIEXPORT void JNICALL | |
| 119 FUN(Story_draw)(JNIEnv *env, jobject self, jobject jdev, jobject jctm) | |
| 120 { | |
| 121 fz_context *ctx = get_context(env); | |
| 122 fz_story *story = from_Story_safe(env, self); | |
| 123 fz_device *dev = from_Device(env, jdev); | |
| 124 fz_matrix ctm = from_Matrix(env, jctm); | |
| 125 NativeDeviceInfo *info; | |
| 126 int err; | |
| 127 | |
| 128 if (!ctx || !story) return; | |
| 129 if (!dev) jni_throw_arg_void(env, "device must not be null"); | |
| 130 | |
| 131 info = lockNativeDevice(env, jdev, &err); | |
| 132 if (err) | |
| 133 return; | |
| 134 fz_try(ctx) | |
| 135 fz_draw_story(ctx, story, dev, ctm); | |
| 136 fz_always(ctx) | |
| 137 unlockNativeDevice(env, info); | |
| 138 fz_catch(ctx) | |
| 139 jni_rethrow_void(env, ctx); | |
| 140 } | |
| 141 | |
| 142 JNIEXPORT jobject JNICALL | |
| 143 FUN(Story_document)(JNIEnv *env, jobject self) | |
| 144 { | |
| 145 fz_context *ctx = get_context(env); | |
| 146 fz_story *story = from_Story_safe(env, self); | |
| 147 | |
| 148 return to_DOM_safe(ctx, env, fz_story_document(ctx, story)); | |
| 149 } |
