summaryrefslogtreecommitdiff
path: root/platform/java/src/com/artifex
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-09-22 18:33:17 +0100
committerRobin Watts <robin.watts@artifex.com>2016-09-23 15:41:18 +0100
commiteef63823f5ced78205b7d0b04599759d5b4eff8e (patch)
tree9a0aa1bd8543720888ff93e594417ba42eb6c772 /platform/java/src/com/artifex
parent32131a60794d1bed3b7555b79aaf2caf69a88769 (diff)
downloadmupdf-eef63823f5ced78205b7d0b04599759d5b4eff8e.tar.xz
JNI: Rework conversion functions and nulls.
Java has a convention that 'toString' should return a printable version of an object. We cannot both support this, and support a sane naming of functions to interpret pdf objects that begins with 'to'. Instead use 'as'. This means we have 'asBoolean', 'asInteger', 'asString' which expect to work just on pdf objects of the required type. 'toString' continues to work on all types and gives a printable version. We split 'toByteString' into 2 separate functions, one for acting on strings (asByteString) and one for acting on names (asByteName) more nicely mirroring the C level functions (pdf_to_string and pdf_to_name). For simplicity of use, we add asString and asName functions that return using java Strings rather than byte arrays. There are potential encoding issues with these, but then there are throughout our string handling at the moment, so we will deal with those in a followup commit. We also update the internal workings of several functions so that they never return NULL pointers, but rather return the null object. To avoid repeatedly creating new null objects we introduce a global static PDFObject.Null object. This is important as we want get("SomethingNonexistent") to return a valid java object, so we can safely do things like: get("Foo").get("Bar").get("Baz").asInteger() without having to error check at every stage. Update DocViewActivity to call the new versions.
Diffstat (limited to 'platform/java/src/com/artifex')
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java2
-rw-r--r--platform/java/src/com/artifex/mupdf/fitz/PDFObject.java18
2 files changed, 14 insertions, 6 deletions
diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java
index 93fd5ebe..601919d7 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java
@@ -42,7 +42,7 @@ public class PDFDocument
public native void deleteObject(int i);
public void deleteObject(PDFObject obj) {
- deleteObject(obj.toIndirect());
+ deleteObject(obj.asIndirect());
}
public native PDFGraftMap newPDFGraftMap();
diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java b/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java
index 10a0e7a8..0f9741b5 100644
--- a/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java
+++ b/platform/java/src/com/artifex/mupdf/fitz/PDFObject.java
@@ -19,6 +19,8 @@ public class PDFObject
pointer = p;
}
+ private static native long newNull();
+
public native boolean isIndirect();
public native boolean isNull();
public native boolean isBoolean();
@@ -31,11 +33,15 @@ public class PDFObject
public native boolean isDictionary();
public native boolean isStream();
- public native boolean toBoolean();
- public native int toInteger();
- public native float toFloat();
- public native byte[] toByteString();
- public native int toIndirect();
+ public native boolean asBoolean();
+ public native int asInteger();
+ public native float asFloat();
+ public native int asIndirect();
+ public native String asName();
+ public native byte[] asByteName();
+ public native String asString();
+ public native byte[] asByteString();
+
public native String toString(boolean tight);
public String toString() {
@@ -201,4 +207,6 @@ public class PDFObject
public void push(PDFObject obj) {
pushPDFObject(obj);
}
+
+ public static final PDFObject Null = new PDFObject(newNull());
}