summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorevrhel <ethanvrhel@gmail.com>2020-09-13 14:42:08 -0700
committerRobin Watts <Robin.Watts@artifex.com>2020-09-24 14:33:51 +0100
commitc5d8133f4401e8fc1e19090e97b43bbc08a816bb (patch)
treef2969ed0bc952e40531145c373f3038fc4f35627
parent4258cf2ceb7e0c367831c6f8d0bd91262b944e54 (diff)
downloadghostpdl-evrhel-test.tar.gz
Added several devices, updated documentation, and README.txt.evrhel-test
-rw-r--r--demos/java/gsjava/README.txt77
1 files changed, 77 insertions, 0 deletions
diff --git a/demos/java/gsjava/README.txt b/demos/java/gsjava/README.txt
index 5eb068cb9..07c556750 100644
--- a/demos/java/gsjava/README.txt
+++ b/demos/java/gsjava/README.txt
@@ -70,3 +70,80 @@ public static void main(String[] args) {
// Deletes the Ghoscript instance
GSAPI.gsapi_delete_instance(instance);
}
+
+C++ Library:
+
+This library builds to gs_jni.dll and uses the
+Java Native Interface (JNI) to bind the functions in
+the GSAPI class to Ghoscript as well as handling callbacks,
+exceptions, and references.
+
+The bindings in GSAPI are in the header com_artifex_gsjava_GSJAVA.h
+and the implementations are in com_artifex_gsjava_GSJAVA.cpp.
+
+Utility methods for throwing exceptions, setting fields, calling
+Java methods, and using the Reference<T> class are declared
+in jni_util.h.
+
+Example method explaining the implementation for
+gsapi_run_string_begin:
+
+
+/* JNIEnv *env - Provided the JNI. Allows interfacing into calling Java methods,
+ * setting Java fields, etc. Different threads have different JNIEnv objects.
+ *
+ * jclass - Provided by the JNI. It represents the class calling this method.
+ *
+ * jlong instance - Instance to be passed to gsapi_run_string_begin
+ *
+ * jint userErrors - User errors to be passed to gsapi_run_string_begin
+ *
+ * jobject pExitCode - A Reference<Integer> object. This is always the case as the Java
+ * code will not allow anything else to be passed. The value which Ghostscript returns
+ * in the pExitCode parameter will be placed into here.
+ */
+JNIEXPORT jint JNICALL Java_com_artifex_gsjava_GSAPI_gsapi_1run_1string_1begin
+ (JNIEnv *env, jclass, jlong instance, jint userErrors, jobject pExitCode)
+{
+ // Declares the exitCode parameter which will be passed as a pointer
+ // to gsapi_run_string_begin
+ int exitCode;
+
+ // Different threads have different JNIEnv objects, so each time a JNI method
+ // is called, this must be set so the Java callback methods can be called.
+ callbacks::setJNIEnv(env);
+
+ // Calls the Ghoscript call gsapi_run_string_begin
+ int code = gsapi_run_string_begin((void *)instance, userErrors, &exitCode);
+
+ // If the reference is not NULL, set the value of the reference to the exitCode returned
+ // from Ghoscript. It must be converted to the wrapper type java.lang.Integer as Java does not support
+ // primitive generic arguments (i.e. int, float, char, etc.)
+ if (pExitCode)
+ Reference::setValueField(env, pExitCode, toWrapperType(env, (jint)exitCode));
+
+ // Return the error code returned by Ghostscript
+ return code;
+}
+
+Viewer:
+
+There is an eclipse project containing a viewer using the
+Java Ghostscript bindings in gsjava. The eclipse project is
+set up such that the gsjava eclipse project must be built
+to a jar file and used in the gsviewer eclipse project.
+
+The viewer is designed to load PDF documents, but can also
+load other files like PostScript files and distill them into
+a PDF document to be opened.
+
+When the document is first loaded, every page is rendered at
+a low resolution. These will be displayed as thumbnails on the
+left side. All loadingg is done in the com.artifex.gsjava.Document
+class. As the user changes the position of the viewport, the
+viewer will dynamically load high resolution images based on
+what page the user is viewing. This is done in the
+com.artifex.gsviewer.ViewerController.SmartLoader class. This
+also handles rendering zoomed images if necessary. Only pages
+which need to be loaded at a high resolution are loaded, and
+zoomed pages are unloaded when no longer necessary to save memory. \ No newline at end of file