summaryrefslogtreecommitdiff
path: root/platform/android
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/android
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/android')
-rw-r--r--platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java67
1 files changed, 14 insertions, 53 deletions
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java
index cbad6fa5..03739349 100644
--- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java
+++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java
@@ -770,72 +770,33 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
private String getEmbeddedProfileName()
{
- PDFDocument doc = mDoc.toPDFDocument();
- if (doc == null)
- return null;
- PDFObject obj = doc.getTrailer();
- if (obj == null)
- return null;
- obj = obj.get("Root");
- if (obj == null)
- return null;
- PDFObject outputIntents = obj.get("OutputIntents");
+ PDFObject outputIntents = mDoc.toPDFDocument().getTrailer().get("Root").get("OutputIntents");
if (outputIntents == null)
return null;
int length = outputIntents.size();
int i;
- for (i = 0 ; i < length; i++)
- {
+ for (i = 0 ; i < length; i++) {
PDFObject intent = outputIntents.get(i);
- if (intent == null || !intent.isDictionary())
- continue;
-
- /* FIXME: Getting a name as a ByteString is horrible */
- obj = intent.get("S");
- if (obj == null)
- continue;
- byte name[] = obj.toByteString();
- if (name == null || name.length != 9)
- continue;
- if (name[0] != 'G' || name[1] != 'T' || name[2] != 'S' || name[3] != '_' ||
- name[4] != 'P' || name[5] != 'D' || name[6] != 'F' || name[7] != 'X' || name[8] != 0)
+ String name = intent.get("S").asName();
+ if (!name.equals("GTS_PDFX"))
continue;
/* We can't use the embedded profile if it's not CMYK based. */
- obj = intent.get("DestOutputProfile");
- if (obj == null)
- continue;
- obj = obj.get("N");
- if (obj == null)
- continue;
- if (obj.toInteger() != 4)
+ if (intent.get("DestOutputProfile").get("N").asInteger() != 4)
continue;
- String id;
- obj = intent.get("Info");
- if (obj != null)
- {
- id = obj.toString();
- if (id != null)
- return id;
- }
- obj = intent.get("OutputConditionIdentifier");
- if (obj != null)
- {
- id = obj.toString();
- if (id != null)
- return id;
- }
- obj = intent.get("OutputCondition");
- if (obj != null)
- {
- id = obj.toString();
- if (id != null)
- return id;
- }
+ PDFObject id = intent.get("Info");
+ if (id.isString())
+ return id.asString();
+ id = intent.get("OutputConditionIdentifier");
+ if (id.isString())
+ return id.asString();
+ id = intent.get("OutputCondition");
+ if (id.isString())
+ return id.asString();
}
return null;
}