From 1fa9a65166acb4077d2b0974ad579dc11d1a92cc Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 10 Feb 2017 14:05:45 +0100 Subject: java: Make PDFDocument a subclass of Document. Requires use of Document.openDocument(path) to open a document. No more new Document(path) since we may need to return a PDFDocument. Create a new blank PDF with new PDFDocument() constructor. --- .../java/src/com/artifex/mupdf/fitz/Document.java | 38 ++++++++++------------ .../src/com/artifex/mupdf/fitz/PDFDocument.java | 25 +++++--------- 2 files changed, 26 insertions(+), 37 deletions(-) (limited to 'platform/java/src/com') diff --git a/platform/java/src/com/artifex/mupdf/fitz/Document.java b/platform/java/src/com/artifex/mupdf/fitz/Document.java index 1fc21c13..52010a02 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/Document.java +++ b/platform/java/src/com/artifex/mupdf/fitz/Document.java @@ -11,7 +11,8 @@ public class Document public static final String META_INFO_AUTHOR = "info:Author"; public static final String META_INFO_TITLE = "info:Title"; - private long pointer; + protected long pointer; + protected String path; /* for proofing */ protected native void finalize(); @@ -20,23 +21,21 @@ public class Document pointer = 0; } - private native long newNativeWithPath(String filename); - private native long newNativeWithBuffer(byte buffer[], String magic); - // private native long newNativeWithRandomAccessFile(RandomAccessFile file, String magic); - - private String mPath=null; - public String getPath() {return mPath;} - public Document(String filename) { - mPath = filename; - pointer = newNativeWithPath(filename); + protected Document(long p) { + pointer = p; } - public Document(byte buffer[], String magic) { - pointer = newNativeWithBuffer(buffer, magic); + protected native static Document openNativeWithPath(String filename); + protected native static Document openNativeWithBuffer(byte buffer[], String magic); + + public static Document openDocument(String filename) { + Document doc = openNativeWithPath(filename); + doc.path = filename; + return doc; } - private Document(long p) { - pointer = p; + public static Document openDocument(byte buffer[], String magic) { + return openNativeWithBuffer(buffer, magic); } public native boolean needsPassword(); @@ -54,17 +53,14 @@ public class Document public native boolean isUnencryptedPDF(); - public native PDFDocument toPDFDocument(); - public boolean isPDF() { - return toPDFDocument() != null; + return false; } - public String makeProof (String currentPath, String printProfile, String displayProfile, int resolution) - { + public String getPath() { return path; } + protected native String proofNative (String currentPath, String printProfile, String displayProfile, int resolution); + public String makeProof (String currentPath, String printProfile, String displayProfile, int resolution) { String proofFile = proofNative( currentPath, printProfile, displayProfile, resolution); return proofFile; } - - public native String proofNative (String currentPath, String printProfile, String displayProfile, int resolution); } diff --git a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java index f866cb86..a925ac90 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java +++ b/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java @@ -1,27 +1,21 @@ package com.artifex.mupdf.fitz; -public class PDFDocument +public class PDFDocument extends Document { - static { - Context.init(); - } - - private long pointer; - - protected native void finalize(); + private static native long newNative(); - public void destroy() { - finalize(); - pointer = 0; + protected PDFDocument(long p) { + super(p); } - private PDFDocument(long p) { - pointer = p; + public PDFDocument() { + super(newNative()); } - public native Document toDocument(); + public boolean isPDF() { + return true; + } - public native int countPages(); public native PDFObject findPage(int at); public native PDFObject getTrailer(); @@ -102,5 +96,4 @@ public class PDFDocument public native boolean hasUnsavedChanges(); public native boolean canBeSavedIncrementally(); public native int save(String filename, String options); - } -- cgit v1.2.3