Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/platform/java/jni/strokestate.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 /* StrokeState interface */ | |
| 24 | |
| 25 JNIEXPORT void JNICALL | |
| 26 FUN(StrokeState_finalize)(JNIEnv *env, jobject self) | |
| 27 { | |
| 28 fz_context *ctx = get_context(env); | |
| 29 fz_stroke_state *stroke = from_StrokeState_safe(env, self); | |
| 30 if (!ctx || !stroke) return; | |
| 31 (*env)->SetLongField(env, self, fid_StrokeState_pointer, 0); | |
| 32 fz_drop_stroke_state(ctx, stroke); | |
| 33 } | |
| 34 | |
| 35 JNIEXPORT jlong JNICALL | |
| 36 FUN(StrokeState_newNativeStrokeState)(JNIEnv *env, jobject self, jint lineCap, jint lineJoin, jfloat lineWidth, jfloat miterLimit, jfloat dashPhase, jfloatArray dash) | |
| 37 { | |
| 38 fz_context *ctx = get_context(env); | |
| 39 fz_stroke_state *stroke = NULL; | |
| 40 jsize len = 0; | |
| 41 | |
| 42 if (!ctx) return 0; | |
| 43 | |
| 44 if (dash) | |
| 45 len = (*env)->GetArrayLength(env, dash); | |
| 46 | |
| 47 fz_try(ctx) | |
| 48 { | |
| 49 stroke = fz_new_stroke_state_with_dash_len(ctx, len); | |
| 50 stroke->start_cap = lineCap; | |
| 51 stroke->dash_cap = lineCap; | |
| 52 stroke->end_cap = lineCap; | |
| 53 stroke->linejoin = lineJoin; | |
| 54 stroke->linewidth = lineWidth; | |
| 55 stroke->miterlimit = miterLimit; | |
| 56 stroke->dash_phase = dashPhase; | |
| 57 stroke->dash_len = len; | |
| 58 } | |
| 59 fz_catch(ctx) | |
| 60 jni_rethrow(env, ctx); | |
| 61 | |
| 62 if (dash) | |
| 63 { | |
| 64 (*env)->GetFloatArrayRegion(env, dash, 0, len, &stroke->dash_list[0]); | |
| 65 if ((*env)->ExceptionCheck(env)) return 0; | |
| 66 } | |
| 67 | |
| 68 return jlong_cast(stroke); | |
| 69 } | |
| 70 | |
| 71 JNIEXPORT jint JNICALL | |
| 72 FUN(StrokeState_getLineCap)(JNIEnv *env, jobject self) | |
| 73 { | |
| 74 fz_stroke_state *stroke = from_StrokeState(env, self); | |
| 75 return stroke ? stroke->start_cap : 0; | |
| 76 } | |
| 77 | |
| 78 JNIEXPORT jint JNICALL | |
| 79 FUN(StrokeState_getLineJoin)(JNIEnv *env, jobject self) | |
| 80 { | |
| 81 fz_stroke_state *stroke = from_StrokeState(env, self); | |
| 82 return stroke ? stroke->linejoin : 0; | |
| 83 } | |
| 84 | |
| 85 JNIEXPORT float JNICALL | |
| 86 FUN(StrokeState_getLineWidth)(JNIEnv *env, jobject self) | |
| 87 { | |
| 88 fz_stroke_state *stroke = from_StrokeState(env, self); | |
| 89 return stroke ? stroke->linewidth : 0; | |
| 90 } | |
| 91 | |
| 92 JNIEXPORT float JNICALL | |
| 93 FUN(StrokeState_getMiterLimit)(JNIEnv *env, jobject self) | |
| 94 { | |
| 95 fz_stroke_state *stroke = from_StrokeState(env, self); | |
| 96 return stroke ? stroke->miterlimit : 0; | |
| 97 } | |
| 98 | |
| 99 JNIEXPORT float JNICALL | |
| 100 FUN(StrokeState_getDashPhase)(JNIEnv *env, jobject self) | |
| 101 { | |
| 102 fz_stroke_state *stroke = from_StrokeState(env, self); | |
| 103 return stroke ? stroke->dash_phase : 0; | |
| 104 } | |
| 105 | |
| 106 JNIEXPORT jfloatArray JNICALL | |
| 107 FUN(StrokeState_getDashPattern)(JNIEnv *env, jobject self) | |
| 108 { | |
| 109 fz_context *ctx = get_context(env); | |
| 110 fz_stroke_state *stroke = from_StrokeState(env, self); | |
| 111 jfloatArray arr; | |
| 112 | |
| 113 if (!ctx || !stroke) return NULL; | |
| 114 | |
| 115 if (stroke->dash_len == 0) | |
| 116 return NULL; /* there are no dashes, so return NULL instead of empty array */ | |
| 117 | |
| 118 arr = (*env)->NewFloatArray(env, stroke->dash_len); | |
| 119 if (!arr || (*env)->ExceptionCheck(env)) return NULL; | |
| 120 | |
| 121 (*env)->SetFloatArrayRegion(env, arr, 0, stroke->dash_len, &stroke->dash_list[0]); | |
| 122 if ((*env)->ExceptionCheck(env)) return NULL; | |
| 123 | |
| 124 return arr; | |
| 125 } |
